dsnet/cmd/dsnet.go

65 lines
1.6 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-02 03:16:53 +01:00
// TODO maybe accept flags to avoid prompt and allow programmatic use
2020-03-02 03:18:15 +01:00
hostname := dsnet.MustPromptString("Hostname (unique)", true)
2020-03-02 03:16:53 +01:00
owner := dsnet.MustPromptString("owner", true)
description := dsnet.MustPromptString("Description", true)
//publicKey := dsnet.MustPromptString("PublicKey (optional)", false)
2020-03-02 03:16:53 +01:00
dsnet.ConfirmOrAbort("\nDo you want to add the above configuration?")
dsnet.Add(hostname, owner, description)//, publicKey)
2020-02-20 21:02:56 +01:00
2020-03-02 01:48:59 +01:00
case "up":
case "update":
2020-03-02 00:08:10 +01:00
case "report":
2020-02-20 21:02:56 +01:00
2020-03-02 00:08:10 +01:00
case "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-02-28 00:22:32 +01:00
add : Generate configuration for a new peer, adding to %s. Send with passworded ffsend.
2020-03-02 01:48:59 +01:00
up : Create the interface, run pre/post up, update
update : Update wireguard configuration with %s, adding/removing peers after validating matching config
2020-02-28 00:22:32 +01:00
report : Generate a JSON status report to the location configured in %s.
2020-03-02 01:48:59 +01:00
down : Destroy the interface, run pre/post down
2020-02-27 23:52:57 +01:00
To remove an interface or bring it down, use standard tools such as iproute2.
To modify or remove peers, edit %s and then run sync.
2020-02-28 00:22:32 +01:00
`, dsnet.CONFIG_FILE, dsnet.CONFIG_FILE, dsnet.CONFIG_FILE, dsnet.CONFIG_FILE, dsnet.CONFIG_FILE)
2020-02-27 23:52:57 +01:00
}