diff options
author | Paul Donald <newtwen+github@gmail.com> | 2024-11-22 23:47:19 +0100 |
---|---|---|
committer | Paul Donald <newtwen+github@gmail.com> | 2024-11-22 23:47:19 +0100 |
commit | 2bf802d844a1eb3f75db6aff26786749df5b2c95 (patch) | |
tree | c6a713c6e402c342a537db7231097cdf04ca7004 /applications | |
parent | ae8bbb814f16c2dc2a82e88d408bee1812ceda9c (diff) |
luci-app-libreswan: prevent proposals and tunnels overwriting each other
Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Diffstat (limited to 'applications')
-rw-r--r-- | applications/luci-app-libreswan/htdocs/luci-static/resources/view/libreswan/proposals.js | 20 | ||||
-rw-r--r-- | applications/luci-app-libreswan/htdocs/luci-static/resources/view/libreswan/tunnels.js | 20 |
2 files changed, 40 insertions, 0 deletions
diff --git a/applications/luci-app-libreswan/htdocs/luci-static/resources/view/libreswan/proposals.js b/applications/luci-app-libreswan/htdocs/luci-static/resources/view/libreswan/proposals.js index 8569e05caa..e1b14a8e32 100644 --- a/applications/luci-app-libreswan/htdocs/luci-static/resources/view/libreswan/proposals.js +++ b/applications/luci-app-libreswan/htdocs/luci-static/resources/view/libreswan/proposals.js @@ -2,6 +2,7 @@ 'require view'; 'require ui'; 'require form'; +'require uci'; return view.extend({ render: function() { @@ -15,6 +16,25 @@ return view.extend({ s.nodescriptions = true; s.addbtntitle = _('Add Proposal'); + s.renderSectionAdd = function(extra_class) { + var el = form.GridSection.prototype.renderSectionAdd.apply(this, arguments), + nameEl = el.querySelector('.cbi-section-create-name'); + ui.addValidator(nameEl, 'uciname', true, function(v) { + let sections = [ + ...uci.sections('libreswan', 'crypto_proposal'), + ...uci.sections('libreswan', 'tunnel'), + ]; + if (sections.find(function(s) { + return s['.name'] == v; + })) { + return _('This may not share the same name as other proposals or configured tunnels.'); + } + if (v.length > 15) return _('Name length shall not exceed 15 characters'); + return true; + }, 'blur', 'keyup'); + return el; + }; + o = s.tab('general', _('General')); o = s.taboption('general', form.MultiValue, 'hash_algorithm', _('Hash Algorithm'), ('* = %s').format(_('Unsafe'))); diff --git a/applications/luci-app-libreswan/htdocs/luci-static/resources/view/libreswan/tunnels.js b/applications/luci-app-libreswan/htdocs/luci-static/resources/view/libreswan/tunnels.js index f7cb439458..762e17cee7 100644 --- a/applications/luci-app-libreswan/htdocs/luci-static/resources/view/libreswan/tunnels.js +++ b/applications/luci-app-libreswan/htdocs/luci-static/resources/view/libreswan/tunnels.js @@ -54,6 +54,26 @@ return view.extend({ s.nodedescription = false; s.addbtntitle = _('Add Tunnel'); + s.renderSectionAdd = function(extra_class) { + var el = form.GridSection.prototype.renderSectionAdd.apply(this, arguments), + nameEl = el.querySelector('.cbi-section-create-name'); + ui.addValidator(nameEl, 'uciname', true, function(v) { + let sections = [ + ...uci.sections('libreswan', 'crypto_proposal'), + ...uci.sections('libreswan', 'tunnel'), + ]; + + if (sections.find(function(s) { + return s['.name'] == v; + })) { + return _('This may not share the same name as other proposals or configured tunnels.'); + } + if (v.length > 15) return _('Name length shall not exceed 15 characters'); + return true; + }, 'blur', 'keyup'); + return el; + }; + o = s.tab('general', _('General')); o = s.tab('authentication', _('Authentication')); o = s.tab('interface', _('Interface')); |