mirror of
https://github.com/bettercap/bettercap
synced 2025-07-05 20:42:09 -07:00
new: -silent and -debug are now mapped to log.silent and log.debug that can be set at runtime (fixes #50).
This commit is contained in:
parent
09808be1a4
commit
21236c257e
3 changed files with 58 additions and 1 deletions
|
@ -9,12 +9,16 @@ import (
|
|||
"github.com/evilsocket/bettercap-ng/core"
|
||||
)
|
||||
|
||||
type SetCallback func(newValue string)
|
||||
|
||||
type Environment struct {
|
||||
sync.Mutex
|
||||
|
||||
Padding int `json:"-"`
|
||||
Storage map[string]string `json:"storage"`
|
||||
sess *Session
|
||||
|
||||
cbs map[string]SetCallback
|
||||
sess *Session
|
||||
}
|
||||
|
||||
func NewEnvironment(s *Session) *Environment {
|
||||
|
@ -22,6 +26,7 @@ func NewEnvironment(s *Session) *Environment {
|
|||
Padding: 0,
|
||||
Storage: make(map[string]string),
|
||||
sess: s,
|
||||
cbs: make(map[string]SetCallback),
|
||||
}
|
||||
|
||||
return env
|
||||
|
@ -36,6 +41,18 @@ func (env *Environment) Has(name string) bool {
|
|||
return found
|
||||
}
|
||||
|
||||
func (env *Environment) SetCallback(name string, cb SetCallback) {
|
||||
env.Lock()
|
||||
defer env.Unlock()
|
||||
env.cbs[name] = cb
|
||||
}
|
||||
|
||||
func (env *Environment) WithCallback(name, value string, cb SetCallback) string {
|
||||
ret := env.Set(name, value)
|
||||
env.SetCallback(name, cb)
|
||||
return ret
|
||||
}
|
||||
|
||||
func (env *Environment) Set(name, value string) string {
|
||||
env.Lock()
|
||||
defer env.Unlock()
|
||||
|
@ -43,6 +60,10 @@ func (env *Environment) Set(name, value string) string {
|
|||
old, _ := env.Storage[name]
|
||||
env.Storage[name] = value
|
||||
|
||||
if cb, hasCallback := env.cbs[name]; hasCallback == true {
|
||||
cb(value)
|
||||
}
|
||||
|
||||
env.sess.Events.Log(core.DEBUG, "env.change: %s -> '%s'", name, value)
|
||||
|
||||
width := len(name)
|
||||
|
|
|
@ -54,6 +54,18 @@ func NewEventPool(debug bool, silent bool) *EventPool {
|
|||
}
|
||||
}
|
||||
|
||||
func (p *EventPool) SetSilent(s bool) {
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
p.silent = s
|
||||
}
|
||||
|
||||
func (p *EventPool) SetDebug(d bool) {
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
p.debug = d
|
||||
}
|
||||
|
||||
func (p *EventPool) Add(tag string, data interface{}) {
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
|
|
|
@ -272,6 +272,30 @@ func (s *Session) setupEnv() {
|
|||
s.Env.Set("iface.mac", s.Interface.HwAddress)
|
||||
s.Env.Set("gateway.address", s.Gateway.IpAddress)
|
||||
s.Env.Set("gateway.mac", s.Gateway.HwAddress)
|
||||
|
||||
dbg := "false"
|
||||
if *s.Options.Debug {
|
||||
dbg = "true"
|
||||
}
|
||||
s.Env.WithCallback("log.debug", dbg, func(newValue string) {
|
||||
newDbg := false
|
||||
if newValue == "true" {
|
||||
newDbg = true
|
||||
}
|
||||
s.Events.SetDebug(newDbg)
|
||||
})
|
||||
|
||||
silent := "false"
|
||||
if *s.Options.Silent {
|
||||
silent = "true"
|
||||
}
|
||||
s.Env.WithCallback("log.silent", silent, func(newValue string) {
|
||||
newSilent := false
|
||||
if newValue == "true" {
|
||||
newSilent = true
|
||||
}
|
||||
s.Events.SetSilent(newSilent)
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Session) Start() error {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue