mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 13:33:21 -07:00
new: centralized logging and implemented DELETE /api/events route, closes #5
This commit is contained in:
parent
269d7d845b
commit
f1f146d3d7
21 changed files with 144 additions and 184 deletions
|
@ -7,7 +7,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/evilsocket/bettercap-ng/core"
|
||||
"github.com/op/go-logging"
|
||||
)
|
||||
|
||||
type LinuxFirewall struct {
|
||||
|
@ -15,8 +14,6 @@ type LinuxFirewall struct {
|
|||
redirections map[string]*Redirection
|
||||
}
|
||||
|
||||
var log = logging.MustGetLogger("mitm")
|
||||
|
||||
const (
|
||||
IPV4ForwardingFile = "/proc/sys/net/ipv4/ip_forward"
|
||||
IPV4ICMPBcastFile = "/proc/sys/net/ipv4/icmp_echo_ignore_broadcasts"
|
||||
|
@ -31,8 +28,6 @@ func Make() FirewallManager {
|
|||
|
||||
firewall.forwarding = firewall.IsForwardingEnabled()
|
||||
|
||||
log.Debugf("Created Linux Firewall ( forwarding=%v )\n", firewall.forwarding)
|
||||
|
||||
return firewall
|
||||
}
|
||||
|
||||
|
@ -60,7 +55,6 @@ func (f LinuxFirewall) enableFeature(filename string, enable bool) error {
|
|||
func (f LinuxFirewall) IsForwardingEnabled() bool {
|
||||
|
||||
if out, err := ioutil.ReadFile(IPV4ForwardingFile); err != nil {
|
||||
log.Error(err)
|
||||
return false
|
||||
} else {
|
||||
return strings.Trim(string(out), "\r\n\t ") == "1"
|
||||
|
@ -90,8 +84,6 @@ func (f *LinuxFirewall) EnableRedirection(r *Redirection, enabled bool) error {
|
|||
return fmt.Errorf("Redirection '%s' already enabled.", rkey)
|
||||
}
|
||||
|
||||
log.Debugf("Enabling redirection %s\n", rkey)
|
||||
|
||||
f.redirections[rkey] = r
|
||||
|
||||
// accept all
|
||||
|
@ -126,12 +118,9 @@ func (f *LinuxFirewall) EnableRedirection(r *Redirection, enabled bool) error {
|
|||
}
|
||||
} else {
|
||||
if found == false {
|
||||
log.Debugf("Did not remove redirection '%s' as it was already removed.\n", r.String())
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Debugf("Disabling redirection %s\n", r.String())
|
||||
|
||||
delete(f.redirections, r.String())
|
||||
|
||||
if r.SrcAddress == "" {
|
||||
|
@ -165,14 +154,13 @@ func (f *LinuxFirewall) EnableRedirection(r *Redirection, enabled bool) error {
|
|||
}
|
||||
|
||||
func (f LinuxFirewall) Restore() {
|
||||
log.Debugf("Restoring firewall state.\n")
|
||||
for _, r := range f.redirections {
|
||||
if err := f.EnableRedirection(r, false); err != nil {
|
||||
log.Error(err)
|
||||
fmt.Printf("%s", err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := f.EnableForwarding(f.forwarding); err != nil {
|
||||
log.Error(err)
|
||||
fmt.Printf("%s", err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue