dsnet/cmd/dsnet.go

72 lines
1.3 KiB
Go
Raw Normal View History

2020-02-09 21:56:51 +01:00
package main
import (
2020-02-27 23:52:57 +01:00
"fmt"
2020-03-12 21:02:57 +01:00
"os"
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-03-07 19:59:34 +01:00
fmt.Printf(`dsnet is a simple tool to manage a centralised wireguard VPN.
2020-02-28 00:14:04 +01:00
Usage: dsnet <cmd>
2020-02-27 23:52:57 +01:00
Available commands:
init : Create %[1]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
report : Generate a JSON status report to the location configured in %[1]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
sync : Update wireguard configuration from %[1]s after validating
2020-03-05 21:43:31 +01:00
2020-10-19 01:04:05 +02:00
Environment variables:
2020-10-30 14:08:39 +01:00
DSNET_OUTPUT=wg-quick : The add command will generate a wg-quick config (default)
2020-10-19 01:04:05 +02:00
DSNET_OUTPUT=vyatta : The add command will generate a vyatta (edgeos) config
dsnet version %[2]s
commit %[3]s
built %[4]s
`, dsnet.CONFIG_FILE, dsnet.VERSION, dsnet.GIT_COMMIT, dsnet.BUILD_DATE)
2020-02-27 23:52:57 +01:00
}