Skip to content

Commit

Permalink
luci-app-usteer: added nslookup/hosthint lookup of AP IP address
Browse files Browse the repository at this point in the history
Signed-off-by: Ramon Van Gorkom <Ramon00c00@gmail.com>
  • Loading branch information
Ramon00 authored and systemcrash committed Jan 29, 2024
1 parent 75a2fd2 commit 7a9ae68
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@

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') {
Expand All @@ -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',
Expand Down Expand Up @@ -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')),
Expand All @@ -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'],
Expand Down Expand Up @@ -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'],
Expand All @@ -144,22 +169,54 @@ 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'))
]);
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'))
])
]);
Expand All @@ -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')),
Expand All @@ -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')),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 7a9ae68

Please sign in to comment.