2020-03-02 01:45:14 +01:00
|
|
|
package dsnet
|
|
|
|
|
2020-03-02 20:13:47 +01:00
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
)
|
|
|
|
|
2020-03-02 20:03:00 +01:00
|
|
|
func Add(hostname string, owner string, description string) { //, publicKey string) {
|
2020-03-02 04:08:28 +01:00
|
|
|
conf := MustLoadDsnetConfig()
|
|
|
|
|
|
|
|
privateKey := GenerateJSONPrivateKey()
|
|
|
|
publicKey := privateKey.PublicKey()
|
|
|
|
|
2020-03-02 21:11:33 +01:00
|
|
|
IP := conf.MustAllocateIP()
|
2020-03-02 19:44:19 +01:00
|
|
|
|
2020-03-02 04:08:28 +01:00
|
|
|
peer := PeerConfig{
|
2020-03-02 20:03:00 +01:00
|
|
|
Owner: owner,
|
|
|
|
Hostname: hostname,
|
|
|
|
Description: description,
|
|
|
|
PublicKey: publicKey,
|
2020-03-02 22:36:41 +01:00
|
|
|
PrivateKey: privateKey, // omitted from server config JSON!
|
|
|
|
PresharedKey: GenerateJSONKey(),
|
2020-03-02 20:26:08 +01:00
|
|
|
AllowedIPs: []JSONIPNet{
|
|
|
|
JSONIPNet{
|
2020-03-02 20:13:47 +01:00
|
|
|
IPNet: net.IPNet{
|
2020-03-02 20:26:08 +01:00
|
|
|
IP: IP,
|
2020-03-02 22:39:45 +01:00
|
|
|
Mask: net.CIDRMask(32, 32),
|
2020-03-02 20:13:47 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-03-02 04:08:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
conf.MustAddPeer(peer)
|
|
|
|
conf.MustSave()
|
2020-03-02 01:45:14 +01:00
|
|
|
}
|
2020-03-02 20:57:52 +01:00
|
|
|
|
2020-03-02 22:36:41 +01:00
|
|
|
func GetPeerWgQuickConf(peer PeerConfig) string {
|
2020-03-02 20:57:52 +01:00
|
|
|
return `[Interface]
|
|
|
|
Address = 10.50.60.2/24
|
2020-03-02 22:36:41 +01:00
|
|
|
PrivateKey={{
|
2020-03-02 20:57:52 +01:00
|
|
|
DNS = 8.8.8.8
|
|
|
|
|
|
|
|
[Peer]
|
|
|
|
PublicKey=cAR+SMd+yvGw2TVzVSRoLtxF5TLA2Y/ceebO8ZAyITw=
|
|
|
|
Endpoint=3.9.82.135:51820
|
|
|
|
AllowedIPs=0.0.0.0/0
|
|
|
|
PersistentKeepalive=21
|
|
|
|
`
|
|
|
|
}
|