Revert "Minor refactors using golint"

This commit is contained in:
Simone Margaritelli 2018-05-03 12:31:42 +02:00 committed by GitHub
parent 9196be7a8b
commit 5328ced392
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 101 additions and 70 deletions

View file

@ -66,8 +66,9 @@ func ExecSilent(executable string, args []string) (string, error) {
raw, err := exec.Command(path, args...).CombinedOutput()
if err != nil {
return "", err
}
} else {
return Trim(string(raw)), nil
}
}
func Exec(executable string, args []string) (string, error) {
@ -92,10 +93,11 @@ func ExpandPath(path string) (string, error) {
usr, err := user.Current()
if err != nil {
return "", err
}
} else {
// Replace only the first occurrence of ~
path = strings.Replace(path, "~", usr.HomeDir, 1)
}
}
return filepath.Abs(path)
}
return "", nil

View file

@ -85,8 +85,9 @@ func (f PfFirewall) enableParam(param string, enabled bool) error {
if _, err := f.sysCtlWrite(param, value); err != nil {
return err
}
} else {
return nil
}
}
func (f PfFirewall) EnableForwarding(enabled bool) error {

View file

@ -107,9 +107,10 @@ func (s *DNSSpoofer) Configure() error {
for _, domain := range domains {
if expr, err := glob.Compile(domain); err != nil {
return fmt.Errorf("'%s' is not a valid domain glob expression: %s", domain, err)
}
} else {
s.Domains = append(s.Domains, expr)
}
}
if err, addr = s.StringParam("dns.spoof.address"); err != nil {
return err

View file

@ -210,8 +210,9 @@ func (s *EventsStream) startWaitingFor(tag string, timeout int) error {
if event == nil {
return fmt.Errorf("'events.waitFor %s %d' timed out.", tag, timeout)
}
} else {
log.Debug("Got event: %v", event)
}
return nil
}

View file

@ -98,10 +98,11 @@ func (gps *GPS) readLine() (line string, err error) {
} else if n == 1 {
if b[0] == '\n' {
return core.Trim(line), nil
}
} else {
line += string(b[0])
}
}
}
}
func (gps *GPS) Show() error {

View file

@ -115,9 +115,10 @@ func (p *HTTPProxy) Configure(address string, proxyPort int, httpPort int, scrip
if scriptPath != "" {
if err, p.Script = LoadHttpProxyScript(scriptPath, p.sess); err != nil {
return err
}
} else {
log.Debug("Proxy script %s loaded.", scriptPath)
}
}
p.Server = &http.Server{
Addr: fmt.Sprintf("%s:%d", p.Address, proxyPort),
@ -335,9 +336,9 @@ func (p *HTTPProxy) Stop() error {
p.isRunning = false
p.sniListener.Close()
return nil
}
} else {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
return p.Server.Shutdown(ctx)
}
}

View file

@ -27,8 +27,9 @@ func (t *CookieTracker) domainOf(req *http.Request) string {
if parsed, err := tld.Parse(req.Host); err != nil {
log.Warning("Could not parse host %s: %s", req.Host, err)
return req.Host
}
} else {
return fmt.Sprintf("%s.%s", parsed.Domain, parsed.TLD)
}
}
func (t *CookieTracker) keyOf(req *http.Request) string {

View file

@ -304,9 +304,10 @@ func (s *SSLStripper) isMaxRedirs(hostname string) bool {
// reset
delete(s.redirs, hostname)
return true
}
} else {
// increment
s.redirs[hostname]++
}
} else {
// start tracking redirections
s.redirs[hostname] = 1

View file

@ -71,8 +71,9 @@ func (p *Prober) Configure() error {
var err error
if err, p.throttle = p.IntParam("net.probe.throttle"); err != nil {
return err
}
} else {
log.Debug("Throttling packets of %d ms.", p.throttle)
}
return nil
}

View file

@ -124,9 +124,10 @@ func (p *TcpProxy) Configure() error {
if scriptPath != "" {
if err, p.script = LoadTcpProxyScript(scriptPath, p.Session); err != nil {
return err
}
} else {
log.Debug("TCP proxy script %s loaded.", scriptPath)
}
}
if !p.Session.Firewall.IsForwardingEnabled() {
log.Info("Enabling forwarding.")

View file

@ -20,9 +20,9 @@ func findMAC(s *session.Session, ip net.IP, probe bool) (net.HardwareAddr, error
mac, err = network.ArpLookup(s.Interface.Name(), ip.String(), false)
if err != nil && probe {
from := s.Interface.IP
fromHw := s.Interface.HW
from_hw := s.Interface.HW
if err, probe := packets.NewUDPProbe(from, fromHw, ip, 139); err != nil {
if err, probe := packets.NewUDPProbe(from, from_hw, ip, 139); err != nil {
log.Error("Error while creating UDP probe packet for %s: %s", ip.String(), err)
} else {
s.Queue.Send(probe)

View file

@ -101,8 +101,9 @@ func NewWiFiModule(s *session.Session) *WiFiModule {
func(args []string) error {
if err := w.parseApConfig(); err != nil {
return err
}
} else {
return w.startAp()
}
}))
w.AddParam(session.NewStringParameter("wifi.ap.ssid",
@ -148,9 +149,10 @@ func NewWiFiModule(s *session.Session) *WiFiModule {
// No channels setted, retrieve frequencies supported by the card
if frequencies, err := network.GetSupportedFrequencies(w.Session.Interface.Name()); err != nil {
return err
}
} else {
newfrequencies = frequencies
}
}
w.frequencies = newfrequencies

View file

@ -83,8 +83,7 @@ func (w *WiFiModule) getRow(station *network.Station) ([]string, bool) {
recvd,
seen,
}, include
}
} else {
// this is ugly, but necessary in order to have this
// method handle both access point and clients
// transparently
@ -107,6 +106,7 @@ func (w *WiFiModule) getRow(station *network.Station) ([]string, bool) {
recvd,
seen,
}, include
}
}
func (w *WiFiModule) Show(by string) error {

View file

@ -31,8 +31,9 @@ func NewWOL(s *session.Session) *WOL {
func(args []string) error {
if mac, err := parseMAC(args); err != nil {
return err
}
} else {
return w.wolETH(mac)
}
}))
w.AddHandler(session.NewModuleHandler("wol.udp MAC", "wol.udp(\\s.+)?",
@ -40,8 +41,9 @@ func NewWOL(s *session.Session) *WOL {
func(args []string) error {
if mac, err := parseMAC(args); err != nil {
return err
}
} else {
return w.wolUDP(mac)
}
}))
return w
@ -54,10 +56,11 @@ func parseMAC(args []string) (string, error) {
if tmp != "" {
if !reMAC.MatchString(tmp) {
return "", fmt.Errorf("%s is not a valid MAC address.", tmp)
}
} else {
mac = tmp
}
}
}
return mac, nil
}

View file

@ -20,13 +20,14 @@ func FindGateway(iface *Endpoint) (*Endpoint, error) {
return IPv4RouteIsGateway(iface.Name(), m, func(gateway string) (*Endpoint, error) {
if gateway == iface.IpAddress {
return iface, nil
}
} else {
// we have the address, now we need its mac
mac, err := ArpLookup(iface.Name(), gateway, false)
if err != nil {
return nil, err
}
return NewEndpoint(gateway, mac), nil
}
})
}
}

View file

@ -40,8 +40,9 @@ func DHCP6For(what dhcp6.MessageType, to dhcp6.Packet, duid []byte) (err error,
var rawCID []byte
if raw, found := to.Options[dhcp6.OptionClientID]; !found || len(raw) < 1 {
return ErrNoCID, p
}
} else {
rawCID = raw[0]
}
p.Options.AddRaw(dhcp6.OptionClientID, rawCID)
p.Options.AddRaw(dhcp6.OptionServerID, duid)

View file

@ -217,8 +217,9 @@ func (q *Queue) Send(raw []byte) error {
if err := q.handle.WritePacketData(raw); err != nil {
q.TrackError()
return err
}
} else {
q.TrackSent(uint64(len(raw)))
}
return nil
}

View file

@ -27,6 +27,7 @@ func (h *CommandHandler) Parse(line string) (bool, []string) {
result := h.Parser.FindStringSubmatch(line)
if len(result) == h.Parser.NumSubexp()+1 {
return true, result[1:]
}
} else {
return false, nil
}
}

View file

@ -114,9 +114,10 @@ func (env *Environment) GetInt(name string) (error, int) {
if found, value := env.Get(name); found {
if i, err := strconv.Atoi(value); err == nil {
return nil, i
}
} else {
return err, 0
}
}
return fmt.Errorf("Not found."), 0
}

View file

@ -62,7 +62,7 @@ func (m SessionModule) ListParam(name string) (err error, values []string) {
list := ""
if err, list = m.StringParam(name); err != nil {
return
}
} else {
parts := strings.Split(list, ",")
for _, part := range parts {
part = core.Trim(part)
@ -70,6 +70,7 @@ func (m SessionModule) ListParam(name string) (err error, values []string) {
values = append(values, part)
}
}
}
return
}
@ -77,27 +78,33 @@ func (m SessionModule) StringParam(name string) (error, string) {
if p, found := m.params[name]; found {
if err, v := p.Get(m.Session); err != nil {
return err, ""
}
} else {
return nil, v.(string)
}
} else {
return fmt.Errorf("Parameter %s does not exist.", name), ""
}
}
func (m SessionModule) IntParam(name string) (error, int) {
if p, found := m.params[name]; found {
if err, v := p.Get(m.Session); err != nil {
return err, 0
}
} else {
return nil, v.(int)
}
} else {
return fmt.Errorf("Parameter %s does not exist.", name), 0
}
}
func (m SessionModule) BoolParam(name string) (error, bool) {
if err, v := m.params[name].Get(m.Session); err != nil {
return err, false
}
} else {
return nil, v.(bool)
}
}
func (m *SessionModule) AddHandler(h ModuleHandler) {
@ -120,9 +127,10 @@ func (m *SessionModule) SetRunning(running bool, cb func()) error {
if running == m.Running() {
if m.Started {
return ErrAlreadyStarted
}
} else {
return ErrAlreadyStopped
}
}
m.StatusLock.Lock()
m.Started = running

View file

@ -148,8 +148,9 @@ func (s *Session) sleepHandler(args []string, sess *Session) error {
if secs, err := strconv.Atoi(args[0]); err == nil {
time.Sleep(time.Duration(secs) * time.Second)
return nil
}
} else {
return err
}
}
func (s *Session) getHandler(args []string, sess *Session) error {
@ -256,8 +257,9 @@ func (s *Session) aliasHandler(args []string, sess *Session) error {
if s.Lan.SetAliasFor(mac, alias) {
return nil
}
} else {
return fmt.Errorf("Could not find endpoint %s", mac)
}
}
func (s *Session) addHandler(h CommandHandler, c *readline.PrefixCompleter) {