From a88d4af4e92bfc7374524c47bd0e53a7d4685a32 Mon Sep 17 00:00:00 2001 From: Erik Karlsson Date: Thu, 9 Jan 2025 16:57:57 +0100 Subject: [PATCH] luci-proto-3g/ppp/pppossh: fix setting of keepalive 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 --- .../htdocs/luci-static/resources/protocol/3g.js | 14 +++++++------- .../htdocs/luci-static/resources/protocol/ppp.js | 14 +++++++------- .../htdocs/luci-static/resources/protocol/pppoa.js | 14 +++++++------- .../htdocs/luci-static/resources/protocol/pppoe.js | 14 +++++++------- .../htdocs/luci-static/resources/protocol/pptp.js | 14 +++++++------- .../luci-static/resources/protocol/pppossh.js | 14 +++++++------- 6 files changed, 42 insertions(+), 42 deletions(-) diff --git a/protocols/luci-proto-3g/htdocs/luci-static/resources/protocol/3g.js b/protocols/luci-proto-3g/htdocs/luci-static/resources/protocol/3g.js index fe3239f9dc6f..85cc102ec50d 100644 --- a/protocols/luci-proto-3g/htdocs/luci-static/resources/protocol/3g.js +++ b/protocols/luci-proto-3g/htdocs/luci-static/resources/protocol/3g.js @@ -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) { diff --git a/protocols/luci-proto-ppp/htdocs/luci-static/resources/protocol/ppp.js b/protocols/luci-proto-ppp/htdocs/luci-static/resources/protocol/ppp.js index 626d5e2a5dfb..6d3db0fbe3f6 100644 --- a/protocols/luci-proto-ppp/htdocs/luci-static/resources/protocol/ppp.js +++ b/protocols/luci-proto-ppp/htdocs/luci-static/resources/protocol/ppp.js @@ -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) { diff --git a/protocols/luci-proto-ppp/htdocs/luci-static/resources/protocol/pppoa.js b/protocols/luci-proto-ppp/htdocs/luci-static/resources/protocol/pppoa.js index a65ae310e8e8..8955d0972525 100644 --- a/protocols/luci-proto-ppp/htdocs/luci-static/resources/protocol/pppoa.js +++ b/protocols/luci-proto-ppp/htdocs/luci-static/resources/protocol/pppoa.js @@ -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) { diff --git a/protocols/luci-proto-ppp/htdocs/luci-static/resources/protocol/pppoe.js b/protocols/luci-proto-ppp/htdocs/luci-static/resources/protocol/pppoe.js index 12dec9b9c80d..5fbeca8c10d6 100644 --- a/protocols/luci-proto-ppp/htdocs/luci-static/resources/protocol/pppoe.js +++ b/protocols/luci-proto-ppp/htdocs/luci-static/resources/protocol/pppoe.js @@ -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) { diff --git a/protocols/luci-proto-ppp/htdocs/luci-static/resources/protocol/pptp.js b/protocols/luci-proto-ppp/htdocs/luci-static/resources/protocol/pptp.js index 7ed2dc550662..abb006700fc5 100644 --- a/protocols/luci-proto-ppp/htdocs/luci-static/resources/protocol/pptp.js +++ b/protocols/luci-proto-ppp/htdocs/luci-static/resources/protocol/pptp.js @@ -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) { diff --git a/protocols/luci-proto-pppossh/htdocs/luci-static/resources/protocol/pppossh.js b/protocols/luci-proto-pppossh/htdocs/luci-static/resources/protocol/pppossh.js index cb6f8265b10a..e24f9159e8c0 100644 --- a/protocols/luci-proto-pppossh/htdocs/luci-static/resources/protocol/pppossh.js +++ b/protocols/luci-proto-pppossh/htdocs/luci-static/resources/protocol/pppossh.js @@ -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) {