Pndpd/main.go

88 lines
2.1 KiB
Go
Raw Normal View History

2021-12-20 14:53:42 -05:00
package main
import (
"fmt"
"os"
"os/signal"
2021-12-25 09:28:59 -05:00
"pndpd/modules"
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-26 11:53:27 +01:00
fmt.Println("PNDPD Version 1.1 - Kioubit 2021")
2021-12-25 09:28:59 -05:00
if modules.ModuleList != nil {
2021-12-25 13:03:11 -05:00
fmt.Print("Loaded Modules: Core ")
2021-12-25 09:28:59 -05:00
for i := range modules.ModuleList {
fmt.Print((*modules.ModuleList[i]).Name + " ")
}
fmt.Println()
}
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, "")
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:
2021-12-25 09:28:59 -05:00
for i := range modules.ModuleList {
2021-12-25 13:03:11 -05:00
for d := range (*modules.ModuleList[i]).Option {
if (*modules.ModuleList[i]).Option[d].Option == os.Args[1] {
(*modules.ModuleList[i]).Callback(modules.Callback{
CallbackType: modules.CommandLine,
Option: os.Args[1],
Arguments: os.Args[1:],
})
return
}
2021-12-25 09:28:59 -05:00
}
}
2021-12-22 06:04:00 -05:00
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() {
2021-12-25 13:03:11 -05:00
fmt.Println("More options and additional documentation in the example config file")
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>")
2021-12-25 13:03:11 -05:00
for i := range modules.ModuleList {
for d := range (*modules.ModuleList[i]).Option {
fmt.Println((*modules.ModuleList[i]).Option[d].Description)
}
}
2021-12-20 14:53:42 -05:00
}