working config generation

This commit is contained in:
Callan Bryant 2020-03-03 21:28:06 +00:00
parent 8f2ac50590
commit 125f3c4e26
No known key found for this signature in database
GPG Key ID: C31FA9DF3ACBFFAA
2 changed files with 24 additions and 10 deletions

View File

@ -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 <cmd>
@ -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.

29
add.go
View File

@ -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)
}