From 125f3c4e26686f099aac7a46a92a280fa726a7c6 Mon Sep 17 00:00:00 2001 From: Callan Bryant Date: Tue, 3 Mar 2020 21:28:06 +0000 Subject: [PATCH] working config generation --- README.md | 5 +++-- add.go | 29 +++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 748c437..8f4d266 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -dsnet is a simple tool to manage a wireguard VPN. Think wg-quick but quicker. +dsnet is a simple tool to manage a centralised wireguard VPN. Think wg-quick +but quicker. Usage: dsnet @@ -12,7 +13,7 @@ dsnet is a simple tool to manage a wireguard VPN. Think wg-quick but quicker. To remove an interface or bring it down, use standard tools such as iproute2. To modify or remove peers, edit /etc/dsnet-config.json and then run sync. - +Dsnet assumes a DNS server is running on the server. To send configurations, ffsend (with separately transferred password) or a local QR code generator may be used. diff --git a/add.go b/add.go index 0997ee8..ddd34ef 100644 --- a/add.go +++ b/add.go @@ -2,6 +2,8 @@ package dsnet import ( "net" + "os" + "text/template" ) func Add(hostname string, owner string, description string) { //, publicKey string) { @@ -30,19 +32,30 @@ func Add(hostname string, owner string, description string) { //, publicKey stri } conf.MustAddPeer(peer) + PrintPeerCfg(peer, conf) conf.MustSave() } -func GetPeerWgQuickConf(peer PeerConfig) string { - return `[Interface] -Address = 10.50.60.2/24 -PrivateKey={{ -DNS = 8.8.8.8 +func PrintPeerCfg(peer PeerConfig, conf *DsnetConfig) { + const peerConf = `[Interface] +Address = {{ index .Peer.AllowedIPs 0 }} +PrivateKey={{ .Peer.PrivateKey.Key }} +PresharedKey={{ .Peer.PresharedKey.Key }} +DNS = {{ .DsnetConfig.InternalDNS }} [Peer] -PublicKey=cAR+SMd+yvGw2TVzVSRoLtxF5TLA2Y/ceebO8ZAyITw= -Endpoint=3.9.82.135:51820 -AllowedIPs=0.0.0.0/0 +PublicKey={{ .DsnetConfig.PrivateKey.PublicKey.Key }} +PresharedKey={{ .DsnetConfig.PresharedKey.Key }} +Endpoint={{ .DsnetConfig.ExternalIP }}:{{ .DsnetConfig.ListenPort }} +#AllowedIPs=0.0.0.0/0 +AllowedIPs={{ .DsnetConfig.Network }} PersistentKeepalive=21 ` + + t := template.Must(template.New("peerConf").Parse(peerConf)) + err := t.Execute(os.Stdout, map[string]interface{}{ + "Peer": peer, + "DsnetConfig": conf, + }) + check(err) }