Skip to content

Commit

Permalink
luci-proto-wireguard: fixed bug with incorrect peer name detection
Browse files Browse the repository at this point in the history
Fixed bug with incorrect peer name detection on `Status -> WireGuard`
page when more than one peer with the same public key exist:
1. Peers are now tested not only by public key, but also by
enabled/disabled status, peer host (both IP and FQDN are supported)
and port.
2. Added required `resolveip` dependency.

Closes openwrt#7342

Signed-off-by: @this-username-has-been-taken
Signed-off-by: Paul Donald <[email protected]>
  • Loading branch information
this-username-has-been-taken authored and systemcrash committed Oct 23, 2024
1 parent 1300761 commit 7acea81
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion protocols/luci-proto-wireguard/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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;
});

Expand Down

0 comments on commit 7acea81

Please sign in to comment.