luci-proto-wireguard: Fix incorrect peer detection for IP v6
authorTom Haley <this_username_has_been_taken2@proton.me>
Mon, 2 Dec 2024 15:40:32 +0000 (18:40 +0300)
committerPaul Donald <newtwen+github@gmail.com>
Mon, 2 Dec 2024 17:22:15 +0000 (18:22 +0100)
This commit fixes incorrect peer detection when using IP v6 by deleting all the square the square brackets from the wgHost variable.

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

index c177da4773a6a5bdf6753767eff9f303c616e1aa..5ffcfd85a274def33b10ed5ee0288cdd4d1db5cb 100644 (file)
@@ -17,10 +17,11 @@ function command(cmd) {
 
 function checkPeerHost(configHost, configPort, wgHost) {
        const ips = popen(`resolveip ${configHost} 2>/dev/null`);
+       const hostIp = replace(wgHost, /\[|\]/g, "");
        if (ips) {
                for (let line = ips.read('line'); length(line); line = ips.read('line')) {
                        const ip =  rtrim(line, '\n');
-                       if (ip + ":" + configPort == wgHost) {
+                       if (ip + ":" + configPort == hostIp) {
                                return true;
                        }
                }