Added option to publish forwarded port to clients.

This commit is contained in:
Ilya Pavkin 2021-06-05 18:00:58 +03:00
parent 024aadbfd2
commit 3e1210ba9d

View file

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"net" "net"
"os" "os"
"strconv"
"strings" "strings"
"text/template" "text/template"
"time" "time"
@ -27,7 +28,18 @@ func BuildClientConfig(client model.Client, server model.Server, setting model.G
peerPublicKey := fmt.Sprintf("PublicKey = %s", server.KeyPair.PublicKey) peerPublicKey := fmt.Sprintf("PublicKey = %s", server.KeyPair.PublicKey)
peerPresharedKey := fmt.Sprintf("PresharedKey = %s", client.PresharedKey) peerPresharedKey := fmt.Sprintf("PresharedKey = %s", client.PresharedKey)
peerAllowedIPs := fmt.Sprintf("AllowedIPs = %s", strings.Join(client.AllowedIPs, ",")) peerAllowedIPs := fmt.Sprintf("AllowedIPs = %s", strings.Join(client.AllowedIPs, ","))
peerEndpoint := fmt.Sprintf("Endpoint = %s:%d", setting.EndpointAddress, server.Interface.ListenPort)
desiredHost := setting.EndpointAddress
desiredPort := server.Interface.ListenPort
if strings.Contains(desiredHost, ":") {
split := strings.Split(desiredHost, ":")
desiredHost = split[0]
if n, err := strconv.Atoi(split[1]); err == nil {
desiredPort = n
}
}
peerEndpoint := fmt.Sprintf("Endpoint = %s:%d", desiredHost, desiredPort)
peerPersistentKeepalive := fmt.Sprintf("PersistentKeepalive = %d", setting.PersistentKeepalive) peerPersistentKeepalive := fmt.Sprintf("PersistentKeepalive = %d", setting.PersistentKeepalive)
// build the config as string // build the config as string