modules/admin-full: fix word wrapping in wifi overview page when using bootstrap...
[project/luci.git] / modules / admin-full / luasrc / view / admin_network / wifi_overview.htm
1 <%#
2 LuCI - Lua Configuration Interface
3 Copyright 2008-2009 Steven Barth <steven@midlink.org>
4 Copyright 2008-2011 Jo-Philipp Wich <xm@subsignal.org>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10         http://www.apache.org/licenses/LICENSE-2.0
11
12 -%>
13
14 <%-
15
16         local sys = require "luci.sys"
17         local fs = require "luci.fs"
18         local utl = require "luci.util"
19         local uci = require "luci.model.uci".cursor()
20         local ntm = require "luci.model.network"
21
22         local has_iwinfo = pcall(require, "iwinfo")
23
24         ntm.init(uci)
25
26         function guess_wifi_hw(ifname)
27                 local bands = ""
28                 local name, idx = ifname:match("^([a-z]+)(%d+)")
29                 idx = tonumber(idx)
30
31                 if has_iwinfo then
32                         local iw = luci.sys.wifi.getiwinfo(ifname)
33                         local bl = iw.hwmodelist
34                         if bl and next(bl) then
35                                 if bl.a then bands = bands .. "a" end
36                                 if bl.b then bands = bands .. "b" end
37                                 if bl.g then bands = bands .. "g" end
38                                 if bl.n then bands = bands .. "n" end
39                         end
40                 end
41
42                 -- wl.o
43                 if name == "wl" then
44                         local name = translatef("Broadcom 802.11%s Wireless Controller", bands)
45                         local nm   = 0
46
47                         local fd = nixio.open("/proc/bus/pci/devices", "r")
48                         if fd then
49                                 local ln
50                                 for ln in fd:linesource() do
51                                         if ln:match("wl$") then
52                                                 if nm == idx then
53                                                         local version = ln:match("^%S+%s+%S%S%S%S([0-9a-f]+)")
54                                                         name = translatef(
55                                                                 "Broadcom BCM%04x 802.11 Wireless Controller",
56                                                                 tonumber(version, 16)
57                                                         )
58
59                                                         break
60                                                 else
61                                                         nm = nm + 1
62                                                 end
63                                         end
64                                 end
65                                 fd:close()
66                         end
67
68                         return name
69
70                 -- madwifi
71                 elseif name == "ath" or name == "wifi" then
72                         return translatef("Atheros 802.11%s Wireless Controller", bands)
73
74                 -- ralink
75                 elseif name == "ra" then
76                         return translatef("RaLink 802.11%s Wireless Controller", bands)
77
78                 -- hermes
79                 elseif name == "eth" then
80                         return translate("Hermes 802.11b Wireless Controller")
81
82                 -- hostap
83                 elseif name == "wlan" and fs.isdirectory("/proc/net/hostap/" .. ifname) then
84                         return translate("Prism2/2.5/3 802.11b Wireless Controller")
85
86                 -- dunno yet
87                 else
88                         return translatef("Generic 802.11%s Wireless Controller", bands)
89                 end
90         end
91
92         local devices  = ntm:get_wifidevs()
93         local arpcache = { }
94         sys.net.arptable(function(e) arpcache[e["HW address"]:upper()] = e["IP address"] end)
95
96         local netlist = { }
97         local netdevs = { }
98
99         local dev
100         for _, dev in ipairs(devices) do
101                 local net
102                 for _, net in ipairs(dev:get_wifinets()) do
103                         netlist[#netlist+1] = net:id()
104                         netdevs[net:id()] = dev:name()
105                 end
106         end
107 -%>
108
109 <%+header%>
110
111 <% if not has_iwinfo then %>
112         <div class="errorbox">
113                 <strong><%:Package libiwinfo required!%></strong><br />
114                 <%_The <em>libiwinfo-lua</em> package is not installed. You must install this component for working wireless configuration!%>
115         </div>
116 <% end %>
117
118 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
119 <script type="text/javascript">//<![CDATA[
120         var wifidevs = <%=luci.http.write_json(netdevs)%>;
121         var arptable = <%=luci.http.write_json(arpcache)%>;
122
123         var is_reconnecting = false;
124
125         function nowrap(s) {
126                 return s.replace(/ /g, '&#160;');
127         }
128
129         function wifi_shutdown(id, toggle) {
130                 var reconnect = (toggle.getAttribute('active') == 'false');
131
132                 if (!reconnect && !confirm(String.format('<%:Really shutdown network ?\nYou might lose access to this device if you are connected via this interface.%>')))
133                         return;
134
135                 is_reconnecting = true;
136
137                 var s = document.getElementById('iw-rc-status');
138                 if (s)
139                 {
140                         s.parentNode.style.display = 'block';
141                         s.innerHTML = '<%:Waiting for changes to be applied...%>';
142                 }
143
144                 for (var net in wifidevs)
145                 {
146                         var st = document.getElementById(net + '-iw-status');
147                         if (st)
148                                 st.innerHTML = '<em><%:Wireless is restarting...%></em>';
149                 }
150
151                 XHR.get('<%=luci.dispatcher.build_url("admin", "network")%>/wireless_' + (reconnect ? 'reconnect' : 'shutdown') + '/' + id, null,
152                         function(x)
153                         {
154                                 if (s)
155                                 {
156                                         s.innerHTML = reconnect
157                                                 ? '<%:Wireless restarted%>'
158                                                 : '<%:Wireless shut down%>';
159
160                                         window.setTimeout(function() {
161                                                 s.parentNode.style.display = 'none';
162                                                 is_reconnecting = false;
163                                         }, 1000);
164                                 }
165                         }
166                 );
167         }
168
169         XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "network", "wireless_status", table.concat(netlist, ","))%>', null,
170                 function(x, st)
171                 {
172                         if (st)
173                         {
174                                 var assoctable = document.getElementById('iw-assoclist');
175                                 if (assoctable)
176                                         while (assoctable.rows.length > 1)
177                                                 assoctable.rows[1].parentNode.removeChild(assoctable.rows[1]);
178
179                                 var devup = { };
180                                 var rowstyle = 1;
181
182                                 for( var i = 0; i < st.length; i++ )
183                                 {
184                                         var iw = st[i];
185                                         var is_assoc = (iw.bssid && iw.bssid != '00:00:00:00:00:00' && iw.channel);
186                                         var p = iw.quality;
187                                         var q = is_assoc ? p : -1;
188
189                                         var icon;
190                                         if (q < 0)
191                                                 icon = "<%=resource%>/icons/signal-none.png";
192                                         else if (q == 0)
193                                                 icon = "<%=resource%>/icons/signal-0.png";
194                                         else if (q < 25)
195                                                 icon = "<%=resource%>/icons/signal-0-25.png";
196                                         else if (q < 50)
197                                                 icon = "<%=resource%>/icons/signal-25-50.png";
198                                         else if (q < 75)
199                                                 icon = "<%=resource%>/icons/signal-50-75.png";
200                                         else
201                                                 icon = "<%=resource%>/icons/signal-75-100.png";
202
203                                         if (!devup[wifidevs[iw.id]])
204                                                 devup[wifidevs[iw.id]] = is_assoc;
205
206                                         var sig = document.getElementById(iw.id + '-iw-signal');
207                                         if (sig)
208                                                 sig.innerHTML = String.format(
209                                                         '<img src="%s" title="<%:Signal%>: %d <%:dBm%> / <%:Noise%>: %d <%:dBm%>" /><br />' +
210                                                         '<small>%d%%</small>', icon, iw.signal, iw.noise, p
211                                                 );
212
213                                         var toggle = document.getElementById(iw.id + '-iw-toggle');
214                                         if (toggle)
215                                         {
216                                                 if (is_assoc)
217                                                 {
218                                                         toggle.className = 'cbi-button cbi-button-reset';
219                                                         toggle.value = '<%:Disable%>';
220                                                         toggle.title = '<%:Shutdown this network%>';
221                                                 }
222                                                 else
223                                                 {
224                                                         toggle.className = 'cbi-button cbi-button-reload';
225                                                         toggle.value = '<%:Enable%>';
226                                                         toggle.title = '<%:Activate this network%>';
227                                                 }
228
229                                                 toggle.setAttribute('active', is_assoc);
230                                         }
231
232                                         var info = document.getElementById(iw.id + '-iw-status');
233                                         if (info)
234                                         {
235                                                 if (is_assoc)
236                                                         info.innerHTML = String.format(
237                                                                 '<strong><%:SSID%>:</strong> %h | ' +
238                                                                 '<strong><%:Mode%>:</strong> %s<br />' +
239                                                                 '<strong><%:BSSID%>:</strong> %s | ' +
240                                                                 '<strong><%:Encryption%>:</strong> %s',
241                                                                         iw.ssid, iw.mode, iw.bssid,
242                                                                         iw.encryption ? iw.encryption : '<%:None%>'
243                                                         );
244                                                 else
245                                                         info.innerHTML = String.format(
246                                                                 '<strong><%:SSID%>:</strong> %h | ' +
247                                                                 '<strong><%:Mode%>:</strong> %s<br />' +
248                                                                 '<em>%s</em>',
249                                                                         iw.ssid || '?', iw.mode,
250                                                                         is_reconnecting
251                                                                                 ? '<em><%:Wireless is restarting...%></em>'
252                                                                                 : '<em><%:Wireless is disabled or not associated%></em>'
253                                                         );
254                                         }
255
256                                         var dev = document.getElementById(wifidevs[iw.id] + '-iw-devinfo');
257                                         if (dev)
258                                         {
259                                                 if (is_assoc)
260                                                         dev.innerHTML = String.format(
261                                                                 '<strong><%:Channel%>:</strong> %s (%s <%:GHz%>) | ' +
262                                                                 '<strong><%:Bitrate%>:</strong> %s <%:Mbit/s%>',
263                                                                         iw.channel ? iw.channel : '?',
264                                                                         iw.frequency ? iw.frequency : '?',
265                                                                         iw.bitrate ? iw.bitrate : '?'
266                                                         );
267                                                 else
268                                                         dev.innerHTML = '';
269                                         }
270
271                                         if (assoctable)
272                                         {
273                                                 var assoclist = [ ];
274                                                 for( var bssid in iw.assoclist )
275                                                 {
276                                                         assoclist.push(iw.assoclist[bssid]);
277                                                         assoclist[assoclist.length-1].bssid = bssid;
278                                                 }
279
280                                                 assoclist.sort(function(a, b) { a.bssid < b.bssid });
281
282                                                 for( var j = 0; j < assoclist.length; j++ )
283                                                 {
284                                                         var tr = assoctable.insertRow(-1);
285                                                             tr.className = 'cbi-section-table-row cbi-rowstyle-' + rowstyle;
286
287                                                         var icon;
288                                                         var q = (-1 * (assoclist[j].noise - assoclist[j].signal)) / 5;
289                                                         if (q < 1)
290                                                                 icon = "<%=resource%>/icons/signal-0.png";
291                                                         else if (q < 2)
292                                                                 icon = "<%=resource%>/icons/signal-0-25.png";
293                                                         else if (q < 3)
294                                                                 icon = "<%=resource%>/icons/signal-25-50.png";
295                                                         else if (q < 4)
296                                                                 icon = "<%=resource%>/icons/signal-50-75.png";
297                                                         else
298                                                                 icon = "<%=resource%>/icons/signal-75-100.png";
299
300                                                         tr.insertCell(-1).innerHTML = String.format(
301                                                                 '<img src="%s" title="<%:Signal%>: %d <%:dBm%> / <%:Noise%>: %d <%:dBm%>" />',
302                                                                 icon, assoclist[j].signal, assoclist[j].noise
303                                                         );
304
305                                                         tr.insertCell(-1).innerHTML = nowrap(String.format('%h', iw.ssid ? iw.ssid : '?'));
306                                                         tr.insertCell(-1).innerHTML = assoclist[j].bssid;
307
308                                                         tr.insertCell(-1).innerHTML = arptable[assoclist[j].bssid]
309                                                                 ? arptable[assoclist[j].bssid] : '?';
310
311                                                         tr.insertCell(-1).innerHTML = nowrap(String.format('%d <%:dBm%>', assoclist[j].signal));
312                                                         tr.insertCell(-1).innerHTML = nowrap(String.format('%d <%:dBm%>', assoclist[j].noise));
313
314                                                         tr.insertCell(-1).innerHTML = nowrap((assoclist[j].rx_mcs > -1)
315                                                                 ? String.format('%.1f <%:Mbit/s%>, MCS %d, %d<%:MHz%>', assoclist[j].rx_rate / 1000, assoclist[j].rx_mcs, assoclist[j].rx_40mhz ? 40 : 20)
316                                                                 : String.format('%.1f <%:Mbit/s%>', assoclist[j].rx_rate / 1000)
317                                                         );
318
319                                                         tr.insertCell(-1).innerHTML = nowrap((assoclist[j].tx_mcs > -1)
320                                                                 ? String.format('%.1f <%:Mbit/s%>, MCS %d, %d<%:MHz%>', assoclist[j].tx_rate / 1000, assoclist[j].tx_mcs, assoclist[j].tx_40mhz ? 40 : 20)
321                                                                 : String.format('%.1f <%:Mbit/s%>', assoclist[j].tx_rate / 1000)
322                                                         );
323
324                                                         rowstyle = (rowstyle == 1) ? 2 : 1;
325                                                 }
326                                         }
327                                 }
328
329                                 if (assoctable && assoctable.rows.length == 1)
330                                 {
331                                         var tr = assoctable.insertRow(-1);
332                                             tr.className = 'cbi-section-table-row';
333
334                                         var td = tr.insertCell(-1);
335                                             td.colSpan = 8;
336                                             td.innerHTML = '<br /><em><%:No information available%></em>';
337                                 }
338
339                                 for (var dev in devup)
340                                 {
341                                         var img = document.getElementById(dev + '-iw-upstate');
342                                         if (img)
343                                                 img.src = '<%=resource%>/icons/wifi_big' + (devup[dev] ? '' : '_disabled') + '.png';
344                                 }
345                         }
346                 }
347         );
348 //]]></script>
349
350 <h2><a id="content" name="content"><%:Wireless Overview%></a></h2>
351
352 <fieldset class="cbi-section" style="display:none">
353         <legend><%:Reconnecting interface%></legend>
354         <img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" />
355         <span id="iw-rc-status"><%:Waiting for changes to be applied...%></span>
356 </fieldset>
357
358 <div class="cbi-map">
359
360         <% for _, dev in ipairs(devices) do local nets = dev:get_wifinets() %>
361         <!-- device <%=dev:name()%> -->
362         <fieldset class="cbi-section">
363                 <table class="cbi-section-table" style="margin:10px; empty-cells:hide">
364                         <!-- physical device -->
365                         <tr>
366                                 <td style="width:34px"><img src="<%=resource%>/icons/wifi_big_disabled.png" style="float:left; margin-right:10px" id="<%=dev:name()%>-iw-upstate" /></td>
367                                 <td colspan="2" style="text-align:left">
368                                         <big><strong><%=guess_wifi_hw(dev:name())%> (<%=dev:name()%>)</strong></big><br />
369                                         <span id="<%=dev:name()%>-iw-devinfo"></span>
370                                 </td>
371                                 <td style="width:310px;text-align:right">
372                                         <input type="button" class="cbi-button cbi-button-find" style="width:100px" onclick="location.href='<%=luci.dispatcher.build_url("admin/network/wireless_join")%>?device=<%=dev:name()%>'" title="<%:Find and join network%>" value="<%:Scan%>" />
373                                         <input type="button" class="cbi-button cbi-button-add" style="width:100px" onclick="location.href='<%=luci.dispatcher.build_url("admin/network/wireless_add")%>?device=<%=dev:name()%>'" title="<%:Provide new network%>" value="<%:Add%>" />
374                                 </td>
375                         </tr>
376                         <!-- /physical device -->
377
378                         <!-- network list -->
379                         <% if #nets > 0 then %>
380                                 <% for i, net in ipairs(nets) do %>
381                                 <tr class="cbi-section-table-row cbi-rowstyle-<%=1 + ((i-1) % 2)%>">
382                                         <td></td>
383                                         <td class="cbi-value-field" style="width:16px; padding:3px" id="<%=net:id()%>-iw-signal">
384                                                 <img src="<%=resource%>/icons/signal-none.png" title="<%:Not associated%>" /><br />
385                                                 <small>0%</small>
386                                         </td>
387                                         <td class="cbi-value-field" style="vertical-align:middle; text-align:left; padding:3px" id="<%=net:id()%>-iw-status">
388                                                 <em><%:Collecting data...%></em>
389                                         </td>
390                                         <td class="cbi-value-field" style="width:310px;text-align:right">
391                                                 <input id="<%=net:id()%>-iw-toggle" type="button" class="cbi-button cbi-button-reload" style="width:100px" onclick="wifi_shutdown('<%=net:id()%>', this)" title="<%:Delete this network%>" value="<%:Enable%>" />
392                                                 <input type="button" class="cbi-button cbi-button-edit" style="width:100px" onclick="location.href='<%=net:adminlink()%>'" title="<%:Edit this network%>" value="<%:Edit%>" />
393                                                 <input type="button" class="cbi-button cbi-button-remove" style="width:100px" onclick="if (confirm('<%:Really delete this wireless network? The deletion cannot be undone!\nYou might lose access to this device if you are connected via this network.%>')) location.href='<%=luci.dispatcher.build_url("admin/network/wireless_delete", net:ifname())%>'" title="<%:Delete this network%>" value="<%:Remove%>" />
394                                         </td>
395                                 </tr>
396                                 <% end %>
397                         <% else %>
398                                 <tr class="cbi-section-table-row cbi-rowstyle-2">
399                                         <td></td>
400                                         <td colspan="3" class="cbi-value-field" style="vertical-align:middle; text-align:left; padding:3px">
401                                                 <em><%:No network configured on this device%></em>
402                                         </td>
403                                 </tr>
404                         <% end %>
405                         <!-- /network list -->
406                 </table>
407         </fieldset>
408         <!-- /device <%=dev:name()%> -->
409         <% end %>
410
411
412         <h2><a id="content" name="content"><%:Associated Stations%></a></h2>
413
414         <fieldset class="cbi-section">
415                 <table class="cbi-section-table" style="margin:10px" id="iw-assoclist">
416                         <tr class="cbi-section-table-titles">
417                                 <th class="cbi-section-table-cell"></th>
418                                 <th class="cbi-section-table-cell"><%:SSID%></th>
419                                 <th class="cbi-section-table-cell"><%:MAC-Address%></th>
420                                 <th class="cbi-section-table-cell"><%:IPv4-Address%></th>
421                                 <th class="cbi-section-table-cell"><%:Signal%></th>
422                                 <th class="cbi-section-table-cell"><%:Noise%></th>
423                                 <th class="cbi-section-table-cell"><%:RX Rate%></th>
424                                 <th class="cbi-section-table-cell"><%:TX Rate%></th>
425                         </tr>
426                         <tr class="cbi-section-table-row cbi-rowstyle-2">
427                                 <td class="cbi-value-field" colspan="8">
428                                         <em><%:Collecting data...%></em>
429                                 </td>
430                         </tr>
431                 </table>
432         </fieldset>
433 </div>
434
435 <%+footer%>