Skip to content

Commit

Permalink
luci-mod-network: validate DHCP leasetime input
Browse files Browse the repository at this point in the history
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 <lyall.beveridge@morsemicro.com>
  • Loading branch information
morse-lyall authored and systemcrash committed Dec 16, 2024
1 parent dd2c7f9 commit 8b3c13f
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 (<code>2m</code>).'));
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 <abbr title="Dynamic Host Configuration Protocol">DHCP</abbr>'), _('Dynamically allocate DHCP addresses for clients. If disabled, only clients having static leases will be served.'));
so.default = so.enabled;
Expand Down

0 comments on commit 8b3c13f

Please sign in to comment.