Pndpd/main.go

64 lines
1.5 KiB
Go
Raw Normal View History

2021-12-20 14:53:42 -05:00
package main
import (
"fmt"
"os"
"os/signal"
2021-12-22 07:01:30 -05:00
"pndpd/pndp"
"syscall"
2021-12-20 14:53:42 -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 16:46:45 -05:00
fmt.Println("PNDPD Version 0.6 - 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":
var r *pndp.ResponderObj
2021-12-21 06:42:30 -05:00
if len(os.Args) == 4 {
r = pndp.NewResponder(os.Args[2], pndp.ParseFilter(os.Args[3]), "")
r.Start()
2021-12-21 06:42:30 -05:00
} else {
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
}
WaitForSignal()
r.Stop()
2021-12-22 06:04:00 -05:00
case "proxy":
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-22 06:04:00 -05:00
}
2021-12-20 16:46:26 -05:00
2021-12-22 06:04:00 -05:00
func printUsage() {
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
}