diff --git a/knockr.go b/knockr.go index 1cfa0e1..6cce622 100644 --- a/knockr.go +++ b/knockr.go @@ -4,13 +4,27 @@ import ( "fmt" "io" "net" + "github.com/mkideal/cli" ) +type knockArguments struct { + cli.Helper + WhitelistPort int `cli:'wp' usage:'The port to launch the whitelist server on'` + GatewayPort int `cli:'gp' usage:'The port to protect'` + Destination string `cli:'d' usage:'The destination to relay traffic to'` +} + var whitelist []string +var arguments *knockArguments func main() { - go listener(9090, whitelist_handler) - listener(8080, gateway_handler) + cli.Run(new(knockArguments), func(ctx *cli.Context) error { + arguments = ctx.Argv() . (*knockArguments) + return nil + }) + + go listener(arguments.WhitelistPort, whitelist_handler) + listener(arguments.GatewayPort, gateway_handler) } func listener(port int, listen_func func(c net.Conn)) { @@ -68,7 +82,7 @@ func is_whitelisted(addr string) bool { } func proxy(c net.Conn) { - ln, err := net.Dial("tcp", "ip.darknebu.la:443") + ln, err := net.Dial("tcp", arguments.Destination) if err != nil { fmt.Println("[ERR] Proxy connection to server failed") } else {