Skip to content

Commit

Permalink
luci-mod-network: Static Leases improvements
Browse files Browse the repository at this point in the history
Under DHCP and DNS, Static Leases tab:
Add extra fields and booleans
Add 'ignore' value for ip field
Add description text for fields
Enable wildcards in mac addresses

Signed-off-by: Paul Dee <[email protected]>
  • Loading branch information
systemcrash committed Aug 3, 2023
1 parent fd6fb5c commit 389674b
Showing 1 changed file with 65 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -750,8 +750,12 @@ return view.extend({
ss.addremove = true;
ss.anonymous = true;
ss.sortable = true;
ss.nodescriptions = true;
ss.max_cols = 8;

so = ss.option(form.Value, 'name', _('Hostname'));
so = ss.option(form.Value, 'name',
_('Hostname'),
_('Optional hostname to assign'));
so.validate = validateHostname;
so.rmempty = true;
so.write = function(section, value) {
Expand All @@ -763,20 +767,33 @@ return view.extend({
uci.unset('dhcp', section, 'dns');
};

so = ss.option(form.Value, 'mac', _('MAC address'));
so.datatype = 'list(macaddr)';
so = ss.option(form.Value, 'mac',
_('MAC address(es)'),
_('The hardware address(es) of this entry/host, separated by spaces.'));
so.validate = function(section_id, value) {
var macaddrs = L.toArray(value);

for (var i = 0; i < macaddrs.length; i++)
if (!macaddrs[i].match(/^([a-fA-F0-9]{2}|\*):([a-fA-F0-9]{2}:|\*:){4}(?:[a-fA-F0-9]{2}|\*)$/))
return _('Expecting a valid MAC address, optionally including wildcards');

return true;
};
so.rmempty = true;
so.cfgvalue = function(section) {
var macs = L.toArray(uci.get('dhcp', section, 'mac')),
result = [];

for (var i = 0, mac; (mac = macs[i]) != null; i++)
if (/^([0-9a-fA-F]{1,2}):([0-9a-fA-F]{1,2}):([0-9a-fA-F]{1,2}):([0-9a-fA-F]{1,2}):([0-9a-fA-F]{1,2}):([0-9a-fA-F]{1,2})$/.test(mac))
result.push('%02X:%02X:%02X:%02X:%02X:%02X'.format(
if (/^([0-9a-fA-F]{1,2}|\*):([0-9a-fA-F]{1,2}|\*):([0-9a-fA-F]{1,2}|\*):([0-9a-fA-F]{1,2}|\*):([0-9a-fA-F]{1,2}|\*):([0-9a-fA-F]{1,2}|\*)$/.test(mac)) {
var m = [
parseInt(RegExp.$1, 16), parseInt(RegExp.$2, 16),
parseInt(RegExp.$3, 16), parseInt(RegExp.$4, 16),
parseInt(RegExp.$5, 16), parseInt(RegExp.$6, 16)));
parseInt(RegExp.$5, 16), parseInt(RegExp.$6, 16)
];

result.push(m.map(function(n) { return isNaN(n) ? '*' : '%02X'.format(n) }).join(':'));
}
return result.length ? result.join(' ') : null;
};
so.renderWidget = function(section_id, option_index, cfgvalue) {
Expand Down Expand Up @@ -810,6 +827,7 @@ return view.extend({
});

so = ss.option(form.Value, 'ip', _('IPv4 address'));
so.value('ignore', _('Ignore'));
so.datatype = 'or(ip4addr,"ignore")';
so.validate = function(section, value) {
var m = this.section.formvalue(section, 'mac'),
Expand Down Expand Up @@ -841,16 +859,53 @@ return view.extend({
so.value(ipv4, ipaddrs[ipv4] ? '%s (%s)'.format(ipv4, ipaddrs[ipv4]) : ipv4);
});

so = ss.option(form.Value, 'leasetime', _('Lease time'));
so = ss.option(form.Value, 'leasetime',
_('Lease time'),
_('Host-specific lease time, e.g. <code>5m</code>, <code>3h</code>, <code>7d</code>.'));
so.rmempty = true;

so = ss.option(form.Value, 'duid', _('DUID'));
so.value('5m', _('5m (5 minutes)'));
so.value('3h', _('3h (3 hours)'));
so.value('12h', _('12h (12 hours - default)'));
so.value('7d', _('7d (7 days)'));
so.value('infinite', _('infinite (lease does not expire)'));

so = ss.option(form.Value, 'duid',
_('DUID'),
_('The DHCPv6-DUID of this host.'));
so.datatype = 'and(rangelength(20,36),hexstring)';
Object.keys(duids).forEach(function(duid) {
so.value(duid, '%s (%s)'.format(duid, duids[duid].hostname || duids[duid].macaddr || duids[duid].ip6addr || '?'));
});

so = ss.option(form.Value, 'hostid', _('IPv6 suffix (hex)'));
so = ss.option(form.Value, 'hostid',
_('IPv6-Suffix (hex)'),
_('The IPv6 interface identifier (address suffix) as hexadecimal number (max. 8 chars).'));
so.datatype = 'and(rangelength(0,8),hexstring)';

so = ss.option(form.Value, 'tag',
_('Tag'),
_('Set the given tag (used to match hosts).'));
so.value('known');
so.value('!known', _('!known (not known)'));
so.value('known-othernet', _('known-othernet (on different subnet)'));

so = ss.option(form.Value, 'instance',
_('Instance'),
_('Dnsmasq instance to which this DHCP host section is bound. If unspecified, the section is valid for all dnsmasq instances.'));
so.optional = true;

Object.values(L.uci.sections('dhcp', 'dnsmasq')).forEach(function(val, index) {
so.value(index, '%s (Domain: %s, Local: %s)'.format(index, val.domain || '?', val.local || '?'));
});


so = ss.option(form.Flag, 'broadcast',
_('Broadcast'),
_('Force broadcast DHCP response.'));

so = ss.option(form.Flag, 'dns',
_('Forward/reverse DNS'),
_('Add static forward and reverse DNS entries for this host.'));

o = s.taboption('leases', CBILeaseStatus, '__status__');

Expand Down

0 comments on commit 389674b

Please sign in to comment.