Add Argument parser and flexible ports and destination

This commit is contained in:
maride 2017-09-27 23:56:07 +02:00
parent 44573d328b
commit ab34e62ff0

View File

@ -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 {