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
16 require "luci.tools.status"
18 local has_ipv6 = luci.fs.access("/proc/net/ipv6_route")
19 local has_dhcp = luci.fs.access("/etc/config/dhcp")
20 local has_wifi = luci.fs.stat("/etc/config/wireless")
21 has_wifi = has_wifi and has_wifi.size > 0
22 local _, _, memtotal, memcached, membuffers, memfree, _, swaptotal, swapcached, swapfree = luci.sys.sysinfo()
28 if luci.http.formvalue("status") == "1" then
29 local ntm = require "luci.model.network".init()
30 local wan = ntm:get_wannet()
31 local wan6 = ntm:get_wan6net()
33 local conn_count = tonumber((
34 luci.sys.exec("wc -l /proc/net/nf_conntrack") or
35 luci.sys.exec("wc -l /proc/net/ip_conntrack") or
36 ""):match("%d+")) or 0
38 local conn_max = tonumber((
39 luci.sys.exec("sysctl net.nf_conntrack_max") or
40 luci.sys.exec("sysctl net.ipv4.netfilter.ip_conntrack_max") or
41 ""):match("%d+")) or 4096
44 uptime = luci.sys.uptime(),
45 localtime = os.date(),
46 loadavg = { luci.sys.loadavg() },
48 memcached = memcached,
49 membuffers = membuffers,
51 swaptotal = swaptotal,
52 swapcached = swapcached,
55 conncount = conn_count,
56 leases = luci.tools.status.dhcp_leases(),
57 leases6 = luci.tools.status.dhcp6_leases(),
58 wifinets = luci.tools.status.wifi_networks()
63 ipaddr = wan:ipaddr(),
64 gwaddr = wan:gwaddr(),
65 netmask = wan:netmask(),
67 expires = wan:expires(),
68 uptime = wan:uptime(),
70 ifname = wan:ifname(),
71 link = wan:adminlink()
77 ip6addr = wan6:ip6addr(),
78 gw6addr = wan6:gw6addr(),
79 dns = wan6:dns6addrs(),
80 uptime = wan6:uptime(),
81 ifname = wan6:ifname(),
82 link = wan6:adminlink()
86 luci.http.prepare_content("application/json")
87 luci.http.write_json(rv)
92 local system, model = luci.sys.sysinfo()
97 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
98 <script type="text/javascript">//<![CDATA[
99 function progressbar(v, m)
101 var vn = parseInt(v) || 0;
102 var mn = parseInt(m) || 100;
103 var pc = Math.floor((100 / mn) * vn);
105 return String.format(
106 '<div style="width:200px; position:relative; border:1px solid #999999">' +
107 '<div style="background-color:#CCCCCC; width:%d%%; height:15px">' +
108 '<div style="position:absolute; left:0; top:0; text-align:center; width:100%%; color:#000000">' +
109 '<small>%s / %s (%d%%)</small>' +
112 '</div>', pc, v, m, pc
116 var wifidevs = <%=luci.http.write_json(netdevs)%>;
117 var arptable = <%=luci.http.write_json(arpcache)%>;
119 XHR.poll(5, '<%=REQUEST_URI%>', { status: 1 },
122 var si = document.getElementById('wan4_i');
123 var ss = document.getElementById('wan4_s');
126 if (ifc && ifc.ifname && ifc.proto != 'none')
128 var s = String.format(
129 '<strong><%:Type%>: </strong>%s<br />' +
130 '<strong><%:Address%>: </strong>%s<br />' +
131 '<strong><%:Netmask%>: </strong>%s<br />' +
132 '<strong><%:Gateway%>: </strong>%s<br />',
134 (ifc.ipaddr) ? ifc.ipaddr : '0.0.0.0',
135 (ifc.netmask && ifc.netmask != ifc.ipaddr) ? ifc.netmask : '255.255.255.255',
136 (ifc.gwaddr) ? ifc.gwaddr : '0.0.0.0'
139 for (var i = 0; i < ifc.dns.length; i++)
142 '<strong><%:DNS%> %d: </strong>%s<br />',
147 if (ifc.expires > -1)
150 '<strong><%:Expires%>: </strong>%t<br />',
158 '<strong><%:Connected%>: </strong>%t<br />',
163 ss.innerHTML = String.format('<small>%s</small>', s);
164 si.innerHTML = String.format(
165 '<img src="<%=resource%>/icons/ethernet.png" />' +
166 '<br /><small><a href="%s">%s</a></small>',
172 si.innerHTML = '<img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small>';
173 ss.innerHTML = '<em><%:Not connected%></em>';
176 <% if has_ipv6 then %>
177 var si6 = document.getElementById('wan6_i');
178 var ss6 = document.getElementById('wan6_s');
179 var ifc6 = info.wan6;
181 if (ifc6 && ifc6.ifname && ifc6.proto != 'none')
183 var s = String.format(
184 '<strong><%:Address%>: </strong>%s<br />' +
185 '<strong><%:Gateway%>: </strong>%s<br />',
186 (ifc6.ip6addr) ? ifc6.ip6addr : '::',
187 (ifc6.gw6addr) ? ifc6.gw6addr : '::'
190 for (var i = 0; i < ifc6.dns.length; i++)
193 '<strong><%:DNS%> %d: </strong>%s<br />',
201 '<strong><%:Connected%>: </strong>%t<br />',
206 ss6.innerHTML = String.format('<small>%s</small>', s);
207 si6.innerHTML = String.format(
208 '<img src="<%=resource%>/icons/ethernet.png" />' +
209 '<br /><small><a href="%s">%s</a></small>',
210 ifc6.link, ifc6.ifname
215 si6.innerHTML = '<img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small>';
216 ss6.innerHTML = '<em><%:Not connected%></em>';
220 <% if has_dhcp then %>
221 var ls = document.getElementById('lease_status_table');
225 while( ls.rows.length > 1 )
226 ls.rows[0].parentNode.deleteRow(1);
228 for( var i = 0; i < info.leases.length; i++ )
232 if (info.leases[i].expires <= 0)
233 timestr = '<em><%:expired%></em>';
235 timestr = String.format('%t', info.leases[i].expires);
237 var tr = ls.rows[0].parentNode.insertRow(-1);
238 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
240 tr.insertCell(-1).innerHTML = info.leases[i].hostname ? info.leases[i].hostname : '?';
241 tr.insertCell(-1).innerHTML = info.leases[i].ipaddr;
242 tr.insertCell(-1).innerHTML = info.leases[i].macaddr;
243 tr.insertCell(-1).innerHTML = timestr;
246 if( ls.rows.length == 1 )
248 var tr = ls.rows[0].parentNode.insertRow(-1);
249 tr.className = 'cbi-section-table-row';
251 var td = tr.insertCell(-1);
253 td.innerHTML = '<em><br /><%:There are no active leases.%></em>';
257 var ls6 = document.getElementById('lease6_status_table');
258 if (ls6 && info.leases6)
260 ls6.parentNode.style.display = 'block';
263 while( ls6.rows.length > 1 )
264 ls6.rows[0].parentNode.deleteRow(1);
266 for( var i = 0; i < info.leases6.length; i++ )
270 if (info.leases6[i].expires <= 0)
271 timestr = '<em><%:expired%></em>';
273 timestr = String.format('%t', info.leases6[i].expires);
275 var tr = ls6.rows[0].parentNode.insertRow(-1);
276 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
278 tr.insertCell(-1).innerHTML = info.leases6[i].hostname ? info.leases6[i].hostname : '?';
279 tr.insertCell(-1).innerHTML = info.leases6[i].ip6addr;
280 tr.insertCell(-1).innerHTML = info.leases6[i].duid;
281 tr.insertCell(-1).innerHTML = timestr;
284 if( ls6.rows.length == 1 )
286 var tr = ls6.rows[0].parentNode.insertRow(-1);
287 tr.className = 'cbi-section-table-row';
289 var td = tr.insertCell(-1);
291 td.innerHTML = '<em><br /><%:There are no active leases.%></em>';
296 <% if has_wifi then %>
299 var ws = document.getElementById('wifi_status_table');
302 var wsbody = ws.rows[0].parentNode;
303 while (ws.rows.length > 0)
306 for (var didx = 0; didx < info.wifinets.length; didx++)
308 var dev = info.wifinets[didx];
310 var tr = wsbody.insertRow(-1);
313 td = tr.insertCell(-1);
315 td.innerHTML = dev.name;
316 td.style.verticalAlign = "top";
318 td = tr.insertCell(-1);
322 for (var nidx = 0; nidx < dev.networks.length; nidx++)
324 var net = dev.networks[nidx];
325 var is_assoc = (net.bssid != '00:00:00:00:00:00' && net.channel);
329 icon = "<%=resource%>/icons/signal-none.png";
330 else if (net.quality == 0)
331 icon = "<%=resource%>/icons/signal-0.png";
332 else if (net.quality < 25)
333 icon = "<%=resource%>/icons/signal-0-25.png";
334 else if (net.quality < 50)
335 icon = "<%=resource%>/icons/signal-25-50.png";
336 else if (net.quality < 75)
337 icon = "<%=resource%>/icons/signal-50-75.png";
339 icon = "<%=resource%>/icons/signal-75-100.png";
342 '<table><tr><td style="text-align:center; width:32px; padding:3px">' +
343 '<img src="%s" title="<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" />' +
344 '<br /><small>%d%%</small>' +
345 '</td><td style="text-align:left; padding:3px"><small>' +
346 '<strong><%:SSID%>:</strong> <a href="%s">%h</a><br />' +
347 '<strong><%:Mode%>:</strong> %s<br />' +
348 '<strong><%:Channel%>:</strong> %d (%.3f <%:GHz%>)<br />' +
349 '<strong><%:Bitrate%>:</strong> %s <%:Mbit/s%><br />',
350 icon, net.signal, net.noise,
354 net.channel, net.frequency,
361 '<strong><%:BSSID%>:</strong> %s<br />' +
362 '<strong><%:Encryption%>:</strong> %s',
369 s += '<em><%:Wireless is disabled or not associated%></em>';
372 s += '</small></td></tr></table>';
374 for (var bssid in net.assoclist)
378 signal: net.assoclist[bssid].signal,
379 noise: net.assoclist[bssid].noise,
380 rx_rate: net.assoclist[bssid].rx_rate,
381 rx_mcs: net.assoclist[bssid].rx_mcs,
382 rx_40mhz: net.assoclist[bssid].rx_40mhz,
383 tx_rate: net.assoclist[bssid].tx_rate,
384 tx_mcs: net.assoclist[bssid].tx_mcs,
385 tx_40mhz: net.assoclist[bssid].tx_40mhz,
393 s = '<em><%:No information available%></em>';
399 var ac = document.getElementById('wifi_assoc_table');
403 while( ac.rows.length > 1 )
404 ac.rows[0].parentNode.deleteRow(1);
406 assoclist.sort(function(a, b) {
407 return (a.name == b.name)
408 ? (a.bssid < b.bssid)
413 for( var i = 0; i < assoclist.length; i++ )
415 var tr = ac.rows[0].parentNode.insertRow(-1);
416 tr.className = 'cbi-section-table-row cbi-rowstyle-' + (1 + (i % 2));
419 var q = (-1 * (assoclist[i].noise - assoclist[i].signal)) / 5;
421 icon = "<%=resource%>/icons/signal-0.png";
423 icon = "<%=resource%>/icons/signal-0-25.png";
425 icon = "<%=resource%>/icons/signal-25-50.png";
427 icon = "<%=resource%>/icons/signal-50-75.png";
429 icon = "<%=resource%>/icons/signal-75-100.png";
431 tr.insertCell(-1).innerHTML = String.format(
432 '<img src="%s" title="<%:Signal%>: %d <%:dBm%> / <%:Noise%>: %d <%:dBm%>" />',
433 icon, assoclist[i].signal, assoclist[i].noise
436 tr.insertCell(-1).innerHTML = assoclist[i].bssid;
438 tr.insertCell(-1).innerHTML = String.format(
439 '<a href="%s">%s</a>',
441 '%h'.format(assoclist[i].name).nobr()
444 tr.insertCell(-1).innerHTML = String.format('%d <%:dBm%>', assoclist[i].signal).nobr();
445 tr.insertCell(-1).innerHTML = String.format('%d <%:dBm%>', assoclist[i].noise).nobr();
447 tr.insertCell(-1).innerHTML = (assoclist[i].rx_mcs > -1)
448 ? 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()
449 : String.format('%.1f <%:Mbit/s%>', assoclist[i].rx_rate / 1000).nobr()
452 tr.insertCell(-1).innerHTML = (assoclist[i].tx_mcs > -1)
453 ? 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()
454 : String.format('%.1f <%:Mbit/s%>', assoclist[i].tx_rate / 1000).nobr()
458 if (ac.rows.length == 1)
460 var tr = ac.rows[0].parentNode.insertRow(-1);
461 tr.className = 'cbi-section-table-row';
463 var td = tr.insertCell(-1);
465 td.innerHTML = '<br /><em><%:No information available%></em>';
472 if (e = document.getElementById('localtime'))
473 e.innerHTML = info.localtime;
475 if (e = document.getElementById('uptime'))
476 e.innerHTML = String.format('%t', info.uptime);
478 if (e = document.getElementById('loadavg'))
479 e.innerHTML = String.format('%.02f, %.02f, %.02f',
480 info.loadavg[0], info.loadavg[1], info.loadavg[2]);
482 if (e = document.getElementById('memtotal'))
483 e.innerHTML = progressbar(
484 (info.memfree + info.membuffers + info.memcached) + " <%:kB%>",
485 info.memtotal + " <%:kB%>"
488 if (e = document.getElementById('memfree'))
489 e.innerHTML = progressbar(
490 info.memfree + " <%:kB%>", info.memtotal + " <%:kB%>"
493 if (e = document.getElementById('memcache'))
494 e.innerHTML = progressbar(
495 info.memcached + " <%:kB%>", info.memtotal + " <%:kB%>"
498 if (e = document.getElementById('membuff'))
499 e.innerHTML = progressbar(
500 info.membuffers + " <%:kB%>", info.memtotal + " <%:kB%>"
503 if (e = document.getElementById('swapcache'))
504 e.innerHTML = progressbar(
505 info.swapcached + " <%:kB%>", info.swaptotal + " <%:kB%>"
508 if (e = document.getElementById('swaptotal'))
509 e.innerHTML = progressbar(
510 (info.swapfree + info.swapcached) + " <%:kB%>",
511 info.swaptotal + " <%:kB%>"
514 if (e = document.getElementById('swapfree'))
515 e.innerHTML = progressbar(
516 info.swapfree + " <%:kB%>", info.swaptotal + " <%:kB%>"
519 if (e = document.getElementById('conns'))
520 e.innerHTML = progressbar(info.conncount, info.connmax);
526 <h2><a id="content" name="content"><%:Status%></a></h2>
528 <fieldset class="cbi-section">
529 <legend><%:System%></legend>
531 <table width="100%" cellspacing="10">
532 <tr><td width="33%"><%:Router Name%></td><td><%=luci.sys.hostname() or "?"%></td></tr>
533 <tr><td width="33%"><%:Router Model%></td><td><%=pcdata(model or "?")%></td></tr>
534 <tr><td width="33%"><%:Firmware Version%></td><td>
535 <%=pcdata(luci.version.distname)%> <%=pcdata(luci.version.distversion)%> /
536 <%=pcdata(luci.version.luciname)%> (<%=pcdata(luci.version.luciversion)%>)
538 <tr><td width="33%"><%:Kernel Version%></td><td><%=luci.sys.exec("uname -r")%></td></tr>
539 <tr><td width="33%"><%:Local Time%></td><td id="localtime">-</td></tr>
540 <tr><td width="33%"><%:Uptime%></td><td id="uptime">-</td></tr>
541 <tr><td width="33%"><%:Load Average%></td><td id="loadavg">-</td></tr>
545 <fieldset class="cbi-section">
546 <legend><%:Memory%></legend>
548 <table width="100%" cellspacing="10">
549 <tr><td width="33%"><%:Total Available%></td><td id="memtotal">-</td></tr>
550 <tr><td width="33%"><%:Free%></td><td id="memfree">-</td></tr>
551 <tr><td width="33%"><%:Cached%></td><td id="memcache">-</td></tr>
552 <tr><td width="33%"><%:Buffered%></td><td id="membuff">-</td></tr>
556 <% if has_swap then %>
557 <fieldset class="cbi-section">
558 <legend><%:Swap%></legend>
560 <table width="100%" cellspacing="10">
561 <tr><td width="33%"><%:Total Available%></td><td id="swaptotal">-</td></tr>
562 <tr><td width="33%"><%:Free%></td><td id="swapfree">-</td></tr>
563 <tr><td width="33%"><%:Cached%></td><td id="swapcache">-</td></tr>
568 <fieldset class="cbi-section">
569 <legend><%:Network%></legend>
571 <table width="100%" cellspacing="10">
572 <tr><td width="33%" style="vertical-align:top"><%:IPv4 WAN Status%></td><td>
574 <td id="wan4_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td>
575 <td id="wan4_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></td>
578 <% if has_ipv6 then %>
579 <tr><td width="33%" style="vertical-align:top"><%:IPv6 WAN Status%></td><td>
581 <td id="wan6_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td>
582 <td id="wan6_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></td>
586 <tr><td width="33%"><%:Active Connections%></td><td id="conns">-</td></tr>
590 <% if has_dhcp then %>
591 <fieldset class="cbi-section">
592 <legend><%:DHCP Leases%></legend>
594 <table class="cbi-section-table" id="lease_status_table">
595 <tr class="cbi-section-table-titles">
596 <th class="cbi-section-table-cell"><%:Hostname%></th>
597 <th class="cbi-section-table-cell"><%:IPv4-Address%></th>
598 <th class="cbi-section-table-cell"><%:MAC-Address%></th>
599 <th class="cbi-section-table-cell"><%:Leasetime remaining%></th>
601 <tr class="cbi-section-table-row">
602 <td colspan="4"><em><br /><%:Collecting data...%></em></td>
607 <fieldset class="cbi-section" style="display:none">
608 <legend><%:DHCPv6 Leases%></legend>
610 <table class="cbi-section-table" id="lease6_status_table">
611 <tr class="cbi-section-table-titles">
612 <th class="cbi-section-table-cell"><%:Hostname%></th>
613 <th class="cbi-section-table-cell"><%:IPv6-Address%></th>
614 <th class="cbi-section-table-cell"><%:DUID%></th>
615 <th class="cbi-section-table-cell"><%:Leasetime remaining%></th>
617 <tr class="cbi-section-table-row">
618 <td colspan="4"><em><br /><%:Collecting data...%></em></td>
624 <% if has_wifi then %>
625 <fieldset class="cbi-section">
626 <legend><%:Wireless%></legend>
628 <table id="wifi_status_table" width="100%" cellspacing="10">
629 <tr><td><em><%:Collecting data...%></em></td></tr>
633 <fieldset class="cbi-section">
634 <legend><%:Associated Stations%></legend>
636 <table class="cbi-section-table" id="wifi_assoc_table">
637 <tr class="cbi-section-table-titles">
638 <th class="cbi-section-table-cell"> </th>
639 <th class="cbi-section-table-cell"><%:MAC-Address%></th>
640 <th class="cbi-section-table-cell"><%:Network%></th>
641 <th class="cbi-section-table-cell"><%:Signal%></th>
642 <th class="cbi-section-table-cell"><%:Noise%></th>
643 <th class="cbi-section-table-cell"><%:RX Rate%></th>
644 <th class="cbi-section-table-cell"><%:TX Rate%></th>
646 <tr class="cbi-section-table-row">
647 <td colspan="7"><em><br /><%:Collecting data...%></em></td>
657 local plugins = nixio.fs.dir(luci.util.libpath() .. "/view/admin_status/index")
660 for inc in plugins do
661 if inc:match("%.htm$") then
662 include("admin_status/index/" .. inc:gsub("%.htm$", ""))