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 utl = require
"luci.util"
20 local uci = require
"luci.model.uci".cursor()
21 local ntm = require
"luci.model.network"
23 local has_iwinfo = pcall(require,
"iwinfo")
27 function guess_wifi_hw(ifname)
29 local name, idx = ifname:match(
"^([a-z]+)(%d+)")
33 local iw = luci.sys.wifi.getiwinfo(ifname)
34 local bl = iw.hwmodelist
35 if bl and next(bl) then
36 if bl.a then bands = bands ..
"a" end
37 if bl.b then bands = bands ..
"b" end
38 if bl.g then bands = bands ..
"g" end
39 if bl.n then bands = bands ..
"n" end
45 local name =
"Broadcom 802.11%s Wireless Controller" % bands
48 local fd = nixio.open(
"/proc/bus/pci/devices",
"r")
51 for ln in fd:linesource() do
52 if ln:match(
"wl$") then
54 local version = ln:match(
"^%S+%s+%S%S%S%S([0-9a-f]+)")
56 "Broadcom BCM%04x 802.11 Wireless Controller",
72 elseif name ==
"ath" or name ==
"wifi" then
73 return
"Atheros 802.11%s Wireless Controller" % bands
76 elseif name ==
"ra" then
77 return
"RaLink 802.11%s Wireless Controller" % bands
80 elseif name ==
"eth" then
81 return
"Prism 802.11%s Wireless Controller" % bands
85 return
"Generic 802.11%s Wireless Controller" % bands
89 local devices = ntm:get_wifidevs()
91 sys.net.arptable(function(e) arpcache[e[
"HW address"]:upper()] = e[
"IP address"] end)
97 for _, dev in ipairs(devices) do
99 for _, net in ipairs(dev:get_wifinets()) do
100 netlist[#netlist+
1] = net:ifname()
101 netdevs[net:ifname()] = dev:name()
108 <% if not has_iwinfo then %
>
109 <div class=
"errorbox">
110 <strong><%:Package libiwinfo required!%
></strong><br />
111 <%_The
<em>libiwinfo
</em> package is not installed. You must install this component for working wireless configuration!%
>
115 <script type=
"text/javascript" src=
"<%=resource%>/cbi.js"></script>
116 <script type=
"text/javascript">//<![CDATA[
117 var iwxhr = new XHR();
118 var wifidevs = <%=luci.http.write_json(netdevs)%
>;
119 var arptable = <%=luci.http.write_json(arpcache)%
>;
121 var update_status = function() {
122 iwxhr.get('<%=luci.dispatcher.build_url(
"admin",
"network",
"wireless_status", table.concat(netlist,
","))%
>', null,
127 var assoctable = document.getElementById('iw-assoclist');
129 while (assoctable.rows.length
> 1)
130 assoctable.rows[
1].parentNode.removeChild(assoctable.rows[
1]);
134 for( var i =
0; i < st.length; i++ )
137 var is_assoc = (iw.bssid && iw.channel);
138 var p = (
100 / iw.quality_max * iw.quality);
139 var q = is_assoc ? p : -
1;
143 icon =
"<%=resource%>/icons/signal-none.png";
145 icon =
"<%=resource%>/icons/signal-0.png";
147 icon =
"<%=resource%>/icons/signal-0-25.png";
149 icon =
"<%=resource%>/icons/signal-25-50.png";
151 icon =
"<%=resource%>/icons/signal-50-75.png";
153 icon =
"<%=resource%>/icons/signal-75-100.png";
155 if (!devup[wifidevs[iw.id]])
156 devup[wifidevs[iw.id]] = is_assoc;
158 var sig = document.getElementById(iw.id + '-iw-signal');
160 sig.innerHTML = String.format(
161 '
<img src=
"%s" title=
"<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" /><br />' +
162 '
<small>%d%%
</small>', icon, iw.signal, iw.noise, p
165 var info = document.getElementById(iw.id + '-iw-status');
169 info.innerHTML = String.format(
170 '
<strong><%:SSID%
>:
</strong> %s | ' +
171 '
<strong><%:Mode%
>:
</strong> %s
<br />' +
172 '
<strong><%:BSSID%
>:
</strong> %s | ' +
173 '
<strong><%:Encryption%
>:
</strong> %s',
174 iw.ssid, iw.mode, iw.bssid,
175 iw.encryption ? iw.encryption.description : '<%:None%
>'
178 info.innerHTML = '
<em><%:Wireless is disabled or not associated%
></em>';
181 var dev = document.getElementById(wifidevs[iw.id] + '-iw-devinfo');
185 dev.innerHTML = String.format(
186 '
<strong><%:Channel%
>:
</strong> %s (%s GHz) | ' +
187 '
<strong><%:Bitrate%
>:
</strong> %s Mb/s',
188 iw.channel ? iw.channel : '?',
189 iw.frequency ? iw.frequency /
1000 : '?',
190 iw.bitrate ? iw.bitrate /
1000 : '?'
199 for( var bssid in iw.assoclist )
201 assoclist.push(iw.assoclist[bssid]);
202 assoclist[assoclist.length-
1].bssid = bssid;
205 assoclist.sort(function(a, b) { a.bssid < b.bssid });
207 for( var j =
0; j < assoclist.length; j++ )
209 var tr = document.createElement('tr');
210 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((j %
2) + (i %
2));
213 var q = (-
1 * (assoclist[j].noise - assoclist[j].signal)) /
5;
215 icon =
"<%=resource%>/icons/signal-0.png";
217 icon =
"<%=resource%>/icons/signal-0-25.png";
219 icon =
"<%=resource%>/icons/signal-25-50.png";
221 icon =
"<%=resource%>/icons/signal-50-75.png";
223 icon =
"<%=resource%>/icons/signal-75-100.png";
225 tr.innerHTML = String.format(
226 '
<td class=
"cbi-value-field">' +
227 '
<img src=
"%s" title=
"<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" />' +
229 '
<td class=
"cbi-value-field">%s
</td>' +
230 '
<td class=
"cbi-value-field">%s
</td>' +
231 '
<td class=
"cbi-value-field">%s
</td>' +
232 '
<td class=
"cbi-value-field">%d dBm
</td>' +
233 '
<td class=
"cbi-value-field">%d dBm
</td>',
235 assoclist[j].signal, assoclist[j].noise,
236 iw.ssid ? iw.ssid : '?',
238 arptable[assoclist[j].bssid]
239 ? arptable[assoclist[j].bssid] : '?',
240 assoclist[j].signal, assoclist[j].noise
243 assoctable.rows[
0].parentNode.appendChild(tr);
248 if (assoctable && assoctable.rows.length ==
1)
250 var tr = document.createElement('tr');
251 tr.className = 'cbi-section-table-row';
253 tr.innerHTML = '
<td class=
"cbi-value-field" colspan=
"6"><br /><em><%:No information available%
></em></td>';
255 assoctable.rows[
0].parentNode.appendChild(tr);
258 for (var dev in devup)
260 var img = document.getElementById(dev + '-iw-upstate');
262 img.src = '<%=resource%
>/icons/wifi_big' + (devup[dev] ? '' : '_disabled') + '.png';
266 window.setTimeout(update_status,
5000);
274 <h2><a id=
"content" name=
"content"><%:Wireless Overview%
></a></h2>
276 <div class=
"cbi-map">
278 <% for _, dev in ipairs(devices) do local nets = dev:get_wifinets() %
>
279 <!-- device <%=dev:name()%> -->
280 <fieldset class=
"cbi-section">
281 <table class=
"cbi-section-table" style=
"margin:10px; empty-cells:hide">
282 <!-- physical device -->
284 <td style=
"width:34px"><img src=
"<%=resource%>/icons/wifi_big_disabled.png" style=
"float:left; margin-right:10px" id=
"<%=dev:name()%>-iw-upstate" /></td>
285 <td colspan=
"2" style=
"text-align:left">
286 <big><strong><%=guess_wifi_hw(dev:name())%
> (<%=dev:name()%
>)
</strong></big><br />
287 <span id=
"<%=dev:name()%>-iw-devinfo"></span>
289 <td style=
"width:40px">
290 <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>
291 <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>
294 <!-- /physical device -->
296 <!-- network list -->
297 <% if #nets
> 0 then %
>
298 <% for i, net in ipairs(nets) do %
>
299 <tr class=
"cbi-section-table-row cbi-rowstyle-<%=1 + ((i-1) % 2)%>">
301 <td class=
"cbi-value-field" style=
"width:16px; padding:3px" id=
"<%=net:ifname()%>-iw-signal">
302 <img src=
"<%=resource%>/icons/signal-none.png" title=
"<%:Not associated%>" /><br />
305 <td class=
"cbi-value-field" style=
"vertical-align:middle; text-align:left; padding:3px" id=
"<%=net:ifname()%>-iw-status">
306 <em><%:Collecting data...%
></em>
308 <td class=
"cbi-value-field" style=
"width:40px">
309 <a href=
"<%=net:adminlink()%>"><img style=
"border:none" src=
"<%=resource%>/cbi/edit.gif" alt=
"<%:Edit this network%>" title=
"<%:Edit this network%>" /></a>
310 <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>
315 <tr class=
"cbi-section-table-row cbi-rowstyle-2">
317 <td colspan=
"3" class=
"cbi-value-field" style=
"vertical-align:middle; text-align:left; padding:3px">
318 <em><%:No network configured on this device%
></em>
322 <!-- /network list -->
325 <!-- /device <%=dev:name()%> -->
329 <h2><a id=
"content" name=
"content"><%:Associated Stations%
></a></h2>
331 <fieldset class=
"cbi-section">
332 <table class=
"cbi-section-table" style=
"margin:10px; width:50%" id=
"iw-assoclist">
333 <tr class=
"cbi-section-table-titles">
334 <th class=
"cbi-section-table-cell"></th>
335 <th class=
"cbi-section-table-cell"><%:SSID%
></th>
336 <th class=
"cbi-section-table-cell"><%:MAC%
></th>
337 <th class=
"cbi-section-table-cell"><%:Address%
></th>
338 <th class=
"cbi-section-table-cell"><%:Signal%
></th>
339 <th class=
"cbi-section-table-cell"><%:Noise%
></th>
341 <tr class=
"cbi-section-table-row cbi-rowstyle-2">
342 <td class=
"cbi-value-field" colspan=
"6">
343 <em><%:Collecting data...%
></em>