Adding an Addresses option to the wireguard peer config generator. 6352/head
authorNicholaos Mouzourakis <nevumx@gmail.com>
Wed, 19 Apr 2023 05:11:21 +0000 (01:11 -0400)
committerNicholaos Mouzourakis <nevumx@gmail.com>
Sun, 22 Oct 2023 02:42:58 +0000 (22:42 -0400)
Some clients like iOS require this explicitly, and so this change
adds the appropriate config with some sensible defaults.
Addresses issue #6050
Signed-off-by: Nicholaos Mouzourakis <nevumx@gmail.com>
protocols/luci-proto-wireguard/htdocs/luci-static/resources/protocol/wireguard.js

index 58537f38f8b9e68c92130e762070ca6ebbeff015..e06f07895fc6a014aaa81aa398380bf7acb95d80 100644 (file)
@@ -692,7 +692,7 @@ return network.registerProtocol('wireguard', {
 
                o.modalonly = true;
 
-               o.createPeerConfig = function(section_id, endpoint, ips) {
+               o.createPeerConfig = function(section_id, endpoint, ips, eips) {
                        var pub = s.formvalue(s.section, 'public_key'),
                            port = s.formvalue(s.section, 'listen_port') || '51820',
                            prv = this.section.formvalue(section_id, 'private_key'),
@@ -708,6 +708,7 @@ return network.registerProtocol('wireguard', {
                        return [
                                '[Interface]',
                                'PrivateKey = ' + prv,
+                               eips && eips.length ? 'Address = ' + eips.join(', ') : '# Address not defined',
                                eport ? 'ListenPort = ' + eport : '# ListenPort not defined',
                                '',
                                '[Peer]',
@@ -723,7 +724,8 @@ return network.registerProtocol('wireguard', {
                        var mapNode = ss.getActiveModalMap(),
                            headNode = mapNode.parentNode.querySelector('h4'),
                            configGenerator = this.createPeerConfig.bind(this, section_id),
-                           parent = this.map;
+                           parent = this.map,
+                               eips = this.section.formvalue(section_id, 'allowed_ips');
 
                        return Promise.all([
                                network.getWANNetworks(),
@@ -754,7 +756,7 @@ return network.registerProtocol('wireguard', {
 
                                var qrm, qrs, qro;
 
-                               qrm = new form.JSONMap({ config: { endpoint: hostnames[0], allowed_ips: ips } }, null, _('The generated configuration can be imported into a WireGuard client application to set up a connection towards this device.'));
+                               qrm = new form.JSONMap({ config: { endpoint: hostnames[0], allowed_ips: ips, addresses: eips } }, null, _('The generated configuration can be imported into a WireGuard client application to set up a connection towards this device.'));
                                qrm.parent = parent;
 
                                qrs = qrm.section(form.NamedSection, 'config');
@@ -764,9 +766,10 @@ return network.registerProtocol('wireguard', {
                                            conf = this.map.findElement('.client-config'),
                                            endpoint = this.section.getUIElement(section_id, 'endpoint'),
                                            ips = this.section.getUIElement(section_id, 'allowed_ips');
+                                           eips = this.section.getUIElement(section_id, 'addresses');
 
                                        if (this.isValid(section_id)) {
-                                               conf.firstChild.data = configGenerator(endpoint.getValue(), ips.getValue());
+                                               conf.firstChild.data = configGenerator(endpoint.getValue(), ips.getValue(), eips.getValue());
                                                code.style.opacity = '.5';
 
                                                invokeQREncode(conf.firstChild.data, code);
@@ -784,9 +787,15 @@ return network.registerProtocol('wireguard', {
                                ips.forEach(function(ip) { qro.value(ip) });
                                qro.onchange = handleConfigChange;
 
+                               qro = qrs.option(form.DynamicList, 'addresses', _('Addresses'), _('IP addresses for the peer to use inside the tunnel. Some clients require this setting.'));
+                               qro.datatype = 'ipaddr';
+                               qro.default = eips;
+                               eips.forEach(function(eip) { qro.value(eip) });
+                               qro.onchange = handleConfigChange;
+
                                qro = qrs.option(form.DummyValue, 'output');
                                qro.renderWidget = function() {
-                                       var peer_config = configGenerator(hostnames[0], ips);
+                                       var peer_config = configGenerator(hostnames[0], ips, eips);
 
                                        var node = E('div', {
                                                'style': 'display:flex;flex-wrap:wrap;align-items:center;gap:.5em;width:100%'