summaryrefslogtreecommitdiffhomepage
path: root/protocols/luci-proto-wireguard
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/luci-proto-wireguard')
-rw-r--r--protocols/luci-proto-wireguard/Makefile3
-rw-r--r--protocols/luci-proto-wireguard/htdocs/luci-static/resources/protocol/wireguard.js43
-rw-r--r--protocols/luci-proto-wireguard/root/usr/share/rpcd/acl.d/luci-wireguard.json3
-rw-r--r--protocols/luci-proto-wireguard/root/usr/share/rpcd/ucode/luci.wireguard15
4 files changed, 33 insertions, 31 deletions
diff --git a/protocols/luci-proto-wireguard/Makefile b/protocols/luci-proto-wireguard/Makefile
index 6c5f80c975..25bf7a69dc 100644
--- a/protocols/luci-proto-wireguard/Makefile
+++ b/protocols/luci-proto-wireguard/Makefile
@@ -7,10 +7,11 @@
include $(TOPDIR)/rules.mk
LUCI_TITLE:=Support for WireGuard VPN
-LUCI_DEPENDS:=+wireguard-tools +ucode
+LUCI_DEPENDS:=+wireguard-tools +ucode +luci-lib-uqr +resolveip
LUCI_PKGARCH:=all
PKG_LICENSE:=Apache-2.0
+PKG_MAINTAINER:=Dan Luedtke <mail@danrl.com>
include ../../luci.mk
diff --git a/protocols/luci-proto-wireguard/htdocs/luci-static/resources/protocol/wireguard.js b/protocols/luci-proto-wireguard/htdocs/luci-static/resources/protocol/wireguard.js
index 9919687b92..a3ce76c96c 100644
--- a/protocols/luci-proto-wireguard/htdocs/luci-static/resources/protocol/wireguard.js
+++ b/protocols/luci-proto-wireguard/htdocs/luci-static/resources/protocol/wireguard.js
@@ -7,6 +7,7 @@
'require form';
'require network';
'require validation';
+'require uqr';
var generateKey = rpc.declare({
object: 'luci.wireguard',
@@ -64,28 +65,16 @@ function generateDescription(name, texts) {
]);
}
-function invokeQREncode(data, code) {
- return fs.exec_direct('/usr/bin/qrencode', [
- '--inline', '--8bit', '--type=SVG',
- '--output=-', '--', data
- ]).then(function(svg) {
- code.style.opacity = '';
- dom.content(code, Object.assign(E(svg), { style: 'width:100%;height:auto' }));
- }).catch(function(error) {
- code.style.opacity = '';
-
- if (L.isObject(error) && error.name == 'NotFoundError') {
- dom.content(code, [
- Object.assign(E(qrIcon), { style: 'width:32px;height:32px;opacity:.2' }),
- E('p', _('The <em>qrencode</em> package is required for generating an QR code image of the configuration.'))
- ]);
- }
- else {
- dom.content(code, [
- _('Unable to generate QR code: %s').format(L.isObject(error) ? error.message : error)
- ]);
- }
- });
+function buildSVGQRCode(data, code) {
+ // pixel size larger than 4 clips right and bottom edges of complex configs
+ const options = {
+ pixelSize: 4,
+ whiteColor: 'white',
+ blackColor: 'black'
+ };
+ const svg = uqr.renderSVG(data, options);
+ code.style.opacity = '';
+ dom.content(code, Object.assign(E(svg), { style: 'width:100%;height:auto' }));
}
var cbiKeyPairGenerate = form.DummyValue.extend({
@@ -221,6 +210,7 @@ return network.registerProtocol('wireguard', {
ss.addbtntitle = _('Add peer');
ss.nodescriptions = true;
ss.modaltitle = _('Edit peer');
+ ss.sortable = true;
ss.handleDragConfig = function(ev) {
ev.stopPropagation();
@@ -507,9 +497,10 @@ return network.registerProtocol('wireguard', {
return E('em', _('No peers defined yet.'));
};
- o = ss.option(form.Flag, 'disabled', _('Peer disabled'), _('Enable / Disable peer. Restart wireguard interface to apply changes.'));
- o.modalonly = true;
+ o = ss.option(form.Flag, 'disabled', _('Disabled'), _('Enable / Disable peer. Restart wireguard interface to apply changes.'));
+ o.editable = true;
o.optional = true;
+ o.width = '5%';
o = ss.option(form.Value, 'description', _('Description'), _('Optional. Description of peer.'));
o.placeholder = 'My Peer';
@@ -779,7 +770,7 @@ return network.registerProtocol('wireguard', {
conf.firstChild.data = configGenerator(endpoint.getValue(), ips.getValue(), eips.getValue(), dns.getValue());
code.style.opacity = '.5';
- invokeQREncode(conf.firstChild.data, code);
+ buildSVGQRCode(conf.firstChild.data, code);
}
};
@@ -833,7 +824,7 @@ return network.registerProtocol('wireguard', {
}, [ peer_config ])
]);
- invokeQREncode(peer_config, node.firstChild);
+ buildSVGQRCode(peer_config, node.firstChild);
return node;
};
diff --git a/protocols/luci-proto-wireguard/root/usr/share/rpcd/acl.d/luci-wireguard.json b/protocols/luci-proto-wireguard/root/usr/share/rpcd/acl.d/luci-wireguard.json
index e7187c0e4f..9c0b2d1df5 100644
--- a/protocols/luci-proto-wireguard/root/usr/share/rpcd/acl.d/luci-wireguard.json
+++ b/protocols/luci-proto-wireguard/root/usr/share/rpcd/acl.d/luci-wireguard.json
@@ -2,9 +2,6 @@
"luci-proto-wireguard": {
"description": "Grant access to LuCI Wireguard procedures",
"read": {
- "file": {
- "/usr/bin/qrencode --inline --8bit --type=SVG --output=- -- *": [ "exec" ]
- },
"ubus": {
"luci.wireguard": [
"getWgInstances"
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..c177da4773 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] && (!s.endpoint_host || checkPeerHost(s.endpoint_host, s.endpoint_port, record[3])))
peer_name = s.description;
});