diff options
Diffstat (limited to 'applications/luci-app-firewall/htdocs/luci-static/resources/tools/firewall.js')
-rw-r--r-- | applications/luci-app-firewall/htdocs/luci-static/resources/tools/firewall.js | 81 |
1 files changed, 64 insertions, 17 deletions
diff --git a/applications/luci-app-firewall/htdocs/luci-static/resources/tools/firewall.js b/applications/luci-app-firewall/htdocs/luci-static/resources/tools/firewall.js index 32998c2ff8..f9d7dc611c 100644 --- a/applications/luci-app-firewall/htdocs/luci-static/resources/tools/firewall.js +++ b/applications/luci-app-firewall/htdocs/luci-static/resources/tools/firewall.js @@ -6,6 +6,7 @@ 'require form'; 'require network'; 'require firewall'; +'require validation'; 'require tools.prng as random'; var protocols = [ @@ -392,12 +393,25 @@ return baseclass.extend({ }, transformHostHints: function(family, hosts) { - var choice_values = [], choice_labels = {}; + var choice_values = [], + choice_labels = {}, + ip6addrs = {}, + ipaddrs = {}; + + for (var mac in hosts) { + L.toArray(hosts[mac].ipaddrs || hosts[mac].ipv4).forEach(function(ip) { + ipaddrs[ip] = mac; + }); + + L.toArray(hosts[mac].ip6addrs || hosts[mac].ipv6).forEach(function(ip) { + ip6addrs[ip] = mac; + }); + } if (!family || family == 'ipv4') { - L.sortedKeys(hosts, 'ipv4', 'addr').forEach(function(mac) { - var val = hosts[mac].ipv4, - txt = hosts[mac].name || mac; + L.sortedKeys(ipaddrs, null, 'addr').forEach(function(ip) { + var val = ip, + txt = hosts[ipaddrs[ip]].name || ipaddrs[ip]; choice_values.push(val); choice_labels[val] = E([], [ val, ' (', E('strong', {}, [txt]), ')' ]); @@ -405,9 +419,9 @@ return baseclass.extend({ } if (!family || family == 'ipv6') { - L.sortedKeys(hosts, 'ipv6', 'addr').forEach(function(mac) { - var val = hosts[mac].ipv6, - txt = hosts[mac].name || mac; + L.sortedKeys(ip6addrs, null, 'addr').forEach(function(ip) { + var val = ip, + txt = hosts[ip6addrs[ip]].name || ip6addrs[ip]; choice_values.push(val); choice_labels[val] = E([], [ val, ' (', E('strong', {}, [txt]), ')' ]); @@ -425,11 +439,27 @@ return baseclass.extend({ opt.addChoices(choices[0], choices[1]); }, + CBIDynamicMultiValueList: form.DynamicList.extend({ + renderWidget: function(/* ... */) { + var dl = form.DynamicList.prototype.renderWidget.apply(this, arguments), + inst = dom.findClassInstance(dl); + + inst.addItem = function(dl, value, text, flash) { + var values = L.toArray(value); + for (var i = 0; i < values.length; i++) + ui.DynamicList.prototype.addItem.call(this, dl, values[i], null, true); + }; + + return dl; + } + }), + addIPOption: function(s, tab, name, label, description, family, hosts, multiple) { - var o = s.taboption(tab, multiple ? form.DynamicList : form.Value, name, label, description); + var o = s.taboption(tab, multiple ? this.CBIDynamicMultiValueList : form.Value, name, label, description); + var fw4 = L.hasSystemFeature('firewall4'); o.modalonly = true; - o.datatype = 'list(neg(ipmask))'; + o.datatype = (fw4 && validation.types.iprange) ? 'list(neg(or(ipmask("true"),iprange)))' : 'list(neg(ipmask("true")))'; o.placeholder = multiple ? _('-- add IP --') : _('any'); if (family != null) { @@ -449,18 +479,20 @@ return baseclass.extend({ addLocalIPOption: function(s, tab, name, label, description, devices) { var o = s.taboption(tab, form.Value, name, label, description); + var fw4 = L.hasSystemFeature('firewall4'); o.modalonly = true; - o.datatype = 'ip4addr("nomask")'; + o.datatype = !fw4?'ip4addr("nomask")':'ipaddr("nomask")'; o.placeholder = _('any'); L.sortedKeys(devices, 'name').forEach(function(dev) { var ip4addrs = devices[dev].ipaddrs; + var ip6addrs = devices[dev].ip6addrs; - if (!L.isObject(devices[dev].flags) || !Array.isArray(ip4addrs) || devices[dev].flags.loopback) + if (!L.isObject(devices[dev].flags) || devices[dev].flags.loopback) return; - for (var i = 0; i < ip4addrs.length; i++) { + for (var i = 0; Array.isArray(ip4addrs) && i < ip4addrs.length; i++) { if (!L.isObject(ip4addrs[i]) || !ip4addrs[i].address) continue; @@ -468,13 +500,21 @@ return baseclass.extend({ ip4addrs[i].address, ' (', E('strong', {}, [dev]), ')' ])); } + for (var i = 0; fw4 && Array.isArray(ip6addrs) && i < ip6addrs.length; i++) { + if (!L.isObject(ip6addrs[i]) || !ip6addrs[i].address) + continue; + + o.value(ip6addrs[i].address, E([], [ + ip6addrs[i].address, ' (', E('strong', {}, [dev]), ')' + ])); + } }); return o; }, addMACOption: function(s, tab, name, label, description, hosts) { - var o = s.taboption(tab, form.DynamicList, name, label, description); + var o = s.taboption(tab, this.CBIDynamicMultiValueList, name, label, description); o.modalonly = true; o.datatype = 'list(macaddr)'; @@ -482,7 +522,10 @@ return baseclass.extend({ L.sortedKeys(hosts).forEach(function(mac) { o.value(mac, E([], [ mac, ' (', E('strong', {}, [ - hosts[mac].name || hosts[mac].ipv4 || hosts[mac].ipv6 || '?' + hosts[mac].name || + L.toArray(hosts[mac].ipaddrs || hosts[mac].ipv4)[0] || + L.toArray(hosts[mac].ip6addrs || hosts[mac].ipv6)[0] || + '?' ]), ')' ])); }); @@ -522,6 +565,9 @@ return baseclass.extend({ } }, this)); + if (cfgvalue == '*' || cfgvalue == 'any' || cfgvalue == 'all') + cfgvalue = 'all'; + return cfgvalue; }, @@ -556,8 +602,7 @@ return baseclass.extend({ }); widget.createChoiceElement = function(sb, value) { - var m = value.match(/^(0x[0-9a-f]{1,2}|[0-9]{1,3})$/), - p = lookupProto(lookupProto(m ? +m[1] : value)[0]); + var p = lookupProto(value); return ui.Dropdown.prototype.createChoiceElement.call(this, sb, p[2], p[1]); }; @@ -567,9 +612,11 @@ return baseclass.extend({ var m = value.match(/^(0x[0-9a-f]{1,2}|[0-9]{1,3})$/), p = lookupProto(m ? +m[1] : value); - return (p[0] > -1) ? p[2] : value; + return (p[0] > -1) ? p[2] : p[1]; }); + values.sort(); + return ui.Dropdown.prototype.createItems.call(this, sb, values.join(' ')); }; |