From 8b3c13f7b3d9fcc02fcb5d6ae22b194a70340b02 Mon Sep 17 00:00:00 2001 From: Lyall Beveridge Date: Fri, 6 Dec 2024 10:30:36 +1100 Subject: [PATCH] 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 --- .../luci-static/resources/view/network/interfaces.js | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 f262aed39cb..8f45fcf5148 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;