Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,8 @@ return baseclass.extend({
var o = s.taboption(tab, this.CBIDynamicMultiValueList, name, label, description);

o.modalonly = true;
o.datatype = 'list(macaddr)';
o.placeholder = _('-- add MAC --');
o.datatype = 'list(neg(or(macaddr,macrange)))';
o.placeholder = _('-- add MAC or MAC range --');

L.sortedKeys(hosts).forEach(function(mac) {
o.value(mac, E([], [ mac, ' (', E('strong', {}, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ return view.extend({
o.modalonly = true;
o.rmempty = true;

fwtool.addMACOption(s, 'advanced', 'src_mac', _('Source MAC address'), null, hosts);
fwtool.addMACOption(s, 'advanced', 'src_mac', _('Source MAC address (range)'),
_('Enter a MAC address or a range'), hosts);
fwtool.addIPOption(s, 'general', 'src_ip', _('Source address'), null, '', hosts, true);

o = s.taboption('general', form.Value, 'src_port', _('Source port'));
Expand Down
29 changes: 29 additions & 0 deletions modules/luci-base/htdocs/luci-static/resources/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,35 @@ const ValidatorFactory = baseclass.extend({
multicast ? _('valid multicast MAC address') : _('valid MAC address'));
},

macrange(multicast) {
const m = this.value.match(/^((?:[a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2})\-((?:[a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2})$/);
let valid, mac1, mac2;

let tonumber = (mac) => {
const n = mac.replace(/[^a-fA-F0-9]/g, '').toUpperCase();
return BigInt('0x' + n);
};

if (m == null)
return this.assert(false, multicast ? _('valid multicast MAC address range') : _('valid MAC address range'));

if (m[1]) {
mac1 = tonumber(m[1]);
valid = this.apply('macaddr', m[1], [multicast]);
if (!valid)
return this.assert(false, multicast ? _('valid multicast MAC address') : _('valid MAC address'));
}

if (m[2]) {
mac2 = tonumber(m[2]);
valid = this.apply('macaddr', m[2], [multicast]);
if (!valid)
return this.assert(false, multicast ? _('valid multicast MAC address') : _('valid MAC address'));
}

return this.assert(mac1 < mac2, multicast ? _('valid multicast MAC address range') : _('valid MAC address range'));
},

host(ipv4only) {
return this.assert(this.apply('hostname') || this.apply(ipv4only == 1 ? 'ip4addr' : 'ipaddr', null, ['nomask']),
_('valid hostname or IP address'));
Expand Down
Loading