dsnet/cmd/dsnet.go

69 lines
1.1 KiB
Go
Raw Normal View History

2020-02-09 21:56:51 +01:00
package main
import (
"os"
2020-02-27 23:52:57 +01:00
"fmt"
2020-02-09 21:56:51 +01:00
"github.com/naggie/dsnet"
)
func main() {
2020-02-28 00:22:32 +01:00
var cmd string
2020-02-09 21:56:51 +01:00
2020-02-28 00:22:32 +01:00
if len(os.Args) == 1 {
cmd = "help"
} else {
cmd = os.Args[1]
}
2020-02-20 21:02:56 +01:00
2020-02-28 00:22:32 +01:00
switch cmd {
2020-03-02 00:08:10 +01:00
case "init":
dsnet.Init()
2020-02-20 21:02:56 +01:00
2020-03-02 00:08:10 +01:00
case "add":
2020-03-03 23:33:48 +01:00
dsnet.Add()
2020-02-20 21:02:56 +01:00
2020-03-02 01:48:59 +01:00
case "up":
2020-03-04 20:56:57 +01:00
dsnet.Up()
2020-03-02 01:48:59 +01:00
case "sync":
dsnet.Sync()
2020-03-02 01:48:59 +01:00
2020-03-02 00:08:10 +01:00
case "report":
2020-03-04 23:49:27 +01:00
dsnet.Report()
2020-02-20 21:02:56 +01:00
2020-03-05 21:35:51 +01:00
case "remove":
dsnet.Remove()
2020-03-02 00:08:10 +01:00
case "down":
2020-03-04 23:11:08 +01:00
dsnet.Down()
2020-02-20 21:02:56 +01:00
2020-03-02 00:08:10 +01:00
default:
help()
2020-02-20 21:02:56 +01:00
}
2020-02-09 21:56:51 +01:00
}
2020-02-27 23:52:57 +01:00
func help() {
2020-02-28 00:14:04 +01:00
fmt.Printf(`dsnet is a simple tool to manage a wireguard VPN.
Usage: dsnet <cmd>
2020-02-27 23:52:57 +01:00
Available commands:
2020-02-28 00:14:04 +01:00
init : Create %s containing default configuration + new keys without loading. Edit to taste.
2020-03-05 21:43:31 +01:00
add : Add a new peer + sync
up : Create the interface, run pre/post up, sync
2020-03-05 21:43:31 +01:00
sync : Update wireguard configuration from %s after validating
2020-02-28 00:22:32 +01:00
report : Generate a JSON status report to the location configured in %s.
2020-03-05 21:43:31 +01:00
remove : Remove a peer by hostname provided as argument + sync
2020-03-02 01:48:59 +01:00
down : Destroy the interface, run pre/post down
2020-02-27 23:52:57 +01:00
2020-03-05 21:43:31 +01:00
Examples:
dsnet add > dsnet.conf
`, dsnet.CONFIG_FILE, dsnet.CONFIG_FILE, dsnet.CONFIG_FILE)
2020-02-27 23:52:57 +01:00
}