From 2bf802d844a1eb3f75db6aff26786749df5b2c95 Mon Sep 17 00:00:00 2001 From: Paul Donald Date: Fri, 22 Nov 2024 23:47:19 +0100 Subject: luci-app-libreswan: prevent proposals and tunnels overwriting each other Signed-off-by: Paul Donald --- .../resources/view/libreswan/proposals.js | 20 ++++++++++++++++++++ .../luci-static/resources/view/libreswan/tunnels.js | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) (limited to 'applications/luci-app-libreswan/htdocs') 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')); -- cgit v1.2.3