prompts: stderr< + misc

This commit is contained in:
Callan Bryant 2020-03-02 21:36:41 +00:00
parent 8e29d1cba7
commit 1fdf4fe71f
No known key found for this signature in database
GPG Key ID: C31FA9DF3ACBFFAA
4 changed files with 12 additions and 6 deletions

8
add.go
View File

@ -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]

View File

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

View File

@ -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"`

View File

@ -19,7 +19,7 @@ func MustPromptString(prompt string, required bool) string {
var err error
for text == "" {
fmt.Printf("%s: ", prompt)
fmt.Fprintf(os.Stderr, "%s: ", prompt)
text, err = reader.ReadString('\n')
check(err)
text = strings.TrimSpace(text)