summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-firewall/htdocs
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2019-07-07 20:11:35 +0200
committerJo-Philipp Wich <jo@mein.io>2019-07-07 20:11:35 +0200
commitf970c485cfb2571dd6d4ee6a1ad36958f1410b6a (patch)
treebac0cd8c4d8fa60c11ac4db804074b2548c020cc /applications/luci-app-firewall/htdocs
parent37ca6fe6d63f748904a18ee5213f52e642980ab5 (diff)
treewide: switch to shared isObject(), toArray() and sortedKeys() helpers
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'applications/luci-app-firewall/htdocs')
-rw-r--r--applications/luci-app-firewall/htdocs/luci-static/resources/tools/firewall.js26
-rw-r--r--applications/luci-app-firewall/htdocs/luci-static/resources/view/firewall/forwards.js36
-rw-r--r--applications/luci-app-firewall/htdocs/luci-static/resources/view/firewall/rules.js34
3 files changed, 12 insertions, 84 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 909540eaf9..6785d1ca63 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
@@ -64,22 +64,6 @@ var protocols = [
'rohc', 142, 'ROHC',
];
-function toArray(x) {
- if (x == null)
- return [];
- else if (Array.isArray(x))
- return x.map(String);
- else if (typeof(x) == 'object')
- return [ x ];
-
- var s = String(x).trim();
-
- if (s == '')
- return [];
-
- return s.split(/\s+/);
-}
-
function lookupProto(x) {
if (x == null || x == '')
return null;
@@ -104,7 +88,7 @@ return L.Class.extend({
},
fmt_mac: function(x) {
- var rv = E([]), l = toArray(x);
+ var rv = E([]), l = L.toArray(x);
if (l.length == 0)
return null;
@@ -123,7 +107,7 @@ return L.Class.extend({
},
fmt_port: function(x, d) {
- var rv = E([]), l = toArray(x);
+ var rv = E([]), l = L.toArray(x);
if (l.length == 0) {
if (d) {
@@ -159,7 +143,7 @@ return L.Class.extend({
},
fmt_ip: function(x, d) {
- var rv = E([]), l = toArray(x);
+ var rv = E([]), l = L.toArray(x);
if (l.length == 0) {
if (d) {
@@ -205,7 +189,7 @@ return L.Class.extend({
},
fmt_icmp_type: function(x) {
- var rv = E([]), l = toArray(x);
+ var rv = E([]), l = L.toArray(x);
if (l.length == 0)
return null;
@@ -228,7 +212,7 @@ return L.Class.extend({
},
fmt_proto: function(x, icmp_types) {
- var rv = E([]), l = toArray(x);
+ var rv = E([]), l = L.toArray(x);
if (l.length == 0)
return null;
diff --git a/applications/luci-app-firewall/htdocs/luci-static/resources/view/firewall/forwards.js b/applications/luci-app-firewall/htdocs/luci-static/resources/view/firewall/forwards.js
index 743d115e88..93bfc29188 100644
--- a/applications/luci-app-firewall/htdocs/luci-static/resources/view/firewall/forwards.js
+++ b/applications/luci-app-firewall/htdocs/luci-static/resources/view/firewall/forwards.js
@@ -6,34 +6,6 @@
'require tools.firewall as fwtool';
'require tools.widgets as widgets';
-function skeys(obj, key, mode) {
- if (obj == null || typeof(obj) != 'object')
- return [];
-
- return Object.keys(obj).map(function(e) {
- var v = (key != null) ? obj[e][key] : e;
-
- switch (mode) {
- case 'addr':
- v = (v != null) ? v.replace(/(?:^|[.:])([0-9a-fA-F]{1,4})/g,
- function(m0, m1) { return ('000' + m1.toLowerCase()).substr(-4) }) : null;
- break;
-
- case 'num':
- v = (v != null) ? +v : null;
- break;
- }
-
- return [ e, v ];
- }).filter(function(e) {
- return (e[1] != null);
- }).sort(function(a, b) {
- return (a[1] > b[1]);
- }).map(function(e) {
- return e[0];
- });
-}
-
function fmt(fmt /*, ...*/) {
var repl = [], wrap = false;
@@ -192,7 +164,7 @@ return L.view.extend({
o.rmempty = true;
o.datatype = 'neg(macaddr)';
o.placeholder = E('em', _('any'));
- skeys(hosts).forEach(function(mac) {
+ L.sortedKeys(hosts).forEach(function(mac) {
o.value(mac, '%s (%s)'.format(
mac,
hosts[mac].name || hosts[mac].ipv4 || hosts[mac].ipv6 || '?'
@@ -205,7 +177,7 @@ return L.view.extend({
o.rmempty = true;
o.datatype = 'neg(ipmask4)';
o.placeholder = E('em', _('any'));
- skeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
+ L.sortedKeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
o.value(hosts[mac].ipv4, '%s (%s)'.format(
hosts[mac].ipv4,
hosts[mac].name || mac
@@ -229,7 +201,7 @@ return L.view.extend({
o.rmempty = true;
o.datatype = 'neg(ipmask4)';
o.placeholder = E('em', _('any'));
- skeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
+ L.sortedKeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
o.value(hosts[mac].ipv4, '%s (%s)'.format(
hosts[mac].ipv4,
hosts[mac].name || mac
@@ -257,7 +229,7 @@ return L.view.extend({
o.modalonly = true;
o.rmempty = true;
o.datatype = 'ipmask4';
- skeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
+ L.sortedKeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
o.value(hosts[mac].ipv4, '%s (%s)'.format(
hosts[mac].ipv4,
hosts[mac].name || mac
diff --git a/applications/luci-app-firewall/htdocs/luci-static/resources/view/firewall/rules.js b/applications/luci-app-firewall/htdocs/luci-static/resources/view/firewall/rules.js
index 9fa1aa252d..d2d1916322 100644
--- a/applications/luci-app-firewall/htdocs/luci-static/resources/view/firewall/rules.js
+++ b/applications/luci-app-firewall/htdocs/luci-static/resources/view/firewall/rules.js
@@ -6,34 +6,6 @@
'require tools.firewall as fwtool';
'require tools.widgets as widgets';
-function skeys(obj, key, mode) {
- if (obj == null || typeof(obj) != 'object')
- return [];
-
- return Object.keys(obj).map(function(e) {
- var v = (key != null) ? obj[e][key] : e;
-
- switch (mode) {
- case 'addr':
- v = (v != null) ? v.replace(/(?:^|[.:])([0-9a-fA-F]{1,4})/g,
- function(m0, m1) { return ('000' + m1.toLowerCase()).substr(-4) }) : null;
- break;
-
- case 'num':
- v = (v != null) ? +v : null;
- break;
- }
-
- return [ e, v ];
- }).filter(function(e) {
- return (e[1] != null);
- }).sort(function(a, b) {
- return (a[1] > b[1]);
- }).map(function(e) {
- return e[0];
- });
-}
-
function fmt(fmt /*, ...*/) {
var repl = [], wrap = false;
@@ -276,7 +248,7 @@ return L.view.extend({
o.modalonly = true;
o.datatype = 'list(macaddr)';
o.placeholder = _('any');
- skeys(hosts).forEach(function(mac) {
+ L.sortedKeys(hosts).forEach(function(mac) {
o.value(mac, '%s (%s)'.format(
mac,
hosts[mac].name || hosts[mac].ipv4 || hosts[mac].ipv6 || '?'
@@ -287,7 +259,7 @@ return L.view.extend({
o.modalonly = true;
o.datatype = 'list(neg(ipmask))';
o.placeholder = _('any');
- skeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
+ L.sortedKeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
o.value(hosts[mac].ipv4, '%s (%s)'.format(
hosts[mac].ipv4,
hosts[mac].name || mac
@@ -324,7 +296,7 @@ return L.view.extend({
o.modalonly = true;
o.datatype = 'list(neg(ipmask))';
o.placeholder = _('any');
- skeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
+ L.sortedKeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
o.value(hosts[mac].ipv4, '%s (%s)'.format(
hosts[mac].ipv4,
hosts[mac].name || mac