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 dr4 = luci.sys.net.defaultroute()
28 local dr6 = luci.sys.net.defaultroute6()
31 if dr4 and dr4.device then
32 wan = ntm:get_interface(dr4.device)
33 wan = wan and wan:get_network()
36 if dr6 and dr6.device then
37 wan6 = ntm:get_interface(dr6.device)
38 wan6 = wan6 and wan6:get_network()
41 local _, _, memtotal, memcached, membuffers, memfree = luci.sys.sysinfo()
43 local conn_count = tonumber((
44 luci.sys.exec(
"wc -l /proc/net/nf_conntrack") or
45 luci.sys.exec(
"wc -l /proc/net/ip_conntrack") or
46 ""):match(
"%d+")) or
0
48 local conn_max = tonumber((
49 luci.sys.exec(
"sysctl net.nf_conntrack_max") or
50 luci.sys.exec(
"sysctl net.ipv4.netfilter.ip_conntrack_max") or
51 ""):match(
"%d+")) or
4096
54 uptime = luci.sys.uptime(),
55 localtime = os.date(),
56 loadavg = { luci.sys.loadavg() },
58 memcached = memcached,
59 membuffers = membuffers,
62 conncount = conn_count,
63 leases = luci.tools.status.dhcp_leases(),
64 wifinets = luci.tools.status.wifi_networks()
69 ipaddr = wan:ipaddr(),
70 gwaddr = wan:gwaddr(),
71 netmask = wan:netmask(),
73 expires = wan:expires(),
74 uptime = wan:uptime(),
76 ifname = wan:ifname(),
77 link = wan:adminlink()
83 ip6addr = wan6:ip6addr(),
84 gw6addr = wan6:gw6addr(),
85 dns = wan6:dns6addrs(),
86 uptime = wan6:uptime(),
87 ifname = wan6:ifname(),
88 link = wan6:adminlink()
92 luci.http.prepare_content(
"application/json")
93 luci.http.write_json(rv)
98 local system, model = luci.sys.sysinfo()
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 iwxhr = new XHR();
123 var wifidevs = <%=luci.http.write_json(netdevs)%
>;
124 var arptable = <%=luci.http.write_json(arpcache)%
>;
127 var func = arguments.callee;
129 iwxhr.get('<%=REQUEST_URI%
>', { status:
1 },
132 var si = document.getElementById('wan4_i');
133 var ss = document.getElementById('wan4_s');
136 if (ifc && ifc.ifname && ifc.proto != 'none')
138 var s = String.format(
139 '
<strong><%:Type%
>:
</strong>%s
<br />' +
140 '
<strong><%:Address%
>:
</strong>%s
<br />' +
141 '
<strong><%:Netmask%
>:
</strong>%s
<br />' +
142 '
<strong><%:Gateway%
>:
</strong>%s
<br />',
144 (ifc.ipaddr) ? ifc.ipaddr : '
0.0.0.0',
145 (ifc.netmask && ifc.netmask != ifc.ipaddr) ? ifc.netmask : '
255.255.255.255',
146 (ifc.gwaddr) ? ifc.gwaddr : '
0.0.0.0'
149 for (var i =
0; i < ifc.dns.length; i++)
152 '
<strong><%:DNS%
> %d:
</strong>%s
<br />',
157 if (ifc.expires
> -
1)
160 '
<strong><%:Expires%
>:
</strong>%t
<br />',
168 '
<strong><%:Connected%
>:
</strong>%t
<br />',
173 ss.innerHTML = String.format('
<small>%s
</small>', s);
174 si.innerHTML = String.format(
175 '
<img src=
"<%=resource%>/icons/ethernet.png" />' +
176 '
<br /><small><a href=
"%s">%s
</a></small>',
182 si.innerHTML = '
<img src=
"<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?
</small>';
183 ss.innerHTML = '
<em>Not connected
</em>';
186 <% if has_ipv6 then %
>
187 var si6 = document.getElementById('wan6_i');
188 var ss6 = document.getElementById('wan6_s');
189 var ifc6 = info.wan6;
191 if (ifc6 && ifc6.ifname && ifc6.proto != 'none')
193 var s = String.format(
194 '
<strong><%:Address%
>:
</strong>%s
<br />' +
195 '
<strong><%:Gateway%
>:
</strong>%s
<br />',
196 (ifc6.ip6addr) ? ifc6.ip6addr : '::',
197 (ifc6.gw6addr) ? ifc6.gw6addr : '::'
200 for (var i =
0; i < ifc6.dns.length; i++)
203 '
<strong><%:DNS%
> %d:
</strong>%s
<br />',
211 '
<strong><%:Connected%
>:
</strong>%t
<br />',
216 ss6.innerHTML = String.format('
<small>%s
</small>', s);
217 si6.innerHTML = String.format(
218 '
<img src=
"<%=resource%>/icons/ethernet.png" />' +
219 '
<br /><small><a href=
"%s">%s
</a></small>',
220 ifc6.link, ifc6.ifname
225 si6.innerHTML = '
<img src=
"<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?
</small>';
226 ss6.innerHTML = '
<em>Not connected
</em>';
230 <% if has_dhcp then %
>
231 var ls = document.getElementById('lease_status_table');
235 while( ls.rows.length
> 1 )
236 ls.rows[
0].parentNode.deleteRow(
1);
238 for( var i =
0; i < info.leases.length; i++ )
242 if (info.leases[i].expires <=
0)
243 timestr = '
<em><%:expired%
></em>';
245 timestr = String.format('%t', info.leases[i].expires);
247 var tr = ls.rows[
0].parentNode.insertRow(-
1);
248 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i %
2) +
1);
250 tr.insertCell(-
1).innerHTML = info.leases[i].hostname ? info.leases[i].hostname : '?';
251 tr.insertCell(-
1).innerHTML = info.leases[i].ipaddr;
252 tr.insertCell(-
1).innerHTML = info.leases[i].macaddr;
253 tr.insertCell(-
1).innerHTML = timestr;
256 if( ls.rows.length ==
1 )
258 var tr = ls.rows[
0].parentNode.insertRow(-
1);
259 tr.className = 'cbi-section-table-row';
261 var td = tr.insertCell(-
1);
263 td.innerHTML = '
<em><br /><%:There are no active leases.%
></em>';
268 <% if has_wifi then %
>
271 var ws = document.getElementById('wifi_status_table');
274 var wsbody = ws.rows[
0].parentNode;
275 while (ws.rows.length
> 0)
278 for (var didx =
0; didx < info.wifinets.length; didx++)
280 var dev = info.wifinets[didx];
282 var tr = wsbody.insertRow(-
1);
285 td = tr.insertCell(-
1);
287 td.innerHTML = dev.name;
288 td.style.verticalAlign =
"top";
290 td = tr.insertCell(-
1);
294 for (var nidx =
0; nidx < dev.networks.length; nidx++)
296 var net = dev.networks[nidx];
297 var is_assoc = (net.bssid != '
00:
00:
00:
00:
00:
00' && net.channel);
301 icon =
"<%=resource%>/icons/signal-none.png";
302 else if (net.quality ==
0)
303 icon =
"<%=resource%>/icons/signal-0.png";
304 else if (net.quality <
25)
305 icon =
"<%=resource%>/icons/signal-0-25.png";
306 else if (net.quality <
50)
307 icon =
"<%=resource%>/icons/signal-25-50.png";
308 else if (net.quality <
75)
309 icon =
"<%=resource%>/icons/signal-50-75.png";
311 icon =
"<%=resource%>/icons/signal-75-100.png";
314 '
<table><tr><td style=
"text-align:center; width:32px; padding:3px">' +
315 '
<img src=
"%s" title=
"<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" />' +
316 '
<br /><small>%d%%
</small>' +
317 '
</td><td style=
"text-align:left; padding:3px"><small>' +
318 '
<strong><%:SSID%
>:
</strong> <a href=
"%s">%h
</a><br />' +
319 '
<strong><%:Mode%
>:
</strong> %s
<br />' +
320 '
<strong><%:Channel%
>:
</strong> %d (%
.2f GHz)
<br />' +
321 '
<strong><%:Bitrate%
>:
</strong> %s Mb/s
<br />',
322 icon, net.signal, net.noise,
326 net.channel, net.frequency,
333 '
<strong><%:BSSID%
>:
</strong> %s
<br />' +
334 '
<strong><%:Encryption%
>:
</strong> %s',
341 s += '
<em><%:Wireless is disabled or not associated%
></em>';
344 s += '
</small></td></tr></table>';
346 for (var bssid in net.assoclist)
350 signal: net.assoclist[bssid].signal,
351 noise: net.assoclist[bssid].noise,
359 s = '
<em><%:No information available%
></em>';
365 var ac = document.getElementById('wifi_assoc_table');
369 while( ac.rows.length
> 1 )
370 ac.rows[
0].parentNode.deleteRow(
1);
372 assoclist.sort(function(a, b) {
373 return (a.name == b.name)
374 ? (a.bssid < b.bssid)
379 for( var i =
0; i < assoclist.length; i++ )
381 var tr = ac.rows[
0].parentNode.insertRow(-
1);
382 tr.className = 'cbi-section-table-row cbi-rowstyle-' + (
1 + (i %
2));
385 var q = (-
1 * (assoclist[i].noise - assoclist[i].signal)) /
5;
387 icon =
"<%=resource%>/icons/signal-0.png";
389 icon =
"<%=resource%>/icons/signal-0-25.png";
391 icon =
"<%=resource%>/icons/signal-25-50.png";
393 icon =
"<%=resource%>/icons/signal-50-75.png";
395 icon =
"<%=resource%>/icons/signal-75-100.png";
397 tr.insertCell(-
1).innerHTML = String.format(
398 '
<img src=
"%s" title=
"<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" />',
399 icon, assoclist[i].signal, assoclist[i].noise
402 tr.insertCell(-
1).innerHTML = assoclist[i].bssid;
404 tr.insertCell(-
1).innerHTML = String.format(
405 '
<a href=
"%s">%h
</a>',
410 tr.insertCell(-
1).innerHTML = String.format('%d dBm', assoclist[i].signal);
411 tr.insertCell(-
1).innerHTML = String.format('%d dBm', assoclist[i].noise);
414 if (ac.rows.length ==
1)
416 var tr = ac.rows[
0].parentNode.insertRow(-
1);
417 tr.className = 'cbi-section-table-row';
419 var td = tr.insertCell(-
1);
421 td.innerHTML = '
<br /><em><%:No information available%
></em>';
428 if (e = document.getElementById('localtime'))
429 e.innerHTML = info.localtime;
431 if (e = document.getElementById('uptime'))
432 e.innerHTML = String.format('%t', info.uptime);
434 if (e = document.getElementById('loadavg'))
435 e.innerHTML = String.format('%
.02f, %
.02f, %
.02f',
436 info.loadavg[
0], info.loadavg[
1], info.loadavg[
2]);
438 if (e = document.getElementById('memtotal'))
439 e.innerHTML = progressbar(
440 (info.memfree + info.membuffers + info.memcached) +
" kB",
441 info.memtotal +
" kB"
444 if (e = document.getElementById('memfree'))
445 e.innerHTML = progressbar(
446 info.memfree +
" kB", info.memtotal +
" kB"
449 if (e = document.getElementById('memcache'))
450 e.innerHTML = progressbar(
451 info.memcached +
" kB", info.memtotal +
" kB"
454 if (e = document.getElementById('membuff'))
455 e.innerHTML = progressbar(
456 info.membuffers +
" kB", info.memtotal +
" kB"
459 if (e = document.getElementById('conns'))
460 e.innerHTML = progressbar(info.conncount, info.connmax);
462 window.setTimeout(func,
5000);
468 <h2><a id=
"content" name=
"content"><%:Status%
></a></h2>
470 <fieldset class=
"cbi-section">
471 <legend><%:System%
></legend>
473 <table width=
"100%" cellspacing=
"10">
474 <tr><td width=
"33%"><%:Router Name%
></td><td><%=luci.sys.hostname() or
"?"%
></td></tr>
475 <tr><td width=
"33%"><%:Router Model%
></td><td><%=pcdata(model or
"?")%
></td></tr>
476 <tr><td width=
"33%"><%:Firmware Version%
></td><td>
477 <%=pcdata(luci.version.distname)%
> <%=pcdata(luci.version.distversion)%
> /
478 <%=pcdata(luci.version.luciname)%
> (<%=pcdata(luci.version.luciversion)%
>)
480 <tr><td width=
"33%"><%:Kernel Version%
></td><td><%=luci.sys.exec(
"uname -r")%
></td></tr>
481 <tr><td width=
"33%"><%:Local Time%
></td><td id=
"localtime">-
</td></tr>
482 <tr><td width=
"33%"><%:Uptime%
></td><td id=
"uptime">-
</td></tr>
483 <tr><td width=
"33%"><%:Load Average%
></td><td id=
"loadavg">-
</td></tr>
487 <fieldset class=
"cbi-section">
488 <legend><%:Memory%
></legend>
490 <table width=
"100%" cellspacing=
"10">
491 <tr><td width=
"33%"><%:Total Available%
></td><td id=
"memtotal">-
</td></tr>
492 <tr><td width=
"33%"><%:Free%
></td><td id=
"memfree">-
</td></tr>
493 <tr><td width=
"33%"><%:Cached%
></td><td id=
"memcache">-
</td></tr>
494 <tr><td width=
"33%"><%:Buffered%
></td><td id=
"membuff">-
</td></tr>
498 <fieldset class=
"cbi-section">
499 <legend><%:Network%
></legend>
501 <table width=
"100%" cellspacing=
"10">
502 <tr><td width=
"33%" style=
"vertical-align:top"><%:IPv4 WAN Status%
></td><td>
504 <td id=
"wan4_i" style=
"width:16px; text-align:center; padding:3px"><img src=
"<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?
</small></td>
505 <td id=
"wan4_s" style=
"vertical-align:middle; padding: 3px"><em><%:Collecting data...%
></em></td>
508 <% if has_ipv6 then %
>
509 <tr><td width=
"33%" style=
"vertical-align:top"><%:IPv6 WAN Status%
></td><td>
511 <td id=
"wan6_i" style=
"width:16px; text-align:center; padding:3px"><img src=
"<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?
</small></td>
512 <td id=
"wan6_s" style=
"vertical-align:middle; padding: 3px"><em><%:Collecting data...%
></em></td>
516 <tr><td width=
"33%"><%:Active Connections%
></td><td id=
"conns">-
</td></tr>
520 <% if has_dhcp then %
>
521 <fieldset class=
"cbi-section">
522 <legend><%:DHCP Leases%
></legend>
524 <table class=
"cbi-section-table" id=
"lease_status_table">
525 <tr class=
"cbi-section-table-titles">
526 <th class=
"cbi-section-table-cell"><%:Hostname%
></th>
527 <th class=
"cbi-section-table-cell"><%:IPv4-Address%
></th>
528 <th class=
"cbi-section-table-cell"><%:MAC-Address%
></th>
529 <th class=
"cbi-section-table-cell"><%:Leasetime remaining%
></th>
531 <tr class=
"cbi-section-table-row">
532 <td colspan=
"4"><em><br /><%:Collecting data...%
></em></td>
538 <% if has_wifi then %
>
539 <fieldset class=
"cbi-section">
540 <legend><%:Wireless%
></legend>
542 <table id=
"wifi_status_table" width=
"100%" cellspacing=
"10">
543 <tr><td><em><%:Collecting data...%
></em></td></tr>
547 <fieldset class=
"cbi-section">
548 <legend><%:Associated Stations%
></legend>
550 <table class=
"cbi-section-table" id=
"wifi_assoc_table">
551 <tr class=
"cbi-section-table-titles">
552 <th class=
"cbi-section-table-cell"> </th>
553 <th class=
"cbi-section-table-cell"><%:BSSID%
></th>
554 <th class=
"cbi-section-table-cell"><%:Network%
></th>
555 <th class=
"cbi-section-table-cell"><%:Signal%
></th>
556 <th class=
"cbi-section-table-cell"><%:Noise%
></th>
558 <tr class=
"cbi-section-table-row">
559 <td colspan=
"5"><em><br /><%:Collecting data...%
></em></td>
569 local plugins = nixio.fs.dir(luci.util.libpath() ..
"/view/admin_status/index")
572 for inc in plugins do
573 if inc:match(
"%.htm$") then
574 include(
"admin_status/index/" .. inc:gsub(
"%.htm$",
""))