luci-proto-wireguard: display interface public key
Signed-off-by: Paul Dee <itsascambutmailmeanyway@gmail.com>
This commit is contained in:
parent
f16a2f3fba
commit
8a9dbe39d5
3 changed files with 37 additions and 1 deletions
|
@ -11,6 +11,13 @@ var generateKey = rpc.declare({
|
||||||
expect: { keys: {} }
|
expect: { keys: {} }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var getPublicAndPrivateKeyFromPrivate = rpc.declare({
|
||||||
|
object: 'luci.wireguard',
|
||||||
|
method: 'getPublicAndPrivateKeyFromPrivate',
|
||||||
|
params: ['privkey'],
|
||||||
|
expect: { keys: {} }
|
||||||
|
});
|
||||||
|
|
||||||
var generateQrCode = rpc.declare({
|
var generateQrCode = rpc.declare({
|
||||||
object: 'luci.wireguard',
|
object: 'luci.wireguard',
|
||||||
method: 'generateQrCode',
|
method: 'generateQrCode',
|
||||||
|
@ -88,14 +95,34 @@ return network.registerProtocol('wireguard', {
|
||||||
o.validate = validateBase64;
|
o.validate = validateBase64;
|
||||||
o.rmempty = false;
|
o.rmempty = false;
|
||||||
|
|
||||||
|
var sections = uci.sections('network');
|
||||||
|
var serverName = this.getIfname();
|
||||||
|
var server = findSection(sections, serverName);
|
||||||
|
|
||||||
|
o = s.taboption('general', form.Value, 'public_key', _('Public Key'), _('Base64-encoded public key of this interface for sharing.'));
|
||||||
|
o.rmempty = false;
|
||||||
|
o.write = function() {/* write nothing */};
|
||||||
|
|
||||||
|
o.load = function(s) {
|
||||||
|
return getPublicAndPrivateKeyFromPrivate(server.private_key).then(
|
||||||
|
function(keypair) {
|
||||||
|
return keypair.pub || '';
|
||||||
|
},
|
||||||
|
function(error){
|
||||||
|
return _('Error getting PublicKey');
|
||||||
|
}, this)
|
||||||
|
};
|
||||||
|
|
||||||
o = s.taboption('general', form.Button, 'generate_key', _('Generate Key'));
|
o = s.taboption('general', form.Button, 'generate_key', _('Generate Key'));
|
||||||
o.inputstyle = 'apply';
|
o.inputstyle = 'apply';
|
||||||
o.onclick = ui.createHandlerFn(this, function(section_id, ev) {
|
o.onclick = ui.createHandlerFn(this, function(section_id, ev) {
|
||||||
return generateKey().then(function(keypair) {
|
return generateKey().then(function(keypair) {
|
||||||
var keyInput = document.getElementById('widget.cbid.network.%s.private_key'.format(section_id)),
|
var keyInput = document.getElementById('widget.cbid.network.%s.private_key'.format(section_id)),
|
||||||
changeEvent = new Event('change');
|
changeEvent = new Event('change'),
|
||||||
|
pubKeyInput = document.getElementById('widget.cbid.network.%s.public_key'.format(section_id));
|
||||||
|
|
||||||
keyInput.value = keypair.priv || '';
|
keyInput.value = keypair.priv || '';
|
||||||
|
pubKeyInput.value = keypair.pub || '';
|
||||||
keyInput.dispatchEvent(changeEvent);
|
keyInput.dispatchEvent(changeEvent);
|
||||||
});
|
});
|
||||||
}, s.section);
|
}, s.section);
|
||||||
|
|
|
@ -16,6 +16,14 @@ local methods = {
|
||||||
return {keys = {priv = prv, pub = pub}}
|
return {keys = {priv = prv, pub = pub}}
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
|
getPublicAndPrivateKeyFromPrivate = {
|
||||||
|
args = {privkey = "privkey"},
|
||||||
|
call = function(args)
|
||||||
|
local pubkey = sys.exec("echo %s | wg pubkey 2>/dev/null" % util.shellquote(args.privkey)):sub(1, -2)
|
||||||
|
|
||||||
|
return {keys = {priv = args.privkey, pub = pubkey}}
|
||||||
|
end
|
||||||
|
},
|
||||||
generateQrCode = {
|
generateQrCode = {
|
||||||
args = {privkey = "privkey", psk = "psk", allowed_ips = {"allowed_ips"}},
|
args = {privkey = "privkey", psk = "psk", allowed_ips = {"allowed_ips"}},
|
||||||
call = function(args)
|
call = function(args)
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
"ubus": {
|
"ubus": {
|
||||||
"luci.wireguard": [
|
"luci.wireguard": [
|
||||||
"generateKeyPair",
|
"generateKeyPair",
|
||||||
|
"getPublicAndPrivateKeyFromPrivate",
|
||||||
"generateQrCode"
|
"generateQrCode"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue