diff options
author | Wojciech Jowsa <wojciech.jowsa@gmail.com> | 2020-08-18 22:51:07 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-08-21 11:03:53 +0200 |
commit | 60ce87a19790e1461da5cf14fcbc24d4c8caf30f (patch) | |
tree | 257db8ab68b7869c8300669a7f178cf53c0acc68 /protocols/luci-proto-wireguard/htdocs | |
parent | c4a4e43e2e97065dcda53c9ac7ee49c05171dbd8 (diff) |
luci-proto-wireguard: Add generate key button
Signed-off-by: Wojciech Jowsa <wojciech.jowsa@gmail.com>
[minor indentation fix, use bound section_id value, remove empty translation]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'protocols/luci-proto-wireguard/htdocs')
-rw-r--r-- | protocols/luci-proto-wireguard/htdocs/luci-static/resources/protocol/wireguard.js | 20 |
1 files changed, 20 insertions, 0 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 e88c07c33..4690ecfc7 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 @@ -1,8 +1,16 @@ 'use strict'; +'require ui'; 'require uci'; +'require rpc'; 'require form'; 'require network'; +var generateKey = rpc.declare({ + object: 'luci.wireguard', + method: 'generateKeyPair', + expect: { keys: {} } +}); + function validateBase64(section_id, value) { if (value.length == 0) return true; @@ -55,6 +63,18 @@ return network.registerProtocol('wireguard', { o.validate = validateBase64; o.rmempty = false; + o = s.taboption('general', form.Button, 'generate_key', _('Generate Key')); + o.inputstyle = 'apply'; + o.onclick = ui.createHandlerFn(this, function(section_id, ev) { + return generateKey().then(function(keypair) { + var keyInput = document.getElementById('widget.cbid.network.%s.private_key'.format(section_id)), + changeEvent = new Event('change'); + + keyInput.value = keypair.priv || ''; + keyInput.dispatchEvent(changeEvent); + }); + }, s.section); + o = s.taboption('general', form.Value, 'listen_port', _('Listen Port'), _('Optional. UDP port used for outgoing and incoming packets.')); o.datatype = 'port'; o.placeholder = _('random'); |