<%
-
local sys = require "luci.sys"
local twa = require "luci.tools.webadmin"
-- System
-local system, model, memtotal, memcached, membuffers, memfree, bogomips = sys.sysinfo()
+local model, system, memtotal, memcached, membuffers, memfree, bogomips = sys.sysinfo()
local uptime = twa.date_format(tonumber(sys.uptime()))
-local_time = os.date("%a, %d %b %Y %H:%M:%S UTC")
+local time = os.date("%a, %d %b %Y, %H:%M:%S")
local load1, load5, load15 = sys.loadavg()
local load = string.format("%.2f, %.2f, %.2f", load1, load5, load15)
-- update interval
local bogomips = bogomips or 100
-local interval
+local interval = 10
if bogomips > 350 then
- interval = "5000"
-else
- interval = "10000"
+ interval = 5
end
-- wireless
local defroutev4 = sys.net.defaultroute()
local defroutev6 = sys.net.defaultroute6()
+if defroutev4 then
+ defroutev4.dest = defroutev4.dest:string()
+ defroutev4.gateway = defroutev4.gateway:string()
+else
+ -- probably policy routing activated, try olsr-default table
+ local dr4 = sys.exec("ip r s t olsr-default")
+ if dr4 then
+ defroutev4 = { }
+ defroutev4.dest, defroutev4.gateway, defroutev4.device, defroutev4.metric = dr4:match("^(%w+) via (%d+.%d+.%d+.%d+) dev ([%w-]+) +metric (%d+)")
+ end
+end
+
+if defroutev6 then
+ defroutev6.dest = defroutev6.dest:string()
+ defroutev6.nexthop = defroutev6.nexthop:string()
+end
+
+if luci.http.formvalue("status") == "1" then
+ local rv = { }
+ for dev in pairs(netdevs) do
+ local j = { id = dev }
+ local iw = luci.sys.wifi.getiwinfo(dev)
+ if iw then
+ local f
+ for _, f in ipairs({
+ "channel", "txpower", "bitrate", "signal", "noise",
+ "quality", "quality_max", "mode", "ssid", "bssid", "encryption", "ifname"
+ }) do
+ j[f] = iw[f]
+ end
+ end
+ rv[#rv+1] = j
+ end
+
+ if defroutev6 then
+ def6 = {
+ gateway = defroutev6.nexthop,
+ dest = defroutev6.dest,
+ dev = defroutev6.device,
+ metr = defroutev6.metric
+ }
+ end
+
+ if defroutev4 then
+ def4 = {
+ gateway = defroutev4.gateway,
+ dest = defroutev4.dest,
+ dev = defroutev4.device,
+ metr = defroutev4.metric
+ }
+ end
+
+ rv[#rv+1] = {
+ time = time,
+ uptime = uptime,
+ load = load,
+ mem = mem,
+ defroutev4 = def4,
+ defroutev6 = def6
+ }
+
+ luci.http.prepare_content("application/json")
+ luci.http.write_json(rv)
+ return
+end
-%>
<%+header%>
-
<script type="text/javascript" src="<%=resource%>/cbi.js"></script>
<script type="text/javascript">//<![CDATA[
- var iwxhr = new XHR();
-
- var update_wifi_status = function() {
- iwxhr.get('<%=luci.dispatcher.build_url("freifunk", "status", "public_status_json", table.concat(netlist, ","))%>', null,
- function(x, st)
+ XHR.poll(<%=interval%> , '<%=REQUEST_URI%>', { status: 1 },
+ function(x, st)
+ {
+ if (st)
{
- if (st)
+ for( var i = 0; i < st.length; i++ )
{
- for( var i = 0; i < st.length; i++ )
- {
- var iw = st[i];
- var is_assoc = (iw.bssid && iw.channel);
- var p = (100 / iw.quality_max * iw.quality);
- var q = is_assoc ? p : -1;
-
- 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";
-
- var power = document.getElementById(iw.id + '-txpower');
- if (power)
- power.innerHTML = String.format('%s dbm', iw.txpower);
-
- var signal = document.getElementById(iw.id + '-signal');
- if (signal)
- signal.innerHTML = String.format(
- '<img src="%s" title="Signal: %s db / Noise: %s db" alt="Signal Quality" />',
- icon, iw.signal, iw.noise
- );
-
- var bitrate = document.getElementById(iw.id + '-bitrate');
- if (bitrate)
- bitrate.innerHTML = String.format('%s Mb/s', iw.bitrate ? iw.bitrate / 1000 : '?');
-
- var ssid = document.getElementById(iw.id + '-ssid');
- if (ssid)
- ssid.innerHTML = iw.ssid;
-
- var bssid = document.getElementById(iw.id + '-bssid');
- if (bssid)
- bssid.innerHTML = iw.bssid;
-
- var channel = document.getElementById(iw.id + '-channel');
- if (channel)
- channel.innerHTML = iw.channel;
-
- var mode = document.getElementById(iw.id + '-mode');
- if (mode)
- mode.innerHTML = iw.mode;
- }
-
- i = st.length - 1
- var u
-
- if (u = document.getElementById('dynuptime'))
- u.innerHTML = st[i].uptime;
-
- if (u = document.getElementById('dynload'))
- u.innerHTML = st[i].load;
-
- if (u = document.getElementById('dynmem'))
- u.innerHTML = st[i].mem;
-
- if (u = document.getElementById('dyntime'))
- u.innerHTML = st[i].time;
-
- if (st[i].defroutev4)
- {
- if (u = document.getElementById('v4dst'))
- u.innerHTML = st[i].defroutev4.dest;
-
- if (u = document.getElementById('v4gw'))
- u.innerHTML = st[i].defroutev4.gateway;
-
- if (u = document.getElementById('v4dev'))
- u.innerHTML = st[i].defroutev4.dev;
-
- if (u = document.getElementById('v4metr'))
- u.innerHTML = st[i].defroutev4.metr;
- }
-
- if (st[i].defroutev6)
- {
- if (u = document.getElementById('v6dst'))
- u.innerHTML = st[i].defroutev6.dest;
-
- if (u = document.getElementById('v6gw'))
- u.innerHTML = st[i].defroutev6.gateway;
-
- if (u = document.getElementById('v6dev'))
- u.innerHTML = st[i].defroutev6.dev;
-
- if (u = document.getElementById('v6metr'))
- u.innerHTML = st[i].defroutev6.metr;
- }
+ var iw = st[i];
+ var is_assoc = (iw.bssid && iw.channel);
+ var p = (100 / iw.quality_max * iw.quality);
+ var q = is_assoc ? p : -1;
+
+ 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";
+
+ var power = document.getElementById(iw.id + '-txpower');
+ if (power)
+ power.innerHTML = String.format('%s dbm', iw.txpower);
+
+ var signal = document.getElementById(iw.id + '-signal');
+ if (signal)
+ signal.innerHTML = String.format(
+ '<img src="%s" title="Signal: %s db / Noise: %s db" alt="Signal Quality" />',
+ icon, iw.signal, iw.noise
+ );
+
+ var bitrate = document.getElementById(iw.id + '-bitrate');
+ if (bitrate)
+ bitrate.innerHTML = String.format('%s Mb/s', iw.bitrate ? iw.bitrate / 1000 : '?');
+
+ var ssid = document.getElementById(iw.id + '-ssid');
+ if (ssid)
+ ssid.innerHTML = iw.ssid;
+
+ var bssid = document.getElementById(iw.id + '-bssid');
+ if (bssid)
+ bssid.innerHTML = iw.bssid;
+
+ var channel = document.getElementById(iw.id + '-channel');
+ if (channel)
+ channel.innerHTML = iw.channel;
+
+ var mode = document.getElementById(iw.id + '-mode');
+ if (mode)
+ mode.innerHTML = iw.mode;
}
- window.setTimeout(update_wifi_status, <%=interval%>);
- }
- )
- };
+ i = st.length - 1
+ var u
+
+ if (u = document.getElementById('dynuptime'))
+ u.innerHTML = st[i].uptime;
+
+ if (u = document.getElementById('dynload'))
+ u.innerHTML = st[i].load;
+
+ if (u = document.getElementById('dynmem'))
+ u.innerHTML = st[i].mem;
+
+ if (u = document.getElementById('dyntime'))
+ u.innerHTML = st[i].time;
+
+ if (st[i].defroutev4)
+ {
+ if (u = document.getElementById('v4dst'))
+ u.innerHTML = st[i].defroutev4.dest;
+
+ if (u = document.getElementById('v4gw'))
+ u.innerHTML = st[i].defroutev4.gateway;
+
+ if (u = document.getElementById('v4dev'))
+ u.innerHTML = st[i].defroutev4.dev;
- update_wifi_status();
+ if (u = document.getElementById('v4metr'))
+ u.innerHTML = st[i].defroutev4.metr;
+ }
+
+ if (st[i].defroutev6)
+ {
+ if (u = document.getElementById('v6dst'))
+ u.innerHTML = st[i].defroutev6.dest;
+
+ if (u = document.getElementById('v6gw'))
+ u.innerHTML = st[i].defroutev6.gateway;
+
+ if (u = document.getElementById('v6dev'))
+ u.innerHTML = st[i].defroutev6.dev;
+
+ if (u = document.getElementById('v6metr'))
+ u.innerHTML = st[i].defroutev6.metr;
+ }
+ }
+ }
+ );
//]]></script>
<div class="cbi-map">
<div class="cbi-value"><label class="cbi-value-title"><%:Processor%></label><div class="cbi-value-field"><%=model%></div></div>
<div class="cbi-value"><label class="cbi-value-title"><%:Load%></label><div class="cbi-value-field" id="dynload"><%=load%></div></div>
<div class="cbi-value"><label class="cbi-value-title"><%:Memory%></label><div class="cbi-value-field" id="dynmem"><%=mem%></div></div>
- <div class="cbi-value"><label class="cbi-value-title"><%:Local Time%></label><div class="cbi-value-field" id="dyntime"><%=local_time%></div></div>
+ <div class="cbi-value"><label class="cbi-value-title"><%:Local Time%></label><div class="cbi-value-field" id="dyntime"><%=time%></div></div>
<div class="cbi-value"><label class="cbi-value-title"><%:Uptime%></label><div class="cbi-value-field" id="dynuptime"><%=uptime%></div></div>
</div>
</div>
<div class="cbi-map">
<h2><%:Wireless Overview%></h2>
-
+
<% if not has_iwinfo then %>
<div class="errorbox">
<strong><%:Package libiwinfo required!%></strong><br />
<th class="cbi-section-table-cell"><%:TX%>-<%:Power%></th>
<th class="cbi-section-table-cell"><%:Interface%></th>
</tr>
- <%
+ <%
for _, dev in ipairs(devices) do
local net
for _, net in ipairs(dev:get_wifinets()) do
netlist[#netlist+1] = net:ifname()
netdevs[net:ifname()] = dev:name()
- if net.iwdata.ifname then
+ if net.iwdata.device then
local signal = net.iwinfo.signal or "N/A"
local noise = net.iwinfo.noise or "N/A"
local q = net.iwinfo.quality or "0"
<% if defroutev4 then %>
<tr class="cbi-section-table-row cbi-rowstyle-1">
- <td class="cbi-value-field" id="v4dst"><%=defroutev4.dest:string()%></td>
+ <td class="cbi-value-field" id="v4dst"><%=defroutev4.dest%></td>
<td class="cbi-value-field" id="v4dev"><%=defroutev4.device%></td>
- <td class="cbi-value-field" id="v4gw"><%=defroutev4.gateway:string()%></td>
+ <td class="cbi-value-field" id="v4gw"><%=defroutev4.gateway%></td>
<td class="cbi-value-field" id="v4metr"><%=defroutev4.metric%></td>
</tr>
if defroutev6 then %>
<tr class="cbi-section-table-row cbi-rowstyle-2">
- <td class="cbi-value-field" id="v6dst"><%=defroutev6.dest:string()%></td>
+ <td class="cbi-value-field" id="v6dst"><%=defroutev6.dest%></td>
<td class="cbi-value-field" id="v6dev"><%=defroutev6.device%></td>
- <td class="cbi-value-field" id="v6gw"><%=defroutev6.nexthop:string()%></td>
+ <td class="cbi-value-field" id="v6gw"><%=defroutev6.nexthop%></td>
<td class="cbi-value-field" id="v6metr"><%=defroutev6.metric%></td>
</tr>