summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base/htdocs
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 /modules/luci-base/htdocs
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 'modules/luci-base/htdocs')
-rw-r--r--modules/luci-base/htdocs/luci-static/resources/network.js72
1 files changed, 53 insertions, 19 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/network.js b/modules/luci-base/htdocs/luci-static/resources/network.js
index fccb72b3d2..40f9eaaa5b 100644
--- a/modules/luci-base/htdocs/luci-static/resources/network.js
+++ b/modules/luci-base/htdocs/luci-static/resources/network.js
@@ -1805,7 +1805,9 @@ Hosts = baseclass.extend(/** @lends LuCI.network.Hosts.prototype */ {
* the corresponding host.
*/
getHostnameByMACAddr: function(mac) {
- return this.hosts[mac] ? this.hosts[mac].name : null;
+ return this.hosts[mac]
+ ? (this.hosts[mac].name || null)
+ : null;
},
/**
@@ -1820,7 +1822,9 @@ Hosts = baseclass.extend(/** @lends LuCI.network.Hosts.prototype */ {
* the corresponding host.
*/
getIPAddrByMACAddr: function(mac) {
- return this.hosts[mac] ? this.hosts[mac].ipv4 : null;
+ return this.hosts[mac]
+ ? (L.toArray(this.hosts[mac].ipaddrs || this.hosts[mac].ipv4)[0] || null)
+ : null;
},
/**
@@ -1835,7 +1839,9 @@ Hosts = baseclass.extend(/** @lends LuCI.network.Hosts.prototype */ {
* the corresponding host.
*/
getIP6AddrByMACAddr: function(mac) {
- return this.hosts[mac] ? this.hosts[mac].ipv6 : null;
+ return this.hosts[mac]
+ ? (L.toArray(this.hosts[mac].ip6addrs || this.hosts[mac].ipv6)[0] || null)
+ : null;
},
/**
@@ -1850,9 +1856,17 @@ Hosts = baseclass.extend(/** @lends LuCI.network.Hosts.prototype */ {
* the corresponding host.
*/
getHostnameByIPAddr: function(ipaddr) {
- for (var mac in this.hosts)
- if (this.hosts[mac].ipv4 == ipaddr && this.hosts[mac].name != null)
- return this.hosts[mac].name;
+ for (var mac in this.hosts) {
+ if (this.hosts[mac].name == null)
+ continue;
+
+ var addrs = L.toArray(this.hosts[mac].ipaddrs || this.hosts[mac].ipv4);
+
+ for (var i = 0; i < addrs.length; i++)
+ if (addrs[i] == ipaddr)
+ return this.hosts[mac].name;
+ }
+
return null;
},
@@ -1868,16 +1882,21 @@ Hosts = baseclass.extend(/** @lends LuCI.network.Hosts.prototype */ {
* the corresponding host.
*/
getMACAddrByIPAddr: function(ipaddr) {
- for (var mac in this.hosts)
- if (this.hosts[mac].ipv4 == ipaddr)
- return mac;
+ for (var mac in this.hosts) {
+ var addrs = L.toArray(this.hosts[mac].ipaddrs || this.hosts[mac].ipv4);
+
+ for (var i = 0; i < addrs.length; i++)
+ if (addrs[i] == ipaddr)
+ return mac;
+ }
+
return null;
},
/**
* Lookup the hostname associated with the given IPv6 address.
*
- * @param {string} ipaddr
+ * @param {string} ip6addr
* The IPv6 address to lookup.
*
* @returns {null|string}
@@ -1886,16 +1905,24 @@ Hosts = baseclass.extend(/** @lends LuCI.network.Hosts.prototype */ {
* the corresponding host.
*/
getHostnameByIP6Addr: function(ip6addr) {
- for (var mac in this.hosts)
- if (this.hosts[mac].ipv6 == ip6addr && this.hosts[mac].name != null)
- return this.hosts[mac].name;
+ for (var mac in this.hosts) {
+ if (this.hosts[mac].name == null)
+ continue;
+
+ var addrs = L.toArray(this.hosts[mac].ip6addrs || this.hosts[mac].ipv6);
+
+ for (var i = 0; i < addrs.length; i++)
+ if (addrs[i] == ip6addr)
+ return this.hosts[mac].name;
+ }
+
return null;
},
/**
* Lookup the MAC address associated with the given IPv6 address.
*
- * @param {string} ipaddr
+ * @param {string} ip6addr
* The IPv6 address to lookup.
*
* @returns {null|string}
@@ -1904,9 +1931,14 @@ Hosts = baseclass.extend(/** @lends LuCI.network.Hosts.prototype */ {
* the corresponding host.
*/
getMACAddrByIP6Addr: function(ip6addr) {
- for (var mac in this.hosts)
- if (this.hosts[mac].ipv6 == ip6addr)
- return mac;
+ for (var mac in this.hosts) {
+ var addrs = L.toArray(this.hosts[mac].ip6addrs || this.hosts[mac].ipv6);
+
+ for (var i = 0; i < addrs.length; i++)
+ if (addrs[i] == ip6addr)
+ return mac;
+ }
+
return null;
},
@@ -1933,13 +1965,15 @@ Hosts = baseclass.extend(/** @lends LuCI.network.Hosts.prototype */ {
*/
getMACHints: function(preferIp6) {
var rv = [];
+
for (var mac in this.hosts) {
var hint = this.hosts[mac].name ||
- this.hosts[mac][preferIp6 ? 'ipv6' : 'ipv4'] ||
- this.hosts[mac][preferIp6 ? 'ipv4' : 'ipv6'];
+ L.toArray(this.hosts[mac][preferIp6 ? 'ip6addrs' : 'ipaddrs'] || this.hosts[mac][preferIp6 ? 'ipv6' : 'ipv4'])[0] ||
+ L.toArray(this.hosts[mac][preferIp6 ? 'ipaddrs' : 'ip6addrs'] || this.hosts[mac][preferIp6 ? 'ipv4' : 'ipv6'])[0];
rv.push([mac, hint]);
}
+
return rv.sort(function(a, b) { return a[0] > b[0] });
}
});