summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-firewall/htdocs/luci-static/resources/tools
diff options
context:
space:
mode:
authorNiels Widger <niels@qacafe.com>2021-03-31 08:23:12 -0400
committerJo-Philipp Wich <jo@mein.io>2021-06-03 09:51:09 +0200
commitc7b7b42cd3840cfd67f412191578a8659eb63c87 (patch)
tree7b2e0c100d7cb6155da7159df3066b5dae7456f0 /applications/luci-app-firewall/htdocs/luci-static/resources/tools
parenta5195e7825cbbc3942ca6e571ae0020c1cf080c4 (diff)
treewide: Update JS using luci-rpc getHostHints
Update frontend JS code which uses luci-rpc getHostHints to support the new response format which removes the `ipv4` and `ipv6` host hint string fields and replaces them with `ipaddrs` and `ip6addrs` weighted string list fields. Signed-off-by: Niels Widger <niels@qacafe.com> [rework code to be forwards/backwards compatible, fix some Network.Hosts methods, fix IP choice ordering, change commit subject, rewrap commit message] Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'applications/luci-app-firewall/htdocs/luci-static/resources/tools')
-rw-r--r--applications/luci-app-firewall/htdocs/luci-static/resources/tools/firewall.js31
1 files changed, 23 insertions, 8 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 ebdd345c98..1f2eff3747 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
@@ -392,12 +392,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).forEach(function(ip) {
+ ipaddrs[ip] = mac;
+ });
+
+ L.toArray(hosts[mac].ip6addrs).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 +418,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]), ')' ]);
@@ -497,7 +510,9 @@ 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 ||
+ (hosts[mac].ipaddrs && hosts[mac].ipaddrs.length && hosts[mac].ipaddrs[0]) ||
+ (hosts[mac].ip6addrs && hosts[mac].ip6addrs.length && hosts[mac].ip6addrs[0]) || '?'
]), ')' ]));
});