Add Verbosity argument to suppress spammage
This commit is contained in:
parent
dbcb695de4
commit
46ffc2d2df
23
knockr.go
23
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()
|
||||
|
Loading…
Reference in New Issue
Block a user