2021-12-20 14:53:42 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2021-12-24 11:19:36 -05:00
|
|
|
"os/signal"
|
2021-12-22 07:01:30 -05:00
|
|
|
"pndpd/pndp"
|
2021-12-24 11:19:36 -05:00
|
|
|
"syscall"
|
2021-12-20 14:53:42 -05:00
|
|
|
)
|
|
|
|
|
2021-12-24 11:19:36 -05:00
|
|
|
// WaitForSignal Waits (blocking) for the program to be interrupted by the OS
|
|
|
|
func WaitForSignal() {
|
|
|
|
var sigCh = make(chan os.Signal)
|
|
|
|
signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)
|
|
|
|
<-sigCh
|
|
|
|
close(sigCh)
|
|
|
|
}
|
|
|
|
|
2021-12-20 14:53:42 -05:00
|
|
|
func main() {
|
2021-12-24 18:06:32 -05:00
|
|
|
fmt.Println("PNDPD Version 0.9 - Kioubit 2021")
|
2021-12-20 16:46:26 -05:00
|
|
|
|
2021-12-22 06:04:00 -05:00
|
|
|
if len(os.Args) <= 2 {
|
|
|
|
printUsage()
|
|
|
|
return
|
2021-12-20 14:53:42 -05:00
|
|
|
}
|
2021-12-22 06:04:00 -05:00
|
|
|
switch os.Args[1] {
|
|
|
|
case "respond":
|
2021-12-24 11:19:36 -05:00
|
|
|
var r *pndp.ResponderObj
|
2021-12-21 06:42:30 -05:00
|
|
|
if len(os.Args) == 4 {
|
2021-12-24 11:19:36 -05:00
|
|
|
r = pndp.NewResponder(os.Args[2], pndp.ParseFilter(os.Args[3]), "")
|
|
|
|
r.Start()
|
2021-12-21 06:42:30 -05:00
|
|
|
} else {
|
2021-12-24 11:19:36 -05:00
|
|
|
r = pndp.NewResponder(os.Args[2], nil, "")
|
|
|
|
fmt.Println("WARNING: You should use a whitelist unless you know what you are doing")
|
|
|
|
r.Start()
|
2021-12-21 06:42:30 -05:00
|
|
|
}
|
2021-12-24 11:19:36 -05:00
|
|
|
WaitForSignal()
|
|
|
|
r.Stop()
|
2021-12-22 06:04:00 -05:00
|
|
|
case "proxy":
|
2021-12-24 11:19:36 -05:00
|
|
|
var p *pndp.ProxyObj
|
|
|
|
if len(os.Args) == 5 {
|
|
|
|
p = pndp.NewProxy(os.Args[2], os.Args[3], pndp.ParseFilter(os.Args[4]), "")
|
|
|
|
} else {
|
|
|
|
p = pndp.NewProxy(os.Args[2], os.Args[3], nil, "")
|
|
|
|
}
|
|
|
|
WaitForSignal()
|
|
|
|
p.Stop()
|
|
|
|
case "config":
|
2021-12-21 06:42:30 -05:00
|
|
|
readConfig(os.Args[2])
|
2021-12-22 06:04:00 -05:00
|
|
|
default:
|
|
|
|
printUsage()
|
|
|
|
return
|
2021-12-21 06:00:28 -05:00
|
|
|
}
|
2021-12-24 11:19:36 -05:00
|
|
|
|
2021-12-22 06:04:00 -05:00
|
|
|
}
|
2021-12-20 16:46:26 -05:00
|
|
|
|
2021-12-22 06:04:00 -05:00
|
|
|
func printUsage() {
|
2021-12-24 11:19:36 -05:00
|
|
|
fmt.Println("Usage:")
|
|
|
|
fmt.Println("pndpd config <path to file>")
|
|
|
|
fmt.Println("pndpd respond <interface> <optional whitelist of CIDRs separated by a semicolon>")
|
|
|
|
fmt.Println("pndpd proxy <interface1> <interface2> <optional whitelist of CIDRs separated by a semicolon applied to interface2>")
|
|
|
|
fmt.Println("More options and additional documentation in the example config file")
|
2021-12-20 14:53:42 -05:00
|
|
|
}
|