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()
27 local has_dsl = luci.fs.stat("/etc/init.d/dsl_control")
29 if luci.http.formvalue("status") == "1" then
30 local ntm = require "luci.model.network".init()
31 local wan = ntm:get_wannet()
32 local wan6 = ntm:get_wan6net()
34 local conn_count = tonumber((
35 luci.sys.exec("wc -l /proc/net/nf_conntrack") or
36 luci.sys.exec("wc -l /proc/net/ip_conntrack") or
37 ""):match("%d+")) or 0
39 local conn_max = tonumber((
40 luci.sys.exec("sysctl net.nf_conntrack_max") or
41 luci.sys.exec("sysctl net.ipv4.netfilter.ip_conntrack_max") or
42 ""):match("%d+")) or 4096
45 uptime = luci.sys.uptime(),
46 localtime = os.date(),
47 loadavg = { luci.sys.loadavg() },
49 memcached = memcached,
50 membuffers = membuffers,
52 swaptotal = swaptotal,
53 swapcached = swapcached,
56 conncount = conn_count,
57 leases = luci.tools.status.dhcp_leases(),
58 leases6 = luci.tools.status.dhcp6_leases(),
59 wifinets = luci.tools.status.wifi_networks()
64 ipaddr = wan:ipaddr(),
65 gwaddr = wan:gwaddr(),
66 netmask = wan:netmask(),
68 expires = wan:expires(),
69 uptime = wan:uptime(),
71 ifname = wan:ifname(),
72 link = wan:adminlink()
78 ip6addr = wan6:ip6addr(),
79 gw6addr = wan6:gw6addr(),
80 dns = wan6:dns6addrs(),
81 uptime = wan6:uptime(),
82 ifname = wan6:ifname(),
83 link = wan6:adminlink()
88 local dsl_stat = luci.sys.exec("/etc/init.d/dsl_control lucistat")
89 local dsl_func = loadstring(dsl_stat)
93 luci.http.prepare_content("application/json")
94 luci.http.write_json(rv)
99 local system, model = luci.sys.sysinfo()
104 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
105 <script type="text/javascript">//<![CDATA[
106 function progressbar(v, m)
108 var vn = parseInt(v) || 0;
109 var mn = parseInt(m) || 100;
110 var pc = Math.floor((100 / mn) * vn);
112 return String.format(
113 '<div style="width:200px; position:relative; border:1px solid #999999">' +
114 '<div style="background-color:#CCCCCC; width:%d%%; height:15px">' +
115 '<div style="position:absolute; left:0; top:0; text-align:center; width:100%%; color:#000000">' +
116 '<small>%s / %s (%d%%)</small>' +
119 '</div>', pc, v, m, pc
123 var wifidevs = <%=luci.http.write_json(netdevs)%>;
124 var arptable = <%=luci.http.write_json(arpcache)%>;
126 XHR.poll(5, '<%=REQUEST_URI%>', { status: 1 },
129 var si = document.getElementById('wan4_i');
130 var ss = document.getElementById('wan4_s');
133 if (ifc && ifc.ifname && ifc.proto != 'none')
135 var s = String.format(
136 '<strong><%:Type%>: </strong>%s<br />' +
137 '<strong><%:Address%>: </strong>%s<br />' +
138 '<strong><%:Netmask%>: </strong>%s<br />' +
139 '<strong><%:Gateway%>: </strong>%s<br />',
141 (ifc.ipaddr) ? ifc.ipaddr : '0.0.0.0',
142 (ifc.netmask && ifc.netmask != ifc.ipaddr) ? ifc.netmask : '255.255.255.255',
143 (ifc.gwaddr) ? ifc.gwaddr : '0.0.0.0'
146 for (var i = 0; i < ifc.dns.length; i++)
149 '<strong><%:DNS%> %d: </strong>%s<br />',
154 if (ifc.expires > -1)
157 '<strong><%:Expires%>: </strong>%t<br />',
165 '<strong><%:Connected%>: </strong>%t<br />',
170 ss.innerHTML = String.format('<small>%s</small>', s);
171 si.innerHTML = String.format(
172 '<img src="<%=resource%>/icons/ethernet.png" />' +
173 '<br /><small><a href="%s">%s</a></small>',
179 si.innerHTML = '<img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small>';
180 ss.innerHTML = '<em><%:Not connected%></em>';
183 <% if has_ipv6 then %>
184 var si6 = document.getElementById('wan6_i');
185 var ss6 = document.getElementById('wan6_s');
186 var ifc6 = info.wan6;
188 if (ifc6 && ifc6.ifname && ifc6.proto != 'none')
190 var s = String.format(
191 '<strong><%:Address%>: </strong>%s<br />' +
192 '<strong><%:Gateway%>: </strong>%s<br />',
193 (ifc6.ip6addr) ? ifc6.ip6addr : '::',
194 (ifc6.gw6addr) ? ifc6.gw6addr : '::'
197 for (var i = 0; i < ifc6.dns.length; i++)
200 '<strong><%:DNS%> %d: </strong>%s<br />',
208 '<strong><%:Connected%>: </strong>%t<br />',
213 ss6.innerHTML = String.format('<small>%s</small>', s);
214 si6.innerHTML = String.format(
215 '<img src="<%=resource%>/icons/ethernet.png" />' +
216 '<br /><small><a href="%s">%s</a></small>',
217 ifc6.link, ifc6.ifname
222 si6.innerHTML = '<img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small>';
223 ss6.innerHTML = '<em><%:Not connected%></em>';
227 <% if has_dsl then %>
228 var dsl_i = document.getElementById('dsl_i');
229 var dsl_s = document.getElementById('dsl_s');
231 var s = String.format(
232 '<strong><%:Status%>: </strong>%s<br />' +
233 '<strong><%:Line State%>: </strong>%s [0x%x]<br />' +
234 '<strong><%:Line Speed%>: </strong>%s/s / %s/s<br />' +
235 '<strong><%:Line Attenuation%>: </strong>%s dB / %s dB<br />' +
236 '<strong><%:Noise Margin%>: </strong>%s dB / %s dB<br />',
237 info.dsl.line_state, info.dsl.line_state_detail,
238 info.dsl.line_state_num,
239 info.dsl.data_rate_down_s, info.dsl.data_rate_up_s,
240 info.dsl.line_attenuation_down, info.dsl.line_attenuation_up,
241 info.dsl.noise_margin_down, info.dsl.noise_margin_up
244 dsl_s.innerHTML = String.format('<small>%s</small>', s);
245 dsl_i.innerHTML = String.format(
246 '<img src="<%=resource%>/icons/ethernet.png" />' +
247 '<br /><small>ADSL</small>'
251 <% if has_dhcp then %>
252 var ls = document.getElementById('lease_status_table');
256 while( ls.rows.length > 1 )
257 ls.rows[0].parentNode.deleteRow(1);
259 for( var i = 0; i < info.leases.length; i++ )
263 if (info.leases[i].expires <= 0)
264 timestr = '<em><%:expired%></em>';
266 timestr = String.format('%t', info.leases[i].expires);
268 var tr = ls.rows[0].parentNode.insertRow(-1);
269 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
271 tr.insertCell(-1).innerHTML = info.leases[i].hostname ? info.leases[i].hostname : '?';
272 tr.insertCell(-1).innerHTML = info.leases[i].ipaddr;
273 tr.insertCell(-1).innerHTML = info.leases[i].macaddr;
274 tr.insertCell(-1).innerHTML = timestr;
277 if( ls.rows.length == 1 )
279 var tr = ls.rows[0].parentNode.insertRow(-1);
280 tr.className = 'cbi-section-table-row';
282 var td = tr.insertCell(-1);
284 td.innerHTML = '<em><br /><%:There are no active leases.%></em>';
288 var ls6 = document.getElementById('lease6_status_table');
289 if (ls6 && info.leases6)
291 ls6.parentNode.style.display = 'block';
294 while( ls6.rows.length > 1 )
295 ls6.rows[0].parentNode.deleteRow(1);
297 for( var i = 0; i < info.leases6.length; i++ )
301 if (info.leases6[i].expires <= 0)
302 timestr = '<em><%:expired%></em>';
304 timestr = String.format('%t', info.leases6[i].expires);
306 var tr = ls6.rows[0].parentNode.insertRow(-1);
307 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
309 tr.insertCell(-1).innerHTML = info.leases6[i].hostname ? info.leases6[i].hostname : '?';
310 tr.insertCell(-1).innerHTML = info.leases6[i].ip6addr;
311 tr.insertCell(-1).innerHTML = info.leases6[i].duid;
312 tr.insertCell(-1).innerHTML = timestr;
315 if( ls6.rows.length == 1 )
317 var tr = ls6.rows[0].parentNode.insertRow(-1);
318 tr.className = 'cbi-section-table-row';
320 var td = tr.insertCell(-1);
322 td.innerHTML = '<em><br /><%:There are no active leases.%></em>';
327 <% if has_wifi then %>
330 var ws = document.getElementById('wifi_status_table');
333 var wsbody = ws.rows[0].parentNode;
334 while (ws.rows.length > 0)
337 for (var didx = 0; didx < info.wifinets.length; didx++)
339 var dev = info.wifinets[didx];
341 var tr = wsbody.insertRow(-1);
344 td = tr.insertCell(-1);
346 td.innerHTML = dev.name;
347 td.style.verticalAlign = "top";
349 td = tr.insertCell(-1);
353 for (var nidx = 0; nidx < dev.networks.length; nidx++)
355 var net = dev.networks[nidx];
356 var is_assoc = (net.bssid != '00:00:00:00:00:00' && net.channel);
360 icon = "<%=resource%>/icons/signal-none.png";
361 else if (net.quality == 0)
362 icon = "<%=resource%>/icons/signal-0.png";
363 else if (net.quality < 25)
364 icon = "<%=resource%>/icons/signal-0-25.png";
365 else if (net.quality < 50)
366 icon = "<%=resource%>/icons/signal-25-50.png";
367 else if (net.quality < 75)
368 icon = "<%=resource%>/icons/signal-50-75.png";
370 icon = "<%=resource%>/icons/signal-75-100.png";
373 '<table><tr><td style="text-align:center; width:32px; padding:3px">' +
374 '<img src="%s" title="<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" />' +
375 '<br /><small>%d%%</small>' +
376 '</td><td style="text-align:left; padding:3px"><small>' +
377 '<strong><%:SSID%>:</strong> <a href="%s">%h</a><br />' +
378 '<strong><%:Mode%>:</strong> %s<br />' +
379 '<strong><%:Channel%>:</strong> %d (%.3f <%:GHz%>)<br />' +
380 '<strong><%:Bitrate%>:</strong> %s <%:Mbit/s%><br />',
381 icon, net.signal, net.noise,
385 net.channel, net.frequency,
392 '<strong><%:BSSID%>:</strong> %s<br />' +
393 '<strong><%:Encryption%>:</strong> %s',
400 s += '<em><%:Wireless is disabled or not associated%></em>';
403 s += '</small></td></tr></table>';
405 for (var bssid in net.assoclist)
409 signal: net.assoclist[bssid].signal,
410 noise: net.assoclist[bssid].noise,
411 rx_rate: net.assoclist[bssid].rx_rate,
412 rx_mcs: net.assoclist[bssid].rx_mcs,
413 rx_40mhz: net.assoclist[bssid].rx_40mhz,
414 tx_rate: net.assoclist[bssid].tx_rate,
415 tx_mcs: net.assoclist[bssid].tx_mcs,
416 tx_40mhz: net.assoclist[bssid].tx_40mhz,
424 s = '<em><%:No information available%></em>';
430 var ac = document.getElementById('wifi_assoc_table');
434 while( ac.rows.length > 1 )
435 ac.rows[0].parentNode.deleteRow(1);
437 assoclist.sort(function(a, b) {
438 return (a.name == b.name)
439 ? (a.bssid < b.bssid)
444 for( var i = 0; i < assoclist.length; i++ )
446 var tr = ac.rows[0].parentNode.insertRow(-1);
447 tr.className = 'cbi-section-table-row cbi-rowstyle-' + (1 + (i % 2));
450 var q = (-1 * (assoclist[i].noise - assoclist[i].signal)) / 5;
452 icon = "<%=resource%>/icons/signal-0.png";
454 icon = "<%=resource%>/icons/signal-0-25.png";
456 icon = "<%=resource%>/icons/signal-25-50.png";
458 icon = "<%=resource%>/icons/signal-50-75.png";
460 icon = "<%=resource%>/icons/signal-75-100.png";
462 tr.insertCell(-1).innerHTML = String.format(
463 '<img src="%s" title="<%:Signal%>: %d <%:dBm%> / <%:Noise%>: %d <%:dBm%>" />',
464 icon, assoclist[i].signal, assoclist[i].noise
467 tr.insertCell(-1).innerHTML = assoclist[i].bssid;
469 tr.insertCell(-1).innerHTML = String.format(
470 '<a href="%s">%s</a>',
472 '%h'.format(assoclist[i].name).nobr()
475 tr.insertCell(-1).innerHTML = String.format('%d <%:dBm%>', assoclist[i].signal).nobr();
476 tr.insertCell(-1).innerHTML = String.format('%d <%:dBm%>', assoclist[i].noise).nobr();
478 tr.insertCell(-1).innerHTML = (assoclist[i].rx_mcs > -1)
479 ? 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()
480 : String.format('%.1f <%:Mbit/s%>', assoclist[i].rx_rate / 1000).nobr()
483 tr.insertCell(-1).innerHTML = (assoclist[i].tx_mcs > -1)
484 ? 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()
485 : String.format('%.1f <%:Mbit/s%>', assoclist[i].tx_rate / 1000).nobr()
489 if (ac.rows.length == 1)
491 var tr = ac.rows[0].parentNode.insertRow(-1);
492 tr.className = 'cbi-section-table-row';
494 var td = tr.insertCell(-1);
496 td.innerHTML = '<br /><em><%:No information available%></em>';
503 if (e = document.getElementById('localtime'))
504 e.innerHTML = info.localtime;
506 if (e = document.getElementById('uptime'))
507 e.innerHTML = String.format('%t', info.uptime);
509 if (e = document.getElementById('loadavg'))
510 e.innerHTML = String.format('%.02f, %.02f, %.02f',
511 info.loadavg[0], info.loadavg[1], info.loadavg[2]);
513 if (e = document.getElementById('memtotal'))
514 e.innerHTML = progressbar(
515 (info.memfree + info.membuffers + info.memcached) + " <%:kB%>",
516 info.memtotal + " <%:kB%>"
519 if (e = document.getElementById('memfree'))
520 e.innerHTML = progressbar(
521 info.memfree + " <%:kB%>", info.memtotal + " <%:kB%>"
524 if (e = document.getElementById('memcache'))
525 e.innerHTML = progressbar(
526 info.memcached + " <%:kB%>", info.memtotal + " <%:kB%>"
529 if (e = document.getElementById('membuff'))
530 e.innerHTML = progressbar(
531 info.membuffers + " <%:kB%>", info.memtotal + " <%:kB%>"
534 if (e = document.getElementById('swapcache'))
535 e.innerHTML = progressbar(
536 info.swapcached + " <%:kB%>", info.swaptotal + " <%:kB%>"
539 if (e = document.getElementById('swaptotal'))
540 e.innerHTML = progressbar(
541 (info.swapfree + info.swapcached) + " <%:kB%>",
542 info.swaptotal + " <%:kB%>"
545 if (e = document.getElementById('swapfree'))
546 e.innerHTML = progressbar(
547 info.swapfree + " <%:kB%>", info.swaptotal + " <%:kB%>"
550 if (e = document.getElementById('conns'))
551 e.innerHTML = progressbar(info.conncount, info.connmax);
557 <h2><a id="content" name="content"><%:Status%></a></h2>
559 <fieldset class="cbi-section">
560 <legend><%:System%></legend>
562 <table width="100%" cellspacing="10">
563 <tr><td width="33%"><%:Hostname%></td><td><%=luci.sys.hostname() or "?"%></td></tr>
564 <tr><td width="33%"><%:Model%></td><td><%=pcdata(model or "?")%></td></tr>
565 <tr><td width="33%"><%:Firmware Version%></td><td>
566 <%=pcdata(luci.version.distname)%> <%=pcdata(luci.version.distversion)%> /
567 <%=pcdata(luci.version.luciname)%> (<%=pcdata(luci.version.luciversion)%>)
569 <tr><td width="33%"><%:Kernel Version%></td><td><%=luci.sys.exec("uname -r")%></td></tr>
570 <tr><td width="33%"><%:Local Time%></td><td id="localtime">-</td></tr>
571 <tr><td width="33%"><%:Uptime%></td><td id="uptime">-</td></tr>
572 <tr><td width="33%"><%:Load Average%></td><td id="loadavg">-</td></tr>
576 <fieldset class="cbi-section">
577 <legend><%:Memory%></legend>
579 <table width="100%" cellspacing="10">
580 <tr><td width="33%"><%:Total Available%></td><td id="memtotal">-</td></tr>
581 <tr><td width="33%"><%:Free%></td><td id="memfree">-</td></tr>
582 <tr><td width="33%"><%:Cached%></td><td id="memcache">-</td></tr>
583 <tr><td width="33%"><%:Buffered%></td><td id="membuff">-</td></tr>
587 <% if has_swap then %>
588 <fieldset class="cbi-section">
589 <legend><%:Swap%></legend>
591 <table width="100%" cellspacing="10">
592 <tr><td width="33%"><%:Total Available%></td><td id="swaptotal">-</td></tr>
593 <tr><td width="33%"><%:Free%></td><td id="swapfree">-</td></tr>
594 <tr><td width="33%"><%:Cached%></td><td id="swapcache">-</td></tr>
599 <fieldset class="cbi-section">
600 <legend><%:Network%></legend>
602 <table width="100%" cellspacing="10">
603 <tr><td width="33%" style="vertical-align:top"><%:IPv4 WAN Status%></td><td>
605 <td id="wan4_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td>
606 <td id="wan4_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></td>
609 <% if has_ipv6 then %>
610 <tr><td width="33%" style="vertical-align:top"><%:IPv6 WAN Status%></td><td>
612 <td id="wan6_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td>
613 <td id="wan6_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></td>
617 <tr><td width="33%"><%:Active Connections%></td><td id="conns">-</td></tr>
621 <% if has_dhcp then %>
622 <fieldset class="cbi-section">
623 <legend><%:DHCP Leases%></legend>
625 <table class="cbi-section-table" id="lease_status_table">
626 <tr class="cbi-section-table-titles">
627 <th class="cbi-section-table-cell"><%:Hostname%></th>
628 <th class="cbi-section-table-cell"><%:IPv4-Address%></th>
629 <th class="cbi-section-table-cell"><%:MAC-Address%></th>
630 <th class="cbi-section-table-cell"><%:Leasetime remaining%></th>
632 <tr class="cbi-section-table-row">
633 <td colspan="4"><em><br /><%:Collecting data...%></em></td>
638 <fieldset class="cbi-section" style="display:none">
639 <legend><%:DHCPv6 Leases%></legend>
641 <table class="cbi-section-table" id="lease6_status_table">
642 <tr class="cbi-section-table-titles">
643 <th class="cbi-section-table-cell"><%:Hostname%></th>
644 <th class="cbi-section-table-cell"><%:IPv6-Address%></th>
645 <th class="cbi-section-table-cell"><%:DUID%></th>
646 <th class="cbi-section-table-cell"><%:Leasetime remaining%></th>
648 <tr class="cbi-section-table-row">
649 <td colspan="4"><em><br /><%:Collecting data...%></em></td>
655 <% if has_dsl then %>
656 <fieldset class="cbi-section">
657 <legend><%:ADSL%></legend>
658 <table width="100%" cellspacing="10">
659 <tr><td width="33%" style="vertical-align:top"><%:ADSL Status%></td><td>
661 <td id="dsl_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td>
662 <td id="dsl_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></td>
669 <% if has_wifi then %>
670 <fieldset class="cbi-section">
671 <legend><%:Wireless%></legend>
673 <table id="wifi_status_table" width="100%" cellspacing="10">
674 <tr><td><em><%:Collecting data...%></em></td></tr>
678 <fieldset class="cbi-section">
679 <legend><%:Associated Stations%></legend>
681 <table class="cbi-section-table" id="wifi_assoc_table">
682 <tr class="cbi-section-table-titles">
683 <th class="cbi-section-table-cell"> </th>
684 <th class="cbi-section-table-cell"><%:MAC-Address%></th>
685 <th class="cbi-section-table-cell"><%:Network%></th>
686 <th class="cbi-section-table-cell"><%:Signal%></th>
687 <th class="cbi-section-table-cell"><%:Noise%></th>
688 <th class="cbi-section-table-cell"><%:RX Rate%></th>
689 <th class="cbi-section-table-cell"><%:TX Rate%></th>
691 <tr class="cbi-section-table-row">
692 <td colspan="7"><em><br /><%:Collecting data...%></em></td>
702 local plugins = nixio.fs.dir(luci.util.libpath() .. "/view/admin_status/index")
705 for inc in plugins do
706 if inc:match("%.htm$") then
707 include("admin_status/index/" .. inc:gsub("%.htm$", ""))