From 46ffc2d2dfa761eb78346cd9ff25f0d0f0e4967e Mon Sep 17 00:00:00 2001 From: maride Date: Thu, 28 Sep 2017 15:09:29 +0200 Subject: [PATCH] Add Verbosity argument to suppress spammage --- knockr.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/knockr.go b/knockr.go index 47f35bf..0f99a9f 100644 --- a/knockr.go +++ b/knockr.go @@ -15,6 +15,7 @@ type knockArguments struct { BlacklistPort int `cli:'wp' usage:'If set: The port to blacklist the connected host'` Destination string `cli:'d' usage:'The destination to relay traffic to'` Timeout int64 `cli:'t' usage:'Time in seconds after which a whitelist entry will be removed'` + Verbose bool `cli:'v' usage:'Verbosity'` } var ( @@ -71,7 +72,9 @@ func whitelist_handler(c net.Conn) { host, _, _ := net.SplitHostPort(c.RemoteAddr().String()) if is_blacklisted(host) { - fmt.Println("[BLK] Denying blacklisted host ", host) + if arguments.Verbose { + fmt.Println("[BLK] Denying blacklisted host ", host) + } } else { io.WriteString(c, fmt.Sprintf("Knock Knock, %s.", host)) add_to_whitelist(host) @@ -85,10 +88,14 @@ func blacklist_handler(c net.Conn) { host, _, _ := net.SplitHostPort(c.RemoteAddr().String()) if ! is_whitelisted(host) { - fmt.Println("[BLK] Blacklisting ", host) + if arguments.Verbose { + fmt.Println("[BLK] Blacklisting ", host) + } add_to_blacklist(host) } else { - fmt.Println("[ERR] Whitelisted host ", host, " connected to blacklist port. Ignoring.") + if arguments.Verbose { + fmt.Println("[ERR] Whitelisted host ", host, " connected to blacklist port. Ignoring.") + } } c.Close() } @@ -98,9 +105,13 @@ func gateway_handler(c net.Conn) { host, _, _ := net.SplitHostPort(c.RemoteAddr().String()) if is_blacklisted(host) { - fmt.Println("[BLK] Blacklisted host ", host, ", ignoring") + if arguments.Verbose { + fmt.Println("[BLK] Blacklisted host ", host, ", ignoring") + } } else if is_whitelisted(host) { - fmt.Println("[OK ] Whitelisted host ", host, " connected") + if arguments.Verbose { + fmt.Println("[OK ] Whitelisted host ", host, " connected") + } update_whitelist_time(host) proxy(c) update_whitelist_time(host) @@ -110,7 +121,7 @@ func gateway_handler(c net.Conn) { // This won't affect this connection (it'll stay open even if the timeout is reached) // but another connection won't be possible, even if it's right after the closing of // the first connection. ¯\_(ツ)_/¯ - } else { + } else if arguments.Verbose { fmt.Println("[BLK] Blocking host ", host) } c.Close()