luci-proto-3g/ppp/pppossh: fix setting of keepalive
authorErik Karlsson <erik.karlsson@iopsys.eu>
Thu, 9 Jan 2025 15:57:57 +0000 (16:57 +0100)
committerPaul Donald <newtwen+github@gmail.com>
Thu, 9 Jan 2025 19:51:27 +0000 (20:51 +0100)
Fix regressions from f3d26a2a560d8ae526c617eb1c28821ec900fa7a:

1) It is now possible again to leave the keepalive option empty.

2) It is possible now to set an interval different from 1 without the
   need to explicitly set the failure threshold.

Signed-off-by: Erik Karlsson <erik.karlsson@iopsys.eu>
protocols/luci-proto-3g/htdocs/luci-static/resources/protocol/3g.js
protocols/luci-proto-ppp/htdocs/luci-static/resources/protocol/ppp.js
protocols/luci-proto-ppp/htdocs/luci-static/resources/protocol/pppoa.js
protocols/luci-proto-ppp/htdocs/luci-static/resources/protocol/pppoe.js
protocols/luci-proto-ppp/htdocs/luci-static/resources/protocol/pptp.js
protocols/luci-proto-pppossh/htdocs/luci-static/resources/protocol/pppossh.js

index fe3239f9dc6fe7654c82159df99aa55081bb380e..85cc102ec50d9096ce9e6733a20e8a70d2770b07 100644 (file)
@@ -23,15 +23,15 @@ network.registerPatternVirtual(/^3g-.+$/);
 function write_keepalive(section_id, value) {
        var f_opt = this.map.lookupOption('_keepalive_failure', section_id),
            i_opt = this.map.lookupOption('_keepalive_interval', section_id),
-           f = (f_opt != null) ? +f_opt[0].formvalue(section_id) : null,
-           i = (i_opt != null) ? +i_opt[0].formvalue(section_id) : null;
+           f = parseInt(f_opt?.[0]?.formvalue(section_id), 10),
+           i = parseInt(i_opt?.[0]?.formvalue(section_id), 10);
 
-       if (f === '' || isNaN(f))
-               f = null;
-
-       if (i == null || i == '' || isNaN(i) || i < 1)
+       if (isNaN(i))
                i = 1;
 
+       if (isNaN(f))
+               f = (i == 1) ? null : 5;
+
        if (f !== null)
                uci.set('network', section_id, 'keepalive', '%d %d'.format(f, i));
        else
@@ -142,7 +142,7 @@ return network.registerProtocol('3g', {
 
                o = s.taboption('advanced', form.Value, '_keepalive_interval', _('LCP echo interval'), _('Send LCP echo requests at the given interval in seconds, only effective in conjunction with failure threshold'));
                o.placeholder = '1';
-               o.datatype    = 'min(1)';
+               o.datatype    = 'and(uinteger,min(1))';
                o.write       = write_keepalive;
                o.remove      = write_keepalive;
                o.cfgvalue = function(section_id) {
index 626d5e2a5dfbb38154a5922e8bfd616f71741b54..6d3db0fbe3f636e638211fde62cb5c58e0785f2f 100644 (file)
@@ -23,15 +23,15 @@ network.registerPatternVirtual(/^ppp-.+$/);
 function write_keepalive(section_id, value) {
        var f_opt = this.map.lookupOption('_keepalive_failure', section_id),
            i_opt = this.map.lookupOption('_keepalive_interval', section_id),
-           f = (f_opt != null) ? +f_opt[0].formvalue(section_id) : null,
-           i = (i_opt != null) ? +i_opt[0].formvalue(section_id) : null;
+           f = parseInt(f_opt?.[0]?.formvalue(section_id), 10),
+           i = parseInt(i_opt?.[0]?.formvalue(section_id), 10);
 
-       if (f === '' || isNaN(f))
-               f = null;
-
-       if (i == null || i == '' || isNaN(i) || i < 1)
+       if (isNaN(i))
                i = 1;
 
+       if (isNaN(f))
+               f = (i == 1) ? null : 5;
+
        if (f !== null)
                uci.set('network', section_id, 'keepalive', '%d %d'.format(f, i));
        else
@@ -114,7 +114,7 @@ return network.registerProtocol('ppp', {
 
                o = s.taboption('advanced', form.Value, '_keepalive_interval', _('LCP echo interval'), _('Send LCP echo requests at the given interval in seconds, only effective in conjunction with failure threshold'));
                o.placeholder = '1';
-               o.datatype    = 'min(1)';
+               o.datatype    = 'and(uinteger,min(1))';
                o.write       = write_keepalive;
                o.remove      = write_keepalive;
                o.cfgvalue = function(section_id) {
index a65ae310e8e8b5a6358a4b4bc1c423cd7801869e..8955d0972525c6352546612bcfd2ab9c16b11b12 100644 (file)
@@ -8,15 +8,15 @@ network.registerPatternVirtual(/^pppoa-.+$/);
 function write_keepalive(section_id, value) {
        var f_opt = this.map.lookupOption('_keepalive_failure', section_id),
            i_opt = this.map.lookupOption('_keepalive_interval', section_id),
-           f = (f_opt != null) ? +f_opt[0].formvalue(section_id) : null,
-           i = (i_opt != null) ? +i_opt[0].formvalue(section_id) : null;
+           f = parseInt(f_opt?.[0]?.formvalue(section_id), 10),
+           i = parseInt(i_opt?.[0]?.formvalue(section_id), 10);
 
-       if (f === '' || isNaN(f))
-               f = null;
-
-       if (i == null || i == '' || isNaN(i) || i < 1)
+       if (isNaN(i))
                i = 1;
 
+       if (isNaN(f))
+               f = (i == 1) ? null : 5;
+
        if (f !== null)
                uci.set('network', section_id, 'keepalive', '%d %d'.format(f, i));
        else
@@ -100,7 +100,7 @@ return network.registerProtocol('pppoa', {
 
                o = s.taboption('advanced', form.Value, '_keepalive_interval', _('LCP echo interval'), _('Send LCP echo requests at the given interval in seconds, only effective in conjunction with failure threshold'));
                o.placeholder = '1';
-               o.datatype    = 'min(1)';
+               o.datatype    = 'and(uinteger,min(1))';
                o.write       = write_keepalive;
                o.remove      = write_keepalive;
                o.cfgvalue = function(section_id) {
index 12dec9b9c80d3e3f1b13c098d6e1862bab71f2dc..5fbeca8c10d62c9b165a46944d9a6bb421c6c908 100644 (file)
@@ -8,15 +8,15 @@ network.registerPatternVirtual(/^pppoe-.+$/);
 function write_keepalive(section_id, value) {
        var f_opt = this.map.lookupOption('_keepalive_failure', section_id),
            i_opt = this.map.lookupOption('_keepalive_interval', section_id),
-           f = (f_opt != null) ? +f_opt[0].formvalue(section_id) : null,
-           i = (i_opt != null) ? +i_opt[0].formvalue(section_id) : null;
+           f = parseInt(f_opt?.[0]?.formvalue(section_id), 10),
+           i = parseInt(i_opt?.[0]?.formvalue(section_id), 10);
 
-       if (f === '' || isNaN(f))
-               f = null;
-
-       if (i == null || i == '' || isNaN(i) || i < 1)
+       if (isNaN(i))
                i = 1;
 
+       if (isNaN(f))
+               f = (i == 1) ? null : 5;
+
        if (f !== null)
                uci.set('network', section_id, 'keepalive', '%d %d'.format(f, i));
        else
@@ -74,7 +74,7 @@ return network.registerProtocol('pppoe', {
 
                o = s.taboption('advanced', form.Value, '_keepalive_interval', _('LCP echo interval'), _('Send LCP echo requests at the given interval in seconds, only effective in conjunction with failure threshold'));
                o.placeholder = '1';
-               o.datatype    = 'min(1)';
+               o.datatype    = 'and(uinteger,min(1))';
                o.write       = write_keepalive;
                o.remove      = write_keepalive;
                o.cfgvalue = function(section_id) {
index 7ed2dc5506627570333d834617b59d4ab7152e9d..abb006700fc5ea778f304362af8e6624c3e0d3c9 100644 (file)
@@ -8,15 +8,15 @@ network.registerPatternVirtual(/^pptp-.+$/);
 function write_keepalive(section_id, value) {
        var f_opt = this.map.lookupOption('_keepalive_failure', section_id),
            i_opt = this.map.lookupOption('_keepalive_interval', section_id),
-           f = (f_opt != null) ? +f_opt[0].formvalue(section_id) : null,
-           i = (i_opt != null) ? +i_opt[0].formvalue(section_id) : null;
+           f = parseInt(f_opt?.[0]?.formvalue(section_id), 10),
+           i = parseInt(i_opt?.[0]?.formvalue(section_id), 10);
 
-       if (f === '' || isNaN(f))
-               f = null;
-
-       if (i == null || i == '' || isNaN(i) || i < 1)
+       if (isNaN(i))
                i = 1;
 
+       if (isNaN(f))
+               f = (i == 1) ? null : 5;
+
        if (f !== null)
                uci.set('network', section_id, 'keepalive', '%d %d'.format(f, i));
        else
@@ -87,7 +87,7 @@ return network.registerProtocol('pptp', {
 
                o = s.taboption('advanced', form.Value, '_keepalive_interval', _('LCP echo interval'), _('Send LCP echo requests at the given interval in seconds, only effective in conjunction with failure threshold'));
                o.placeholder = '1';
-               o.datatype    = 'min(1)';
+               o.datatype    = 'and(uinteger,min(1))';
                o.write       = write_keepalive;
                o.remove      = write_keepalive;
                o.cfgvalue = function(section_id) {
index cb6f8265b10ae691792cdd4be621a4064d33a8e6..e24f9159e8c0a5fc46f93bfbe26ecfb626c27b1b 100644 (file)
@@ -8,15 +8,15 @@ network.registerPatternVirtual(/^pppossh-.+$/);
 function write_keepalive(section_id, value) {
        var f_opt = this.map.lookupOption('_keepalive_failure', section_id),
            i_opt = this.map.lookupOption('_keepalive_interval', section_id),
-           f = (f_opt != null) ? +f_opt[0].formvalue(section_id) : null,
-           i = (i_opt != null) ? +i_opt[0].formvalue(section_id) : null;
+           f = parseInt(f_opt?.[0]?.formvalue(section_id), 10),
+           i = parseInt(i_opt?.[0]?.formvalue(section_id), 10);
 
-       if (f === '' || isNaN(f))
-               f = null;
-
-       if (i == null || i == '' || isNaN(i) || i < 1)
+       if (isNaN(i))
                i = 1;
 
+       if (isNaN(f))
+               f = (i == 1) ? null : 5;
+
        if (f !== null)
                uci.set('network', section_id, 'keepalive', '%d %d'.format(f, i));
        else
@@ -110,7 +110,7 @@ return network.registerProtocol('pppossh', {
 
                o = s.taboption('advanced', form.Value, '_keepalive_interval', _('LCP echo interval'), _('Send LCP echo requests at the given interval in seconds, only effective in conjunction with failure threshold'));
                o.placeholder = '1';
-               o.datatype    = 'min(1)';
+               o.datatype    = 'and(uinteger,min(1))';
                o.write       = write_keepalive;
                o.remove      = write_keepalive;
                o.cfgvalue = function(section_id) {