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"
25 function guess_wifi_hw(ifname)
26 local name, idx = ifname:match(
"^([a-z]+)(%d+)")
31 local name =
"Broadcom 802.11 Wireless Controller"
34 local fd = nixio.open(
"/proc/bus/pci/devices",
"r")
37 for ln in fd:linesource() do
38 if ln:match(
"wl$") then
40 local version = ln:match(
"^%S+%s+%S%S%S%S([0-9a-f]+)")
42 "Broadcom BCM%04x 802.11 Wireless Controller",
58 elseif name ==
"ath" or name ==
"wifi" then
59 return
"Atheros 802.11 Wireless Controller"
62 elseif name ==
"ra" then
63 return
"RaLink 802.11 Wireless Controller"
66 elseif name ==
"eth" then
67 return
"Prism 802.11 Wireless Controller"
71 return
"Generic 802.11 Wireless Controller"
75 local devices = ntm:get_wifidevs()
77 sys.net.arptable(function(e) arpcache[e[
"HW address"]:upper()] = e[
"IP address"] end)
83 for _, dev in ipairs(devices) do
85 for _, net in ipairs(dev:get_wifinets()) do
86 netlist[#netlist+
1] = net:ifname()
87 netdevs[net:ifname()] = dev:name()
94 <script type=
"text/javascript" src=
"<%=resource%>/cbi.js"></script>
95 <script type=
"text/javascript"><![CDATA[
96 var iwxhr = new XHR();
97 var wifidevs = <%=luci.http.write_json(netdevs)%
>;
98 var arptable = <%=luci.http.write_json(arpcache)%
>;
100 var update_status = function() {
101 iwxhr.get('<%=luci.dispatcher.build_url(
"admin",
"network",
"wireless_status", table.concat(netlist,
","))%
>', null,
106 var assoctable = document.getElementById('iw-assoclist');
108 while (assoctable.rows.length
> 1)
109 assoctable.rows[
1].parentNode.removeChild(assoctable.rows[
1]);
113 for( var i =
0; i < st.length; i++ )
116 var is_assoc = (iw.bssid && iw.channel);
117 var p = (
100 / iw.quality_max * iw.quality);
118 var q = is_assoc ? p : -
1;
122 icon =
"<%=resource%>/icons/signal-none.png";
124 icon =
"<%=resource%>/icons/signal-0.png";
126 icon =
"<%=resource%>/icons/signal-0-25.png";
128 icon =
"<%=resource%>/icons/signal-25-50.png";
130 icon =
"<%=resource%>/icons/signal-50-75.png";
132 icon =
"<%=resource%>/icons/signal-75-100.png";
134 if (!devup[wifidevs[iw.id]])
135 devup[wifidevs[iw.id]] = is_assoc;
137 var sig = document.getElementById(iw.id + '-iw-signal');
139 sig.innerHTML = String.format(
140 '
<img src=
"%s" title=
"<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" /><br />' +
141 '
<small>%d%%
</small>', icon, iw.signal, iw.noise, p
144 var info = document.getElementById(iw.id + '-iw-status');
148 info.innerHTML = String.format(
149 '
<strong><%:SSID%
>:
</strong> %s | ' +
150 '
<strong><%:Mode%
>:
</strong> %s
<br />' +
151 '
<strong><%:BSSID%
>:
</strong> %s | ' +
152 '
<strong><%:Encryption%
>:
</strong> %s',
153 iw.ssid, iw.mode, iw.bssid,
154 iw.encryption ? iw.encryption.description : '<%:None%
>'
157 info.innerHTML = '
<em><%:Wireless is disabled or not associated%
></em>';
160 var dev = document.getElementById(wifidevs[iw.id] + '-iw-devinfo');
164 dev.innerHTML = String.format(
165 '
<strong><%:Channel%
>:
</strong> %s (%s GHz) | ' +
166 '
<strong><%:Bitrate%
>:
</strong> %s Mb/s',
167 iw.channel ? iw.channel : '?',
168 iw.frequency ? iw.frequency /
1000 : '?',
169 iw.bitrate ? iw.bitrate /
1000 : '?'
178 for( var bssid in iw.assoclist )
180 assoclist.push(iw.assoclist[bssid]);
181 assoclist[assoclist.length-
1].bssid = bssid;
184 assoclist.sort(function(a, b) { a.bssid < b.bssid });
186 for( var j =
0; j < assoclist.length; j++ )
188 var tr = document.createElement('tr');
189 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((j %
2) + (i %
2));
192 var q = (-
1 * (assoclist[j].noise - assoclist[j].signal)) /
5;
194 icon =
"<%=resource%>/icons/signal-0.png";
196 icon =
"<%=resource%>/icons/signal-0-25.png";
198 icon =
"<%=resource%>/icons/signal-25-50.png";
200 icon =
"<%=resource%>/icons/signal-50-75.png";
202 icon =
"<%=resource%>/icons/signal-75-100.png";
204 tr.innerHTML = String.format(
205 '
<td class=
"cbi-value-field">' +
206 '
<img src=
"%s" title=
"<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" />' +
208 '
<td class=
"cbi-value-field">%s
</td>' +
209 '
<td class=
"cbi-value-field">%s
</td>' +
210 '
<td class=
"cbi-value-field">%s
</td>' +
211 '
<td class=
"cbi-value-field">%d dBm
</td>' +
212 '
<td class=
"cbi-value-field">%d dBm
</td>',
214 assoclist[j].signal, assoclist[j].noise,
215 iw.ssid ? iw.ssid : '?',
217 arptable[assoclist[j].bssid]
218 ? arptable[assoclist[j].bssid] : '?',
219 assoclist[j].signal, assoclist[j].noise
222 assoctable.rows[
0].parentNode.appendChild(tr);
227 if (assoctable && assoctable.rows.length ==
1)
229 var tr = document.createElement('tr');
230 tr.className = 'cbi-section-table-row';
232 tr.innerHTML = '
<td class=
"cbi-value-field" colspan=
"6"><br /><em><%:No information available%
></em></td>';
234 assoctable.rows[
0].parentNode.appendChild(tr);
237 for (var dev in devup)
239 var img = document.getElementById(dev + '-iw-upstate');
241 img.src = '<%=resource%
>/icons/wifi' + (devup[dev] ? '' : '_disabled') + '.png';
245 window.setTimeout(update_status,
5000);
253 <h2><a id=
"content" name=
"content"><%:Wireless Overview%
></a></h2>
255 <div class=
"cbi-map">
257 <% for _, dev in ipairs(devices) do local nets = dev:get_wifinets() %
>
258 <!-- device <%=dev:name()%> -->
259 <fieldset class=
"cbi-section">
260 <table class=
"cbi-section-table" style=
"margin:10px; empty-cells:hide">
261 <!-- physical device -->
263 <td style=
"width:34px"><img src=
"<%=resource%>/icons/wifi_disabled.png" style=
"float:left; margin-right:10px" id=
"<%=dev:name()%>-iw-upstate" /></td>
264 <td colspan=
"2" style=
"text-align:left">
265 <big><strong><%=guess_wifi_hw(dev:name())%
> (<%=dev:name()%
>)
</strong></big><br />
266 <span id=
"<%=dev:name()%>-iw-devinfo"></span>
268 <td style=
"width:40px">
269 <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>
270 <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>
273 <!-- /physical device -->
275 <!-- network list -->
276 <% if #nets
> 0 then %
>
277 <% for i, net in ipairs(nets) do %
>
278 <tr class=
"cbi-section-table-row cbi-rowstyle-<%=1 + ((i-1) % 2)%>">
280 <td class=
"cbi-value-field" style=
"width:16px; padding:3px" id=
"<%=net:ifname()%>-iw-signal">
281 <img src=
"<%=resource%>/icons/signal-none.png" title=
"<%:Not associated%>" /><br />
284 <td class=
"cbi-value-field" style=
"vertical-align:middle; text-align:left; padding:3px" id=
"<%=net:ifname()%>-iw-status">
285 <em><%:Collecting data...%
></em>
287 <td class=
"cbi-value-field" style=
"width:40px">
288 <a href=
"<%=net:adminlink()%>"><img style=
"border:none" src=
"<%=resource%>/cbi/edit.gif" alt=
"<%:Edit this network%>" title=
"<%:Edit this network%>" /></a>
289 <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>
294 <tr class=
"cbi-section-table-row cbi-rowstyle-2">
296 <td colspan=
"3" class=
"cbi-value-field" style=
"vertical-align:middle; text-align:left; padding:3px">
297 <em><%:No network configured on this device%
></em>
301 <!-- /network list -->
304 <!-- /device <%=dev:name()%> -->
308 <h2><a id=
"content" name=
"content"><%:Associated Stations%
></a></h2>
310 <fieldset class=
"cbi-section">
311 <table class=
"cbi-section-table" style=
"margin:10px; width:50%" id=
"iw-assoclist">
312 <tr class=
"cbi-section-table-titles">
313 <th class=
"cbi-section-table-cell"></th>
314 <th class=
"cbi-section-table-cell"><%:SSID%
></th>
315 <th class=
"cbi-section-table-cell"><%:MAC%
></th>
316 <th class=
"cbi-section-table-cell"><%:Address%
></th>
317 <th class=
"cbi-section-table-cell"><%:Signal%
></th>
318 <th class=
"cbi-section-table-cell"><%:Noise%
></th>
320 <tr class=
"cbi-section-table-row cbi-rowstyle-2">
321 <td class=
"cbi-value-field" colspan=
"6">
322 <em><%:Collecting data...%
></em>