2020-02-09 21:56:51 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2020-03-02 01:45:14 +01:00
|
|
|
"flag"
|
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-03-02 01:45:14 +01:00
|
|
|
addCmd := flag.NewFlagSet("add", flag.ExitOnError)
|
2020-03-02 02:35:59 +01:00
|
|
|
hostname := addCmd.String("hostname", "", "Hostname of device")
|
|
|
|
owner := addCmd.String("owner", "", "Username of owner of device")
|
|
|
|
description := addCmd.String("description", "", "Information about device")
|
|
|
|
publicKey := addCmd.String("publicKey", "", "Optional existing public key of device")
|
2020-03-02 01:45:14 +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 02:35:59 +01:00
|
|
|
addCmd.PrintDefaults()
|
|
|
|
addCmd.Parse(os.Args[2:])
|
|
|
|
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
|
|
|
}
|