luci-app-mwan3: add name length error check and name collision check
authorPaul Donald <redacted>
Sat, 14 Sep 2024 18:43:55 +0000 (20:43 +0200)
committerPaul Donald <redacted>
Sat, 14 Sep 2024 19:10:56 +0000 (21:10 +0200)
Closes #7231

Signed-off-by: Paul Donald <redacted>
applications/luci-app-mwan3/htdocs/luci-static/resources/view/mwan3/network/interface.js
applications/luci-app-mwan3/htdocs/luci-static/resources/view/mwan3/network/member.js
applications/luci-app-mwan3/htdocs/luci-static/resources/view/mwan3/network/policy.js
applications/luci-app-mwan3/htdocs/luci-static/resources/view/mwan3/network/rule.js

index 74c1718322ec35dda0444b12632cfc2f1d0cd896..c9ec5209c799cfa05d072529afc580b62771706f 100644 (file)
@@ -3,6 +3,7 @@
 'require fs';
 'require view';
 'require uci';
+'require ui';
 
 return view.extend({
        load: function() {
@@ -28,6 +29,29 @@ return view.extend({
                s.anonymous = false;
                s.nodescriptions = true;
 
+               /* This name length error check can likely be removed when mwan3 migrates to nftables */
+               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('mwan3', 'interface'),
+                                       ...uci.sections('mwan3', 'member'),
+                                       ...uci.sections('mwan3', 'policy'),
+                                       ...uci.sections('mwan3', 'rule')
+                               ];
+
+                               for (let j = 0; j < sections.length; j++) {
+                                       if (sections[j]['.name'] == v) {
+                                               return _('Interfaces may not share the same name as configured members, policies or rules.');
+                                       }
+                               }
+                               if (v.length > 15) return _('Name length shall not exceed 15 characters');
+                               return true;
+                       }, 'blur', 'keyup');
+                       return el;
+               };
+
                o = s.option(form.Flag, 'enabled', _('Enabled'));
                o.default = false;
 
index c49cc6e1ef45e58945d64c6a04033d895fbdca72..17946da2c875a62c3427f4ab61a07ad0b11044ee 100644 (file)
@@ -2,6 +2,7 @@
 'require form';
 'require view';
 'require uci';
+'require ui';
 
 return view.extend({
        load: function() {
@@ -23,6 +24,29 @@ return view.extend({
                s.anonymous = false;
                s.nodescriptions = true;
 
+               /* This name length error check can likely be removed when mwan3 migrates to nftables */
+               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('mwan3', 'interface'),
+                                       ...uci.sections('mwan3', 'member'),
+                                       ...uci.sections('mwan3', 'policy'),
+                                       ...uci.sections('mwan3', 'rule')
+                               ];
+
+                               for (let j = 0; j < sections.length; j++) {
+                                       if (sections[j]['.name'] == v) {
+                                               return _('Members may not share the same name as configured interfaces, policies or rules.');
+                                       }
+                               }
+                               if (v.length > 15) return _('Name length shall not exceed 15 characters');
+                               return true;
+                       }, 'blur', 'keyup');
+                       return el;
+               };
+
                o = s.option(form.ListValue, 'interface', _('Interface'));
                var options = uci.sections('mwan3', 'interface')
                for (var i = 0; i < options.length; i++) {
index d39eb3bfbaf1be936dd51d4f301ac955c64c7af9..3963185f6af40d41848b3e35b5a1858f61e936d8 100644 (file)
@@ -2,6 +2,7 @@
 'require form';
 'require view';
 'require uci';
+'require ui';
 
 return view.extend({
        load: function() {
@@ -14,12 +15,12 @@ return view.extend({
                var m, s, o;
 
                m = new form.Map('mwan3', _('MultiWAN Manager - Policies'),
-                       _('Policies are profiles grouping one or more members controlling how Mwan3 distributes traffic.') +
-                       _('Member interfaces with lower metrics are used first.') +
-                       _('Member interfaces with the same metric will be load-balanced.') +
-                       _('Load-balanced member interfaces distribute more traffic out those with higher weights.') +
-                       _('Names may contain characters A-Z, a-z, 0-9, _ and no spaces.') +
-                       _('Names must be 15 characters or less.') +
+                       _('Policies are profiles grouping one or more members controlling how Mwan3 distributes traffic.') + '<br />' +
+                       _('Member interfaces with lower metrics are used first.') + '<br />' +
+                       _('Member interfaces with the same metric will be load-balanced.') + '<br />' +
+                       _('Load-balanced member interfaces distribute more traffic out those with higher weights.') + '<br />' +
+                       _('Names may contain characters A-Z, a-z, 0-9, _ and no spaces.') + '<br />' +
+                       _('Names must be 15 characters or less.') + '<br />' +
                        _('Policies may not share the same name as configured interfaces, members or rules'));
 
                s = m.section(form.GridSection, 'policy');
@@ -27,6 +28,29 @@ return view.extend({
                s.anonymous = false;
                s.nodescriptions = true;
 
+               /* This name length error check can likely be removed when mwan3 migrates to nftables */
+               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('mwan3', 'interface'),
+                                       ...uci.sections('mwan3', 'member'),
+                                       ...uci.sections('mwan3', 'policy'),
+                                       ...uci.sections('mwan3', 'rule')
+                               ];
+
+                               for (let j = 0; j < sections.length; j++) {
+                                       if (sections[j]['.name'] == v) {
+                                               return _('Policies may not share the same name as configured interfaces, members or rules');
+                                       }
+                               }
+                               if (v.length > 15) return _('Name length shall not exceed 15 characters');
+                               return true;
+                       }, 'blur', 'keyup');
+                       return el;
+               };
+
                o = s.option(form.DynamicList, 'use_member', _('Member used'));
                var options = uci.sections('mwan3', 'member')
                for (var i = 0; i < options.length; i++) {
index 6452caf58a6af479b2280a05249aa06497ef752f..2e90e5dd269298aa95b58dbd805930c81390dbb1 100644 (file)
@@ -3,6 +3,7 @@
 'require fs';
 'require view';
 'require uci';
+'require ui';
 
 return view.extend({
        load: function() {
@@ -32,6 +33,29 @@ return view.extend({
                s.nodescriptions = true;
                s.sortable  = true;
 
+               /* This name length error check can likely be removed when mwan3 migrates to nftables */
+               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('mwan3', 'interface'),
+                                       ...uci.sections('mwan3', 'member'),
+                                       ...uci.sections('mwan3', 'policy'),
+                                       ...uci.sections('mwan3', 'rule')
+                               ];
+
+                               for (let j = 0; j < sections.length; j++) {
+                                       if (sections[j]['.name'] == v) {
+                                               return _('Rules may not share the same name as configured interfaces, members or policies.');
+                                       }
+                               }
+                               if (v.length > 15) return _('Name length shall not exceed 15 characters');
+                               return true;
+                       }, 'blur', 'keyup');
+                       return el;
+               };
+
                o = s.option(form.ListValue, 'family', _('Internet Protocol'));
                o.default = '';
                o.value('', _('IPv4 and IPv6'));
git clone https://git.99rst.org/PROJECT