mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-04-19 19:59:13 +03:00
Port forwarding for server (#69)
This commit is contained in:
parent
2fa4ca32ab
commit
de0c9fd26b
1 changed files with 16 additions and 1 deletions
17
util/util.go
17
util/util.go
|
@ -6,12 +6,14 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
rice "github.com/GeertJohan/go.rice"
|
rice "github.com/GeertJohan/go.rice"
|
||||||
externalip "github.com/glendc/go-external-ip"
|
externalip "github.com/glendc/go-external-ip"
|
||||||
|
"github.com/labstack/gommon/log"
|
||||||
"github.com/ngoduykhanh/wireguard-ui/model"
|
"github.com/ngoduykhanh/wireguard-ui/model"
|
||||||
"github.com/sdomino/scribble"
|
"github.com/sdomino/scribble"
|
||||||
)
|
)
|
||||||
|
@ -27,7 +29,20 @@ 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
|
||||||
|
} else {
|
||||||
|
log.Error("Endpoint appears to be incorrectly formated: ", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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
|
||||||
|
|
Loading…
Add table
Reference in a new issue