working config generation
This commit is contained in:
parent
8f2ac50590
commit
125f3c4e26
@ -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>
|
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 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.
|
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.
|
To send configurations, ffsend (with separately transferred password) or a local QR code generator may be used.
|
||||||
|
|
||||||
|
29
add.go
29
add.go
@ -2,6 +2,8 @@ package dsnet
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
|
"text/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Add(hostname string, owner string, description string) { //, publicKey string) {
|
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)
|
conf.MustAddPeer(peer)
|
||||||
|
PrintPeerCfg(peer, conf)
|
||||||
conf.MustSave()
|
conf.MustSave()
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPeerWgQuickConf(peer PeerConfig) string {
|
func PrintPeerCfg(peer PeerConfig, conf *DsnetConfig) {
|
||||||
return `[Interface]
|
const peerConf = `[Interface]
|
||||||
Address = 10.50.60.2/24
|
Address = {{ index .Peer.AllowedIPs 0 }}
|
||||||
PrivateKey={{
|
PrivateKey={{ .Peer.PrivateKey.Key }}
|
||||||
DNS = 8.8.8.8
|
PresharedKey={{ .Peer.PresharedKey.Key }}
|
||||||
|
DNS = {{ .DsnetConfig.InternalDNS }}
|
||||||
|
|
||||||
[Peer]
|
[Peer]
|
||||||
PublicKey=cAR+SMd+yvGw2TVzVSRoLtxF5TLA2Y/ceebO8ZAyITw=
|
PublicKey={{ .DsnetConfig.PrivateKey.PublicKey.Key }}
|
||||||
Endpoint=3.9.82.135:51820
|
PresharedKey={{ .DsnetConfig.PresharedKey.Key }}
|
||||||
AllowedIPs=0.0.0.0/0
|
Endpoint={{ .DsnetConfig.ExternalIP }}:{{ .DsnetConfig.ListenPort }}
|
||||||
|
#AllowedIPs=0.0.0.0/0
|
||||||
|
AllowedIPs={{ .DsnetConfig.Network }}
|
||||||
PersistentKeepalive=21
|
PersistentKeepalive=21
|
||||||
`
|
`
|
||||||
|
|
||||||
|
t := template.Must(template.New("peerConf").Parse(peerConf))
|
||||||
|
err := t.Execute(os.Stdout, map[string]interface{}{
|
||||||
|
"Peer": peer,
|
||||||
|
"DsnetConfig": conf,
|
||||||
|
})
|
||||||
|
check(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user