diff --git a/core/core.go b/core/core.go index ffbcf8e2..2fe2d19c 100644 --- a/core/core.go +++ b/core/core.go @@ -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 } - return Trim(string(raw)), nil } func Exec(executable string, args []string) (string, error) { @@ -92,9 +93,10 @@ 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) } - // Replace only the first occurrence of ~ - path = strings.Replace(path, "~", usr.HomeDir, 1) } return filepath.Abs(path) } diff --git a/firewall/firewall_darwin.go b/firewall/firewall_darwin.go index 287779b2..d328a0fb 100644 --- a/firewall/firewall_darwin.go +++ b/firewall/firewall_darwin.go @@ -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 } - return nil } func (f PfFirewall) EnableForwarding(enabled bool) error { diff --git a/modules/dns_spoof.go b/modules/dns_spoof.go index 0f1ea6b3..e75a31bc 100644 --- a/modules/dns_spoof.go +++ b/modules/dns_spoof.go @@ -107,8 +107,9 @@ 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) } - s.Domains = append(s.Domains, expr) } if err, addr = s.StringParam("dns.spoof.address"); err != nil { diff --git a/modules/events_stream.go b/modules/events_stream.go index a716e4cd..6c5597f8 100644 --- a/modules/events_stream.go +++ b/modules/events_stream.go @@ -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) } - log.Debug("Got event: %v", event) return nil } diff --git a/modules/gps.go b/modules/gps.go index 7994f0e2..50ee1ed0 100644 --- a/modules/gps.go +++ b/modules/gps.go @@ -98,8 +98,9 @@ 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]) } - line += string(b[0]) } } } diff --git a/modules/http_proxy_base.go b/modules/http_proxy_base.go index 600f0ead..38ba658f 100644 --- a/modules/http_proxy_base.go +++ b/modules/http_proxy_base.go @@ -115,8 +115,9 @@ 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) } - log.Debug("Proxy script %s loaded.", scriptPath) } p.Server = &http.Server{ @@ -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) } - - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() - return p.Server.Shutdown(ctx) } diff --git a/modules/http_proxy_base_cookietracker.go b/modules/http_proxy_base_cookietracker.go index 9804b718..d60f7802 100644 --- a/modules/http_proxy_base_cookietracker.go +++ b/modules/http_proxy_base_cookietracker.go @@ -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) } - return fmt.Sprintf("%s.%s", parsed.Domain, parsed.TLD) } func (t *CookieTracker) keyOf(req *http.Request) string { diff --git a/modules/http_proxy_base_sslstriper.go b/modules/http_proxy_base_sslstriper.go index 412d4694..5d2142ae 100644 --- a/modules/http_proxy_base_sslstriper.go +++ b/modules/http_proxy_base_sslstriper.go @@ -304,9 +304,10 @@ func (s *SSLStripper) isMaxRedirs(hostname string) bool { // reset delete(s.redirs, hostname) return true + } else { + // increment + s.redirs[hostname]++ } - // increment - s.redirs[hostname]++ } else { // start tracking redirections s.redirs[hostname] = 1 diff --git a/modules/net_probe.go b/modules/net_probe.go index 64784810..334b26fc 100644 --- a/modules/net_probe.go +++ b/modules/net_probe.go @@ -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) } - log.Debug("Throttling packets of %d ms.", p.throttle) return nil } diff --git a/modules/tcp_proxy.go b/modules/tcp_proxy.go index 18f2b664..d3be611a 100644 --- a/modules/tcp_proxy.go +++ b/modules/tcp_proxy.go @@ -124,8 +124,9 @@ 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) } - log.Debug("TCP proxy script %s loaded.", scriptPath) } if !p.Session.Firewall.IsForwardingEnabled() { diff --git a/modules/utils.go b/modules/utils.go index 341408ea..06bb6eb8 100644 --- a/modules/utils.go +++ b/modules/utils.go @@ -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) diff --git a/modules/wifi.go b/modules/wifi.go index 27f32eab..ada4f99a 100644 --- a/modules/wifi.go +++ b/modules/wifi.go @@ -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() } - return w.startAp() })) w.AddParam(session.NewStringParameter("wifi.ap.ssid", @@ -148,8 +149,9 @@ 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 } - newfrequencies = frequencies } w.frequencies = newfrequencies diff --git a/modules/wifi_show.go b/modules/wifi_show.go index c84ecc16..d977d2f8 100644 --- a/modules/wifi_show.go +++ b/modules/wifi_show.go @@ -83,30 +83,30 @@ func (w *WiFiModule) getRow(station *network.Station) ([]string, bool) { recvd, seen, }, include - } - - // this is ugly, but necessary in order to have this - // method handle both access point and clients - // transparently - clients := "" - if ap, found := w.Session.WiFi.Get(station.HwAddress); found { - if ap.NumClients() > 0 { - clients = strconv.Itoa(ap.NumClients()) + } else { + // this is ugly, but necessary in order to have this + // method handle both access point and clients + // transparently + clients := "" + if ap, found := w.Session.WiFi.Get(station.HwAddress); found { + if ap.NumClients() > 0 { + clients = strconv.Itoa(ap.NumClients()) + } } - } - return []string{ - fmt.Sprintf("%d dBm", station.RSSI), - bssid, - ssid, - /* station.Vendor, */ - encryption, - strconv.Itoa(network.Dot11Freq2Chan(station.Frequency)), - clients, - sent, - recvd, - seen, - }, include + return []string{ + fmt.Sprintf("%d dBm", station.RSSI), + bssid, + ssid, + /* station.Vendor, */ + encryption, + strconv.Itoa(network.Dot11Freq2Chan(station.Frequency)), + clients, + sent, + recvd, + seen, + }, include + } } func (w *WiFiModule) Show(by string) error { diff --git a/modules/wol.go b/modules/wol.go index 31719ae5..54be2419 100644 --- a/modules/wol.go +++ b/modules/wol.go @@ -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) } - 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.wolUDP(mac) })) return w @@ -54,8 +56,9 @@ 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 } - mac = tmp } } diff --git a/network/net_gateway.go b/network/net_gateway.go index 0db60274..4a47698b 100644 --- a/network/net_gateway.go +++ b/network/net_gateway.go @@ -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 } - // 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 }) } } diff --git a/packets/dhcp6.go b/packets/dhcp6.go index 39e4d3eb..01056597 100644 --- a/packets/dhcp6.go +++ b/packets/dhcp6.go @@ -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] } - rawCID = raw[0] p.Options.AddRaw(dhcp6.OptionClientID, rawCID) p.Options.AddRaw(dhcp6.OptionServerID, duid) diff --git a/packets/queue.go b/packets/queue.go index 4d79e85c..12bbb08a 100644 --- a/packets/queue.go +++ b/packets/queue.go @@ -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))) } - q.TrackSent(uint64(len(raw))) return nil } diff --git a/session/command_handler.go b/session/command_handler.go index 677238d4..e7efad17 100644 --- a/session/command_handler.go +++ b/session/command_handler.go @@ -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 } - return false, nil } diff --git a/session/environment.go b/session/environment.go index e71cae7a..a47496bd 100644 --- a/session/environment.go +++ b/session/environment.go @@ -114,8 +114,9 @@ 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 err, 0 } return fmt.Errorf("Not found."), 0 diff --git a/session/module.go b/session/module.go index 210d49a0..3d17995c 100644 --- a/session/module.go +++ b/session/module.go @@ -62,12 +62,13 @@ func (m SessionModule) ListParam(name string) (err error, values []string) { list := "" if err, list = m.StringParam(name); err != nil { return - } - parts := strings.Split(list, ",") - for _, part := range parts { - part = core.Trim(part) - if part != "" { - values = append(values, part) + } else { + parts := strings.Split(list, ",") + for _, part := range parts { + part = core.Trim(part) + if part != "" { + 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) } - return nil, v.(string) + } else { + return fmt.Errorf("Parameter %s does not exist.", name), "" } - 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) } - return nil, v.(int) + + } else { + return fmt.Errorf("Parameter %s does not exist.", name), 0 } - 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) } - return nil, v.(bool) } func (m *SessionModule) AddHandler(h ModuleHandler) { @@ -120,8 +127,9 @@ func (m *SessionModule) SetRunning(running bool, cb func()) error { if running == m.Running() { if m.Started { return ErrAlreadyStarted + } else { + return ErrAlreadyStopped } - return ErrAlreadyStopped } m.StatusLock.Lock() diff --git a/session/session_core_handlers.go b/session/session_core_handlers.go index d9f05279..05c281a8 100644 --- a/session/session_core_handlers.go +++ b/session/session_core_handlers.go @@ -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 } - 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) } - return fmt.Errorf("Could not find endpoint %s", mac) } func (s *Session) addHandler(h CommandHandler, c *readline.PrefixCompleter) {