luci-app-usteer: added nslookup/hosthint lookup of AP IP address
authorRamon Van Gorkom <Ramon00c00@gmail.com>
Tue, 16 Jan 2024 17:40:31 +0000 (18:40 +0100)
committerPaul Donald <itsascambutmailmeanyway@gmail.com>
Mon, 29 Jan 2024 01:18:39 +0000 (02:18 +0100)
Signed-off-by: Ramon Van Gorkom <Ramon00c00@gmail.com>
applications/luci-app-usteer/htdocs/luci-static/resources/view/usteer/usteer.js
applications/luci-app-usteer/root/usr/share/rpcd/acl.d/luci-app-usteer.json

index c92febcc0a961c75d275a2543860cd6f37ee7472..6fedd2f41a4625d6a6a2b9d14cc6bae8f47e67a3 100644 (file)
 
 var Hosts, Remotehosts, Remoteinfo, Localinfo, Clients;
 
+var dns_cache = [];
+
+function SplitWlan(wlan) {
+       var wlansplit = [];
+       if (typeof wlan.split('#')[1] !== 'undefined') {
+               wlansplit=wlan.split('#');
+               if (typeof dns_cache[wlansplit[0]] !== 'undefined') {
+                       wlansplit[0]=dns_cache[wlansplit[0]];
+               }
+       } else {
+               wlansplit[0]=_('This AP'); 
+               wlansplit[1]=wlan; 
+       }
+       return wlansplit;
+}
+
 
 function collectHearingClient(client_table_entries, mac) {
        if (typeof Clients[mac] !== 'undefined') {
@@ -24,8 +40,10 @@ function collectHearingClient(client_table_entries, mac) {
                                SSID = Remoteinfo[wlanc]['ssid'];
                                freq = Remoteinfo[wlanc]['freq'];
                        }
+                       var wlansplit=SplitWlan(wlanc);
                        client_table_entries.push([
-                               '<nobr>' + wlanc + '</nobr>',
+                               '<nobr>' + '%h'.format(wlansplit[0]) + '</nobr>',
+                               '<nobr>' + '%h'.format(wlansplit[1]) + '</nobr>',
                                SSID,
                                freq,
                                Clients[mac][wlanc]['connected'] === true ? 'Yes' : 'No',
@@ -57,7 +75,8 @@ var HearingMap = form.DummyValue.extend({
                        );
                        var client_table = E('table', {'class': 'table cbi-section-table','id':'client_table'+macn}, [
                                E('tr', {'class': 'tr table-titles'}, [
-                                       E('th', {'class': 'th', 'style': 'width:35%'}, _('IP & Interface','Combination of IP and interface name in usteer overview')),
+                                       E('th', {'class': 'th'}, _('AP','Name or IP address of access point')),
+                                       E('th', {'class': 'th'}, _('Interface name','interface name in usteer overview')),
                                        E('th', {'class': 'th', 'style': 'width:25%'}, _('SSID')),
                                        E('th', {'class': 'th', 'style': 'width:15%'}, _('Frequency','BSS operating frequency in usteer overview')),
                                        E('th', {'class': 'th', 'style': 'width:15%'}, _('Connected','Connection state in usteer overview')),
@@ -74,10 +93,14 @@ var HearingMap = form.DummyValue.extend({
 });
 
 
+
+
 function collectWlanAPInfoEntries(connectioninfo_table_entries, wlanAPInfos) {
        for (var wlan in wlanAPInfos) {
+               var wlansplit=SplitWlan(wlan);
                connectioninfo_table_entries.push([
-                       '<nobr>' + wlan + '</nobr>',
+                       '<nobr>' + '%h'.format(wlansplit[0]) + '</nobr>',
+                       '<nobr>' + '%h'.format(wlansplit[1]) + '</nobr>',
                        wlanAPInfos[wlan]['bssid'],
                        wlanAPInfos[wlan]['ssid'],
                        wlanAPInfos[wlan]['freq'],
@@ -133,8 +156,10 @@ function collectWlanAPInfos(compactconnectioninfo_table_entries, wlanAPInfos) {
                                                );
                                        }
                }
+               var wlansplit=SplitWlan(wlan);
                compactconnectioninfo_table_entries.push([
-                       '<nobr>'+wlan+'</nobr>', 
+                       '<nobr>' + '%h'.format(wlansplit[0]) + '</nobr>',
+                       '<nobr>' + '%h'.format(wlansplit[1]) + '</nobr>',
                        wlanAPInfos[wlan]['ssid'],
                        wlanAPInfos[wlan]['freq'],
                        wlanAPInfos[wlan]['load'],
@@ -144,15 +169,46 @@ function collectWlanAPInfos(compactconnectioninfo_table_entries, wlanAPInfos) {
        }
 };
 
+var callNetworkRrdnsLookup = rpc.declare({
+       object: 'network.rrdns',
+       method: 'lookup',
+       params: [ 'addrs', 'timeout', 'limit' ],
+       expect: { '': {} }
+});
+
+
 function collectRemoteHosts (remotehosttableentries,Remotehosts) {
+       const getUndefinedDnsCacheIPs = (Remotehosts, dns_cache) =>
+               Object.keys(Remotehosts).filter(IPaddr => !dns_cache.hasOwnProperty(IPaddr));
+
+       var ipAddrs = getUndefinedDnsCacheIPs(Remotehosts, dns_cache);
+
+       L.resolveDefault(callNetworkRrdnsLookup(ipAddrs, 1000, 1000), {}).then(function(replies) {
+                               for (var address of ipAddrs) {
+                                       if (!address)
+                                               continue;
+                                       if (replies[address]) {
+                                               dns_cache[address] = replies[address];
+                                               continue;
+                                       } else {
+                                               dns_cache[address]=Hosts[
+                                                       Object.keys(Hosts).find(mac =>   
+                                                               ((typeof Hosts[mac]['name'] !== 'undefined') && 
+                                                                       ((Object.keys(Hosts[mac]['ip6addrs']).find(IPaddr2 => (address === Hosts[mac]['ip6addrs'][IPaddr2]))) ||
+                                                                       (Object.keys(Hosts[mac]['ipaddrs']).find(IPaddr2 => (address === Hosts[mac]['ipaddrs'][IPaddr2])))))
+                                                                       )
+                                                       ]['name'];
+                                       }
+                               }
+       });
+
        for (var IPaddr in Remotehosts) {
-                       remotehosttableentries.push([IPaddr, Remotehosts[IPaddr]['id']]);
-               }
+               remotehosttableentries.push([IPaddr,'%h'.format(dns_cache[IPaddr]),Remotehosts[IPaddr]['id']]);
+       }
 }
 
 
 var Clientinfooverview = form.DummyValue.extend({
-
        renderWidget: function () {
                var body = E([
                        E('h3', _('Remote hosts'))
@@ -160,6 +216,7 @@ var Clientinfooverview = form.DummyValue.extend({
                var remotehost_table = E('table', {'class': 'table cbi-section-table', 'id': 'remotehost_table'}, [
                        E('tr', {'class': 'tr table-titles'}, [
                                E('th', {'class': 'th'}, _('IP address')),
+                               E('th', {'class': 'th'}, _('Hostname')),
                                E('th', {'class': 'th'}, _('Identifier'))
                        ])
                ]);
@@ -172,7 +229,8 @@ var Clientinfooverview = form.DummyValue.extend({
                );
                var connectioninfo_table = E('table', {'class': 'table cbi-section-table', 'id': 'connectioninfo_table'}, [
                        E('tr', {'class': 'tr table-titles'}, [
-                               E('th', {'class': 'th'}, _('IP & Interface name','Combination of IP and interface name in usteer overview')),
+                               E('th', {'class': 'th'}, _('AP','Name or IP address of access point')),
+                               E('th', {'class': 'th'}, _('Interface name','interface name in usteer overview')),
                                E('th', {'class': 'th'}, _('BSSID')),
                                E('th', {'class': 'th'}, _('SSID')),
                                E('th', {'class': 'th'}, _('Frequency','BSS operating frequency in usteer overview')),
@@ -192,7 +250,8 @@ var Clientinfooverview = form.DummyValue.extend({
                body.appendChild(connectioninfo_table);
                var compactconnectioninfo_table = E('table', {'class': 'table cbi-section-table','id': 'compactconnectioninfo_table'}, [
                        E('tr', {'class': 'tr table-titles'}, [
-                               E('th', {'class': 'th'}, _('IP & Interface name', 'Combination of IP and interface name in usteer overview')),
+                               E('th', {'class': 'th'}, _('AP','Name or IP address of access point')),
+                               E('th', {'class': 'th'}, _('Interface name','interface name in usteer overview')),
                                E('th', {'class': 'th'}, _('SSID')),
                                E('th', {'class': 'th'}, _('Frequency', 'BSS operating frequency in usteer overview')),
                                E('th', {'class': 'th'}, _('Load', 'Channel load in usteer overview')),
index e5740f515595573ee31eb7b6b838121fa1c4ae44..e0d24e880b0f894a50f184c64830b103d97e1aec 100644 (file)
@@ -5,7 +5,8 @@
       "ubus": {
         "uci": [ "get" ],
         "usteer": [ "remote_info","remote_hosts", "local_info", "get_clients"],
-        "luci-rpc": [ "getHostHints" ]
+        "luci-rpc": [ "getHostHints" ],
+        "network.rrdns": [ "lookup" ]
       },
       "uci": [
         "usteer"