mirror of
https://github.com/bettercap/bettercap
synced 2025-07-07 05:22:04 -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,11 +9,15 @@ import (
|
||||||
"github.com/evilsocket/bettercap-ng/core"
|
"github.com/evilsocket/bettercap-ng/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type SetCallback func(newValue string)
|
||||||
|
|
||||||
type Environment struct {
|
type Environment struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
|
|
||||||
Padding int `json:"-"`
|
Padding int `json:"-"`
|
||||||
Storage map[string]string `json:"storage"`
|
Storage map[string]string `json:"storage"`
|
||||||
|
|
||||||
|
cbs map[string]SetCallback
|
||||||
sess *Session
|
sess *Session
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +26,7 @@ func NewEnvironment(s *Session) *Environment {
|
||||||
Padding: 0,
|
Padding: 0,
|
||||||
Storage: make(map[string]string),
|
Storage: make(map[string]string),
|
||||||
sess: s,
|
sess: s,
|
||||||
|
cbs: make(map[string]SetCallback),
|
||||||
}
|
}
|
||||||
|
|
||||||
return env
|
return env
|
||||||
|
@ -36,6 +41,18 @@ func (env *Environment) Has(name string) bool {
|
||||||
return found
|
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 {
|
func (env *Environment) Set(name, value string) string {
|
||||||
env.Lock()
|
env.Lock()
|
||||||
defer env.Unlock()
|
defer env.Unlock()
|
||||||
|
@ -43,6 +60,10 @@ func (env *Environment) Set(name, value string) string {
|
||||||
old, _ := env.Storage[name]
|
old, _ := env.Storage[name]
|
||||||
env.Storage[name] = value
|
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)
|
env.sess.Events.Log(core.DEBUG, "env.change: %s -> '%s'", name, value)
|
||||||
|
|
||||||
width := len(name)
|
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{}) {
|
func (p *EventPool) Add(tag string, data interface{}) {
|
||||||
p.Lock()
|
p.Lock()
|
||||||
defer p.Unlock()
|
defer p.Unlock()
|
||||||
|
|
|
@ -272,6 +272,30 @@ func (s *Session) setupEnv() {
|
||||||
s.Env.Set("iface.mac", s.Interface.HwAddress)
|
s.Env.Set("iface.mac", s.Interface.HwAddress)
|
||||||
s.Env.Set("gateway.address", s.Gateway.IpAddress)
|
s.Env.Set("gateway.address", s.Gateway.IpAddress)
|
||||||
s.Env.Set("gateway.mac", s.Gateway.HwAddress)
|
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 {
|
func (s *Session) Start() error {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue