completed lint driven refactoring

This commit is contained in:
evilsocket 2018-04-26 12:41:18 +02:00
parent e383e4d9b1
commit 557d7dbe17
No known key found for this signature in database
GPG key ID: 1564D7F30393A456
8 changed files with 27 additions and 47 deletions

View file

@ -2,6 +2,7 @@ sudo: false
language: go language: go
go: go:
- 1.8.x
- 1.9.x - 1.9.x
- 1.10.x - 1.10.x
- master - master

View file

@ -92,7 +92,7 @@ func (env *Environment) Set(name, value string) string {
env.Lock() env.Lock()
defer env.Unlock() defer env.Unlock()
old, _ := env.Data[name] old := env.Data[name]
env.Data[name] = value env.Data[name] = value
if cb, hasCallback := env.cbs[name]; hasCallback { if cb, hasCallback := env.cbs[name]; hasCallback {

View file

@ -97,7 +97,7 @@ func (p *EventPool) Add(tag string, data interface{}) {
} }
func (p *EventPool) Log(level int, format string, args ...interface{}) { func (p *EventPool) Log(level int, format string, args ...interface{}) {
if level == core.DEBUG && p.debug == false { if level == core.DEBUG && !p.debug {
return return
} else if level < core.ERROR && p.silent { } else if level < core.ERROR && p.silent {
return return

View file

@ -157,7 +157,7 @@ func (m *SessionModule) SetRunning(running bool, cb func()) error {
}() }()
select { select {
case _ = <-done: case <-done:
return nil return nil
case <-time.After(10 * time.Second): case <-time.After(10 * time.Second):
fmt.Printf("%s: Stopping module %s timed out.", core.Yellow(core.Bold("WARNING")), m.Name) fmt.Printf("%s: Stopping module %s timed out.", core.Yellow(core.Bold("WARNING")), m.Name)

View file

@ -58,7 +58,7 @@ func NewIntParameter(name string, def_value string, desc string) *ModuleParam {
func (p ModuleParam) Validate(value string) (error, interface{}) { func (p ModuleParam) Validate(value string) (error, interface{}) {
if p.Validator != nil { if p.Validator != nil {
if p.Validator.MatchString(value) == false { if !p.Validator.MatchString(value) {
return fmt.Errorf("Parameter %s not valid: '%s' does not match rule '%s'.", core.Bold(p.Name), value, p.Validator.String()), nil return fmt.Errorf("Parameter %s not valid: '%s' does not match rule '%s'.", core.Bold(p.Name), value, p.Validator.String()), nil
} }
} }
@ -88,15 +88,7 @@ const ParamSubnet = "<entire subnet>"
const ParamRandomMAC = "<random mac>" const ParamRandomMAC = "<random mac>"
func (p ModuleParam) Get(s *Session) (error, interface{}) { func (p ModuleParam) Get(s *Session) (error, interface{}) {
var v string _, v := s.Env.Get(p.Name)
var found bool
var obj interface{}
var err error
if found, v = s.Env.Get(p.Name); found == false {
v = ""
}
if v == ParamIfaceName { if v == ParamIfaceName {
v = s.Interface.Name() v = s.Interface.Name()
} else if v == ParamIfaceAddress { } else if v == ParamIfaceAddress {
@ -108,10 +100,7 @@ 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 p.Validate(v)
err, obj = p.Validate(v)
return err, obj
} }
func (p ModuleParam) Dump(padding int) string { func (p ModuleParam) Dump(padding int) string {

View file

@ -39,7 +39,7 @@ var PromptCallbacks = map[string]func(s *Session) string{
}, },
} }
var envRe = regexp.MustCompile("{env\\.([^}]+)}") var envRe = regexp.MustCompile(`{env\.([^}]+)}`)
type Prompt struct { type Prompt struct {
} }
@ -50,7 +50,7 @@ func NewPrompt() Prompt {
func (p Prompt) Render(s *Session) string { func (p Prompt) Render(s *Session) string {
found, prompt := s.Env.Get(PromptVariable) found, prompt := s.Env.Get(PromptVariable)
if found == false { if !found {
prompt = DefaultPrompt prompt = DefaultPrompt
} }
@ -89,7 +89,7 @@ func (p Prompt) Render(s *Session) string {
} }
// make sure an user error does not screw all terminal // make sure an user error does not screw all terminal
if strings.HasPrefix(prompt, core.RESET) == false { if !strings.HasPrefix(prompt, core.RESET) {
prompt += core.RESET prompt += core.RESET
} }

View file

@ -2,7 +2,6 @@ package session
import ( import (
"bufio" "bufio"
"bytes"
"errors" "errors"
"fmt" "fmt"
"net" "net"
@ -76,7 +75,7 @@ func ParseCommands(line string) []string {
for _, c := range line { for _, c := range line {
switch c { switch c {
case ';': case ';':
if singleQuoted == false && doubleQuoted == false { if !singleQuoted && !doubleQuoted {
finish = true finish = true
} else { } else {
buf += string(c) buf += string(c)
@ -191,14 +190,13 @@ func (s *Session) setupReadline() error {
} }
} }
tree := make(map[string][]string, 0) tree := make(map[string][]string)
for _, m := range s.Modules { for _, m := range s.Modules {
for _, h := range m.Handlers() { for _, h := range m.Handlers() {
parts := strings.Split(h.Name, " ") parts := strings.Split(h.Name, " ")
name := parts[0] name := parts[0]
if _, found := tree[name]; found == false { if _, found := tree[name]; !found {
tree[name] = []string{} tree[name] = []string{}
} }
@ -222,7 +220,7 @@ func (s *Session) setupReadline() error {
} }
history := "" history := ""
if *s.Options.NoHistory == false { if !*s.Options.NoHistory {
history, _ = core.ExpandPath(HistoryFile) history, _ = core.ExpandPath(HistoryFile)
} }
@ -234,11 +232,7 @@ func (s *Session) setupReadline() error {
} }
s.Input, err = readline.NewEx(&cfg) s.Input, err = readline.NewEx(&cfg)
if err != nil { return err
return err
}
return nil
} }
func (s *Session) Close() { func (s *Session) Close() {
@ -290,11 +284,11 @@ func (s *Session) startNetMon() {
// keep reading network events in order to add / update endpoints // keep reading network events in order to add / update endpoints
go func() { go func() {
for event := range s.Queue.Activities { for event := range s.Queue.Activities {
if s.Active == false { if !s.Active {
return return
} }
if s.IsOn("net.recon") && event.Source == true { if s.IsOn("net.recon") && event.Source {
addr := event.IP.String() addr := event.IP.String()
mac := event.MAC.String() mac := event.MAC.String()
@ -329,7 +323,7 @@ func (s *Session) setupEnv() {
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)
if found, v := s.Env.Get(PromptVariable); found == false || v == "" { if found, v := s.Env.Get(PromptVariable); !found || v == "" {
s.Env.Set(PromptVariable, DefaultPrompt) s.Env.Set(PromptVariable, DefaultPrompt)
} }
@ -425,9 +419,9 @@ func (s *Session) Start() error {
func (s *Session) Skip(ip net.IP) bool { func (s *Session) Skip(ip net.IP) bool {
if ip.IsLoopback() { if ip.IsLoopback() {
return true return true
} else if bytes.Compare(ip, s.Interface.IP) == 0 { } else if ip.Equal(s.Interface.IP) {
return true return true
} else if bytes.Compare(ip, s.Gateway.IP) == 0 { } else if ip.Equal(s.Gateway.IP) {
return true return true
} }
return false return false
@ -485,10 +479,7 @@ func (s *Session) isCapletCommand(line string) (is bool, filename string, argv [
} }
capspath := core.Trim(os.Getenv("CAPSPATH")) capspath := core.Trim(os.Getenv("CAPSPATH"))
for _, folder := range core.SepSplit(capspath, ":") { paths = append(paths, core.SepSplit(capspath, ":")...)
paths = append(paths, folder)
}
file := core.Trim(line) file := core.Trim(line)
parts := strings.Split(file, " ") parts := strings.Split(file, " ")
argc := len(parts) argc := len(parts)

View file

@ -37,7 +37,7 @@ func (s *Session) helpHandler(args []string, sess *Session) error {
fmt.Printf(" "+core.Yellow(pad)+" : %s\n", h.Name, h.Description) fmt.Printf(" "+core.Yellow(pad)+" : %s\n", h.Name, h.Description)
} }
fmt.Printf(core.Bold("\nModules\n\n")) fmt.Println(core.Bold("\nModules\n"))
maxLen = 0 maxLen = 0
for _, m := range s.Modules { for _, m := range s.Modules {
@ -85,13 +85,13 @@ func (s *Session) helpHandler(args []string, sess *Session) error {
} }
for _, h := range handlers { for _, h := range handlers {
fmt.Printf(h.Help(maxLen)) fmt.Print(h.Help(maxLen))
} }
fmt.Println() fmt.Println()
params := m.Parameters() params := m.Parameters()
if len(params) > 0 { if len(params) > 0 {
fmt.Printf(" Parameters\n\n") fmt.Print(" Parameters\n\n")
maxLen := 0 maxLen := 0
for _, h := range params { for _, h := range params {
len := len(h.Name) len := len(h.Name)
@ -101,7 +101,7 @@ func (s *Session) helpHandler(args []string, sess *Session) error {
} }
for _, p := range params { for _, p := range params {
fmt.Printf(p.Help(maxLen)) fmt.Print(p.Help(maxLen))
} }
fmt.Println() fmt.Println()
} }
@ -112,7 +112,7 @@ func (s *Session) helpHandler(args []string, sess *Session) error {
func (s *Session) activeHandler(args []string, sess *Session) error { func (s *Session) activeHandler(args []string, sess *Session) error {
for _, m := range s.Modules { for _, m := range s.Modules {
if m.Running() == false { if !m.Running() {
continue continue
} }
@ -343,8 +343,7 @@ func (s *Session) registerCoreHandlers() {
prefix = "." prefix = "."
} }
files := []string{} files, _ := filepath.Glob(prefix + "*")
files, _ = filepath.Glob(prefix + "*")
return files return files
}))) })))