luci-app-strongswan-swanctl: fix Tunnel/Remote modal crash
authorJoshua Vlantis <redacted>
Mon, 4 May 2026 05:20:08 +0000 (07:20 +0200)
committerFlorian Eckert <redacted>
Tue, 5 May 2026 05:41:01 +0000 (07:41 +0200)
Opening the Tunnel (or Remote) configuration modal threw

  TypeError: Cannot convert undefined or null to object

and the modal never opened.

The crypto_proposal MultiValue fields on remote and tunnel sections
showed the "Please create a Proposal first" placeholder only when no
crypto_proposal sections existed at all. When proposals existed but
none matched the required type (IKE/non-ESP for remote, ESP for
tunnel), the inner forEach added no choices, leaving keylist empty.

An empty keylist makes form.MultiValue.transformChoices() return null,
which is then passed to ui.Dropdown. Because typeof null === 'object',
the null check in UIDropdown.__init__ does not replace it, and the
subsequent Object.keys(this.choices) call throws.

Filter the sections list by is_esp before the length check so the
placeholder is shown whenever no proposals of the required type exist.

Fixes: https://github.com/openwrt/luci/issues/8606
Signed-off-by: Joshua Vlantis <redacted>
applications/luci-app-strongswan-swanctl/htdocs/luci-static/resources/view/strongswan-swanctl/swanctl.js

index 73fcb4cc827970dc20060e71f04f5f19e8f78c97..aea22185f4835b86feb0573cbbb2a1199f407dd0 100644 (file)
@@ -121,14 +121,14 @@ return view.extend({
                        this.keylist = [];
                        this.vallist = [];
 
-                       var sections = uci.sections('ipsec', 'crypto_proposal');
+                       var sections = uci.sections('ipsec', 'crypto_proposal').filter(function (section) {
+                               return section.is_esp != '1';
+                       });
                        if (sections.length == 0) {
                                this.value('', _('Please create a Proposal first'));
                        } else {
                                sections.forEach(L.bind(function (section) {
-                                       if (section.is_esp != '1') {
-                                               this.value(section['.name']);
-                                       }
+                                       this.value(section['.name']);
                                }, this));
                        }
 
@@ -318,14 +318,14 @@ return view.extend({
                        this.keylist = [];
                        this.vallist = [];
 
-                       var sections = uci.sections('ipsec', 'crypto_proposal');
+                       var sections = uci.sections('ipsec', 'crypto_proposal').filter(function (section) {
+                               return section.is_esp == '1';
+                       });
                        if (sections.length == 0) {
                                this.value('', _('Please create an ESP Proposal first'));
                        } else {
                                sections.forEach(L.bind(function (section) {
-                                       if (section.is_esp == '1') {
-                                               this.value(section['.name']);
-                                       }
+                                       this.value(section['.name']);
                                }, this));
                        }
 
git clone https://git.99rst.org/PROJECT