Merge pull request #3158 from dibdot/banIP
[oweals/luci.git] / modules / luci-base / luasrc / view / wifi_assoclist.htm
1 <%
2         local supports_deauth = {}
3
4         local _, v
5         for _, v in ipairs(luci.util.ubus()) do
6                 local iface = v:match("^hostapd%.(.+)$")
7                 if iface then
8                         local funcs = luci.util.ubus(v)
9                         if type(funcs) == "table" and funcs.del_client then
10                                 supports_deauth[iface] = true
11                         end
12                 end
13         end
14 %>
15
16 <script type="text/javascript">//<![CDATA[
17         var supports_deauth = <%= luci.http.write_json(supports_deauth) %>;
18
19         function wifirate(bss, rx) {
20                 var p = rx ? 'rx_' : 'tx_',
21                     s = '%.1f <%:Mbit/s%>, %d<%:MHz%>'
22                                         .format(bss[p+'rate'] / 1000, bss[p+'mhz']),
23                     ht = bss[p+'ht'], vht = bss[p+'vht'],
24                         mhz = bss[p+'mhz'], nss = bss[p+'nss'],
25                         mcs = bss[p+'mcs'], sgi = bss[p+'short_gi'];
26
27                 if (ht || vht) {
28                         if (vht) s += ', VHT-MCS %d'.format(mcs);
29                         if (nss) s += ', VHT-NSS %d'.format(nss);
30                         if (ht)  s += ', MCS %s'.format(mcs);
31                         if (sgi) s += ', <%:Short GI%>';
32                 }
33
34                 return s;
35         }
36
37         function handleDeauth(ev) {
38                 (new XHR()).post('<%=url('admin/wireless_deauth')%>', {
39                         token: '<%=token%>',
40                         iface: ev.target.getAttribute('data-iface'),
41                         bssid: ev.target.getAttribute('data-bssid')
42                 }, function() {
43                         ev.target.disabled = true;
44                 });
45         }
46
47         XHR.poll(-1, '<%=url('admin/wireless_assoclist')%>', null,
48                 function(x, st)
49                 {
50                         var tb = document.getElementById('wifi_assoclist_table');
51                         if (st && tb)
52                         {
53                                 var rows = [];
54
55                                 st.forEach(function(bss) {
56                                         var icon;
57                                         var q = (-1 * (bss.noise - bss.signal)) / 5;
58                                         if (q < 1)
59                                                 icon = "<%=resource%>/icons/signal-0.png";
60                                         else if (q < 2)
61                                                 icon = "<%=resource%>/icons/signal-0-25.png";
62                                         else if (q < 3)
63                                                 icon = "<%=resource%>/icons/signal-25-50.png";
64                                         else if (q < 4)
65                                                 icon = "<%=resource%>/icons/signal-50-75.png";
66                                         else
67                                                 icon = "<%=resource%>/icons/signal-75-100.png";
68
69                                         rows.push([
70                                                 '<span class="ifacebadge" title="%q"><img src="<%=resource%>/icons/wifi.png" /> <a href="%s">%h</a><small>&#160;(%h)</small></span>'.format(
71                                                         bss.radio,
72                                                         bss.link,
73                                                         bss.name,
74                                                         bss.ifname),
75                                                 bss.bssid,
76                                                 bss.host_hint ? '%h (%h)'.format(bss.host_name || '?', bss.host_hint) : (bss.host_name || '?'),
77                                                 '<span class="ifacebadge" title="<%:Signal%>: %d <%:dBm%> / <%:Noise%>: %d <%:dBm%> / <%:SNR%>: %d"><img src="%s" /> %d / %d <%:dBm%></span>'.format(
78                                                         bss.signal,
79                                                         bss.noise,
80                                                         bss.signal - bss.noise,
81                                                         icon,
82                                                         bss.signal,
83                                                         bss.noise),
84                                                 E('span', {}, [
85                                                         E('span', wifirate(bss, true)),
86                                                         E('br'),
87                                                         E('span', wifirate(bss, false))
88                                                 ]),
89                                                 supports_deauth[bss.ifname] ? E('input', {
90                                                         type: 'button',
91                                                         class: 'cbi-button cbi-button-remove',
92                                                         value: '<%:Disconnect%>',
93                                                         'data-bssid': bss.bssid,
94                                                         'data-iface': bss.ifname,
95                                                         click: handleDeauth
96                                                 }) : '-'
97                                         ]);
98                                 });
99
100                                 cbi_update_table(tb, rows, '<em><%:No information available%></em>');
101                         }
102                 }
103         );
104 //]]></script>
105
106 <div class="table" id="wifi_assoclist_table">
107         <div class="tr table-titles">
108                 <div class="th nowrap"><%:Network%></div>
109                 <div class="th hide-xs"><%:MAC-Address%></div>
110                 <div class="th nowrap"><%:Host%></div>
111                 <div class="th nowrap"><%:Signal%> / <%:Noise%></div>
112                 <div class="th nowrap"><%:RX Rate%> / <%:TX Rate%></div>
113                 <% if next(supports_deauth) then %>
114                         <div class="th right"><%:Disconnect%></div>
115                 <% end %>
116         </div>
117         <div class="tr placeholder">
118                 <div class="td"><em><%:Collecting data...%></em></div>
119         </div>
120 </div>