prompts: stderr< + misc
This commit is contained in:
parent
8e29d1cba7
commit
1fdf4fe71f
8
add.go
8
add.go
@ -8,7 +8,6 @@ func Add(hostname string, owner string, description string) { //, publicKey stri
|
||||
conf := MustLoadDsnetConfig()
|
||||
|
||||
privateKey := GenerateJSONPrivateKey()
|
||||
presharedKey := GenerateJSONKey()
|
||||
publicKey := privateKey.PublicKey()
|
||||
|
||||
IP := conf.MustAllocateIP()
|
||||
@ -18,7 +17,8 @@ func Add(hostname string, owner string, description string) { //, publicKey stri
|
||||
Hostname: hostname,
|
||||
Description: description,
|
||||
PublicKey: publicKey,
|
||||
PresharedKey: presharedKey,
|
||||
PrivateKey: privateKey, // omitted from server config JSON!
|
||||
PresharedKey: GenerateJSONKey(),
|
||||
AllowedIPs: []JSONIPNet{
|
||||
JSONIPNet{
|
||||
IPNet: net.IPNet{
|
||||
@ -33,10 +33,10 @@ func Add(hostname string, owner string, description string) { //, publicKey stri
|
||||
conf.MustSave()
|
||||
}
|
||||
|
||||
func GetPeerWgQuickConf(peer PeerConfig, privKey JSONKey) string {
|
||||
func GetPeerWgQuickConf(peer PeerConfig) string {
|
||||
return `[Interface]
|
||||
Address = 10.50.60.2/24
|
||||
PrivateKey=REDACTED
|
||||
PrivateKey={{
|
||||
DNS = 8.8.8.8
|
||||
|
||||
[Peer]
|
||||
|
7
init.go
7
init.go
@ -46,6 +46,7 @@ func getRandomNetwork() JSONIPNet {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO support IPv6
|
||||
func getExternalIP() net.IP {
|
||||
conn, _ := net.Dial("udp", "8.8.8.8:80")
|
||||
defer conn.Close()
|
||||
@ -53,6 +54,10 @@ func getExternalIP() net.IP {
|
||||
localAddr := conn.LocalAddr().String()
|
||||
IP := net.ParseIP(strings.Split(localAddr, ":")[0])
|
||||
|
||||
if !(IP[0] == 10 || (IP[0] == 172 && IP[1] >= 16 && IP[1] <= 31) || (IP[0] == 192 && IP[1] == 168)) {
|
||||
// not private, so public
|
||||
return IP
|
||||
}
|
||||
// TODO detect private IP and use icanhazip.com instead
|
||||
return IP
|
||||
return net.IP{}
|
||||
}
|
||||
|
1
types.go
1
types.go
@ -20,6 +20,7 @@ type PeerConfig struct {
|
||||
Description string `validate:"required,gte=1,lte=255"`
|
||||
|
||||
PublicKey JSONKey `validate:"required,len=44"`
|
||||
PrivateKey JSONKey `json:"-"` // omitted from config!
|
||||
PresharedKey JSONKey `validate:"required,len=44"`
|
||||
// TODO endpoint support
|
||||
//Endpoint net.UDPAddr `validate:"required,udp4_addr"`
|
||||
|
Loading…
Reference in New Issue
Block a user