Add Verbosity argument to suppress spammage

This commit is contained in:
maride 2017-09-28 15:09:29 +02:00
parent dbcb695de4
commit 46ffc2d2df

View File

@ -15,6 +15,7 @@ type knockArguments struct {
BlacklistPort int `cli:'wp' usage:'If set: The port to blacklist the connected host'` 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'` 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'` Timeout int64 `cli:'t' usage:'Time in seconds after which a whitelist entry will be removed'`
Verbose bool `cli:'v' usage:'Verbosity'`
} }
var ( var (
@ -71,7 +72,9 @@ func whitelist_handler(c net.Conn) {
host, _, _ := net.SplitHostPort(c.RemoteAddr().String()) host, _, _ := net.SplitHostPort(c.RemoteAddr().String())
if is_blacklisted(host) { if is_blacklisted(host) {
fmt.Println("[BLK] Denying blacklisted host ", host) if arguments.Verbose {
fmt.Println("[BLK] Denying blacklisted host ", host)
}
} else { } else {
io.WriteString(c, fmt.Sprintf("Knock Knock, %s.", host)) io.WriteString(c, fmt.Sprintf("Knock Knock, %s.", host))
add_to_whitelist(host) add_to_whitelist(host)
@ -85,10 +88,14 @@ func blacklist_handler(c net.Conn) {
host, _, _ := net.SplitHostPort(c.RemoteAddr().String()) host, _, _ := net.SplitHostPort(c.RemoteAddr().String())
if ! is_whitelisted(host) { if ! is_whitelisted(host) {
fmt.Println("[BLK] Blacklisting ", host) if arguments.Verbose {
fmt.Println("[BLK] Blacklisting ", host)
}
add_to_blacklist(host) add_to_blacklist(host)
} else { } 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() c.Close()
} }
@ -98,9 +105,13 @@ func gateway_handler(c net.Conn) {
host, _, _ := net.SplitHostPort(c.RemoteAddr().String()) host, _, _ := net.SplitHostPort(c.RemoteAddr().String())
if is_blacklisted(host) { 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) { } 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) update_whitelist_time(host)
proxy(c) proxy(c)
update_whitelist_time(host) 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) // 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 // but another connection won't be possible, even if it's right after the closing of
// the first connection. ¯\_(ツ)_/¯ // the first connection. ¯\_(ツ)_/¯
} else { } else if arguments.Verbose {
fmt.Println("[BLK] Blocking host ", host) fmt.Println("[BLK] Blocking host ", host)
} }
c.Close() c.Close()