2 LuCI - Lua Configuration Interface
3 Copyright
2008-
2009 Steven Barth
<steven@midlink.org
>
4 Copyright
2008-
2010 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
18 local sys = require
"luci.sys"
19 local fs = require
"luci.fs"
20 local utl = require
"luci.util"
21 local uci = require
"luci.model.uci".cursor()
22 local ntm = require
"luci.model.network"
24 local has_iwinfo = pcall(require,
"iwinfo")
28 function guess_wifi_hw(ifname)
30 local name, idx = ifname:match(
"^([a-z]+)(%d+)")
34 local iw = luci.sys.wifi.getiwinfo(ifname)
35 local bl = iw.hwmodelist
36 if bl and next(bl) then
37 if bl.a then bands = bands ..
"a" end
38 if bl.b then bands = bands ..
"b" end
39 if bl.g then bands = bands ..
"g" end
40 if bl.n then bands = bands ..
"n" end
46 local name =
"Broadcom 802.11%s Wireless Controller" % bands
49 local fd = nixio.open(
"/proc/bus/pci/devices",
"r")
52 for ln in fd:linesource() do
53 if ln:match(
"wl$") then
55 local version = ln:match(
"^%S+%s+%S%S%S%S([0-9a-f]+)")
57 "Broadcom BCM%04x 802.11 Wireless Controller",
73 elseif name ==
"ath" or name ==
"wifi" then
74 return
"Atheros 802.11%s Wireless Controller" % bands
77 elseif name ==
"ra" then
78 return
"RaLink 802.11%s Wireless Controller" % bands
81 elseif name ==
"eth" then
82 return
"Prism 802.11b Wireless Controller"
85 elseif name ==
"wlan" and fs.isdirectory(
"/proc/net/hostap/" .. ifname) then
86 return
"Prism2/2.5/3 802.11b Wireless Controller"
90 return
"Generic 802.11%s Wireless Controller" % bands
94 local devices = ntm:get_wifidevs()
96 sys.net.arptable(function(e) arpcache[e[
"HW address"]:upper()] = e[
"IP address"] end)
102 for _, dev in ipairs(devices) do
104 for _, net in ipairs(dev:get_wifinets()) do
105 netlist[#netlist+
1] = net:ifname()
106 netdevs[net:ifname()] = dev:name()
113 <% if not has_iwinfo then %
>
114 <div class=
"errorbox">
115 <strong><%:Package libiwinfo required!%
></strong><br />
116 <%_The
<em>libiwinfo
</em> package is not installed. You must install this component for working wireless configuration!%
>
120 <script type=
"text/javascript" src=
"<%=resource%>/cbi.js"></script>
121 <script type=
"text/javascript">//<![CDATA[
122 var iwxhr = new XHR();
123 var wifidevs = <%=luci.http.write_json(netdevs)%
>;
124 var arptable = <%=luci.http.write_json(arpcache)%
>;
126 var update_status = function() {
127 iwxhr.get('<%=luci.dispatcher.build_url(
"admin",
"network",
"wireless_status", table.concat(netlist,
","))%
>', null,
132 var assoctable = document.getElementById('iw-assoclist');
134 while (assoctable.rows.length
> 1)
135 assoctable.rows[
1].parentNode.removeChild(assoctable.rows[
1]);
139 for( var i =
0; i < st.length; i++ )
142 var is_assoc = (iw.bssid && iw.channel);
143 var p = (
100 / iw.quality_max * iw.quality);
144 var q = is_assoc ? p : -
1;
148 icon =
"<%=resource%>/icons/signal-none.png";
150 icon =
"<%=resource%>/icons/signal-0.png";
152 icon =
"<%=resource%>/icons/signal-0-25.png";
154 icon =
"<%=resource%>/icons/signal-25-50.png";
156 icon =
"<%=resource%>/icons/signal-50-75.png";
158 icon =
"<%=resource%>/icons/signal-75-100.png";
160 if (!devup[wifidevs[iw.id]])
161 devup[wifidevs[iw.id]] = is_assoc;
163 var sig = document.getElementById(iw.id + '-iw-signal');
165 sig.innerHTML = String.format(
166 '
<img src=
"%s" title=
"<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" /><br />' +
167 '
<small>%d%%
</small>', icon, iw.signal, iw.noise, p
170 var info = document.getElementById(iw.id + '-iw-status');
174 info.innerHTML = String.format(
175 '
<strong><%:SSID%
>:
</strong> %h | ' +
176 '
<strong><%:Mode%
>:
</strong> %s
<br />' +
177 '
<strong><%:BSSID%
>:
</strong> %s | ' +
178 '
<strong><%:Encryption%
>:
</strong> %s',
179 iw.ssid, iw.mode, iw.bssid,
180 iw.encryption ? iw.encryption.description : '<%:None%
>'
183 info.innerHTML = String.format(
184 '
<strong><%:SSID%
>:
</strong> %h | ' +
185 '
<strong><%:Mode%
>:
</strong> %s
<br />' +
186 '
<em><%:Wireless is disabled or not associated%
></em>',
187 iw.ssid || '?', iw.mode
191 var dev = document.getElementById(wifidevs[iw.id] + '-iw-devinfo');
195 dev.innerHTML = String.format(
196 '
<strong><%:Channel%
>:
</strong> %s (%s GHz) | ' +
197 '
<strong><%:Bitrate%
>:
</strong> %s Mb/s',
198 iw.channel ? iw.channel : '?',
199 iw.frequency ? iw.frequency /
1000 : '?',
200 iw.bitrate ? iw.bitrate /
1000 : '?'
209 for( var bssid in iw.assoclist )
211 assoclist.push(iw.assoclist[bssid]);
212 assoclist[assoclist.length-
1].bssid = bssid;
215 assoclist.sort(function(a, b) { a.bssid < b.bssid });
217 for( var j =
0; j < assoclist.length; j++ )
219 var tr = assoctable.insertRow(-
1);
220 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((j %
2) + (i %
2));
223 var q = (-
1 * (assoclist[j].noise - assoclist[j].signal)) /
5;
225 icon =
"<%=resource%>/icons/signal-0.png";
227 icon =
"<%=resource%>/icons/signal-0-25.png";
229 icon =
"<%=resource%>/icons/signal-25-50.png";
231 icon =
"<%=resource%>/icons/signal-50-75.png";
233 icon =
"<%=resource%>/icons/signal-75-100.png";
235 tr.insertCell(-
1).innerHTML = String.format(
236 '
<img src=
"%s" title=
"<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" />',
237 icon, assoclist[j].signal, assoclist[j].noise
240 tr.insertCell(-
1).innerHTML = iw.ssid ? iw.ssid : '?';
241 tr.insertCell(-
1).innerHTML = assoclist[j].bssid;
243 tr.insertCell(-
1).innerHTML = arptable[assoclist[j].bssid]
244 ? arptable[assoclist[j].bssid] : '?';
246 tr.insertCell(-
1).innerHTML = String.format('%d dBm', assoclist[j].signal);
247 tr.insertCell(-
1).innerHTML = String.format('%d dBm', assoclist[j].noise);
252 if (assoctable && assoctable.rows.length ==
1)
254 var tr = assoctable.insertRow(-
1);
255 tr.className = 'cbi-section-table-row';
257 var td = tr.insertCell(-
1);
259 td.innerHTML = '
<br /><em><%:No information available%
></em>';
262 for (var dev in devup)
264 var img = document.getElementById(dev + '-iw-upstate');
266 img.src = '<%=resource%
>/icons/wifi_big' + (devup[dev] ? '' : '_disabled') + '.png';
270 window.setTimeout(update_status,
5000);
278 <h2><a id=
"content" name=
"content"><%:Wireless Overview%
></a></h2>
280 <div class=
"cbi-map">
282 <% for _, dev in ipairs(devices) do local nets = dev:get_wifinets() %
>
283 <!-- device <%=dev:name()%> -->
284 <fieldset class=
"cbi-section">
285 <table class=
"cbi-section-table" style=
"margin:10px; empty-cells:hide">
286 <!-- physical device -->
288 <td style=
"width:34px"><img src=
"<%=resource%>/icons/wifi_big_disabled.png" style=
"float:left; margin-right:10px" id=
"<%=dev:name()%>-iw-upstate" /></td>
289 <td colspan=
"2" style=
"text-align:left">
290 <big><strong><%=guess_wifi_hw(dev:name())%
> (<%=dev:name()%
>)
</strong></big><br />
291 <span id=
"<%=dev:name()%>-iw-devinfo"></span>
293 <td style=
"width:40px">
294 <a href=
"<%=luci.dispatcher.build_url("admin/network/wireless_join
")%>?device=<%=dev:name()%>"><img style=
"border:none" src=
"<%=resource%>/cbi/find.gif" alt=
"<%:Find and join network%>" title=
"<%:Find and join network%>" /></a>
295 <a href=
"<%=luci.dispatcher.build_url("admin/network/wireless_add
")%>?device=<%=dev:name()%>"><img style=
"border:none" src=
"<%=resource%>/cbi/add.gif" alt=
"<%:Provide new network%>" title=
"<%:Provide new network%>" /></a>
298 <!-- /physical device -->
300 <!-- network list -->
301 <% if #nets
> 0 then %
>
302 <% for i, net in ipairs(nets) do %
>
303 <tr class=
"cbi-section-table-row cbi-rowstyle-<%=1 + ((i-1) % 2)%>">
305 <td class=
"cbi-value-field" style=
"width:16px; padding:3px" id=
"<%=net:ifname()%>-iw-signal">
306 <img src=
"<%=resource%>/icons/signal-none.png" title=
"<%:Not associated%>" /><br />
309 <td class=
"cbi-value-field" style=
"vertical-align:middle; text-align:left; padding:3px" id=
"<%=net:ifname()%>-iw-status">
310 <em><%:Collecting data...%
></em>
312 <td class=
"cbi-value-field" style=
"width:40px">
313 <a href=
"<%=net:adminlink()%>"><img style=
"border:none" src=
"<%=resource%>/cbi/edit.gif" alt=
"<%:Edit this network%>" title=
"<%:Edit this network%>" /></a>
314 <a href=
"<%=luci.dispatcher.build_url("admin/network/wireless_delete
", net:ifname())%>" onclick=
"return confirm('<%:Really delete this wireless network? The deletion cannot be undone!\nYou might loose access to this router if you are connected via this network.%>')"><img style=
"border:none" src=
"<%=resource%>/cbi/remove.gif" alt=
"<%:Delete this network%>" title=
"<%:Delete this network%>" /></a>
319 <tr class=
"cbi-section-table-row cbi-rowstyle-2">
321 <td colspan=
"3" class=
"cbi-value-field" style=
"vertical-align:middle; text-align:left; padding:3px">
322 <em><%:No network configured on this device%
></em>
326 <!-- /network list -->
329 <!-- /device <%=dev:name()%> -->
333 <h2><a id=
"content" name=
"content"><%:Associated Stations%
></a></h2>
335 <fieldset class=
"cbi-section">
336 <table class=
"cbi-section-table" style=
"margin:10px; width:50%" id=
"iw-assoclist">
337 <tr class=
"cbi-section-table-titles">
338 <th class=
"cbi-section-table-cell"></th>
339 <th class=
"cbi-section-table-cell"><%:SSID%
></th>
340 <th class=
"cbi-section-table-cell"><%:MAC%
></th>
341 <th class=
"cbi-section-table-cell"><%:Address%
></th>
342 <th class=
"cbi-section-table-cell"><%:Signal%
></th>
343 <th class=
"cbi-section-table-cell"><%:Noise%
></th>
345 <tr class=
"cbi-section-table-row cbi-rowstyle-2">
346 <td class=
"cbi-value-field" colspan=
"6">
347 <em><%:Collecting data...%
></em>