2 LuCI - Lua Configuration Interface
3 Copyright
2008 Steven Barth
<steven@midlink.org
>
4 Copyright
2008-
2011 Jo-Philipp Wich
<xm@subsignal.org
>
6 Licensed under the Apache License, Version
2.0 (the
"License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-
2.0
18 require
"luci.tools.status"
20 local has_ipv6 = luci.fs.access(
"/proc/net/ipv6_route")
21 local has_dhcp = luci.fs.access(
"/etc/config/dhcp")
22 local has_wifi = luci.fs.stat(
"/etc/config/wireless")
23 has_wifi = has_wifi and has_wifi.size
> 0
25 if luci.http.formvalue(
"status") ==
"1" then
26 local ntm = require
"luci.model.network".init()
27 local wan = ntm:get_wannet()
28 local wan6 = ntm:get_wan6net()
30 local _, _, memtotal, memcached, membuffers, memfree = luci.sys.sysinfo()
32 local conn_count = tonumber((
33 luci.sys.exec(
"wc -l /proc/net/nf_conntrack") or
34 luci.sys.exec(
"wc -l /proc/net/ip_conntrack") or
35 ""):match(
"%d+")) or
0
37 local conn_max = tonumber((
38 luci.sys.exec(
"sysctl net.nf_conntrack_max") or
39 luci.sys.exec(
"sysctl net.ipv4.netfilter.ip_conntrack_max") or
40 ""):match(
"%d+")) or
4096
43 uptime = luci.sys.uptime(),
44 localtime = os.date(),
45 loadavg = { luci.sys.loadavg() },
47 memcached = memcached,
48 membuffers = membuffers,
51 conncount = conn_count,
52 leases = luci.tools.status.dhcp_leases(),
53 wifinets = luci.tools.status.wifi_networks()
58 ipaddr = wan:ipaddr(),
59 gwaddr = wan:gwaddr(),
60 netmask = wan:netmask(),
62 expires = wan:expires(),
63 uptime = wan:uptime(),
65 ifname = wan:ifname(),
66 link = wan:adminlink()
72 ip6addr = wan6:ip6addr(),
73 gw6addr = wan6:gw6addr(),
74 dns = wan6:dns6addrs(),
75 uptime = wan6:uptime(),
76 ifname = wan6:ifname(),
77 link = wan6:adminlink()
81 luci.http.prepare_content(
"application/json")
82 luci.http.write_json(rv)
87 local system, model = luci.sys.sysinfo()
92 <script type=
"text/javascript" src=
"<%=resource%>/cbi.js"></script>
93 <script type=
"text/javascript">//<![CDATA[
94 function progressbar(v, m)
96 var vn = parseInt(v) ||
0;
97 var mn = parseInt(m) ||
100;
98 var pc = Math.floor((
100 / mn) * vn);
100 return String.format(
101 '
<div style=
"width:200px; position:relative; border:1px solid #999999">' +
102 '
<div style=
"background-color:#CCCCCC; width:%d%%; height:15px">' +
103 '
<div style=
"position:absolute; left:0; top:0; text-align:center; width:100%%; color:#000000">' +
104 '
<small>%s / %s (%d%%)
</small>' +
107 '
</div>', pc, v, m, pc
111 var wifidevs = <%=luci.http.write_json(netdevs)%
>;
112 var arptable = <%=luci.http.write_json(arpcache)%
>;
114 XHR.poll(
5, '<%=REQUEST_URI%
>', { status:
1 },
117 var si = document.getElementById('wan4_i');
118 var ss = document.getElementById('wan4_s');
121 if (ifc && ifc.ifname && ifc.proto != 'none')
123 var s = String.format(
124 '
<strong><%:Type%
>:
</strong>%s
<br />' +
125 '
<strong><%:Address%
>:
</strong>%s
<br />' +
126 '
<strong><%:Netmask%
>:
</strong>%s
<br />' +
127 '
<strong><%:Gateway%
>:
</strong>%s
<br />',
129 (ifc.ipaddr) ? ifc.ipaddr : '
0.0.0.0',
130 (ifc.netmask && ifc.netmask != ifc.ipaddr) ? ifc.netmask : '
255.255.255.255',
131 (ifc.gwaddr) ? ifc.gwaddr : '
0.0.0.0'
134 for (var i =
0; i < ifc.dns.length; i++)
137 '
<strong><%:DNS%
> %d:
</strong>%s
<br />',
142 if (ifc.expires
> -
1)
145 '
<strong><%:Expires%
>:
</strong>%t
<br />',
153 '
<strong><%:Connected%
>:
</strong>%t
<br />',
158 ss.innerHTML = String.format('
<small>%s
</small>', s);
159 si.innerHTML = String.format(
160 '
<img src=
"<%=resource%>/icons/ethernet.png" />' +
161 '
<br /><small><a href=
"%s">%s
</a></small>',
167 si.innerHTML = '
<img src=
"<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?
</small>';
168 ss.innerHTML = '
<em><%:Not connected%
></em>';
171 <% if has_ipv6 then %
>
172 var si6 = document.getElementById('wan6_i');
173 var ss6 = document.getElementById('wan6_s');
174 var ifc6 = info.wan6;
176 if (ifc6 && ifc6.ifname && ifc6.proto != 'none')
178 var s = String.format(
179 '
<strong><%:Address%
>:
</strong>%s
<br />' +
180 '
<strong><%:Gateway%
>:
</strong>%s
<br />',
181 (ifc6.ip6addr) ? ifc6.ip6addr : '::',
182 (ifc6.gw6addr) ? ifc6.gw6addr : '::'
185 for (var i =
0; i < ifc6.dns.length; i++)
188 '
<strong><%:DNS%
> %d:
</strong>%s
<br />',
196 '
<strong><%:Connected%
>:
</strong>%t
<br />',
201 ss6.innerHTML = String.format('
<small>%s
</small>', s);
202 si6.innerHTML = String.format(
203 '
<img src=
"<%=resource%>/icons/ethernet.png" />' +
204 '
<br /><small><a href=
"%s">%s
</a></small>',
205 ifc6.link, ifc6.ifname
210 si6.innerHTML = '
<img src=
"<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?
</small>';
211 ss6.innerHTML = '
<em><%:Not connected%
></em>';
215 <% if has_dhcp then %
>
216 var ls = document.getElementById('lease_status_table');
220 while( ls.rows.length
> 1 )
221 ls.rows[
0].parentNode.deleteRow(
1);
223 for( var i =
0; i < info.leases.length; i++ )
227 if (info.leases[i].expires <=
0)
228 timestr = '
<em><%:expired%
></em>';
230 timestr = String.format('%t', info.leases[i].expires);
232 var tr = ls.rows[
0].parentNode.insertRow(-
1);
233 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i %
2) +
1);
235 tr.insertCell(-
1).innerHTML = info.leases[i].hostname ? info.leases[i].hostname : '?';
236 tr.insertCell(-
1).innerHTML = info.leases[i].ipaddr;
237 tr.insertCell(-
1).innerHTML = info.leases[i].macaddr;
238 tr.insertCell(-
1).innerHTML = timestr;
241 if( ls.rows.length ==
1 )
243 var tr = ls.rows[
0].parentNode.insertRow(-
1);
244 tr.className = 'cbi-section-table-row';
246 var td = tr.insertCell(-
1);
248 td.innerHTML = '
<em><br /><%:There are no active leases.%
></em>';
253 <% if has_wifi then %
>
256 var ws = document.getElementById('wifi_status_table');
259 var wsbody = ws.rows[
0].parentNode;
260 while (ws.rows.length
> 0)
263 for (var didx =
0; didx < info.wifinets.length; didx++)
265 var dev = info.wifinets[didx];
267 var tr = wsbody.insertRow(-
1);
270 td = tr.insertCell(-
1);
272 td.innerHTML = dev.name;
273 td.style.verticalAlign =
"top";
275 td = tr.insertCell(-
1);
279 for (var nidx =
0; nidx < dev.networks.length; nidx++)
281 var net = dev.networks[nidx];
282 var is_assoc = (net.bssid != '
00:
00:
00:
00:
00:
00' && net.channel);
286 icon =
"<%=resource%>/icons/signal-none.png";
287 else if (net.quality ==
0)
288 icon =
"<%=resource%>/icons/signal-0.png";
289 else if (net.quality <
25)
290 icon =
"<%=resource%>/icons/signal-0-25.png";
291 else if (net.quality <
50)
292 icon =
"<%=resource%>/icons/signal-25-50.png";
293 else if (net.quality <
75)
294 icon =
"<%=resource%>/icons/signal-50-75.png";
296 icon =
"<%=resource%>/icons/signal-75-100.png";
299 '
<table><tr><td style=
"text-align:center; width:32px; padding:3px">' +
300 '
<img src=
"%s" title=
"<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" />' +
301 '
<br /><small>%d%%
</small>' +
302 '
</td><td style=
"text-align:left; padding:3px"><small>' +
303 '
<strong><%:SSID%
>:
</strong> <a href=
"%s">%h
</a><br />' +
304 '
<strong><%:Mode%
>:
</strong> %s
<br />' +
305 '
<strong><%:Channel%
>:
</strong> %d (%
.2f GHz)
<br />' +
306 '
<strong><%:Bitrate%
>:
</strong> %s Mb/s
<br />',
307 icon, net.signal, net.noise,
311 net.channel, net.frequency,
318 '
<strong><%:BSSID%
>:
</strong> %s
<br />' +
319 '
<strong><%:Encryption%
>:
</strong> %s',
326 s += '
<em><%:Wireless is disabled or not associated%
></em>';
329 s += '
</small></td></tr></table>';
331 for (var bssid in net.assoclist)
335 signal: net.assoclist[bssid].signal,
336 noise: net.assoclist[bssid].noise,
337 rx_rate: net.assoclist[bssid].rx_rate,
338 rx_mcs: net.assoclist[bssid].rx_mcs,
339 rx_40mhz: net.assoclist[bssid].rx_40mhz,
340 tx_rate: net.assoclist[bssid].tx_rate,
341 tx_mcs: net.assoclist[bssid].tx_mcs,
342 tx_40mhz: net.assoclist[bssid].tx_40mhz,
350 s = '
<em><%:No information available%
></em>';
356 var ac = document.getElementById('wifi_assoc_table');
360 while( ac.rows.length
> 1 )
361 ac.rows[
0].parentNode.deleteRow(
1);
363 assoclist.sort(function(a, b) {
364 return (a.name == b.name)
365 ? (a.bssid < b.bssid)
370 for( var i =
0; i < assoclist.length; i++ )
372 var tr = ac.rows[
0].parentNode.insertRow(-
1);
373 tr.className = 'cbi-section-table-row cbi-rowstyle-' + (
1 + (i %
2));
376 var q = (-
1 * (assoclist[i].noise - assoclist[i].signal)) /
5;
378 icon =
"<%=resource%>/icons/signal-0.png";
380 icon =
"<%=resource%>/icons/signal-0-25.png";
382 icon =
"<%=resource%>/icons/signal-25-50.png";
384 icon =
"<%=resource%>/icons/signal-50-75.png";
386 icon =
"<%=resource%>/icons/signal-75-100.png";
388 tr.insertCell(-
1).innerHTML = String.format(
389 '
<img src=
"%s" title=
"<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" />',
390 icon, assoclist[i].signal, assoclist[i].noise
393 tr.insertCell(-
1).innerHTML = assoclist[i].bssid;
395 tr.insertCell(-
1).innerHTML = String.format(
396 '
<a href=
"%s">%h
</a>',
401 tr.insertCell(-
1).innerHTML = String.format('%d dBm', assoclist[i].signal);
402 tr.insertCell(-
1).innerHTML = String.format('%d dBm', assoclist[i].noise);
404 tr.insertCell(-
1).innerHTML = (assoclist[i].rx_mcs
> -
1)
405 ? String.format('%
.1f Mbit/s, MCS %d, %dMHz', assoclist[i].rx_rate /
1000, assoclist[i].rx_mcs, assoclist[i].rx_40mhz ?
40 :
20)
406 : String.format('%
.1f Mbit/s', assoclist[i].rx_rate /
1000)
409 tr.insertCell(-
1).innerHTML = (assoclist[i].tx_mcs
> -
1)
410 ? String.format('%
.1f Mbit/s, MCS %d, %dMHz', assoclist[i].tx_rate /
1000, assoclist[i].tx_mcs, assoclist[i].tx_40mhz ?
40 :
20)
411 : String.format('%
.1f Mbit/s', assoclist[i].tx_rate /
1000)
415 if (ac.rows.length ==
1)
417 var tr = ac.rows[
0].parentNode.insertRow(-
1);
418 tr.className = 'cbi-section-table-row';
420 var td = tr.insertCell(-
1);
422 td.innerHTML = '
<br /><em><%:No information available%
></em>';
429 if (e = document.getElementById('localtime'))
430 e.innerHTML = info.localtime;
432 if (e = document.getElementById('uptime'))
433 e.innerHTML = String.format('%t', info.uptime);
435 if (e = document.getElementById('loadavg'))
436 e.innerHTML = String.format('%
.02f, %
.02f, %
.02f',
437 info.loadavg[
0], info.loadavg[
1], info.loadavg[
2]);
439 if (e = document.getElementById('memtotal'))
440 e.innerHTML = progressbar(
441 (info.memfree + info.membuffers + info.memcached) +
" kB",
442 info.memtotal +
" kB"
445 if (e = document.getElementById('memfree'))
446 e.innerHTML = progressbar(
447 info.memfree +
" kB", info.memtotal +
" kB"
450 if (e = document.getElementById('memcache'))
451 e.innerHTML = progressbar(
452 info.memcached +
" kB", info.memtotal +
" kB"
455 if (e = document.getElementById('membuff'))
456 e.innerHTML = progressbar(
457 info.membuffers +
" kB", info.memtotal +
" kB"
460 if (e = document.getElementById('conns'))
461 e.innerHTML = progressbar(info.conncount, info.connmax);
467 <h2><a id=
"content" name=
"content"><%:Status%
></a></h2>
469 <fieldset class=
"cbi-section">
470 <legend><%:System%
></legend>
472 <table width=
"100%" cellspacing=
"10">
473 <tr><td width=
"33%"><%:Router Name%
></td><td><%=luci.sys.hostname() or
"?"%
></td></tr>
474 <tr><td width=
"33%"><%:Router Model%
></td><td><%=pcdata(model or
"?")%
></td></tr>
475 <tr><td width=
"33%"><%:Firmware Version%
></td><td>
476 <%=pcdata(luci.version.distname)%
> <%=pcdata(luci.version.distversion)%
> /
477 <%=pcdata(luci.version.luciname)%
> (<%=pcdata(luci.version.luciversion)%
>)
479 <tr><td width=
"33%"><%:Kernel Version%
></td><td><%=luci.sys.exec(
"uname -r")%
></td></tr>
480 <tr><td width=
"33%"><%:Local Time%
></td><td id=
"localtime">-
</td></tr>
481 <tr><td width=
"33%"><%:Uptime%
></td><td id=
"uptime">-
</td></tr>
482 <tr><td width=
"33%"><%:Load Average%
></td><td id=
"loadavg">-
</td></tr>
486 <fieldset class=
"cbi-section">
487 <legend><%:Memory%
></legend>
489 <table width=
"100%" cellspacing=
"10">
490 <tr><td width=
"33%"><%:Total Available%
></td><td id=
"memtotal">-
</td></tr>
491 <tr><td width=
"33%"><%:Free%
></td><td id=
"memfree">-
</td></tr>
492 <tr><td width=
"33%"><%:Cached%
></td><td id=
"memcache">-
</td></tr>
493 <tr><td width=
"33%"><%:Buffered%
></td><td id=
"membuff">-
</td></tr>
497 <fieldset class=
"cbi-section">
498 <legend><%:Network%
></legend>
500 <table width=
"100%" cellspacing=
"10">
501 <tr><td width=
"33%" style=
"vertical-align:top"><%:IPv4 WAN Status%
></td><td>
503 <td id=
"wan4_i" style=
"width:16px; text-align:center; padding:3px"><img src=
"<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?
</small></td>
504 <td id=
"wan4_s" style=
"vertical-align:middle; padding: 3px"><em><%:Collecting data...%
></em></td>
507 <% if has_ipv6 then %
>
508 <tr><td width=
"33%" style=
"vertical-align:top"><%:IPv6 WAN Status%
></td><td>
510 <td id=
"wan6_i" style=
"width:16px; text-align:center; padding:3px"><img src=
"<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?
</small></td>
511 <td id=
"wan6_s" style=
"vertical-align:middle; padding: 3px"><em><%:Collecting data...%
></em></td>
515 <tr><td width=
"33%"><%:Active Connections%
></td><td id=
"conns">-
</td></tr>
519 <% if has_dhcp then %
>
520 <fieldset class=
"cbi-section">
521 <legend><%:DHCP Leases%
></legend>
523 <table class=
"cbi-section-table" id=
"lease_status_table">
524 <tr class=
"cbi-section-table-titles">
525 <th class=
"cbi-section-table-cell"><%:Hostname%
></th>
526 <th class=
"cbi-section-table-cell"><%:IPv4-Address%
></th>
527 <th class=
"cbi-section-table-cell"><%:MAC-Address%
></th>
528 <th class=
"cbi-section-table-cell"><%:Leasetime remaining%
></th>
530 <tr class=
"cbi-section-table-row">
531 <td colspan=
"4"><em><br /><%:Collecting data...%
></em></td>
537 <% if has_wifi then %
>
538 <fieldset class=
"cbi-section">
539 <legend><%:Wireless%
></legend>
541 <table id=
"wifi_status_table" width=
"100%" cellspacing=
"10">
542 <tr><td><em><%:Collecting data...%
></em></td></tr>
546 <fieldset class=
"cbi-section">
547 <legend><%:Associated Stations%
></legend>
549 <table class=
"cbi-section-table" id=
"wifi_assoc_table">
550 <tr class=
"cbi-section-table-titles">
551 <th class=
"cbi-section-table-cell"> </th>
552 <th class=
"cbi-section-table-cell"><%:MAC-Address%
></th>
553 <th class=
"cbi-section-table-cell"><%:Network%
></th>
554 <th class=
"cbi-section-table-cell"><%:Signal%
></th>
555 <th class=
"cbi-section-table-cell"><%:Noise%
></th>
556 <th class=
"cbi-section-table-cell"><%:RX Rate%
></th>
557 <th class=
"cbi-section-table-cell"><%:TX Rate%
></th>
559 <tr class=
"cbi-section-table-row">
560 <td colspan=
"7"><em><br /><%:Collecting data...%
></em></td>
570 local plugins = nixio.fs.dir(luci.util.libpath() ..
"/view/admin_status/index")
573 for inc in plugins do
574 if inc:match(
"%.htm$") then
575 include(
"admin_status/index/" .. inc:gsub(
"%.htm$",
""))