From: Lyall Beveridge Date: Thu, 5 Dec 2024 23:30:36 +0000 (+1100) Subject: luci-mod-network: validate DHCP leasetime input X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=8b3c13f7b3d9fcc02fcb5d6ae22b194a70340b02;p=project%2Fluci.git luci-mod-network: validate DHCP leasetime input Without validation, `dnsmasq` can fail silently if users enter invalid leasetime input. This change adds input validation to align user input with the backend parsing logic. Whilst it does not enforce the >120 seconds requirement, this is documented in the field description and handled by `dnsmasq`'s `option.c`, which adjusts values <120 to meet this minimum. Signed-off-by: Lyall Beveridge --- diff --git a/modules/luci-mod-network/htdocs/luci-static/resources/view/network/interfaces.js b/modules/luci-mod-network/htdocs/luci-static/resources/view/network/interfaces.js index f262aed39c..8f45fcf514 100644 --- a/modules/luci-mod-network/htdocs/luci-static/resources/view/network/interfaces.js +++ b/modules/luci-mod-network/htdocs/luci-static/resources/view/network/interfaces.js @@ -674,6 +674,17 @@ return view.extend({ so = ss.taboption('general', form.Value, 'leasetime', _('Lease time'), _('Expiry time of leased addresses, minimum is 2 minutes (2m).')); so.optional = true; so.default = '12h'; + so.validate = function (section_id, value) { + if (value === "infinite" || value === "deprecated") { + return true; + } + + const regex = new RegExp("^[0-9]+[smhdw]?$", "i"); + if (regex.test(value)) { + return true; + } + return _("Invalid DHCP lease time format. Use integer values optionally followed by s, m, h, d, or w."); + } so = ss.taboption('advanced', form.Flag, 'dynamicdhcp', _('Dynamic DHCP'), _('Dynamically allocate DHCP addresses for clients. If disabled, only clients having static leases will be served.')); so.default = so.enabled;