2 Copyright 2008 Steven Barth <steven@midlink.org>
3 Copyright 2008-2011 Jo-Philipp Wich <jow@openwrt.org>
4 Licensed to the public under the Apache License 2.0.
8 local fs = require "nixio.fs"
9 local util = require "luci.util"
10 local stat = require "luci.tools.status"
11 local ver = require "luci.version"
13 local has_ipv6 = fs.access("/proc/net/ipv6_route")
14 local has_dhcp = fs.access("/etc/config/dhcp")
15 local has_wifi = ((fs.stat("/etc/config/wireless", "size") or 0) > 0)
17 local sysinfo = luci.util.ubus("system", "info") or { }
18 local boardinfo = luci.util.ubus("system", "board") or { }
19 local unameinfo = nixio.uname() or { }
21 local meminfo = sysinfo.memory or {
28 local swapinfo = sysinfo.swap or {
33 local has_dsl = fs.access("/etc/init.d/dsl_control")
35 if luci.http.formvalue("status") == "1" then
36 local ntm = require "luci.model.network".init()
37 local wan = ntm:get_wannet()
38 local wan6 = ntm:get_wan6net()
40 local conn_count = tonumber((
41 luci.sys.exec("wc -l /proc/net/nf_conntrack") or
42 luci.sys.exec("wc -l /proc/net/ip_conntrack") or
43 ""):match("%d+")) or 0
45 local conn_max = tonumber((
46 luci.sys.exec("sysctl net.nf_conntrack_max") or
47 luci.sys.exec("sysctl net.ipv4.netfilter.ip_conntrack_max") or
48 ""):match("%d+")) or 4096
51 uptime = sysinfo.uptime or 0,
52 localtime = os.date(),
53 loadavg = sysinfo.load or { 0, 0, 0 },
57 conncount = conn_count,
58 leases = stat.dhcp_leases(),
59 leases6 = stat.dhcp6_leases(),
60 wifinets = stat.wifi_networks()
65 ipaddr = wan:ipaddr(),
66 gwaddr = wan:gwaddr(),
67 netmask = wan:netmask(),
69 expires = wan:expires(),
70 uptime = wan:uptime(),
72 ifname = wan:ifname(),
73 link = wan:adminlink()
79 ip6addr = wan6:ip6addr(),
80 gw6addr = wan6:gw6addr(),
81 dns = wan6:dns6addrs(),
82 uptime = wan6:uptime(),
83 ifname = wan6:ifname(),
84 link = wan6:adminlink()
89 local dsl_stat = luci.sys.exec("/etc/init.d/dsl_control lucistat")
90 local dsl_func = loadstring(dsl_stat)
96 luci.http.prepare_content("application/json")
97 luci.http.write_json(rv)
105 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
106 <script type="text/javascript">//<![CDATA[
107 function progressbar(v, m)
109 var vn = parseInt(v) || 0;
110 var mn = parseInt(m) || 100;
111 var pc = Math.floor((100 / mn) * vn);
113 return String.format(
114 '<div style="width:200px; position:relative; border:1px solid #999999">' +
115 '<div style="background-color:#CCCCCC; width:%d%%; height:15px">' +
116 '<div style="position:absolute; left:0; top:0; text-align:center; width:100%%; color:#000000">' +
117 '<small>%s / %s (%d%%)</small>' +
120 '</div>', pc, v, m, pc
124 var wifidevs = <%=luci.http.write_json(netdevs)%>;
125 var arptable = <%=luci.http.write_json(arpcache)%>;
127 XHR.poll(5, '<%=REQUEST_URI%>', { status: 1 },
130 var si = document.getElementById('wan4_i');
131 var ss = document.getElementById('wan4_s');
134 if (ifc && ifc.ifname && ifc.proto != 'none')
136 var s = String.format(
137 '<strong><%:Type%>: </strong>%s<br />' +
138 '<strong><%:Address%>: </strong>%s<br />' +
139 '<strong><%:Netmask%>: </strong>%s<br />' +
140 '<strong><%:Gateway%>: </strong>%s<br />',
142 (ifc.ipaddr) ? ifc.ipaddr : '0.0.0.0',
143 (ifc.netmask && ifc.netmask != ifc.ipaddr) ? ifc.netmask : '255.255.255.255',
144 (ifc.gwaddr) ? ifc.gwaddr : '0.0.0.0'
147 for (var i = 0; i < ifc.dns.length; i++)
150 '<strong><%:DNS%> %d: </strong>%s<br />',
155 if (ifc.expires > -1)
158 '<strong><%:Expires%>: </strong>%t<br />',
166 '<strong><%:Connected%>: </strong>%t<br />',
171 ss.innerHTML = String.format('<small>%s</small>', s);
172 si.innerHTML = String.format(
173 '<img src="<%=resource%>/icons/ethernet.png" />' +
174 '<br /><small><a href="%s">%s</a></small>',
180 si.innerHTML = '<img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small>';
181 ss.innerHTML = '<em><%:Not connected%></em>';
184 <% if has_ipv6 then %>
185 var si6 = document.getElementById('wan6_i');
186 var ss6 = document.getElementById('wan6_s');
187 var ifc6 = info.wan6;
189 if (ifc6 && ifc6.ifname && ifc6.proto != 'none')
191 var s = String.format(
192 '<strong><%:Address%>: </strong>%s<br />' +
193 '<strong><%:Gateway%>: </strong>%s<br />',
194 (ifc6.ip6addr) ? ifc6.ip6addr : '::',
195 (ifc6.gw6addr) ? ifc6.gw6addr : '::'
198 for (var i = 0; i < ifc6.dns.length; i++)
201 '<strong><%:DNS%> %d: </strong>%s<br />',
209 '<strong><%:Connected%>: </strong>%t<br />',
214 ss6.innerHTML = String.format('<small>%s</small>', s);
215 si6.innerHTML = String.format(
216 '<img src="<%=resource%>/icons/ethernet.png" />' +
217 '<br /><small><a href="%s">%s</a></small>',
218 ifc6.link, ifc6.ifname
223 si6.innerHTML = '<img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small>';
224 ss6.innerHTML = '<em><%:Not connected%></em>';
228 <% if has_dsl then %>
229 var dsl_i = document.getElementById('dsl_i');
230 var dsl_s = document.getElementById('dsl_s');
232 var s = String.format(
233 '<strong><%:Status%>: </strong>%s<br />' +
234 '<strong><%:Line State%>: </strong>%s [0x%x]<br />' +
235 '<strong><%:Line Speed%>: </strong>%s/s / %s/s<br />' +
236 '<strong><%:Line Attenuation%>: </strong>%s dB / %s dB<br />' +
237 '<strong><%:Noise Margin%>: </strong>%s dB / %s dB<br />',
238 info.dsl.line_state, info.dsl.line_state_detail,
239 info.dsl.line_state_num,
240 info.dsl.data_rate_down_s, info.dsl.data_rate_up_s,
241 info.dsl.line_attenuation_down, info.dsl.line_attenuation_up,
242 info.dsl.noise_margin_down, info.dsl.noise_margin_up
245 dsl_s.innerHTML = String.format('<small>%s</small>', s);
246 dsl_i.innerHTML = String.format(
247 '<img src="<%=resource%>/icons/ethernet.png" />' +
248 '<br /><small>ADSL</small>'
252 <% if has_dhcp then %>
253 var ls = document.getElementById('lease_status_table');
257 while( ls.rows.length > 1 )
258 ls.rows[0].parentNode.deleteRow(1);
260 for( var i = 0; i < info.leases.length; i++ )
264 if (info.leases[i].expires <= 0)
265 timestr = '<em><%:expired%></em>';
267 timestr = String.format('%t', info.leases[i].expires);
269 var tr = ls.rows[0].parentNode.insertRow(-1);
270 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
272 tr.insertCell(-1).innerHTML = info.leases[i].hostname ? info.leases[i].hostname : '?';
273 tr.insertCell(-1).innerHTML = info.leases[i].ipaddr;
274 tr.insertCell(-1).innerHTML = info.leases[i].macaddr;
275 tr.insertCell(-1).innerHTML = timestr;
278 if( ls.rows.length == 1 )
280 var tr = ls.rows[0].parentNode.insertRow(-1);
281 tr.className = 'cbi-section-table-row';
283 var td = tr.insertCell(-1);
285 td.innerHTML = '<em><br /><%:There are no active leases.%></em>';
289 var ls6 = document.getElementById('lease6_status_table');
290 if (ls6 && info.leases6)
292 ls6.parentNode.style.display = 'block';
295 while( ls6.rows.length > 1 )
296 ls6.rows[0].parentNode.deleteRow(1);
298 for( var i = 0; i < info.leases6.length; i++ )
302 if (info.leases6[i].expires <= 0)
303 timestr = '<em><%:expired%></em>';
305 timestr = String.format('%t', info.leases6[i].expires);
307 var tr = ls6.rows[0].parentNode.insertRow(-1);
308 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
310 tr.insertCell(-1).innerHTML = info.leases6[i].hostname ? info.leases6[i].hostname : '?';
311 tr.insertCell(-1).innerHTML = info.leases6[i].ip6addr;
312 tr.insertCell(-1).innerHTML = info.leases6[i].duid;
313 tr.insertCell(-1).innerHTML = timestr;
316 if( ls6.rows.length == 1 )
318 var tr = ls6.rows[0].parentNode.insertRow(-1);
319 tr.className = 'cbi-section-table-row';
321 var td = tr.insertCell(-1);
323 td.innerHTML = '<em><br /><%:There are no active leases.%></em>';
328 <% if has_wifi then %>
331 var ws = document.getElementById('wifi_status_table');
334 var wsbody = ws.rows[0].parentNode;
335 while (ws.rows.length > 0)
338 for (var didx = 0; didx < info.wifinets.length; didx++)
340 var dev = info.wifinets[didx];
342 var tr = wsbody.insertRow(-1);
345 td = tr.insertCell(-1);
347 td.innerHTML = dev.name;
348 td.style.verticalAlign = "top";
350 td = tr.insertCell(-1);
354 for (var nidx = 0; nidx < dev.networks.length; nidx++)
356 var net = dev.networks[nidx];
357 var is_assoc = (net.bssid != '00:00:00:00:00:00' && net.channel && !net.disabled);
361 icon = "<%=resource%>/icons/signal-none.png";
362 else if (net.quality == 0)
363 icon = "<%=resource%>/icons/signal-0.png";
364 else if (net.quality < 25)
365 icon = "<%=resource%>/icons/signal-0-25.png";
366 else if (net.quality < 50)
367 icon = "<%=resource%>/icons/signal-25-50.png";
368 else if (net.quality < 75)
369 icon = "<%=resource%>/icons/signal-50-75.png";
371 icon = "<%=resource%>/icons/signal-75-100.png";
374 '<table><tr><td style="text-align:center; width:32px; padding:3px">' +
375 '<img src="%s" title="<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" />' +
376 '<br /><small>%d%%</small>' +
377 '</td><td style="text-align:left; padding:3px"><small>' +
378 '<strong><%:SSID%>:</strong> <a href="%s">%h</a><br />' +
379 '<strong><%:Mode%>:</strong> %s<br />' +
380 '<strong><%:Channel%>:</strong> %d (%.3f <%:GHz%>)<br />' +
381 '<strong><%:Bitrate%>:</strong> %s <%:Mbit/s%><br />',
382 icon, net.signal, net.noise,
386 net.channel, net.frequency,
393 '<strong><%:BSSID%>:</strong> %s<br />' +
394 '<strong><%:Encryption%>:</strong> %s',
401 s += '<em><%:Wireless is disabled or not associated%></em>';
404 s += '</small></td></tr></table>';
406 for (var bssid in net.assoclist)
410 signal: net.assoclist[bssid].signal,
411 noise: net.assoclist[bssid].noise,
412 rx_rate: net.assoclist[bssid].rx_rate,
413 rx_mcs: net.assoclist[bssid].rx_mcs,
414 rx_40mhz: net.assoclist[bssid].rx_40mhz,
415 tx_rate: net.assoclist[bssid].tx_rate,
416 tx_mcs: net.assoclist[bssid].tx_mcs,
417 tx_40mhz: net.assoclist[bssid].tx_40mhz,
425 s = '<em><%:No information available%></em>';
431 var ac = document.getElementById('wifi_assoc_table');
435 while( ac.rows.length > 1 )
436 ac.rows[0].parentNode.deleteRow(1);
438 assoclist.sort(function(a, b) {
439 return (a.name == b.name)
440 ? (a.bssid < b.bssid)
445 for( var i = 0; i < assoclist.length; i++ )
447 var tr = ac.rows[0].parentNode.insertRow(-1);
448 tr.className = 'cbi-section-table-row cbi-rowstyle-' + (1 + (i % 2));
451 var q = (-1 * (assoclist[i].noise - assoclist[i].signal)) / 5;
453 icon = "<%=resource%>/icons/signal-0.png";
455 icon = "<%=resource%>/icons/signal-0-25.png";
457 icon = "<%=resource%>/icons/signal-25-50.png";
459 icon = "<%=resource%>/icons/signal-50-75.png";
461 icon = "<%=resource%>/icons/signal-75-100.png";
463 tr.insertCell(-1).innerHTML = String.format(
464 '<img src="%s" title="<%:Signal%>: %d <%:dBm%> / <%:Noise%>: %d <%:dBm%>" />',
465 icon, assoclist[i].signal, assoclist[i].noise
468 tr.insertCell(-1).innerHTML = assoclist[i].bssid;
470 tr.insertCell(-1).innerHTML = String.format(
471 '<a href="%s">%s</a>',
473 '%h'.format(assoclist[i].name).nobr()
476 tr.insertCell(-1).innerHTML = String.format('%d <%:dBm%>', assoclist[i].signal).nobr();
477 tr.insertCell(-1).innerHTML = String.format('%d <%:dBm%>', assoclist[i].noise).nobr();
479 tr.insertCell(-1).innerHTML = (assoclist[i].rx_mcs > -1)
480 ? String.format('%.1f <%:Mbit/s%>, MCS %d, %d<%:MHz%>', assoclist[i].rx_rate / 1000, assoclist[i].rx_mcs, assoclist[i].rx_40mhz ? 40 : 20).nobr()
481 : String.format('%.1f <%:Mbit/s%>', assoclist[i].rx_rate / 1000).nobr()
484 tr.insertCell(-1).innerHTML = (assoclist[i].tx_mcs > -1)
485 ? String.format('%.1f <%:Mbit/s%>, MCS %d, %d<%:MHz%>', assoclist[i].tx_rate / 1000, assoclist[i].tx_mcs, assoclist[i].tx_40mhz ? 40 : 20).nobr()
486 : String.format('%.1f <%:Mbit/s%>', assoclist[i].tx_rate / 1000).nobr()
490 if (ac.rows.length == 1)
492 var tr = ac.rows[0].parentNode.insertRow(-1);
493 tr.className = 'cbi-section-table-row';
495 var td = tr.insertCell(-1);
497 td.innerHTML = '<br /><em><%:No information available%></em>';
504 if (e = document.getElementById('localtime'))
505 e.innerHTML = info.localtime;
507 if (e = document.getElementById('uptime'))
508 e.innerHTML = String.format('%t', info.uptime);
510 if (e = document.getElementById('loadavg'))
511 e.innerHTML = String.format(
512 '%.02f, %.02f, %.02f',
513 info.loadavg[0] / 65535.0,
514 info.loadavg[1] / 65535.0,
515 info.loadavg[2] / 65535.0
518 if (e = document.getElementById('memtotal'))
519 e.innerHTML = progressbar(
520 ((info.memory.free + info.memory.buffered) / 1024) + " <%:kB%>",
521 (info.memory.total / 1024) + " <%:kB%>"
524 if (e = document.getElementById('memfree'))
525 e.innerHTML = progressbar(
526 (info.memory.free / 1024) + " <%:kB%>",
527 (info.memory.total / 1024) + " <%:kB%>"
530 if (e = document.getElementById('membuff'))
531 e.innerHTML = progressbar(
532 (info.memory.buffered / 1024) + " <%:kB%>",
533 (info.memory.total / 1024) + " <%:kB%>"
536 if (e = document.getElementById('swaptotal'))
537 e.innerHTML = progressbar(
538 (info.swap.free / 1024) + " <%:kB%>",
539 (info.swap.total / 1024) + " <%:kB%>"
542 if (e = document.getElementById('swapfree'))
543 e.innerHTML = progressbar(
544 (info.swap.free / 1024) + " <%:kB%>",
545 (info.swap.total / 1024) + " <%:kB%>"
548 if (e = document.getElementById('conns'))
549 e.innerHTML = progressbar(info.conncount, info.connmax);
555 <h2><a id="content" name="content"><%:Status%></a></h2>
557 <fieldset class="cbi-section">
558 <legend><%:System%></legend>
560 <table width="100%" cellspacing="10">
561 <tr><td width="33%"><%:Hostname%></td><td><%=luci.sys.hostname() or "?"%></td></tr>
562 <tr><td width="33%"><%:Model%></td><td><%=pcdata(boardinfo.model or boardinfo.system or "?")%></td></tr>
563 <tr><td width="33%"><%:Firmware Version%></td><td>
564 <%=pcdata(ver.distname)%> <%=pcdata(ver.distversion)%> /
565 <%=pcdata(ver.luciname)%> (<%=pcdata(ver.luciversion)%>)
567 <tr><td width="33%"><%:Kernel Version%></td><td><%=unameinfo.release or "?"%></td></tr>
568 <tr><td width="33%"><%:Local Time%></td><td id="localtime">-</td></tr>
569 <tr><td width="33%"><%:Uptime%></td><td id="uptime">-</td></tr>
570 <tr><td width="33%"><%:Load Average%></td><td id="loadavg">-</td></tr>
574 <fieldset class="cbi-section">
575 <legend><%:Memory%></legend>
577 <table width="100%" cellspacing="10">
578 <tr><td width="33%"><%:Total Available%></td><td id="memtotal">-</td></tr>
579 <tr><td width="33%"><%:Free%></td><td id="memfree">-</td></tr>
580 <tr><td width="33%"><%:Buffered%></td><td id="membuff">-</td></tr>
584 <% if swapinfo.total > 0 then %>
585 <fieldset class="cbi-section">
586 <legend><%:Swap%></legend>
588 <table width="100%" cellspacing="10">
589 <tr><td width="33%"><%:Total Available%></td><td id="swaptotal">-</td></tr>
590 <tr><td width="33%"><%:Free%></td><td id="swapfree">-</td></tr>
595 <fieldset class="cbi-section">
596 <legend><%:Network%></legend>
598 <table width="100%" cellspacing="10">
599 <tr><td width="33%" style="vertical-align:top"><%:IPv4 WAN Status%></td><td>
601 <td id="wan4_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td>
602 <td id="wan4_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></td>
605 <% if has_ipv6 then %>
606 <tr><td width="33%" style="vertical-align:top"><%:IPv6 WAN Status%></td><td>
608 <td id="wan6_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td>
609 <td id="wan6_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></td>
613 <tr><td width="33%"><%:Active Connections%></td><td id="conns">-</td></tr>
617 <% if has_dhcp then %>
618 <fieldset class="cbi-section">
619 <legend><%:DHCP Leases%></legend>
621 <table class="cbi-section-table" id="lease_status_table">
622 <tr class="cbi-section-table-titles">
623 <th class="cbi-section-table-cell"><%:Hostname%></th>
624 <th class="cbi-section-table-cell"><%:IPv4-Address%></th>
625 <th class="cbi-section-table-cell"><%:MAC-Address%></th>
626 <th class="cbi-section-table-cell"><%:Leasetime remaining%></th>
628 <tr class="cbi-section-table-row">
629 <td colspan="4"><em><br /><%:Collecting data...%></em></td>
634 <fieldset class="cbi-section" style="display:none">
635 <legend><%:DHCPv6 Leases%></legend>
637 <table class="cbi-section-table" id="lease6_status_table">
638 <tr class="cbi-section-table-titles">
639 <th class="cbi-section-table-cell"><%:Hostname%></th>
640 <th class="cbi-section-table-cell"><%:IPv6-Address%></th>
641 <th class="cbi-section-table-cell"><%:DUID%></th>
642 <th class="cbi-section-table-cell"><%:Leasetime remaining%></th>
644 <tr class="cbi-section-table-row">
645 <td colspan="4"><em><br /><%:Collecting data...%></em></td>
651 <% if has_dsl then %>
652 <fieldset class="cbi-section">
653 <legend><%:ADSL%></legend>
654 <table width="100%" cellspacing="10">
655 <tr><td width="33%" style="vertical-align:top"><%:ADSL Status%></td><td>
657 <td id="dsl_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td>
658 <td id="dsl_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></td>
665 <% if has_wifi then %>
666 <fieldset class="cbi-section">
667 <legend><%:Wireless%></legend>
669 <table id="wifi_status_table" width="100%" cellspacing="10">
670 <tr><td><em><%:Collecting data...%></em></td></tr>
674 <fieldset class="cbi-section">
675 <legend><%:Associated Stations%></legend>
677 <table class="cbi-section-table" id="wifi_assoc_table">
678 <tr class="cbi-section-table-titles">
679 <th class="cbi-section-table-cell"> </th>
680 <th class="cbi-section-table-cell"><%:MAC-Address%></th>
681 <th class="cbi-section-table-cell"><%:Network%></th>
682 <th class="cbi-section-table-cell"><%:Signal%></th>
683 <th class="cbi-section-table-cell"><%:Noise%></th>
684 <th class="cbi-section-table-cell"><%:RX Rate%></th>
685 <th class="cbi-section-table-cell"><%:TX Rate%></th>
687 <tr class="cbi-section-table-row">
688 <td colspan="7"><em><br /><%:Collecting data...%></em></td>
695 local incdir = util.libpath() .. "/view/admin_status/index/"
696 if fs.access(incdir) then
698 for inc in fs.dir(incdir) do
699 if inc:match("%.htm$") then
700 include("admin_status/index/" .. inc:gsub("%.htm$", ""))