Merge pull request #373 from Edznux/refactoring

Refactoring and fix tests
This commit is contained in:
evilsocket 2018-10-29 15:24:31 +01:00 committed by GitHub
commit 24037bce47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 35181 additions and 35268 deletions

View file

@ -69,9 +69,10 @@ func (p ModuleParam) Validate(value string) (error, interface{}) {
}
}
if p.Type == STRING {
switch p.Type {
case STRING:
return nil, value
} else if p.Type == BOOL {
case BOOL:
lvalue := strings.ToLower(value)
if lvalue == "true" {
return nil, true
@ -80,7 +81,7 @@ func (p ModuleParam) Validate(value string) (error, interface{}) {
} else {
return fmt.Errorf("Can't typecast '%s' to boolean.", value), nil
}
} else if p.Type == INT {
case INT:
i, err := strconv.Atoi(value)
return err, i
} else if p.Type == FLOAT {
@ -98,17 +99,21 @@ const ParamRandomMAC = "<random mac>"
func (p ModuleParam) Get(s *Session) (error, interface{}) {
_, v := s.Env.Get(p.Name)
if v == ParamIfaceName {
switch v {
case ParamIfaceName:
v = s.Interface.Name()
} else if v == ParamIfaceAddress {
case ParamIfaceAddress:
v = s.Interface.IpAddress
} else if v == ParamSubnet {
case ParamSubnet:
v = s.Interface.CIDR()
} else if v == ParamRandomMAC {
case ParamRandomMAC:
hw := make([]byte, 6)
rand.Read(hw)
v = net.HardwareAddr(hw).String()
default:
return fmt.Errorf("Uknown value for v"), nil
}
return p.Validate(v)
}