summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFlorian Eckert <fe@dev.tdt.de>2022-04-06 17:38:03 +0200
committerGitHub <noreply@github.com>2022-04-06 17:38:03 +0200
commit661c42d09cf379d15e5d5e5419841bbf625e55df (patch)
tree57adf2a47744d7166e2789ced23c62d15d9233b6
parent3646b0cd1f65dc929dbc0b29daaa7252f6a2507b (diff)
parentb6925a12277224b4a02dc1febb58de8d4d6fdbe0 (diff)
Merge pull request #5729 from lvoegl/luci-proto-wireguard-generate-psk
luci-proto-wireguard: add generate psk button
-rw-r--r--protocols/luci-proto-wireguard/htdocs/luci-static/resources/protocol/wireguard.js18
-rwxr-xr-xprotocols/luci-proto-wireguard/root/usr/libexec/rpcd/luci.wireguard7
-rw-r--r--protocols/luci-proto-wireguard/root/usr/share/rpcd/acl.d/luci-wireguard.json3
3 files changed, 27 insertions, 1 deletions
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 50080ca9b6..677edb8bec 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
@@ -25,6 +25,12 @@ var generateQrCode = rpc.declare({
expect: { qr_code: '' }
});
+var generatePsk = rpc.declare({
+ object: 'luci.wireguard',
+ method: 'generatePsk',
+ expect: { psk: '' }
+});
+
function validateBase64(section_id, value) {
if (value.length == 0)
return true;
@@ -273,6 +279,18 @@ return network.registerProtocol('wireguard', {
o.validate = validateBase64;
o.optional = true;
+ o = ss.option(form.Button, 'generate_key', _('Generate Key'));
+ o.inputstyle = 'apply';
+ o.onclick = ui.createHandlerFn(this, function (section_id, ev, peer_id) {
+ return generatePsk().then(function (psk) {
+ var keyInput = document.getElementById('widget.cbid.network.%s.preshared_key'.format(peer_id)),
+ changeEvent = new Event('change');
+
+ keyInput.value = psk;
+ keyInput.dispatchEvent(changeEvent);
+ });
+ }, s.section);
+
o = ss.option(form.DynamicList, 'allowed_ips', _('Allowed IPs'), _("Optional. IP addresses and prefixes that this peer is allowed to use inside the tunnel. Usually the peer's tunnel IP addresses and the networks the peer routes through the tunnel."));
o.datatype = 'ipaddr';
o.optional = true;
diff --git a/protocols/luci-proto-wireguard/root/usr/libexec/rpcd/luci.wireguard b/protocols/luci-proto-wireguard/root/usr/libexec/rpcd/luci.wireguard
index bbe91cdd6a..f1f8f16d00 100755
--- a/protocols/luci-proto-wireguard/root/usr/libexec/rpcd/luci.wireguard
+++ b/protocols/luci-proto-wireguard/root/usr/libexec/rpcd/luci.wireguard
@@ -8,6 +8,13 @@ local uci = require "uci"
local fs = require "nixio.fs"
local methods = {
+ generatePsk = {
+ call = function()
+ local psk = sys.exec("wg genpsk"):sub(1, -2)
+
+ return {psk = psk}
+ end
+ },
generateKeyPair = {
call = function()
local prv = sys.exec("wg genkey 2>/dev/null"):sub(1, -2)
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 aa949b9d14..9d0a561411 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
@@ -6,7 +6,8 @@
"luci.wireguard": [
"generateKeyPair",
"getPublicAndPrivateKeyFromPrivate",
- "generateQrCode"
+ "generateQrCode",
+ "generatePsk"
]
}
}