2 Copyright
2008-
2009 Steven Barth
<steven@midlink.org
>
3 Copyright
2008-
2015 Jo-Philipp Wich
<jow@openwrt.org
>
4 Licensed to the public under the Apache License
2.0.
9 local ip = require
"luci.ip"
10 local fs = require
"nixio.fs"
11 local utl = require
"luci.util"
12 local uci = require
"luci.model.uci".cursor()
13 local ntm = require
"luci.model.network"
15 local has_iwinfo = pcall(require,
"iwinfo")
19 function guess_wifi_hw(dev)
21 local ifname = dev:name()
22 local name, idx = ifname:match(
"^([a-z]+)(%d+)")
26 local bl = dev.iwinfo.hwmodelist
27 if bl and next(bl) then
28 if bl.a then bands = bands ..
"a" end
29 if bl.b then bands = bands ..
"b" end
30 if bl.g then bands = bands ..
"g" end
31 if bl.n then bands = bands ..
"n" end
32 if bl.ac then bands = bands ..
"ac" end
35 local hw = dev.iwinfo.hardware_name
37 return
"%s 802.11%s" %{ hw, bands }
43 local name = translatef(
"Broadcom 802.11%s Wireless Controller", bands)
46 local fd = nixio.open(
"/proc/bus/pci/devices",
"r")
49 for ln in fd:linesource() do
50 if ln:match(
"wl$") then
52 local version = ln:match(
"^%S+%s+%S%S%S%S([0-9a-f]+)")
54 "Broadcom BCM%04x 802.11 Wireless Controller",
70 elseif name ==
"ra" then
71 return translatef(
"RaLink 802.11%s Wireless Controller", bands)
74 elseif name ==
"eth" then
75 return translate(
"Hermes 802.11b Wireless Controller")
78 elseif name ==
"wlan" and fs.stat(
"/proc/net/hostap/" .. ifname,
"type") ==
"dir" then
79 return translate(
"Prism2/2.5/3 802.11b Wireless Controller")
83 return translatef(
"Generic 802.11%s Wireless Controller", bands)
87 local devices = ntm:get_wifidevs()
92 for _, dev in ipairs(devices) do
94 for _, net in ipairs(dev:get_wifinets()) do
95 netlist[#netlist+
1] = net:id()
96 netdevs[net:id()] = dev:name()
103 <% if not has_iwinfo then %
>
104 <div class=
"alert-message warning">
105 <h4><%:Package libiwinfo required!%
></h4>
106 <p><%_The
<em>libiwinfo-lua
</em> package is not installed. You must install this component for working wireless configuration!%
></p>
110 <script type=
"text/javascript">//<![CDATA[
111 var wifidevs = <%=luci.http.write_json(netdevs)%
>;
113 var is_reconnecting = false;
115 function wifi_shutdown(id, toggle) {
116 var reconnect = (toggle.getAttribute('active') == 'false');
118 if (!reconnect && !confirm(<%=luci.http.write_json(translate('Really shut down network? You might lose access to this device if you are connected via this interface'))%
>))
121 is_reconnecting = true;
123 var s = document.getElementById('iw-rc-status');
126 s.parentNode.style.display = 'block';
127 s.innerHTML = '<%:Waiting for changes to be applied...%
>';
130 for (var net in wifidevs)
132 var st = document.getElementById(net + '-iw-status');
134 st.innerHTML = '
<em><%:Wireless is restarting...%
></em>';
137 (new XHR()).post('<%=url('admin/network')%
>/wireless_' + (reconnect ? 'reconnect' : 'shutdown') + '/' + id, { token: '<%=token%
>' },
142 s.innerHTML = reconnect
143 ? '<%:Wireless restarted%
>'
144 : '<%:Wireless shut down%
>';
146 window.setTimeout(function() {
147 s.parentNode.style.display = 'none';
148 is_reconnecting = false;
155 function wifi_delete(id) {
156 if (!confirm(<%=luci.http.write_json(translate('Really delete this wireless network? The deletion cannot be undone! You might lose access to this device if you are connected via this network.'))%
>))
159 (new XHR()).post('<%=url('admin/network/wireless_delete')%
>/' + id, { token: '<%=token%
>' },
161 location.href = '<%=url('admin/network/wireless')%
>';
166 var hosts = <%=luci.http.write_json(luci.sys.net.host_hints())%
>;
168 XHR.poll(
5, '<%=url('admin/network/wireless_status', table.concat(netlist,
","))%
>', null,
174 var radiostate = { };
176 st.forEach(function(s) {
177 var r = radiostate[wifidevs[s.id]] || (radiostate[wifidevs[s.id]] = {});
179 s.is_assoc = (s.bssid && s.bssid != '
00:
00:
00:
00:
00:
00' && s.channel && s.mode != 'Unknown' && !s.disabled);
181 r.up = r.up || s.is_assoc;
182 r.channel = r.channel || s.channel;
183 r.bitrate = r.bitrate || s.bitrate;
184 r.frequency = r.frequency || s.frequency;
187 for( var i =
0; i < st.length; i++ )
191 var q = iw.is_assoc ? p : -
1;
195 icon =
"<%=resource%>/icons/signal-none.png";
197 icon =
"<%=resource%>/icons/signal-0.png";
199 icon =
"<%=resource%>/icons/signal-0-25.png";
201 icon =
"<%=resource%>/icons/signal-25-50.png";
203 icon =
"<%=resource%>/icons/signal-50-75.png";
205 icon =
"<%=resource%>/icons/signal-75-100.png";
207 var sig = document.getElementById(iw.id + '-iw-signal');
209 sig.innerHTML = String.format(
210 '
<span class=
"ifacebadge" title=
"<%:Signal%>: %d <%:dBm%> / <%:Noise%>: %d <%:dBm%>"><img src=
"%s" /> %d%%
</span>',
211 iw.signal, iw.noise, icon, p
214 var toggle = document.getElementById(iw.id + '-iw-toggle');
219 toggle.className = 'cbi-button cbi-button-neutral';
220 toggle.value = '<%:Disable%
>';
221 toggle.title = '<%:Shutdown this network%
>';
225 toggle.className = 'cbi-button cbi-button-neutral';
226 toggle.value = '<%:Enable%
>';
227 toggle.title = '<%:Activate this network%
>';
230 toggle.setAttribute('active', !iw.disabled);
233 var info = document.getElementById(iw.id + '-iw-status');
237 info.innerHTML = String.format(
238 '
<strong><%:SSID%
>:
</strong> %h | ' +
239 '
<strong><%:Mode%
>:
</strong> %s
<br />' +
240 '
<strong><%:BSSID%
>:
</strong> %s | ' +
241 '
<strong><%:Encryption%
>:
</strong> %s',
242 iw.ssid, iw.mode, iw.bssid,
243 iw.encryption ? iw.encryption : '<%:None%
>'
246 info.innerHTML = String.format(
247 '
<strong><%:SSID%
>:
</strong> %h | ' +
248 '
<strong><%:Mode%
>:
</strong> %s
<br />' +
250 iw.ssid || '?', iw.mode,
252 ? '
<em><%:Wireless is restarting...%
></em>'
253 : '
<em><%:Wireless is disabled or not associated%
></em>'
258 for (var dev in radiostate)
260 var img = document.getElementById(dev + '-iw-upstate');
262 img.src = '<%=resource%
>/icons/wifi' + (radiostate[dev].up ? '' : '_disabled') + '.png';
264 var stat = document.getElementById(dev + '-iw-devinfo');
266 stat.innerHTML = String.format(
267 '
<strong><%:Channel%
>:
</strong> %s (%s <%:GHz%
>) | ' +
268 '
<strong><%:Bitrate%
>:
</strong> %s <%:Mbit/s%
>',
269 radiostate[dev].channel ? radiostate[dev].channel : '?',
270 radiostate[dev].frequency ? radiostate[dev].frequency : '?',
271 radiostate[dev].bitrate ? radiostate[dev].bitrate : '?'
279 <h2 name=
"content"><%:Wireless Overview%
></h2>
281 <div class=
"cbi-section" style=
"display:none">
282 <legend><%:Reconnecting interface%
></legend>
283 <img src=
"<%=resource%>/icons/loading.gif" alt=
"<%:Loading%>" style=
"vertical-align:middle" />
284 <span id=
"iw-rc-status"><%:Waiting for changes to be applied...%
></span>
287 <div id=
"cbi-wireless-overview" class=
"cbi-map">
289 <% for _, dev in ipairs(devices) do local nets = dev:get_wifinets() %
>
290 <!-- device <%=dev:name()%> -->
291 <div class=
"cbi-section-node">
293 <!-- physical device -->
295 <div class=
"td col-2 center">
296 <span class=
"ifacebadge"><img src=
"<%=resource%>/icons/wifi_disabled.png" id=
"<%=dev:name()%>-iw-upstate" /> <%=dev:name()%
></span>
298 <div class=
"td col-7 left">
299 <big><strong><%=guess_wifi_hw(dev)%
></strong></big><br />
300 <span id=
"<%=dev:name()%>-iw-devinfo"></span>
302 <div class=
"td cbi-section-actions">
303 <form action=
"<%=url('admin/network/wireless_join')%>" method=
"post" class=
"inline">
304 <input type=
"hidden" name=
"device" value=
"<%=dev:name()%>" />
305 <input type=
"hidden" name=
"token" value=
"<%=token%>" />
306 <input type=
"submit" class=
"cbi-button cbi-button-action" title=
"<%:Find and join network%>" value=
"<%:Scan%>" />
308 <form action=
"<%=url('admin/network/wireless_add')%>" method=
"post" class=
"inline">
309 <input type=
"hidden" name=
"device" value=
"<%=dev:name()%>" />
310 <input type=
"hidden" name=
"token" value=
"<%=token%>" />
311 <input type=
"submit" class=
"cbi-button cbi-button-add" title=
"<%:Provide new network%>" value=
"<%:Add%>" />
315 <!-- /physical device -->
317 <!-- network list -->
318 <% if #nets
> 0 then %
>
319 <% for i, net in ipairs(nets) do %
>
320 <div class=
"tr cbi-rowstyle-<%=1 + ((i-1) % 2)%>">
321 <div class=
"td col-2 center" id=
"<%=net:id()%>-iw-signal">
322 <span class=
"ifacebadge" title=
"<%:Not associated%>"><img src=
"<%=resource%>/icons/signal-none.png" /> 0%
</span>
324 <div class=
"td col-7 left" id=
"<%=net:id()%>-iw-status">
325 <em><%:Collecting data...%
></em>
327 <div class=
"td cbi-section-actions">
328 <input id=
"<%=net:id()%>-iw-toggle" type=
"button" class=
"cbi-button cbi-button-neutral" onclick=
"wifi_shutdown('<%=net:id()%>', this)" title=
"<%:Enable this network%>" value=
"<%:Enable%>" />
329 <input type=
"button" class=
"cbi-button cbi-button-action important" onclick=
"location.href='<%=net:adminlink()%>'" title=
"<%:Edit this network%>" value=
"<%:Edit%>" />
330 <input type=
"button" class=
"cbi-button cbi-button-negative" onclick=
"wifi_delete('<%=net:id()%>')" title=
"<%:Delete this network%>" value=
"<%:Remove%>" />
335 <div class=
"tr cbi-rowstyle-2">
336 <div class=
"td left">
337 <em><%:No network configured on this device%
></em>
341 <!-- /network list -->
344 <!-- /device <%=dev:name()%> -->
348 <h2><%:Associated Stations%
></h2>
350 <%+admin_network/wifi_assoclist%
>