2009-09-26 11:10:01 +00:00
< %#
LuCI - Lua Configuration Interface
Copyright 2008-2009 Steven Barth < steven @ midlink . org >
2011-03-13 17:25:54 +00:00
Copyright 2008-2011 Jo-Philipp Wich < xm @ subsignal . org >
2009-09-26 11:10:01 +00:00
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
$Id$
-%>
< %-
local sys = require "luci.sys"
2011-02-26 22:30:58 +00:00
local fs = require "luci.fs"
2009-09-26 11:10:01 +00:00
local utl = require "luci.util"
2009-10-29 02:22:00 +00:00
local uci = require "luci.model.uci".cursor()
2010-10-30 00:44:34 +00:00
local ntm = require "luci.model.network"
2009-10-29 02:22:00 +00:00
2010-12-02 12:21:18 +00:00
local has_iwinfo = pcall(require, "iwinfo")
2010-10-30 00:44:34 +00:00
ntm.init(uci)
2009-09-26 11:10:01 +00:00
function guess_wifi_hw(ifname)
2010-12-02 12:21:18 +00:00
local bands = ""
2009-09-26 11:10:01 +00:00
local name, idx = ifname:match("^([a-z]+)(%d+)")
idx = tonumber(idx)
2010-12-02 12:21:18 +00:00
if has_iwinfo then
local iw = luci.sys.wifi.getiwinfo(ifname)
local bl = iw.hwmodelist
if bl and next(bl) then
if bl.a then bands = bands .. "a" end
if bl.b then bands = bands .. "b" end
if bl.g then bands = bands .. "g" end
if bl.n then bands = bands .. "n" end
end
end
2009-09-26 11:10:01 +00:00
-- wl.o
if name == "wl" then
2010-12-02 12:21:18 +00:00
local name = "Broadcom 802.11%s Wireless Controller" % bands
2009-09-26 11:10:01 +00:00
local nm = 0
local fd = nixio.open("/proc/bus/pci/devices", "r")
if fd then
local ln
for ln in fd:linesource() do
if ln:match("wl$") then
if nm == idx then
local version = ln:match("^%S+%s+%S%S%S%S([0-9a-f]+)")
name = string.format(
"Broadcom BCM%04x 802.11 Wireless Controller",
tonumber(version, 16)
)
break
else
nm = nm + 1
end
end
end
fd:close()
end
return name
-- madwifi
elseif name == "ath" or name == "wifi" then
2010-12-02 12:21:18 +00:00
return "Atheros 802.11%s Wireless Controller" % bands
2009-09-26 11:10:01 +00:00
-- ralink
elseif name == "ra" then
2010-12-02 12:21:18 +00:00
return "RaLink 802.11%s Wireless Controller" % bands
2009-09-26 11:10:01 +00:00
2011-02-26 22:30:58 +00:00
-- hermes
2009-09-26 11:10:01 +00:00
elseif name == "eth" then
2011-03-06 11:16:14 +00:00
return "Hermes 802.11b Wireless Controller"
2009-09-26 11:10:01 +00:00
2011-02-26 22:30:58 +00:00
-- hostap
elseif name == "wlan" and fs.isdirectory("/proc/net/hostap/" .. ifname) then
2011-03-06 11:16:07 +00:00
return "Prism2/2.5/3 802.11b Wireless Controller"
2011-02-26 22:30:58 +00:00
2009-09-26 11:10:01 +00:00
-- dunno yet
else
2010-12-02 12:21:18 +00:00
return "Generic 802.11%s Wireless Controller" % bands
2009-09-26 11:10:01 +00:00
end
end
2010-10-30 00:44:34 +00:00
local devices = ntm:get_wifidevs()
2009-09-26 11:10:01 +00:00
local arpcache = { }
2010-11-08 21:51:24 +00:00
sys.net.arptable(function(e) arpcache[e["HW address"]:upper()] = e["IP address"] end)
local netlist = { }
local netdevs = { }
local dev
for _, dev in ipairs(devices) do
local net
for _, net in ipairs(dev:get_wifinets()) do
2011-03-13 17:25:54 +00:00
netlist[#netlist+1] = net:id()
netdevs[net:id()] = dev:name()
2010-11-08 21:51:24 +00:00
end
end
2009-09-26 11:10:01 +00:00
-%>
< %+header%>
2010-11-27 18:24:38 +00:00
< % if not has_iwinfo then %>
< div class = "errorbox" >
< strong > < %:Package libiwinfo required!%>< / strong > < br / >
< %_The < em > libiwinfo< / em > package is not installed. You must install this component for working wireless configuration!%>
< / div >
< % end %>
2010-11-08 21:51:24 +00:00
< script type = "text/javascript" src = "<%=resource%>/cbi.js" > < / script >
2010-11-18 01:34:56 +00:00
< script type = "text/javascript" > / / < ! [ C D A T A [
2010-11-08 21:51:24 +00:00
var iwxhr = new XHR();
var wifidevs = < %=luci.http.write_json(netdevs)%>;
var arptable = < %=luci.http.write_json(arpcache)%>;
2010-11-17 15:23:21 +00:00
var update_status = function() {
2010-11-08 21:51:24 +00:00
iwxhr.get('< %=luci.dispatcher.build_url("admin", "network", "wireless_status", table.concat(netlist, ","))%>', null,
2010-11-15 14:41:30 +00:00
function(x, st)
2010-11-08 21:51:24 +00:00
{
if (st)
{
var assoctable = document.getElementById('iw-assoclist');
if (assoctable)
while (assoctable.rows.length > 1)
assoctable.rows[1].parentNode.removeChild(assoctable.rows[1]);
2010-11-08 22:40:04 +00:00
var devup = { };
2011-04-30 16:13:30 +00:00
var rowstyle = 1;
2010-11-08 22:40:04 +00:00
2010-11-08 21:51:24 +00:00
for( var i = 0; i < st.length ; i + + )
{
var iw = st[i];
2011-03-13 17:25:54 +00:00
var is_assoc = (iw.bssid & & iw.bssid != '00:00:00:00:00:00' & & iw.channel);
var p = iw.quality;
2010-11-08 22:40:04 +00:00
var q = is_assoc ? p : -1;
2010-11-08 21:51:24 +00:00
var icon;
if (q < 0 )
icon = "< %=resource%>/icons/signal-none.png";
else if (q == 0)
icon = "< %=resource%>/icons/signal-0.png";
else if (q < 25 )
icon = "< %=resource%>/icons/signal-0-25.png";
else if (q < 50 )
icon = "< %=resource%>/icons/signal-25-50.png";
else if (q < 75 )
icon = "< %=resource%>/icons/signal-50-75.png";
else
icon = "< %=resource%>/icons/signal-75-100.png";
2010-11-08 22:40:04 +00:00
if (!devup[wifidevs[iw.id]])
devup[wifidevs[iw.id]] = is_assoc;
2010-11-08 21:51:24 +00:00
var sig = document.getElementById(iw.id + '-iw-signal');
if (sig)
sig.innerHTML = String.format(
'< img src = "%s" title = "<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" / > < br / > ' +
'< small > %d%%< / small > ', icon, iw.signal, iw.noise, p
);
var info = document.getElementById(iw.id + '-iw-status');
if (info)
2010-11-08 22:40:04 +00:00
{
if (is_assoc)
info.innerHTML = String.format(
2011-01-20 23:27:48 +00:00
'< strong > < %:SSID%>:< / strong > %h | ' +
2010-11-08 22:40:04 +00:00
'< strong > < %:Mode%>:< / strong > %s< br / > ' +
'< strong > < %:BSSID%>:< / strong > %s | ' +
'< strong > < %:Encryption%>:< / strong > %s',
iw.ssid, iw.mode, iw.bssid,
2011-03-13 17:25:54 +00:00
iw.encryption ? iw.encryption : '< %:None%>'
2010-11-08 22:40:04 +00:00
);
else
2011-01-20 23:27:48 +00:00
info.innerHTML = String.format(
'< strong > < %:SSID%>:< / strong > %h | ' +
'< strong > < %:Mode%>:< / strong > %s< br / > ' +
'< em > < %:Wireless is disabled or not associated%>< / em > ',
iw.ssid || '?', iw.mode
);
2010-11-08 22:40:04 +00:00
}
2010-11-08 21:51:24 +00:00
var dev = document.getElementById(wifidevs[iw.id] + '-iw-devinfo');
if (dev)
2010-11-08 22:40:04 +00:00
{
if (is_assoc)
dev.innerHTML = String.format(
'< strong > < %:Channel%>:< / strong > %s (%s GHz) | ' +
'< strong > < %:Bitrate%>:< / strong > %s Mb/s',
iw.channel ? iw.channel : '?',
2011-03-13 17:25:54 +00:00
iw.frequency ? iw.frequency : '?',
iw.bitrate ? iw.bitrate : '?'
2010-11-08 22:40:04 +00:00
);
else
dev.innerHTML = '';
}
2010-11-08 21:51:24 +00:00
if (assoctable)
{
var assoclist = [ ];
for( var bssid in iw.assoclist )
{
assoclist.push(iw.assoclist[bssid]);
assoclist[assoclist.length-1].bssid = bssid;
}
assoclist.sort(function(a, b) { a.bssid < b.bssid } ) ;
for( var j = 0; j < assoclist.length ; j + + )
{
2011-02-06 01:58:55 +00:00
var tr = assoctable.insertRow(-1);
2011-04-30 16:13:30 +00:00
tr.className = 'cbi-section-table-row cbi-rowstyle-' + rowstyle;
2010-11-08 21:51:24 +00:00
var icon;
var q = (-1 * (assoclist[j].noise - assoclist[j].signal)) / 5;
if (q < 1 )
icon = "< %=resource%>/icons/signal-0.png";
else if (q < 2 )
icon = "< %=resource%>/icons/signal-0-25.png";
else if (q < 3 )
icon = "< %=resource%>/icons/signal-25-50.png";
else if (q < 4 )
icon = "< %=resource%>/icons/signal-50-75.png";
else
icon = "< %=resource%>/icons/signal-75-100.png";
2011-02-06 01:58:55 +00:00
tr.insertCell(-1).innerHTML = String.format(
'< img src = "%s" title = "<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" / > ',
icon, assoclist[j].signal, assoclist[j].noise
2010-11-08 21:51:24 +00:00
);
2011-02-06 01:58:55 +00:00
tr.insertCell(-1).innerHTML = iw.ssid ? iw.ssid : '?';
tr.insertCell(-1).innerHTML = assoclist[j].bssid;
tr.insertCell(-1).innerHTML = arptable[assoclist[j].bssid]
? arptable[assoclist[j].bssid] : '?';
tr.insertCell(-1).innerHTML = String.format('%d dBm', assoclist[j].signal);
tr.insertCell(-1).innerHTML = String.format('%d dBm', assoclist[j].noise);
2011-04-30 16:13:30 +00:00
rowstyle = (rowstyle == 1) ? 2 : 1;
2010-11-08 21:51:24 +00:00
}
}
}
if (assoctable & & assoctable.rows.length == 1)
{
2011-02-06 01:58:55 +00:00
var tr = assoctable.insertRow(-1);
tr.className = 'cbi-section-table-row';
2010-11-08 21:51:24 +00:00
2011-02-06 01:58:55 +00:00
var td = tr.insertCell(-1);
td.colSpan = 6;
td.innerHTML = '< br / > < em > < %:No information available%>< / em > ';
2010-11-08 21:51:24 +00:00
}
2010-11-08 22:40:04 +00:00
for (var dev in devup)
{
var img = document.getElementById(dev + '-iw-upstate');
if (img)
2010-11-18 03:41:13 +00:00
img.src = '< %=resource%>/icons/wifi_big' + (devup[dev] ? '' : '_disabled') + '.png';
2010-11-08 22:40:04 +00:00
}
2010-11-08 21:51:24 +00:00
}
2010-11-17 15:23:21 +00:00
window.setTimeout(update_status, 5000);
2010-11-08 21:51:24 +00:00
}
)
2010-11-17 15:23:21 +00:00
};
2010-11-08 21:51:24 +00:00
2010-11-17 15:23:21 +00:00
update_status();
2010-11-18 01:34:56 +00:00
//]]>< / script >
2010-11-08 21:51:24 +00:00
2009-10-31 15:54:11 +00:00
< h2 > < a id = "content" name = "content" > < %:Wireless Overview%>< / a > < / h2 >
2009-09-26 11:10:01 +00:00
< div class = "cbi-map" >
2010-10-30 00:44:34 +00:00
< % for _, dev in ipairs(devices) do local nets = dev:get_wifinets() %>
2009-10-29 02:22:00 +00:00
<!-- device <%=dev:name()%> -->
2009-09-26 11:10:01 +00:00
< fieldset class = "cbi-section" >
< table class = "cbi-section-table" style = "margin:10px; empty-cells:hide" >
<!-- physical device -->
< tr >
2010-11-18 03:41:13 +00:00
< td style = "width:34px" > < img src = "<%=resource%>/icons/wifi_big_disabled.png" style = "float:left; margin-right:10px" id = "<%=dev:name()%>-iw-upstate" / > < / td >
2009-09-26 11:10:01 +00:00
< td colspan = "2" style = "text-align:left" >
2009-10-29 02:22:00 +00:00
< big > < strong > < %=guess_wifi_hw(dev:name())%> (< %=dev:name()%>)< / strong > < / big > < br / >
2010-11-08 21:51:24 +00:00
< span id = "<%=dev:name()%>-iw-devinfo" > < / span >
2009-09-26 11:10:01 +00:00
< / td >
< td style = "width:40px" >
2010-11-13 20:52:00 +00:00
< 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 >
< 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 >
2009-09-26 11:10:01 +00:00
< / td >
< / tr >
<!-- /physical device -->
<!-- network list -->
2009-10-29 02:22:00 +00:00
< % if #nets > 0 then %>
< % for i, net in ipairs(nets) do %>
2009-09-26 11:10:01 +00:00
< tr class = "cbi-section-table-row cbi-rowstyle-<%=1 + ((i-1) % 2)%>" >
< td > < / td >
2011-03-13 17:25:54 +00:00
< td class = "cbi-value-field" style = "width:16px; padding:3px" id = "<%=net:id()%>-iw-signal" >
2010-11-08 21:51:24 +00:00
< img src = "<%=resource%>/icons/signal-none.png" title = "<%:Not associated%>" / > < br / >
< small > 0%< / small >
2009-09-26 11:10:01 +00:00
< / td >
2011-03-13 17:25:54 +00:00
< td class = "cbi-value-field" style = "vertical-align:middle; text-align:left; padding:3px" id = "<%=net:id()%>-iw-status" >
2010-11-08 21:51:24 +00:00
< em > < %:Collecting data...%>< / em >
2009-09-26 11:10:01 +00:00
< / td >
< td class = "cbi-value-field" style = "width:40px" >
2010-11-15 22:08:42 +00:00
< a href = "<%=net:adminlink()%>" > < img style = "border:none" src = "<%=resource%>/cbi/edit.gif" alt = "<%:Edit this network%>" title = "<%:Edit this network%>" / > < / a >
2010-11-16 00:04:28 +00:00
< 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 >
2009-09-26 11:10:01 +00:00
< / td >
< / tr >
< % end %>
< % else %>
< tr class = "cbi-section-table-row cbi-rowstyle-2" >
< td > < / td >
< td colspan = "3" class = "cbi-value-field" style = "vertical-align:middle; text-align:left; padding:3px" >
2010-11-09 19:33:09 +00:00
< em > < %:No network configured on this device%>< / em >
2009-09-26 11:10:01 +00:00
< / td >
< / tr >
< % end %>
<!-- /network list -->
< / table >
< / fieldset >
2009-10-29 02:22:00 +00:00
<!-- /device <%=dev:name()%> -->
2009-09-26 11:10:01 +00:00
< % end %>
2009-10-31 15:54:11 +00:00
< h2 > < a id = "content" name = "content" > < %:Associated Stations%>< / a > < / h2 >
2009-09-26 11:10:01 +00:00
< fieldset class = "cbi-section" >
2010-11-08 21:51:24 +00:00
< table class = "cbi-section-table" style = "margin:10px; width:50%" id = "iw-assoclist" >
2009-09-26 11:10:01 +00:00
< tr class = "cbi-section-table-titles" >
< th class = "cbi-section-table-cell" > < / th >
2010-11-08 21:51:24 +00:00
< th class = "cbi-section-table-cell" > < %:SSID%>< / th >
< th class = "cbi-section-table-cell" > < %:MAC%>< / th >
< th class = "cbi-section-table-cell" > < %:Address%>< / th >
< th class = "cbi-section-table-cell" > < %:Signal%>< / th >
< th class = "cbi-section-table-cell" > < %:Noise%>< / th >
2009-09-26 11:10:01 +00:00
< / tr >
< tr class = "cbi-section-table-row cbi-rowstyle-2" >
< td class = "cbi-value-field" colspan = "6" >
2010-11-08 21:51:24 +00:00
< em > < %:Collecting data...%>< / em >
2009-09-26 11:10:01 +00:00
< / td >
< / tr >
< / table >
< / fieldset >
< / div >
< %+footer%>