sync on add/remove

This commit is contained in:
Callan Bryant 2020-03-05 20:43:31 +00:00
parent 0380753104
commit 586292a25a
No known key found for this signature in database
GPG Key ID: C31FA9DF3ACBFFAA
3 changed files with 16 additions and 5 deletions

5
add.go
View File

@ -2,6 +2,7 @@ package dsnet
import ( import (
"os" "os"
"fmt"
"text/template" "text/template"
) )
@ -16,6 +17,9 @@ func Add() {
//publicKey := MustPromptString("PublicKey (optional)", false) //publicKey := MustPromptString("PublicKey (optional)", false)
ConfirmOrAbort("\nDo you want to add the above configuration?") ConfirmOrAbort("\nDo you want to add the above configuration?")
// newline (not on stdout) to separate config
fmt.Fprintln(os.Stderr)
privateKey := GenerateJSONPrivateKey() privateKey := GenerateJSONPrivateKey()
publicKey := privateKey.PublicKey() publicKey := privateKey.PublicKey()
@ -35,6 +39,7 @@ func Add() {
conf.MustAddPeer(peer) conf.MustAddPeer(peer)
PrintPeerCfg(peer, conf) PrintPeerCfg(peer, conf)
conf.MustSave() conf.MustSave()
ConfigureDevice(conf)
} }
func PrintPeerCfg(peer PeerConfig, conf *DsnetConfig) { func PrintPeerCfg(peer PeerConfig, conf *DsnetConfig) {

View File

@ -50,14 +50,19 @@ Usage: dsnet <cmd>
Available commands: Available commands:
init : Create %s containing default configuration + new keys without loading. Edit to taste. init : Create %s containing default configuration + new keys without loading. Edit to taste.
add : Generate configuration for a new peer, adding to %s. Send with passworded ffsend. add : Add a new peer + sync
up : Create the interface, run pre/post up, sync up : Create the interface, run pre/post up, sync
sync : Update wireguard configuration with %s, adding/removing peers after validating matching config sync : Update wireguard configuration from %s after validating
report : Generate a JSON status report to the location configured in %s. report : Generate a JSON status report to the location configured in %s.
remove : Remove a peer by hostname provided as argument + sync
down : Destroy the interface, run pre/post down down : Destroy the interface, run pre/post down
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.
`, dsnet.CONFIG_FILE, dsnet.CONFIG_FILE, dsnet.CONFIG_FILE, dsnet.CONFIG_FILE, dsnet.CONFIG_FILE) Examples:
dsnet add > dsnet.conf
`, dsnet.CONFIG_FILE, dsnet.CONFIG_FILE, dsnet.CONFIG_FILE)
} }

View File

@ -12,4 +12,5 @@ func Remove() {
hostname := os.Args[2] hostname := os.Args[2]
conf.MustRemovePeer(hostname) conf.MustRemovePeer(hostname)
conf.MustSave() conf.MustSave()
ConfigureDevice(conf)
} }