luci-proto-wireguard: fixed incorrect peer name detection
authorthis-username-has-been-taken <[email protected]>
Sun, 13 Apr 2025 13:38:46 +0000 (16:38 +0300)
committerPaul Donald <[email protected]>
Sun, 13 Apr 2025 14:17:49 +0000 (16:17 +0200)
Added the legacy peer name detection algorithm. If the new algorithm
fails to find a peer's name (e.g. when the IP address has been changed)
then the legacy value will be used.

Signed-off-by: Tom Haley <[email protected]>
(cherry picked from commit 8bff54dc47057e36c0ceb263efe4c82580003924)
(cherry picked from commit f8dea77b35f082fc7e326f3207560164ebc2b7e3)

protocols/luci-proto-wireguard/root/usr/share/rpcd/ucode/luci.wireguard

index 55f0bba2a9432d13ce858e447eff5b9234c1dd3c..b8e20daf94c2d4fa5d133c227f8882dd0b23eb2e 100644 (file)
@@ -89,12 +89,17 @@ const methods = {
                                        }
                                        else {
                                                let peer_name;
+                                               let peer_name_legacy;
 
                                                uci.foreach('network', `wireguard_${last_device}`, (s) => {
                                                        if (!s.disabled && s.public_key == record[1] && (!s.endpoint_host || checkPeerHost(s.endpoint_host, s.endpoint_port, record[3])))
                                                                peer_name = s.description;
+                                                       if (s.public_key == record[1])
+                                                               peer_name_legacy = s.description;
                                                });
 
+                                               if (!peer_name) peer_name = peer_name_legacy;
+
                                                const peer = {
                                                        name: peer_name,
                                                        public_key: record[1],