mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-04-19 19:59:13 +03:00
Merge 05fd3a025c
into 2fdafd34ca
This commit is contained in:
commit
fbea9c29cf
1 changed files with 22 additions and 6 deletions
28
util/util.go
28
util/util.go
|
@ -62,13 +62,29 @@ func BuildClientConfig(client model.Client, server model.Server, setting model.G
|
||||||
|
|
||||||
desiredHost := setting.EndpointAddress
|
desiredHost := setting.EndpointAddress
|
||||||
desiredPort := server.Interface.ListenPort
|
desiredPort := server.Interface.ListenPort
|
||||||
if strings.Contains(desiredHost, ":") {
|
is_ipv4 := strings.Contains(desiredHost, ".")
|
||||||
split := strings.Split(desiredHost, ":")
|
if is_ipv4 {
|
||||||
desiredHost = split[0]
|
if strings.Contains(desiredHost, ":") {
|
||||||
if n, err := strconv.Atoi(split[1]); err == nil {
|
split := strings.Split(desiredHost, ":")
|
||||||
desiredPort = n
|
desiredHost = split[0]
|
||||||
|
if n, err := strconv.Atoi(split[1]); err == nil {
|
||||||
|
desiredPort = n
|
||||||
|
} else {
|
||||||
|
log.Error("Endpoint appears to be incorrectly formatted: ", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if strings.Contains(desiredHost, "]") {
|
||||||
|
// IPv6 with port
|
||||||
|
split := strings.Split(desiredHost, "]")
|
||||||
|
desiredHost = split[0] + "]"
|
||||||
|
if n, err := strconv.Atoi(split[1][1:]); err == nil {
|
||||||
|
desiredPort = n
|
||||||
|
} else {
|
||||||
|
log.Error("Endpoint appears to be incorrectly formatted: ", err)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Error("Endpoint appears to be incorrectly formatted: ", err)
|
desiredHost = "[" + desiredHost + "]"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
peerEndpoint := fmt.Sprintf("Endpoint = %s:%d\n", desiredHost, desiredPort)
|
peerEndpoint := fmt.Sprintf("Endpoint = %s:%d\n", desiredHost, desiredPort)
|
||||||
|
|
Loading…
Add table
Reference in a new issue