luci-proto-wireguard: fixed incorrect peer detection for ipv6 and default port

Fixed incorrect peer detection if IP v6 is used and no port for peer is defined.

Signed-off-by: Tom Haley <this_username_has_been_taken2@proton.me>
This commit is contained in:
Tom Haley
2024-12-05 10:54:19 +03:00
committed by Paul Donald
parent 27ecfdaafe
commit 461d632d5c

View File

@@ -20,10 +20,10 @@ function checkPeerHost(configHost, configPort, wgHost) {
const hostIp = replace(wgHost, /\[|\]/g, "");
if (ips) {
for (let line = ips.read('line'); length(line); line = ips.read('line')) {
const ip = rtrim(line, '\n');
const ip = rtrim(line, '\n');
if (configPort && (ip + ":" + configPort == hostIp)) {
return true;
} else if (ip == substr(hostIp, 0, index(hostIp, ":"))) {
} else if (ip == substr(hostIp, 0, rindex(hostIp, ":"))) {
return true;
}
}