luci-proto-wireguard: fixed incorrect peer detection if port is not set
authorTom Haley <this_username_has_been_taken2@proton.me>
Thu, 5 Dec 2024 07:27:38 +0000 (10:27 +0300)
committerPaul Donald <newtwen+github@gmail.com>
Thu, 5 Dec 2024 17:09:39 +0000 (18:09 +0100)
Fixed incorrect peer detection if port is not set (default port is used)

Signed-off-by: Tom Haley <this_username_has_been_taken2@proton.me>
protocols/luci-proto-wireguard/root/usr/share/rpcd/ucode/luci.wireguard

index 4d2a5912b7b518f75c0c2abff9b4a8380fd3013e..32acbb639d2614b7fe4e8b0428b861e56c1d4b9d 100644 (file)
@@ -21,7 +21,9 @@ function checkPeerHost(configHost, configPort, wgHost) {
        if (ips) {
                for (let line = ips.read('line'); length(line); line = ips.read('line')) {
                        const ip =  rtrim(line, '\n');
-                       if (ip + ":" + configPort == hostIp) {
+                       if (configPort && (ip + ":" + configPort == hostIp)) {
+                               return true;
+                       } else if (ip == substr(hostIp, 0, index(hostIp, ":"))) {
                                return true;
                        }
                }
@@ -29,7 +31,6 @@ function checkPeerHost(configHost, configPort, wgHost) {
        return false;
 }
 
-
 const methods = {
        generatePsk: {
                call: function() {