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)
94 luci.http.prepare_content(
"application/json")
95 luci.http.write_json(rv)
103 <script type=
"text/javascript" src=
"<%=resource%>/cbi.js"></script>
104 <script type=
"text/javascript">//<![CDATA[
105 function progressbar(v, m)
107 var vn = parseInt(v) ||
0;
108 var mn = parseInt(m) ||
100;
109 var pc = Math.floor((
100 / mn) * vn);
111 return String.format(
112 '
<div style=
"width:200px; position:relative; border:1px solid #999999">' +
113 '
<div style=
"background-color:#CCCCCC; width:%d%%; height:15px">' +
114 '
<div style=
"position:absolute; left:0; top:0; text-align:center; width:100%%; color:#000000">' +
115 '
<small>%s / %s (%d%%)
</small>' +
118 '
</div>', pc, v, m, pc
122 var wifidevs = <%=luci.http.write_json(netdevs)%
>;
123 var arptable = <%=luci.http.write_json(arpcache)%
>;
125 XHR.poll(
5, '<%=REQUEST_URI%
>', { status:
1 },
128 var si = document.getElementById('wan4_i');
129 var ss = document.getElementById('wan4_s');
132 if (ifc && ifc.ifname && ifc.proto != 'none')
134 var s = String.format(
135 '
<strong><%:Type%
>:
</strong>%s
<br />' +
136 '
<strong><%:Address%
>:
</strong>%s
<br />' +
137 '
<strong><%:Netmask%
>:
</strong>%s
<br />' +
138 '
<strong><%:Gateway%
>:
</strong>%s
<br />',
140 (ifc.ipaddr) ? ifc.ipaddr : '
0.0.0.0',
141 (ifc.netmask && ifc.netmask != ifc.ipaddr) ? ifc.netmask : '
255.255.255.255',
142 (ifc.gwaddr) ? ifc.gwaddr : '
0.0.0.0'
145 for (var i =
0; i < ifc.dns.length; i++)
148 '
<strong><%:DNS%
> %d:
</strong>%s
<br />',
153 if (ifc.expires
> -
1)
156 '
<strong><%:Expires%
>:
</strong>%t
<br />',
164 '
<strong><%:Connected%
>:
</strong>%t
<br />',
169 ss.innerHTML = String.format('
<small>%s
</small>', s);
170 si.innerHTML = String.format(
171 '
<img src=
"<%=resource%>/icons/ethernet.png" />' +
172 '
<br /><small><a href=
"%s">%s
</a></small>',
178 si.innerHTML = '
<img src=
"<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?
</small>';
179 ss.innerHTML = '
<em><%:Not connected%
></em>';
182 <% if has_ipv6 then %
>
183 var si6 = document.getElementById('wan6_i');
184 var ss6 = document.getElementById('wan6_s');
185 var ifc6 = info.wan6;
187 if (ifc6 && ifc6.ifname && ifc6.proto != 'none')
189 var s = String.format(
190 '
<strong><%:Address%
>:
</strong>%s
<br />' +
191 '
<strong><%:Gateway%
>:
</strong>%s
<br />',
192 (ifc6.ip6addr) ? ifc6.ip6addr : '::',
193 (ifc6.gw6addr) ? ifc6.gw6addr : '::'
196 for (var i =
0; i < ifc6.dns.length; i++)
199 '
<strong><%:DNS%
> %d:
</strong>%s
<br />',
207 '
<strong><%:Connected%
>:
</strong>%t
<br />',
212 ss6.innerHTML = String.format('
<small>%s
</small>', s);
213 si6.innerHTML = String.format(
214 '
<img src=
"<%=resource%>/icons/ethernet.png" />' +
215 '
<br /><small><a href=
"%s">%s
</a></small>',
216 ifc6.link, ifc6.ifname
221 si6.innerHTML = '
<img src=
"<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?
</small>';
222 ss6.innerHTML = '
<em><%:Not connected%
></em>';
226 <% if has_dsl then %
>
227 var dsl_i = document.getElementById('dsl_i');
228 var dsl_s = document.getElementById('dsl_s');
230 var s = String.format(
231 '
<strong><%:Status%
>:
</strong>%s
<br />' +
232 '
<strong><%:Line State%
>:
</strong>%s [
0x%x]
<br />' +
233 '
<strong><%:Line Speed%
>:
</strong>%s/s / %s/s
<br />' +
234 '
<strong><%:Line Attenuation%
>:
</strong>%s dB / %s dB
<br />' +
235 '
<strong><%:Noise Margin%
>:
</strong>%s dB / %s dB
<br />',
236 info.dsl.line_state, info.dsl.line_state_detail,
237 info.dsl.line_state_num,
238 info.dsl.data_rate_down_s, info.dsl.data_rate_up_s,
239 info.dsl.line_attenuation_down, info.dsl.line_attenuation_up,
240 info.dsl.noise_margin_down, info.dsl.noise_margin_up
243 dsl_s.innerHTML = String.format('
<small>%s
</small>', s);
244 dsl_i.innerHTML = String.format(
245 '
<img src=
"<%=resource%>/icons/ethernet.png" />' +
246 '
<br /><small>ADSL
</small>'
250 <% if has_dhcp then %
>
251 var ls = document.getElementById('lease_status_table');
255 while( ls.rows.length
> 1 )
256 ls.rows[
0].parentNode.deleteRow(
1);
258 for( var i =
0; i < info.leases.length; i++ )
262 if (info.leases[i].expires <=
0)
263 timestr = '
<em><%:expired%
></em>';
265 timestr = String.format('%t', info.leases[i].expires);
267 var tr = ls.rows[
0].parentNode.insertRow(-
1);
268 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i %
2) +
1);
270 tr.insertCell(-
1).innerHTML = info.leases[i].hostname ? info.leases[i].hostname : '?';
271 tr.insertCell(-
1).innerHTML = info.leases[i].ipaddr;
272 tr.insertCell(-
1).innerHTML = info.leases[i].macaddr;
273 tr.insertCell(-
1).innerHTML = timestr;
276 if( ls.rows.length ==
1 )
278 var tr = ls.rows[
0].parentNode.insertRow(-
1);
279 tr.className = 'cbi-section-table-row';
281 var td = tr.insertCell(-
1);
283 td.innerHTML = '
<em><br /><%:There are no active leases.%
></em>';
287 var ls6 = document.getElementById('lease6_status_table');
288 if (ls6 && info.leases6)
290 ls6.parentNode.style.display = 'block';
293 while( ls6.rows.length
> 1 )
294 ls6.rows[
0].parentNode.deleteRow(
1);
296 for( var i =
0; i < info.leases6.length; i++ )
300 if (info.leases6[i].expires <=
0)
301 timestr = '
<em><%:expired%
></em>';
303 timestr = String.format('%t', info.leases6[i].expires);
305 var tr = ls6.rows[
0].parentNode.insertRow(-
1);
306 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i %
2) +
1);
308 tr.insertCell(-
1).innerHTML = info.leases6[i].hostname ? info.leases6[i].hostname : '?';
309 tr.insertCell(-
1).innerHTML = info.leases6[i].ip6addr;
310 tr.insertCell(-
1).innerHTML = info.leases6[i].duid;
311 tr.insertCell(-
1).innerHTML = timestr;
314 if( ls6.rows.length ==
1 )
316 var tr = ls6.rows[
0].parentNode.insertRow(-
1);
317 tr.className = 'cbi-section-table-row';
319 var td = tr.insertCell(-
1);
321 td.innerHTML = '
<em><br /><%:There are no active leases.%
></em>';
326 <% if has_wifi then %
>
329 var ws = document.getElementById('wifi_status_table');
332 var wsbody = ws.rows[
0].parentNode;
333 while (ws.rows.length
> 0)
336 for (var didx =
0; didx < info.wifinets.length; didx++)
338 var dev = info.wifinets[didx];
340 var tr = wsbody.insertRow(-
1);
343 td = tr.insertCell(-
1);
345 td.innerHTML = dev.name;
346 td.style.verticalAlign =
"top";
348 td = tr.insertCell(-
1);
352 for (var nidx =
0; nidx < dev.networks.length; nidx++)
354 var net = dev.networks[nidx];
355 var is_assoc = (net.bssid != '
00:
00:
00:
00:
00:
00' && net.channel && !net.disabled);
359 icon =
"<%=resource%>/icons/signal-none.png";
360 else if (net.quality ==
0)
361 icon =
"<%=resource%>/icons/signal-0.png";
362 else if (net.quality <
25)
363 icon =
"<%=resource%>/icons/signal-0-25.png";
364 else if (net.quality <
50)
365 icon =
"<%=resource%>/icons/signal-25-50.png";
366 else if (net.quality <
75)
367 icon =
"<%=resource%>/icons/signal-50-75.png";
369 icon =
"<%=resource%>/icons/signal-75-100.png";
372 '
<table><tr><td style=
"text-align:center; width:32px; padding:3px">' +
373 '
<img src=
"%s" title=
"<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" />' +
374 '
<br /><small>%d%%
</small>' +
375 '
</td><td style=
"text-align:left; padding:3px"><small>' +
376 '
<strong><%:SSID%
>:
</strong> <a href=
"%s">%h
</a><br />' +
377 '
<strong><%:Mode%
>:
</strong> %s
<br />' +
378 '
<strong><%:Channel%
>:
</strong> %d (%
.3f <%:GHz%
>)
<br />' +
379 '
<strong><%:Bitrate%
>:
</strong> %s <%:Mbit/s%
><br />',
380 icon, net.signal, net.noise,
384 net.channel, net.frequency,
391 '
<strong><%:BSSID%
>:
</strong> %s
<br />' +
392 '
<strong><%:Encryption%
>:
</strong> %s',
399 s += '
<em><%:Wireless is disabled or not associated%
></em>';
402 s += '
</small></td></tr></table>';
404 for (var bssid in net.assoclist)
408 signal: net.assoclist[bssid].signal,
409 noise: net.assoclist[bssid].noise,
410 rx_rate: net.assoclist[bssid].rx_rate,
411 rx_mcs: net.assoclist[bssid].rx_mcs,
412 rx_40mhz: net.assoclist[bssid].rx_40mhz,
413 tx_rate: net.assoclist[bssid].tx_rate,
414 tx_mcs: net.assoclist[bssid].tx_mcs,
415 tx_40mhz: net.assoclist[bssid].tx_40mhz,
423 s = '
<em><%:No information available%
></em>';
429 var ac = document.getElementById('wifi_assoc_table');
433 while( ac.rows.length
> 1 )
434 ac.rows[
0].parentNode.deleteRow(
1);
436 assoclist.sort(function(a, b) {
437 return (a.name == b.name)
438 ? (a.bssid < b.bssid)
443 for( var i =
0; i < assoclist.length; i++ )
445 var tr = ac.rows[
0].parentNode.insertRow(-
1);
446 tr.className = 'cbi-section-table-row cbi-rowstyle-' + (
1 + (i %
2));
449 var q = (-
1 * (assoclist[i].noise - assoclist[i].signal)) /
5;
451 icon =
"<%=resource%>/icons/signal-0.png";
453 icon =
"<%=resource%>/icons/signal-0-25.png";
455 icon =
"<%=resource%>/icons/signal-25-50.png";
457 icon =
"<%=resource%>/icons/signal-50-75.png";
459 icon =
"<%=resource%>/icons/signal-75-100.png";
461 tr.insertCell(-
1).innerHTML = String.format(
462 '
<img src=
"%s" title=
"<%:Signal%>: %d <%:dBm%> / <%:Noise%>: %d <%:dBm%>" />',
463 icon, assoclist[i].signal, assoclist[i].noise
466 tr.insertCell(-
1).innerHTML = assoclist[i].bssid;
468 tr.insertCell(-
1).innerHTML = String.format(
469 '
<a href=
"%s">%s
</a>',
471 '%h'.format(assoclist[i].name).nobr()
474 tr.insertCell(-
1).innerHTML = String.format('%d <%:dBm%
>', assoclist[i].signal).nobr();
475 tr.insertCell(-
1).innerHTML = String.format('%d <%:dBm%
>', assoclist[i].noise).nobr();
477 tr.insertCell(-
1).innerHTML = (assoclist[i].rx_mcs
> -
1)
478 ? 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()
479 : String.format('%
.1f <%:Mbit/s%
>', assoclist[i].rx_rate /
1000).nobr()
482 tr.insertCell(-
1).innerHTML = (assoclist[i].tx_mcs
> -
1)
483 ? 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()
484 : String.format('%
.1f <%:Mbit/s%
>', assoclist[i].tx_rate /
1000).nobr()
488 if (ac.rows.length ==
1)
490 var tr = ac.rows[
0].parentNode.insertRow(-
1);
491 tr.className = 'cbi-section-table-row';
493 var td = tr.insertCell(-
1);
495 td.innerHTML = '
<br /><em><%:No information available%
></em>';
502 if (e = document.getElementById('localtime'))
503 e.innerHTML = info.localtime;
505 if (e = document.getElementById('uptime'))
506 e.innerHTML = String.format('%t', info.uptime);
508 if (e = document.getElementById('loadavg'))
509 e.innerHTML = String.format(
510 '%
.02f, %
.02f, %
.02f',
511 info.loadavg[
0] /
65535.0,
512 info.loadavg[
1] /
65535.0,
513 info.loadavg[
2] /
65535.0
516 if (e = document.getElementById('memtotal'))
517 e.innerHTML = progressbar(
518 ((info.memory.free + info.memory.buffered) /
1024) +
" <%:kB%>",
519 (info.memory.total /
1024) +
" <%:kB%>"
522 if (e = document.getElementById('memfree'))
523 e.innerHTML = progressbar(
524 (info.memory.free /
1024) +
" <%:kB%>",
525 (info.memory.total /
1024) +
" <%:kB%>"
528 if (e = document.getElementById('membuff'))
529 e.innerHTML = progressbar(
530 (info.memory.buffered /
1024) +
" <%:kB%>",
531 (info.memory.total /
1024) +
" <%:kB%>"
534 if (e = document.getElementById('swaptotal'))
535 e.innerHTML = progressbar(
536 (info.swap.free /
1024) +
" <%:kB%>",
537 (info.swap.total /
1024) +
" <%:kB%>"
540 if (e = document.getElementById('swapfree'))
541 e.innerHTML = progressbar(
542 (info.swap.free /
1024) +
" <%:kB%>",
543 (info.swap.total /
1024) +
" <%:kB%>"
546 if (e = document.getElementById('conns'))
547 e.innerHTML = progressbar(info.conncount, info.connmax);
553 <h2><a id=
"content" name=
"content"><%:Status%
></a></h2>
555 <fieldset class=
"cbi-section">
556 <legend><%:System%
></legend>
558 <table width=
"100%" cellspacing=
"10">
559 <tr><td width=
"33%"><%:Hostname%
></td><td><%=luci.sys.hostname() or
"?"%
></td></tr>
560 <tr><td width=
"33%"><%:Model%
></td><td><%=pcdata(boardinfo.model or boardinfo.system or
"?")%
></td></tr>
561 <tr><td width=
"33%"><%:Firmware Version%
></td><td>
562 <%=pcdata(ver.distname)%
> <%=pcdata(ver.distversion)%
> /
563 <%=pcdata(ver.luciname)%
> (<%=pcdata(ver.luciversion)%
>)
565 <tr><td width=
"33%"><%:Kernel Version%
></td><td><%=unameinfo.release or
"?"%
></td></tr>
566 <tr><td width=
"33%"><%:Local Time%
></td><td id=
"localtime">-
</td></tr>
567 <tr><td width=
"33%"><%:Uptime%
></td><td id=
"uptime">-
</td></tr>
568 <tr><td width=
"33%"><%:Load Average%
></td><td id=
"loadavg">-
</td></tr>
572 <fieldset class=
"cbi-section">
573 <legend><%:Memory%
></legend>
575 <table width=
"100%" cellspacing=
"10">
576 <tr><td width=
"33%"><%:Total Available%
></td><td id=
"memtotal">-
</td></tr>
577 <tr><td width=
"33%"><%:Free%
></td><td id=
"memfree">-
</td></tr>
578 <tr><td width=
"33%"><%:Buffered%
></td><td id=
"membuff">-
</td></tr>
582 <% if swapinfo.total
> 0 then %
>
583 <fieldset class=
"cbi-section">
584 <legend><%:Swap%
></legend>
586 <table width=
"100%" cellspacing=
"10">
587 <tr><td width=
"33%"><%:Total Available%
></td><td id=
"swaptotal">-
</td></tr>
588 <tr><td width=
"33%"><%:Free%
></td><td id=
"swapfree">-
</td></tr>
593 <fieldset class=
"cbi-section">
594 <legend><%:Network%
></legend>
596 <table width=
"100%" cellspacing=
"10">
597 <tr><td width=
"33%" style=
"vertical-align:top"><%:IPv4 WAN Status%
></td><td>
599 <td id=
"wan4_i" style=
"width:16px; text-align:center; padding:3px"><img src=
"<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?
</small></td>
600 <td id=
"wan4_s" style=
"vertical-align:middle; padding: 3px"><em><%:Collecting data...%
></em></td>
603 <% if has_ipv6 then %
>
604 <tr><td width=
"33%" style=
"vertical-align:top"><%:IPv6 WAN Status%
></td><td>
606 <td id=
"wan6_i" style=
"width:16px; text-align:center; padding:3px"><img src=
"<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?
</small></td>
607 <td id=
"wan6_s" style=
"vertical-align:middle; padding: 3px"><em><%:Collecting data...%
></em></td>
611 <tr><td width=
"33%"><%:Active Connections%
></td><td id=
"conns">-
</td></tr>
615 <% if has_dhcp then %
>
616 <fieldset class=
"cbi-section">
617 <legend><%:DHCP Leases%
></legend>
619 <table class=
"cbi-section-table" id=
"lease_status_table">
620 <tr class=
"cbi-section-table-titles">
621 <th class=
"cbi-section-table-cell"><%:Hostname%
></th>
622 <th class=
"cbi-section-table-cell"><%:IPv4-Address%
></th>
623 <th class=
"cbi-section-table-cell"><%:MAC-Address%
></th>
624 <th class=
"cbi-section-table-cell"><%:Leasetime remaining%
></th>
626 <tr class=
"cbi-section-table-row">
627 <td colspan=
"4"><em><br /><%:Collecting data...%
></em></td>
632 <fieldset class=
"cbi-section" style=
"display:none">
633 <legend><%:DHCPv6 Leases%
></legend>
635 <table class=
"cbi-section-table" id=
"lease6_status_table">
636 <tr class=
"cbi-section-table-titles">
637 <th class=
"cbi-section-table-cell"><%:Hostname%
></th>
638 <th class=
"cbi-section-table-cell"><%:IPv6-Address%
></th>
639 <th class=
"cbi-section-table-cell"><%:DUID%
></th>
640 <th class=
"cbi-section-table-cell"><%:Leasetime remaining%
></th>
642 <tr class=
"cbi-section-table-row">
643 <td colspan=
"4"><em><br /><%:Collecting data...%
></em></td>
649 <% if has_dsl then %
>
650 <fieldset class=
"cbi-section">
651 <legend><%:ADSL%
></legend>
652 <table width=
"100%" cellspacing=
"10">
653 <tr><td width=
"33%" style=
"vertical-align:top"><%:ADSL Status%
></td><td>
655 <td id=
"dsl_i" style=
"width:16px; text-align:center; padding:3px"><img src=
"<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?
</small></td>
656 <td id=
"dsl_s" style=
"vertical-align:middle; padding: 3px"><em><%:Collecting data...%
></em></td>
663 <% if has_wifi then %
>
664 <fieldset class=
"cbi-section">
665 <legend><%:Wireless%
></legend>
667 <table id=
"wifi_status_table" width=
"100%" cellspacing=
"10">
668 <tr><td><em><%:Collecting data...%
></em></td></tr>
672 <fieldset class=
"cbi-section">
673 <legend><%:Associated Stations%
></legend>
675 <table class=
"cbi-section-table" id=
"wifi_assoc_table">
676 <tr class=
"cbi-section-table-titles">
677 <th class=
"cbi-section-table-cell"> </th>
678 <th class=
"cbi-section-table-cell"><%:MAC-Address%
></th>
679 <th class=
"cbi-section-table-cell"><%:Network%
></th>
680 <th class=
"cbi-section-table-cell"><%:Signal%
></th>
681 <th class=
"cbi-section-table-cell"><%:Noise%
></th>
682 <th class=
"cbi-section-table-cell"><%:RX Rate%
></th>
683 <th class=
"cbi-section-table-cell"><%:TX Rate%
></th>
685 <tr class=
"cbi-section-table-row">
686 <td colspan=
"7"><em><br /><%:Collecting data...%
></em></td>
693 local incdir = util.libpath() ..
"/view/admin_status/index/"
694 if fs.access(incdir) then
696 for inc in fs.dir(incdir) do
697 if inc:match(
"%.htm$") then
698 include(
"admin_status/index/" .. inc:gsub(
"%.htm$",
""))