Skip to content

Commit 7a9ae68

Browse files
Ramon00systemcrash
authored andcommitted
luci-app-usteer: added nslookup/hosthint lookup of AP IP address
Signed-off-by: Ramon Van Gorkom <[email protected]>
1 parent 75a2fd2 commit 7a9ae68

File tree

2 files changed

+70
-10
lines changed

2 files changed

+70
-10
lines changed

applications/luci-app-usteer/htdocs/luci-static/resources/view/usteer/usteer.js

+68-9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,22 @@
1010

1111
var Hosts, Remotehosts, Remoteinfo, Localinfo, Clients;
1212

13+
var dns_cache = [];
14+
15+
function SplitWlan(wlan) {
16+
var wlansplit = [];
17+
if (typeof wlan.split('#')[1] !== 'undefined') {
18+
wlansplit=wlan.split('#');
19+
if (typeof dns_cache[wlansplit[0]] !== 'undefined') {
20+
wlansplit[0]=dns_cache[wlansplit[0]];
21+
}
22+
} else {
23+
wlansplit[0]=_('This AP');
24+
wlansplit[1]=wlan;
25+
}
26+
return wlansplit;
27+
}
28+
1329

1430
function collectHearingClient(client_table_entries, mac) {
1531
if (typeof Clients[mac] !== 'undefined') {
@@ -24,8 +40,10 @@ function collectHearingClient(client_table_entries, mac) {
2440
SSID = Remoteinfo[wlanc]['ssid'];
2541
freq = Remoteinfo[wlanc]['freq'];
2642
}
43+
var wlansplit=SplitWlan(wlanc);
2744
client_table_entries.push([
28-
'<nobr>' + wlanc + '</nobr>',
45+
'<nobr>' + '%h'.format(wlansplit[0]) + '</nobr>',
46+
'<nobr>' + '%h'.format(wlansplit[1]) + '</nobr>',
2947
SSID,
3048
freq,
3149
Clients[mac][wlanc]['connected'] === true ? 'Yes' : 'No',
@@ -57,7 +75,8 @@ var HearingMap = form.DummyValue.extend({
5775
);
5876
var client_table = E('table', {'class': 'table cbi-section-table','id':'client_table'+macn}, [
5977
E('tr', {'class': 'tr table-titles'}, [
60-
E('th', {'class': 'th', 'style': 'width:35%'}, _('IP & Interface','Combination of IP and interface name in usteer overview')),
78+
E('th', {'class': 'th'}, _('AP','Name or IP address of access point')),
79+
E('th', {'class': 'th'}, _('Interface name','interface name in usteer overview')),
6180
E('th', {'class': 'th', 'style': 'width:25%'}, _('SSID')),
6281
E('th', {'class': 'th', 'style': 'width:15%'}, _('Frequency','BSS operating frequency in usteer overview')),
6382
E('th', {'class': 'th', 'style': 'width:15%'}, _('Connected','Connection state in usteer overview')),
@@ -74,10 +93,14 @@ var HearingMap = form.DummyValue.extend({
7493
});
7594

7695

96+
97+
7798
function collectWlanAPInfoEntries(connectioninfo_table_entries, wlanAPInfos) {
7899
for (var wlan in wlanAPInfos) {
100+
var wlansplit=SplitWlan(wlan);
79101
connectioninfo_table_entries.push([
80-
'<nobr>' + wlan + '</nobr>',
102+
'<nobr>' + '%h'.format(wlansplit[0]) + '</nobr>',
103+
'<nobr>' + '%h'.format(wlansplit[1]) + '</nobr>',
81104
wlanAPInfos[wlan]['bssid'],
82105
wlanAPInfos[wlan]['ssid'],
83106
wlanAPInfos[wlan]['freq'],
@@ -133,8 +156,10 @@ function collectWlanAPInfos(compactconnectioninfo_table_entries, wlanAPInfos) {
133156
);
134157
}
135158
}
159+
var wlansplit=SplitWlan(wlan);
136160
compactconnectioninfo_table_entries.push([
137-
'<nobr>'+wlan+'</nobr>',
161+
'<nobr>' + '%h'.format(wlansplit[0]) + '</nobr>',
162+
'<nobr>' + '%h'.format(wlansplit[1]) + '</nobr>',
138163
wlanAPInfos[wlan]['ssid'],
139164
wlanAPInfos[wlan]['freq'],
140165
wlanAPInfos[wlan]['load'],
@@ -144,22 +169,54 @@ function collectWlanAPInfos(compactconnectioninfo_table_entries, wlanAPInfos) {
144169
}
145170
};
146171

172+
var callNetworkRrdnsLookup = rpc.declare({
173+
object: 'network.rrdns',
174+
method: 'lookup',
175+
params: [ 'addrs', 'timeout', 'limit' ],
176+
expect: { '': {} }
177+
});
178+
179+
147180
function collectRemoteHosts (remotehosttableentries,Remotehosts) {
181+
const getUndefinedDnsCacheIPs = (Remotehosts, dns_cache) =>
182+
Object.keys(Remotehosts).filter(IPaddr => !dns_cache.hasOwnProperty(IPaddr));
183+
184+
var ipAddrs = getUndefinedDnsCacheIPs(Remotehosts, dns_cache);
185+
186+
L.resolveDefault(callNetworkRrdnsLookup(ipAddrs, 1000, 1000), {}).then(function(replies) {
187+
for (var address of ipAddrs) {
188+
if (!address)
189+
continue;
190+
if (replies[address]) {
191+
dns_cache[address] = replies[address];
192+
continue;
193+
} else {
194+
dns_cache[address]=Hosts[
195+
Object.keys(Hosts).find(mac =>
196+
((typeof Hosts[mac]['name'] !== 'undefined') &&
197+
((Object.keys(Hosts[mac]['ip6addrs']).find(IPaddr2 => (address === Hosts[mac]['ip6addrs'][IPaddr2]))) ||
198+
(Object.keys(Hosts[mac]['ipaddrs']).find(IPaddr2 => (address === Hosts[mac]['ipaddrs'][IPaddr2])))))
199+
)
200+
]['name'];
201+
}
202+
}
203+
});
204+
148205
for (var IPaddr in Remotehosts) {
149-
remotehosttableentries.push([IPaddr, Remotehosts[IPaddr]['id']]);
150-
}
206+
remotehosttableentries.push([IPaddr,'%h'.format(dns_cache[IPaddr]),Remotehosts[IPaddr]['id']]);
207+
}
151208
}
152209

153210

154211
var Clientinfooverview = form.DummyValue.extend({
155-
156212
renderWidget: function () {
157213
var body = E([
158214
E('h3', _('Remote hosts'))
159215
]);
160216
var remotehost_table = E('table', {'class': 'table cbi-section-table', 'id': 'remotehost_table'}, [
161217
E('tr', {'class': 'tr table-titles'}, [
162218
E('th', {'class': 'th'}, _('IP address')),
219+
E('th', {'class': 'th'}, _('Hostname')),
163220
E('th', {'class': 'th'}, _('Identifier'))
164221
])
165222
]);
@@ -172,7 +229,8 @@ var Clientinfooverview = form.DummyValue.extend({
172229
);
173230
var connectioninfo_table = E('table', {'class': 'table cbi-section-table', 'id': 'connectioninfo_table'}, [
174231
E('tr', {'class': 'tr table-titles'}, [
175-
E('th', {'class': 'th'}, _('IP & Interface name','Combination of IP and interface name in usteer overview')),
232+
E('th', {'class': 'th'}, _('AP','Name or IP address of access point')),
233+
E('th', {'class': 'th'}, _('Interface name','interface name in usteer overview')),
176234
E('th', {'class': 'th'}, _('BSSID')),
177235
E('th', {'class': 'th'}, _('SSID')),
178236
E('th', {'class': 'th'}, _('Frequency','BSS operating frequency in usteer overview')),
@@ -192,7 +250,8 @@ var Clientinfooverview = form.DummyValue.extend({
192250
body.appendChild(connectioninfo_table);
193251
var compactconnectioninfo_table = E('table', {'class': 'table cbi-section-table','id': 'compactconnectioninfo_table'}, [
194252
E('tr', {'class': 'tr table-titles'}, [
195-
E('th', {'class': 'th'}, _('IP & Interface name', 'Combination of IP and interface name in usteer overview')),
253+
E('th', {'class': 'th'}, _('AP','Name or IP address of access point')),
254+
E('th', {'class': 'th'}, _('Interface name','interface name in usteer overview')),
196255
E('th', {'class': 'th'}, _('SSID')),
197256
E('th', {'class': 'th'}, _('Frequency', 'BSS operating frequency in usteer overview')),
198257
E('th', {'class': 'th'}, _('Load', 'Channel load in usteer overview')),

applications/luci-app-usteer/root/usr/share/rpcd/acl.d/luci-app-usteer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"ubus": {
66
"uci": [ "get" ],
77
"usteer": [ "remote_info","remote_hosts", "local_info", "get_clients"],
8-
"luci-rpc": [ "getHostHints" ]
8+
"luci-rpc": [ "getHostHints" ],
9+
"network.rrdns": [ "lookup" ]
910
},
1011
"uci": [
1112
"usteer"

0 commit comments

Comments
 (0)