2 LuCI - Lua Configuration Interface
3 Copyright
2008-
2009 Steven Barth
<steven@midlink.org
>
4 Copyright
2008-
2013 Jo-Philipp Wich
<xm@subsignal.org
>
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
10 http://www.apache.org/licenses/LICENSE-
2.0
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"
22 local has_iwinfo = pcall(require,
"iwinfo")
26 function guess_wifi_hw(dev)
28 local ifname = dev:name()
29 local name, idx = ifname:match(
"^([a-z]+)(%d+)")
33 local bl = dev.iwinfo.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
41 local hw = dev.iwinfo.hardware_name
43 return
"%s 802.11%s" %{ hw, bands }
49 local name = translatef(
"Broadcom 802.11%s Wireless Controller", bands)
52 local fd = nixio.open(
"/proc/bus/pci/devices",
"r")
55 for ln in fd:linesource() do
56 if ln:match(
"wl$") then
58 local version = ln:match(
"^%S+%s+%S%S%S%S([0-9a-f]+)")
60 "Broadcom BCM%04x 802.11 Wireless Controller",
76 elseif name ==
"ath" or name ==
"wifi" then
77 return translatef(
"Atheros 802.11%s Wireless Controller", bands)
80 elseif name ==
"ra" then
81 return translatef(
"RaLink 802.11%s Wireless Controller", bands)
84 elseif name ==
"eth" then
85 return translate(
"Hermes 802.11b Wireless Controller")
88 elseif name ==
"wlan" and fs.isdirectory(
"/proc/net/hostap/" .. ifname) then
89 return translate(
"Prism2/2.5/3 802.11b Wireless Controller")
93 return translatef(
"Generic 802.11%s Wireless Controller", bands)
97 local devices = ntm:get_wifidevs()
99 sys.net.arptable(function(e) arpcache[e[
"HW address"]:upper()] = e[
"IP address"] end)
105 for _, dev in ipairs(devices) do
107 for _, net in ipairs(dev:get_wifinets()) do
108 netlist[#netlist+
1] = net:id()
109 netdevs[net:id()] = dev:name()
116 <% if not has_iwinfo then %
>
117 <div class=
"errorbox">
118 <strong><%:Package libiwinfo required!%
></strong><br />
119 <%_The
<em>libiwinfo-lua
</em> package is not installed. You must install this component for working wireless configuration!%
>
123 <script type=
"text/javascript" src=
"<%=resource%>/cbi.js"></script>
124 <script type=
"text/javascript">//<![CDATA[
125 var wifidevs = <%=luci.http.write_json(netdevs)%
>;
126 var arptable = <%=luci.http.write_json(arpcache)%
>;
128 var is_reconnecting = false;
131 return s.replace(/ /g, '
 ');
134 function wifi_shutdown(id, toggle) {
135 var reconnect = (toggle.getAttribute('active') == 'false');
137 if (!reconnect && !confirm(String.format('<%:Really shut down network?\nYou might lose access to this device if you are connected via this interface.%
>')))
140 is_reconnecting = true;
142 var s = document.getElementById('iw-rc-status');
145 s.parentNode.style.display = 'block';
146 s.innerHTML = '<%:Waiting for changes to be applied...%
>';
149 for (var net in wifidevs)
151 var st = document.getElementById(net + '-iw-status');
153 st.innerHTML = '
<em><%:Wireless is restarting...%
></em>';
156 XHR.get('<%=luci.dispatcher.build_url(
"admin",
"network")%
>/wireless_' + (reconnect ? 'reconnect' : 'shutdown') + '/' + id, null,
161 s.innerHTML = reconnect
162 ? '<%:Wireless restarted%
>'
163 : '<%:Wireless shut down%
>';
165 window.setTimeout(function() {
166 s.parentNode.style.display = 'none';
167 is_reconnecting = false;
174 XHR.poll(
5, '<%=luci.dispatcher.build_url(
"admin",
"network",
"wireless_status", table.concat(netlist,
","))%
>', null,
179 var assoctable = document.getElementById('iw-assoclist');
181 while (assoctable.rows.length
> 1)
182 assoctable.rows[
1].parentNode.removeChild(assoctable.rows[
1]);
187 for( var i =
0; i < st.length; i++ )
190 var is_assoc = (iw.bssid && iw.bssid != '
00:
00:
00:
00:
00:
00' && iw.channel);
192 var q = is_assoc ? p : -
1;
196 icon =
"<%=resource%>/icons/signal-none.png";
198 icon =
"<%=resource%>/icons/signal-0.png";
200 icon =
"<%=resource%>/icons/signal-0-25.png";
202 icon =
"<%=resource%>/icons/signal-25-50.png";
204 icon =
"<%=resource%>/icons/signal-50-75.png";
206 icon =
"<%=resource%>/icons/signal-75-100.png";
208 if (!devup[wifidevs[iw.id]])
209 devup[wifidevs[iw.id]] = is_assoc;
211 var sig = document.getElementById(iw.id + '-iw-signal');
213 sig.innerHTML = String.format(
214 '
<img src=
"%s" title=
"<%:Signal%>: %d <%:dBm%> / <%:Noise%>: %d <%:dBm%>" /><br />' +
215 '
<small>%d%%
</small>', icon, iw.signal, iw.noise, p
218 var toggle = document.getElementById(iw.id + '-iw-toggle');
223 toggle.className = 'cbi-button cbi-button-reset';
224 toggle.value = '<%:Disable%
>';
225 toggle.title = '<%:Shutdown this network%
>';
229 toggle.className = 'cbi-button cbi-button-reload';
230 toggle.value = '<%:Enable%
>';
231 toggle.title = '<%:Activate this network%
>';
234 toggle.setAttribute('active', is_assoc);
237 var info = document.getElementById(iw.id + '-iw-status');
241 info.innerHTML = String.format(
242 '
<strong><%:SSID%
>:
</strong> %h | ' +
243 '
<strong><%:Mode%
>:
</strong> %s
<br />' +
244 '
<strong><%:BSSID%
>:
</strong> %s | ' +
245 '
<strong><%:Encryption%
>:
</strong> %s',
246 iw.ssid, iw.mode, iw.bssid,
247 iw.encryption ? iw.encryption : '<%:None%
>'
250 info.innerHTML = String.format(
251 '
<strong><%:SSID%
>:
</strong> %h | ' +
252 '
<strong><%:Mode%
>:
</strong> %s
<br />' +
254 iw.ssid || '?', iw.mode,
256 ? '
<em><%:Wireless is restarting...%
></em>'
257 : '
<em><%:Wireless is disabled or not associated%
></em>'
261 var dev = document.getElementById(wifidevs[iw.id] + '-iw-devinfo');
265 dev.innerHTML = String.format(
266 '
<strong><%:Channel%
>:
</strong> %s (%s <%:GHz%
>) | ' +
267 '
<strong><%:Bitrate%
>:
</strong> %s <%:Mbit/s%
>',
268 iw.channel ? iw.channel : '?',
269 iw.frequency ? iw.frequency : '?',
270 iw.bitrate ? iw.bitrate : '?'
279 for( var bssid in iw.assoclist )
281 assoclist.push(iw.assoclist[bssid]);
282 assoclist[assoclist.length-
1].bssid = bssid;
285 assoclist.sort(function(a, b) { a.bssid < b.bssid });
287 for( var j =
0; j < assoclist.length; j++ )
289 var tr = assoctable.insertRow(-
1);
290 tr.className = 'cbi-section-table-row cbi-rowstyle-' + rowstyle;
293 var q = (-
1 * (assoclist[j].noise - assoclist[j].signal)) /
5;
295 icon =
"<%=resource%>/icons/signal-0.png";
297 icon =
"<%=resource%>/icons/signal-0-25.png";
299 icon =
"<%=resource%>/icons/signal-25-50.png";
301 icon =
"<%=resource%>/icons/signal-50-75.png";
303 icon =
"<%=resource%>/icons/signal-75-100.png";
305 tr.insertCell(-
1).innerHTML = String.format(
306 '
<img src=
"%s" title=
"<%:Signal%>: %d <%:dBm%> / <%:Noise%>: %d <%:dBm%>" />',
307 icon, assoclist[j].signal, assoclist[j].noise
310 tr.insertCell(-
1).innerHTML = nowrap(String.format('%h', iw.ssid ? iw.ssid : '?'));
311 tr.insertCell(-
1).innerHTML = assoclist[j].bssid;
313 tr.insertCell(-
1).innerHTML = arptable[assoclist[j].bssid]
314 ? arptable[assoclist[j].bssid] : '?';
316 tr.insertCell(-
1).innerHTML = nowrap(String.format('%d <%:dBm%
>', assoclist[j].signal));
317 tr.insertCell(-
1).innerHTML = nowrap(String.format('%d <%:dBm%
>', assoclist[j].noise));
319 tr.insertCell(-
1).innerHTML = nowrap((assoclist[j].rx_mcs
> -
1)
320 ? String.format('%
.1f <%:Mbit/s%
>, MCS %d, %d<%:MHz%
>', assoclist[j].rx_rate /
1000, assoclist[j].rx_mcs, assoclist[j].rx_40mhz ?
40 :
20)
321 : String.format('%
.1f <%:Mbit/s%
>', assoclist[j].rx_rate /
1000)
324 tr.insertCell(-
1).innerHTML = nowrap((assoclist[j].tx_mcs
> -
1)
325 ? String.format('%
.1f <%:Mbit/s%
>, MCS %d, %d<%:MHz%
>', assoclist[j].tx_rate /
1000, assoclist[j].tx_mcs, assoclist[j].tx_40mhz ?
40 :
20)
326 : String.format('%
.1f <%:Mbit/s%
>', assoclist[j].tx_rate /
1000)
329 rowstyle = (rowstyle ==
1) ?
2 :
1;
334 if (assoctable && assoctable.rows.length ==
1)
336 var tr = assoctable.insertRow(-
1);
337 tr.className = 'cbi-section-table-row';
339 var td = tr.insertCell(-
1);
341 td.innerHTML = '
<br /><em><%:No information available%
></em>';
344 for (var dev in devup)
346 var img = document.getElementById(dev + '-iw-upstate');
348 img.src = '<%=resource%
>/icons/wifi_big' + (devup[dev] ? '' : '_disabled') + '.png';
355 <h2><a id=
"content" name=
"content"><%:Wireless Overview%
></a></h2>
357 <fieldset class=
"cbi-section" style=
"display:none">
358 <legend><%:Reconnecting interface%
></legend>
359 <img src=
"<%=resource%>/icons/loading.gif" alt=
"<%:Loading%>" style=
"vertical-align:middle" />
360 <span id=
"iw-rc-status"><%:Waiting for changes to be applied...%
></span>
363 <div class=
"cbi-map">
365 <% for _, dev in ipairs(devices) do local nets = dev:get_wifinets() %
>
366 <!-- device <%=dev:name()%> -->
367 <fieldset class=
"cbi-section">
368 <table class=
"cbi-section-table" style=
"margin:10px; empty-cells:hide">
369 <!-- physical device -->
371 <td style=
"width:34px"><img src=
"<%=resource%>/icons/wifi_big_disabled.png" style=
"float:left; margin-right:10px" id=
"<%=dev:name()%>-iw-upstate" /></td>
372 <td colspan=
"2" style=
"text-align:left">
373 <big><strong><%=guess_wifi_hw(dev)%
> (<%=dev:name()%
>)
</strong></big><br />
374 <span id=
"<%=dev:name()%>-iw-devinfo"></span>
376 <td style=
"width:310px;text-align:right">
377 <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%>" />
378 <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%>" />
381 <!-- /physical device -->
383 <!-- network list -->
384 <% if #nets
> 0 then %
>
385 <% for i, net in ipairs(nets) do %
>
386 <tr class=
"cbi-section-table-row cbi-rowstyle-<%=1 + ((i-1) % 2)%>">
388 <td class=
"cbi-value-field" style=
"width:16px; padding:3px" id=
"<%=net:id()%>-iw-signal">
389 <img src=
"<%=resource%>/icons/signal-none.png" title=
"<%:Not associated%>" /><br />
392 <td class=
"cbi-value-field" style=
"vertical-align:middle; text-align:left; padding:3px" id=
"<%=net:id()%>-iw-status">
393 <em><%:Collecting data...%
></em>
395 <td class=
"cbi-value-field" style=
"width:310px;text-align:right">
396 <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%>" />
397 <input type=
"button" class=
"cbi-button cbi-button-edit" style=
"width:100px" onclick=
"location.href='<%=net:adminlink()%>'" title=
"<%:Edit this network%>" value=
"<%:Edit%>" />
398 <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%>" />
403 <tr class=
"cbi-section-table-row cbi-rowstyle-2">
405 <td colspan=
"3" class=
"cbi-value-field" style=
"vertical-align:middle; text-align:left; padding:3px">
406 <em><%:No network configured on this device%
></em>
410 <!-- /network list -->
413 <!-- /device <%=dev:name()%> -->
417 <h2><a id=
"content" name=
"content"><%:Associated Stations%
></a></h2>
419 <fieldset class=
"cbi-section">
420 <table class=
"cbi-section-table" style=
"margin:10px" id=
"iw-assoclist">
421 <tr class=
"cbi-section-table-titles">
422 <th class=
"cbi-section-table-cell"></th>
423 <th class=
"cbi-section-table-cell"><%:SSID%
></th>
424 <th class=
"cbi-section-table-cell"><%:MAC-Address%
></th>
425 <th class=
"cbi-section-table-cell"><%:IPv4-Address%
></th>
426 <th class=
"cbi-section-table-cell"><%:Signal%
></th>
427 <th class=
"cbi-section-table-cell"><%:Noise%
></th>
428 <th class=
"cbi-section-table-cell"><%:RX Rate%
></th>
429 <th class=
"cbi-section-table-cell"><%:TX Rate%
></th>
431 <tr class=
"cbi-section-table-row cbi-rowstyle-2">
432 <td class=
"cbi-value-field" colspan=
"8">
433 <em><%:Collecting data...%
></em>