mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 21:13:18 -07:00
new: exporting module parameters current value in api.rest
This commit is contained in:
parent
ee8fe972e0
commit
0f427911be
2 changed files with 21 additions and 7 deletions
|
@ -99,17 +99,19 @@ func (env *Environment) Set(name, value string) string {
|
||||||
return old
|
return old
|
||||||
}
|
}
|
||||||
|
|
||||||
func (env *Environment) Get(name string) (bool, string) {
|
func (env *Environment) GetUnlocked(name string) (bool, string) {
|
||||||
env.Lock()
|
|
||||||
defer env.Unlock()
|
|
||||||
|
|
||||||
if value, found := env.Data[name]; found {
|
if value, found := env.Data[name]; found {
|
||||||
return true, value
|
return true, value
|
||||||
}
|
}
|
||||||
|
|
||||||
return false, ""
|
return false, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (env *Environment) Get(name string) (bool, string) {
|
||||||
|
env.Lock()
|
||||||
|
defer env.Unlock()
|
||||||
|
return env.GetUnlocked(name)
|
||||||
|
}
|
||||||
|
|
||||||
func (env *Environment) GetInt(name string) (error, int) {
|
func (env *Environment) GetInt(name string) (error, int) {
|
||||||
if found, value := env.Get(name); found {
|
if found, value := env.Get(name); found {
|
||||||
if i, err := strconv.Atoi(value); err == nil {
|
if i, err := strconv.Atoi(value); err == nil {
|
||||||
|
|
|
@ -97,8 +97,7 @@ const ParamIfaceAddress = "<interface address>"
|
||||||
const ParamSubnet = "<entire subnet>"
|
const ParamSubnet = "<entire subnet>"
|
||||||
const ParamRandomMAC = "<random mac>"
|
const ParamRandomMAC = "<random mac>"
|
||||||
|
|
||||||
func (p ModuleParam) Get(s *Session) (error, interface{}) {
|
func (p ModuleParam) parse(s *Session, v string) string {
|
||||||
_, v := s.Env.Get(p.Name)
|
|
||||||
switch v {
|
switch v {
|
||||||
case ParamIfaceName:
|
case ParamIfaceName:
|
||||||
v = s.Interface.Name()
|
v = s.Interface.Name()
|
||||||
|
@ -111,7 +110,18 @@ func (p ModuleParam) Get(s *Session) (error, interface{}) {
|
||||||
rand.Read(hw)
|
rand.Read(hw)
|
||||||
v = net.HardwareAddr(hw).String()
|
v = net.HardwareAddr(hw).String()
|
||||||
}
|
}
|
||||||
|
return v
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p ModuleParam) getUnlocked(s *Session) string {
|
||||||
|
_, v := s.Env.GetUnlocked(p.Name)
|
||||||
|
return p.parse(s, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p ModuleParam) Get(s *Session) (error, interface{}) {
|
||||||
|
_, v := s.Env.Get(p.Name)
|
||||||
|
v = p.parse(s, v)
|
||||||
return p.Validate(v)
|
return p.Validate(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,6 +140,7 @@ type JSONModuleParam struct {
|
||||||
Type ParamType `json:"type"`
|
Type ParamType `json:"type"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Value string `json:"default_value"`
|
Value string `json:"default_value"`
|
||||||
|
Current string `json:"current_value"`
|
||||||
Validator string `json:"validator"`
|
Validator string `json:"validator"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,6 +150,7 @@ func (p ModuleParam) MarshalJSON() ([]byte, error) {
|
||||||
Type: p.Type,
|
Type: p.Type,
|
||||||
Description: p.Description,
|
Description: p.Description,
|
||||||
Value: p.Value,
|
Value: p.Value,
|
||||||
|
Current: p.getUnlocked(I), // if we're here, Env is already locked
|
||||||
}
|
}
|
||||||
if p.Validator != nil {
|
if p.Validator != nil {
|
||||||
j.Validator = p.Validator.String()
|
j.Validator = p.Validator.String()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue