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
go:
- 1.8.x
- 1.9.x
- 1.10.x
- master

View file

@ -92,7 +92,7 @@ func (env *Environment) Set(name, value string) string {
env.Lock()
defer env.Unlock()
old, _ := env.Data[name]
old := env.Data[name]
env.Data[name] = value
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{}) {
if level == core.DEBUG && p.debug == false {
if level == core.DEBUG && !p.debug {
return
} else if level < core.ERROR && p.silent {
return

View file

@ -157,7 +157,7 @@ func (m *SessionModule) SetRunning(running bool, cb func()) error {
}()
select {
case _ = <-done:
case <-done:
return nil
case <-time.After(10 * time.Second):
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{}) {
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
}
}
@ -88,15 +88,7 @@ const ParamSubnet = "<entire subnet>"
const ParamRandomMAC = "<random mac>"
func (p ModuleParam) Get(s *Session) (error, interface{}) {
var v string
var found bool
var obj interface{}
var err error
if found, v = s.Env.Get(p.Name); found == false {
v = ""
}
_, v := s.Env.Get(p.Name)
if v == ParamIfaceName {
v = s.Interface.Name()
} else if v == ParamIfaceAddress {
@ -108,10 +100,7 @@ func (p ModuleParam) Get(s *Session) (error, interface{}) {
rand.Read(hw)
v = net.HardwareAddr(hw).String()
}
err, obj = p.Validate(v)
return err, obj
return p.Validate(v)
}
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 {
}
@ -50,7 +50,7 @@ func NewPrompt() Prompt {
func (p Prompt) Render(s *Session) string {
found, prompt := s.Env.Get(PromptVariable)
if found == false {
if !found {
prompt = DefaultPrompt
}
@ -89,7 +89,7 @@ func (p Prompt) Render(s *Session) string {
}
// 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
}

View file

@ -2,7 +2,6 @@ package session
import (
"bufio"
"bytes"
"errors"
"fmt"
"net"
@ -76,7 +75,7 @@ func ParseCommands(line string) []string {
for _, c := range line {
switch c {
case ';':
if singleQuoted == false && doubleQuoted == false {
if !singleQuoted && !doubleQuoted {
finish = true
} else {
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 _, h := range m.Handlers() {
parts := strings.Split(h.Name, " ")
name := parts[0]
if _, found := tree[name]; found == false {
if _, found := tree[name]; !found {
tree[name] = []string{}
}
@ -222,7 +220,7 @@ func (s *Session) setupReadline() error {
}
history := ""
if *s.Options.NoHistory == false {
if !*s.Options.NoHistory {
history, _ = core.ExpandPath(HistoryFile)
}
@ -234,11 +232,7 @@ func (s *Session) setupReadline() error {
}
s.Input, err = readline.NewEx(&cfg)
if err != nil {
return err
}
return nil
return err
}
func (s *Session) Close() {
@ -290,11 +284,11 @@ func (s *Session) startNetMon() {
// keep reading network events in order to add / update endpoints
go func() {
for event := range s.Queue.Activities {
if s.Active == false {
if !s.Active {
return
}
if s.IsOn("net.recon") && event.Source == true {
if s.IsOn("net.recon") && event.Source {
addr := event.IP.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.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)
}
@ -425,9 +419,9 @@ func (s *Session) Start() error {
func (s *Session) Skip(ip net.IP) bool {
if ip.IsLoopback() {
return true
} else if bytes.Compare(ip, s.Interface.IP) == 0 {
} else if ip.Equal(s.Interface.IP) {
return true
} else if bytes.Compare(ip, s.Gateway.IP) == 0 {
} else if ip.Equal(s.Gateway.IP) {
return true
}
return false
@ -485,10 +479,7 @@ func (s *Session) isCapletCommand(line string) (is bool, filename string, argv [
}
capspath := core.Trim(os.Getenv("CAPSPATH"))
for _, folder := range core.SepSplit(capspath, ":") {
paths = append(paths, folder)
}
paths = append(paths, core.SepSplit(capspath, ":")...)
file := core.Trim(line)
parts := strings.Split(file, " ")
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.Bold("\nModules\n\n"))
fmt.Println(core.Bold("\nModules\n"))
maxLen = 0
for _, m := range s.Modules {
@ -85,13 +85,13 @@ func (s *Session) helpHandler(args []string, sess *Session) error {
}
for _, h := range handlers {
fmt.Printf(h.Help(maxLen))
fmt.Print(h.Help(maxLen))
}
fmt.Println()
params := m.Parameters()
if len(params) > 0 {
fmt.Printf(" Parameters\n\n")
fmt.Print(" Parameters\n\n")
maxLen := 0
for _, h := range params {
len := len(h.Name)
@ -101,7 +101,7 @@ func (s *Session) helpHandler(args []string, sess *Session) error {
}
for _, p := range params {
fmt.Printf(p.Help(maxLen))
fmt.Print(p.Help(maxLen))
}
fmt.Println()
}
@ -112,7 +112,7 @@ func (s *Session) helpHandler(args []string, sess *Session) error {
func (s *Session) activeHandler(args []string, sess *Session) error {
for _, m := range s.Modules {
if m.Running() == false {
if !m.Running() {
continue
}
@ -343,8 +343,7 @@ func (s *Session) registerCoreHandlers() {
prefix = "."
}
files := []string{}
files, _ = filepath.Glob(prefix + "*")
files, _ := filepath.Glob(prefix + "*")
return files
})))