summaryrefslogtreecommitdiffhomepage
path: root/protocols/luci-proto-wireguard
diff options
context:
space:
mode:
authorFlorian Eckert <fe@dev.tdt.de>2021-11-30 14:10:19 +0100
committerGitHub <noreply@github.com>2021-11-30 14:10:19 +0100
commita1723c22723db3fec169eba90ab0fb4bb18ee348 (patch)
treec13a0c3b7ad9a1b613797d0e48a0cbc47397ef5c /protocols/luci-proto-wireguard
parenta75ab22e62f0689d4c716246c703d1a10e99865c (diff)
parent8a9dbe39d5b5f3227f46868b3b15f7cc72a50651 (diff)
Merge pull request #5400 from systemcrash/wg_pubkey
luci-proto-wireguard: display interface public key
Diffstat (limited to 'protocols/luci-proto-wireguard')
-rw-r--r--protocols/luci-proto-wireguard/htdocs/luci-static/resources/protocol/wireguard.js29
-rwxr-xr-xprotocols/luci-proto-wireguard/root/usr/libexec/rpcd/luci.wireguard8
-rw-r--r--protocols/luci-proto-wireguard/root/usr/share/rpcd/acl.d/luci-wireguard.json1
3 files changed, 37 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 ef4712dc6e..74327f3001 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
@@ -11,6 +11,13 @@ var generateKey = rpc.declare({
expect: { keys: {} }
});
+var getPublicAndPrivateKeyFromPrivate = rpc.declare({
+ object: 'luci.wireguard',
+ method: 'getPublicAndPrivateKeyFromPrivate',
+ params: ['privkey'],
+ expect: { keys: {} }
+});
+
var generateQrCode = rpc.declare({
object: 'luci.wireguard',
method: 'generateQrCode',
@@ -88,14 +95,34 @@ return network.registerProtocol('wireguard', {
o.validate = validateBase64;
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.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');
+ changeEvent = new Event('change'),
+ pubKeyInput = document.getElementById('widget.cbid.network.%s.public_key'.format(section_id));
keyInput.value = keypair.priv || '';
+ pubKeyInput.value = keypair.pub || '';
keyInput.dispatchEvent(changeEvent);
});
}, s.section);
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 681e98e5c4..bbe91cdd6a 100755
--- a/protocols/luci-proto-wireguard/root/usr/libexec/rpcd/luci.wireguard
+++ b/protocols/luci-proto-wireguard/root/usr/libexec/rpcd/luci.wireguard
@@ -16,6 +16,14 @@ local methods = {
return {keys = {priv = prv, pub = pub}}
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 = {
args = {privkey = "privkey", psk = "psk", allowed_ips = {"allowed_ips"}},
call = function(args)
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 04877d4f49..aa949b9d14 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
@@ -5,6 +5,7 @@
"ubus": {
"luci.wireguard": [
"generateKeyPair",
+ "getPublicAndPrivateKeyFromPrivate",
"generateQrCode"
]
}