luci-proto-wireguard: add generate psk button
Signed-off-by: Lukas Voegl <lvoegl@tdt.de>
This commit is contained in:
parent
f27fe280aa
commit
b6925a1227
3 changed files with 27 additions and 1 deletions
|
@ -25,6 +25,12 @@ var generateQrCode = rpc.declare({
|
||||||
expect: { qr_code: '' }
|
expect: { qr_code: '' }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var generatePsk = rpc.declare({
|
||||||
|
object: 'luci.wireguard',
|
||||||
|
method: 'generatePsk',
|
||||||
|
expect: { psk: '' }
|
||||||
|
});
|
||||||
|
|
||||||
function validateBase64(section_id, value) {
|
function validateBase64(section_id, value) {
|
||||||
if (value.length == 0)
|
if (value.length == 0)
|
||||||
return true;
|
return true;
|
||||||
|
@ -273,6 +279,18 @@ return network.registerProtocol('wireguard', {
|
||||||
o.validate = validateBase64;
|
o.validate = validateBase64;
|
||||||
o.optional = true;
|
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 = 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.datatype = 'ipaddr';
|
||||||
o.optional = true;
|
o.optional = true;
|
||||||
|
|
|
@ -8,6 +8,13 @@ local uci = require "uci"
|
||||||
local fs = require "nixio.fs"
|
local fs = require "nixio.fs"
|
||||||
|
|
||||||
local methods = {
|
local methods = {
|
||||||
|
generatePsk = {
|
||||||
|
call = function()
|
||||||
|
local psk = sys.exec("wg genpsk"):sub(1, -2)
|
||||||
|
|
||||||
|
return {psk = psk}
|
||||||
|
end
|
||||||
|
},
|
||||||
generateKeyPair = {
|
generateKeyPair = {
|
||||||
call = function()
|
call = function()
|
||||||
local prv = sys.exec("wg genkey 2>/dev/null"):sub(1, -2)
|
local prv = sys.exec("wg genkey 2>/dev/null"):sub(1, -2)
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
"luci.wireguard": [
|
"luci.wireguard": [
|
||||||
"generateKeyPair",
|
"generateKeyPair",
|
||||||
"getPublicAndPrivateKeyFromPrivate",
|
"getPublicAndPrivateKeyFromPrivate",
|
||||||
"generateQrCode"
|
"generateQrCode",
|
||||||
|
"generatePsk"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue