summaryrefslogtreecommitdiffhomepage
path: root/protocols
diff options
context:
space:
mode:
Diffstat (limited to 'protocols')
-rw-r--r--protocols/luci-proto-wireguard/Makefile2
-rw-r--r--protocols/luci-proto-wireguard/root/usr/share/rpcd/ucode/luci.wireguard15
2 files changed, 15 insertions, 2 deletions
diff --git a/protocols/luci-proto-wireguard/Makefile b/protocols/luci-proto-wireguard/Makefile
index 58aa34acd8..25bf7a69dc 100644
--- a/protocols/luci-proto-wireguard/Makefile
+++ b/protocols/luci-proto-wireguard/Makefile
@@ -7,7 +7,7 @@
include $(TOPDIR)/rules.mk
LUCI_TITLE:=Support for WireGuard VPN
-LUCI_DEPENDS:=+wireguard-tools +ucode +luci-lib-uqr
+LUCI_DEPENDS:=+wireguard-tools +ucode +luci-lib-uqr +resolveip
LUCI_PKGARCH:=all
PKG_LICENSE:=Apache-2.0
diff --git a/protocols/luci-proto-wireguard/root/usr/share/rpcd/ucode/luci.wireguard b/protocols/luci-proto-wireguard/root/usr/share/rpcd/ucode/luci.wireguard
index add810c8ae..c6ae13c94b 100644
--- a/protocols/luci-proto-wireguard/root/usr/share/rpcd/ucode/luci.wireguard
+++ b/protocols/luci-proto-wireguard/root/usr/share/rpcd/ucode/luci.wireguard
@@ -15,6 +15,19 @@ function command(cmd) {
return trim(popen(cmd)?.read?.('all'));
}
+function checkPeerHost(configHost, configPort, wgHost) {
+ const ips = popen(`resolveip ${configHost} 2>/dev/null`);
+ if (ips) {
+ for (let line = ips.read('line'); length(line); line = ips.read('line')) {
+ const ip = rtrim(line, '\n');
+ if (ip + ":" + configPort == wgHost) {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
const methods = {
generatePsk: {
@@ -76,7 +89,7 @@ const methods = {
let peer_name;
uci.foreach('network', `wireguard_${last_device}`, (s) => {
- if (s.public_key == record[1])
+ if (!s.disabled && s.public_key == record[1] && checkPeerHost(s.endpoint_host, s.endpoint_port, record[3]))
peer_name = s.description;
});