'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;
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');
--- /dev/null
+#!/bin/sh
+
+. /usr/share/libubox/jshn.sh
+
+case "$1" in
+ list)
+ json_init
+ json_add_object "generateKeyPair"
+ json_close_object
+ json_dump
+ ;;
+ call)
+ case "$2" in
+ generateKeyPair)
+ prv=$(wg genkey)
+ pub=$(echo $prv | wg pubkey)
+ json_init
+ json_add_object "keys"
+ json_add_string "priv" "$prv"
+ json_add_string "pub" "$pub"
+ json_close_object
+ json_dump
+ ;;
+ esac
+ ;;
+esac