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
23 local sysinfo = luci.util.ubus("system", "info") or { }
24 local boardinfo = luci.util.ubus("system", "board") or { }
26 local meminfo = sysinfo.memory or {
33 local swapinfo = sysinfo.swap or {
38 local has_dsl = luci.fs.stat("/etc/init.d/dsl_control")
40 if luci.http.formvalue("status") == "1" then
41 local ntm = require "luci.model.network".init()
42 local wan = ntm:get_wannet()
43 local wan6 = ntm:get_wan6net()
45 local conn_count = tonumber((
46 luci.sys.exec("wc -l /proc/net/nf_conntrack") or
47 luci.sys.exec("wc -l /proc/net/ip_conntrack") or
48 ""):match("%d+")) or 0
50 local conn_max = tonumber((
51 luci.sys.exec("sysctl net.nf_conntrack_max") or
52 luci.sys.exec("sysctl net.ipv4.netfilter.ip_conntrack_max") or
53 ""):match("%d+")) or 4096
56 uptime = sysinfo.uptime or 0,
57 localtime = sysinfo.localtime or 0,
58 loadavg = sysinfo.load or { 0, 0, 0 },
62 conncount = conn_count,
63 leases = luci.tools.status.dhcp_leases(),
64 leases6 = luci.tools.status.dhcp6_leases(),
65 wifinets = luci.tools.status.wifi_networks()
70 ipaddr = wan:ipaddr(),
71 gwaddr = wan:gwaddr(),
72 netmask = wan:netmask(),
74 expires = wan:expires(),
75 uptime = wan:uptime(),
77 ifname = wan:ifname(),
78 link = wan:adminlink()
84 ip6addr = wan6:ip6addr(),
85 gw6addr = wan6:gw6addr(),
86 dns = wan6:dns6addrs(),
87 uptime = wan6:uptime(),
88 ifname = wan6:ifname(),
89 link = wan6:adminlink()
94 local dsl_stat = luci.sys.exec("/etc/init.d/dsl_control lucistat")
95 local dsl_func = loadstring(dsl_stat)
99 luci.http.prepare_content("application/json")
100 luci.http.write_json(rv)
108 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
109 <script type="text/javascript">//<![CDATA[
110 function progressbar(v, m)
112 var vn = parseInt(v) || 0;
113 var mn = parseInt(m) || 100;
114 var pc = Math.floor((100 / mn) * vn);
116 return String.format(
117 '<div style="width:200px; position:relative; border:1px solid #999999">' +
118 '<div style="background-color:#CCCCCC; width:%d%%; height:15px">' +
119 '<div style="position:absolute; left:0; top:0; text-align:center; width:100%%; color:#000000">' +
120 '<small>%s / %s (%d%%)</small>' +
123 '</div>', pc, v, m, pc
127 var wifidevs = <%=luci.http.write_json(netdevs)%>;
128 var arptable = <%=luci.http.write_json(arpcache)%>;
130 XHR.poll(5, '<%=REQUEST_URI%>', { status: 1 },
133 var si = document.getElementById('wan4_i');
134 var ss = document.getElementById('wan4_s');
137 if (ifc && ifc.ifname && ifc.proto != 'none')
139 var s = String.format(
140 '<strong><%:Type%>: </strong>%s<br />' +
141 '<strong><%:Address%>: </strong>%s<br />' +
142 '<strong><%:Netmask%>: </strong>%s<br />' +
143 '<strong><%:Gateway%>: </strong>%s<br />',
145 (ifc.ipaddr) ? ifc.ipaddr : '0.0.0.0',
146 (ifc.netmask && ifc.netmask != ifc.ipaddr) ? ifc.netmask : '255.255.255.255',
147 (ifc.gwaddr) ? ifc.gwaddr : '0.0.0.0'
150 for (var i = 0; i < ifc.dns.length; i++)
153 '<strong><%:DNS%> %d: </strong>%s<br />',
158 if (ifc.expires > -1)
161 '<strong><%:Expires%>: </strong>%t<br />',
169 '<strong><%:Connected%>: </strong>%t<br />',
174 ss.innerHTML = String.format('<small>%s</small>', s);
175 si.innerHTML = String.format(
176 '<img src="<%=resource%>/icons/ethernet.png" />' +
177 '<br /><small><a href="%s">%s</a></small>',
183 si.innerHTML = '<img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small>';
184 ss.innerHTML = '<em><%:Not connected%></em>';
187 <% if has_ipv6 then %>
188 var si6 = document.getElementById('wan6_i');
189 var ss6 = document.getElementById('wan6_s');
190 var ifc6 = info.wan6;
192 if (ifc6 && ifc6.ifname && ifc6.proto != 'none')
194 var s = String.format(
195 '<strong><%:Address%>: </strong>%s<br />' +
196 '<strong><%:Gateway%>: </strong>%s<br />',
197 (ifc6.ip6addr) ? ifc6.ip6addr : '::',
198 (ifc6.gw6addr) ? ifc6.gw6addr : '::'
201 for (var i = 0; i < ifc6.dns.length; i++)
204 '<strong><%:DNS%> %d: </strong>%s<br />',
212 '<strong><%:Connected%>: </strong>%t<br />',
217 ss6.innerHTML = String.format('<small>%s</small>', s);
218 si6.innerHTML = String.format(
219 '<img src="<%=resource%>/icons/ethernet.png" />' +
220 '<br /><small><a href="%s">%s</a></small>',
221 ifc6.link, ifc6.ifname
226 si6.innerHTML = '<img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small>';
227 ss6.innerHTML = '<em><%:Not connected%></em>';
231 <% if has_dsl then %>
232 var dsl_i = document.getElementById('dsl_i');
233 var dsl_s = document.getElementById('dsl_s');
235 var s = String.format(
236 '<strong><%:Status%>: </strong>%s<br />' +
237 '<strong><%:Line State%>: </strong>%s [0x%x]<br />' +
238 '<strong><%:Line Speed%>: </strong>%s/s / %s/s<br />' +
239 '<strong><%:Line Attenuation%>: </strong>%s dB / %s dB<br />' +
240 '<strong><%:Noise Margin%>: </strong>%s dB / %s dB<br />',
241 info.dsl.line_state, info.dsl.line_state_detail,
242 info.dsl.line_state_num,
243 info.dsl.data_rate_down_s, info.dsl.data_rate_up_s,
244 info.dsl.line_attenuation_down, info.dsl.line_attenuation_up,
245 info.dsl.noise_margin_down, info.dsl.noise_margin_up
248 dsl_s.innerHTML = String.format('<small>%s</small>', s);
249 dsl_i.innerHTML = String.format(
250 '<img src="<%=resource%>/icons/ethernet.png" />' +
251 '<br /><small>ADSL</small>'
255 <% if has_dhcp then %>
256 var ls = document.getElementById('lease_status_table');
260 while( ls.rows.length > 1 )
261 ls.rows[0].parentNode.deleteRow(1);
263 for( var i = 0; i < info.leases.length; i++ )
267 if (info.leases[i].expires <= 0)
268 timestr = '<em><%:expired%></em>';
270 timestr = String.format('%t', info.leases[i].expires);
272 var tr = ls.rows[0].parentNode.insertRow(-1);
273 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
275 tr.insertCell(-1).innerHTML = info.leases[i].hostname ? info.leases[i].hostname : '?';
276 tr.insertCell(-1).innerHTML = info.leases[i].ipaddr;
277 tr.insertCell(-1).innerHTML = info.leases[i].macaddr;
278 tr.insertCell(-1).innerHTML = timestr;
281 if( ls.rows.length == 1 )
283 var tr = ls.rows[0].parentNode.insertRow(-1);
284 tr.className = 'cbi-section-table-row';
286 var td = tr.insertCell(-1);
288 td.innerHTML = '<em><br /><%:There are no active leases.%></em>';
292 var ls6 = document.getElementById('lease6_status_table');
293 if (ls6 && info.leases6)
295 ls6.parentNode.style.display = 'block';
298 while( ls6.rows.length > 1 )
299 ls6.rows[0].parentNode.deleteRow(1);
301 for( var i = 0; i < info.leases6.length; i++ )
305 if (info.leases6[i].expires <= 0)
306 timestr = '<em><%:expired%></em>';
308 timestr = String.format('%t', info.leases6[i].expires);
310 var tr = ls6.rows[0].parentNode.insertRow(-1);
311 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
313 tr.insertCell(-1).innerHTML = info.leases6[i].hostname ? info.leases6[i].hostname : '?';
314 tr.insertCell(-1).innerHTML = info.leases6[i].ip6addr;
315 tr.insertCell(-1).innerHTML = info.leases6[i].duid;
316 tr.insertCell(-1).innerHTML = timestr;
319 if( ls6.rows.length == 1 )
321 var tr = ls6.rows[0].parentNode.insertRow(-1);
322 tr.className = 'cbi-section-table-row';
324 var td = tr.insertCell(-1);
326 td.innerHTML = '<em><br /><%:There are no active leases.%></em>';
331 <% if has_wifi then %>
334 var ws = document.getElementById('wifi_status_table');
337 var wsbody = ws.rows[0].parentNode;
338 while (ws.rows.length > 0)
341 for (var didx = 0; didx < info.wifinets.length; didx++)
343 var dev = info.wifinets[didx];
345 var tr = wsbody.insertRow(-1);
348 td = tr.insertCell(-1);
350 td.innerHTML = dev.name;
351 td.style.verticalAlign = "top";
353 td = tr.insertCell(-1);
357 for (var nidx = 0; nidx < dev.networks.length; nidx++)
359 var net = dev.networks[nidx];
360 var is_assoc = (net.bssid != '00:00:00:00:00:00' && net.channel);
364 icon = "<%=resource%>/icons/signal-none.png";
365 else if (net.quality == 0)
366 icon = "<%=resource%>/icons/signal-0.png";
367 else if (net.quality < 25)
368 icon = "<%=resource%>/icons/signal-0-25.png";
369 else if (net.quality < 50)
370 icon = "<%=resource%>/icons/signal-25-50.png";
371 else if (net.quality < 75)
372 icon = "<%=resource%>/icons/signal-50-75.png";
374 icon = "<%=resource%>/icons/signal-75-100.png";
377 '<table><tr><td style="text-align:center; width:32px; padding:3px">' +
378 '<img src="%s" title="<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" />' +
379 '<br /><small>%d%%</small>' +
380 '</td><td style="text-align:left; padding:3px"><small>' +
381 '<strong><%:SSID%>:</strong> <a href="%s">%h</a><br />' +
382 '<strong><%:Mode%>:</strong> %s<br />' +
383 '<strong><%:Channel%>:</strong> %d (%.3f <%:GHz%>)<br />' +
384 '<strong><%:Bitrate%>:</strong> %s <%:Mbit/s%><br />',
385 icon, net.signal, net.noise,
389 net.channel, net.frequency,
396 '<strong><%:BSSID%>:</strong> %s<br />' +
397 '<strong><%:Encryption%>:</strong> %s',
404 s += '<em><%:Wireless is disabled or not associated%></em>';
407 s += '</small></td></tr></table>';
409 for (var bssid in net.assoclist)
413 signal: net.assoclist[bssid].signal,
414 noise: net.assoclist[bssid].noise,
415 rx_rate: net.assoclist[bssid].rx_rate,
416 rx_mcs: net.assoclist[bssid].rx_mcs,
417 rx_40mhz: net.assoclist[bssid].rx_40mhz,
418 tx_rate: net.assoclist[bssid].tx_rate,
419 tx_mcs: net.assoclist[bssid].tx_mcs,
420 tx_40mhz: net.assoclist[bssid].tx_40mhz,
428 s = '<em><%:No information available%></em>';
434 var ac = document.getElementById('wifi_assoc_table');
438 while( ac.rows.length > 1 )
439 ac.rows[0].parentNode.deleteRow(1);
441 assoclist.sort(function(a, b) {
442 return (a.name == b.name)
443 ? (a.bssid < b.bssid)
448 for( var i = 0; i < assoclist.length; i++ )
450 var tr = ac.rows[0].parentNode.insertRow(-1);
451 tr.className = 'cbi-section-table-row cbi-rowstyle-' + (1 + (i % 2));
454 var q = (-1 * (assoclist[i].noise - assoclist[i].signal)) / 5;
456 icon = "<%=resource%>/icons/signal-0.png";
458 icon = "<%=resource%>/icons/signal-0-25.png";
460 icon = "<%=resource%>/icons/signal-25-50.png";
462 icon = "<%=resource%>/icons/signal-50-75.png";
464 icon = "<%=resource%>/icons/signal-75-100.png";
466 tr.insertCell(-1).innerHTML = String.format(
467 '<img src="%s" title="<%:Signal%>: %d <%:dBm%> / <%:Noise%>: %d <%:dBm%>" />',
468 icon, assoclist[i].signal, assoclist[i].noise
471 tr.insertCell(-1).innerHTML = assoclist[i].bssid;
473 tr.insertCell(-1).innerHTML = String.format(
474 '<a href="%s">%s</a>',
476 '%h'.format(assoclist[i].name).nobr()
479 tr.insertCell(-1).innerHTML = String.format('%d <%:dBm%>', assoclist[i].signal).nobr();
480 tr.insertCell(-1).innerHTML = String.format('%d <%:dBm%>', assoclist[i].noise).nobr();
482 tr.insertCell(-1).innerHTML = (assoclist[i].rx_mcs > -1)
483 ? 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()
484 : String.format('%.1f <%:Mbit/s%>', assoclist[i].rx_rate / 1000).nobr()
487 tr.insertCell(-1).innerHTML = (assoclist[i].tx_mcs > -1)
488 ? 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()
489 : String.format('%.1f <%:Mbit/s%>', assoclist[i].tx_rate / 1000).nobr()
493 if (ac.rows.length == 1)
495 var tr = ac.rows[0].parentNode.insertRow(-1);
496 tr.className = 'cbi-section-table-row';
498 var td = tr.insertCell(-1);
500 td.innerHTML = '<br /><em><%:No information available%></em>';
507 if (e = document.getElementById('localtime'))
508 e.innerHTML = (new Date(info.localtime * 1000)).toUTCString();
510 if (e = document.getElementById('uptime'))
511 e.innerHTML = String.format('%t', info.uptime);
513 if (e = document.getElementById('loadavg'))
514 e.innerHTML = String.format(
515 '%.02f, %.02f, %.02f',
516 info.loadavg[0] / 65535.0,
517 info.loadavg[1] / 65535.0,
518 info.loadavg[2] / 65535.0
521 if (e = document.getElementById('memtotal'))
522 e.innerHTML = progressbar(
523 ((info.memory.free + info.memory.buffered) / 1024) + " <%:kB%>",
524 (info.memory.total / 1024) + " <%:kB%>"
527 if (e = document.getElementById('memfree'))
528 e.innerHTML = progressbar(
529 (info.memory.free / 1024) + " <%:kB%>",
530 (info.memory.total / 1024) + " <%:kB%>"
533 if (e = document.getElementById('membuff'))
534 e.innerHTML = progressbar(
535 (info.memory.buffered / 1024) + " <%:kB%>",
536 (info.memory.total / 1024) + " <%:kB%>"
539 if (e = document.getElementById('swaptotal'))
540 e.innerHTML = progressbar(
541 (info.swap.free / 1024) + " <%:kB%>",
542 (info.swap.total / 1024) + " <%:kB%>"
545 if (e = document.getElementById('swapfree'))
546 e.innerHTML = progressbar(
547 (info.swap.free / 1024) + " <%:kB%>",
548 (info.swap.total / 1024) + " <%:kB%>"
551 if (e = document.getElementById('conns'))
552 e.innerHTML = progressbar(info.conncount, info.connmax);
558 <h2><a id="content" name="content"><%:Status%></a></h2>
560 <fieldset class="cbi-section">
561 <legend><%:System%></legend>
563 <table width="100%" cellspacing="10">
564 <tr><td width="33%"><%:Hostname%></td><td><%=luci.sys.hostname() or "?"%></td></tr>
565 <tr><td width="33%"><%:Model%></td><td><%=pcdata(boardinfo.model or boardinfo.system or "?")%></td></tr>
566 <tr><td width="33%"><%:Firmware Version%></td><td>
567 <%=pcdata(luci.version.distname)%> <%=pcdata(luci.version.distversion)%> /
568 <%=pcdata(luci.version.luciname)%> (<%=pcdata(luci.version.luciversion)%>)
570 <tr><td width="33%"><%:Kernel Version%></td><td><%=luci.sys.exec("uname -r")%></td></tr>
571 <tr><td width="33%"><%:Local Time%></td><td id="localtime">-</td></tr>
572 <tr><td width="33%"><%:Uptime%></td><td id="uptime">-</td></tr>
573 <tr><td width="33%"><%:Load Average%></td><td id="loadavg">-</td></tr>
577 <fieldset class="cbi-section">
578 <legend><%:Memory%></legend>
580 <table width="100%" cellspacing="10">
581 <tr><td width="33%"><%:Total Available%></td><td id="memtotal">-</td></tr>
582 <tr><td width="33%"><%:Free%></td><td id="memfree">-</td></tr>
583 <tr><td width="33%"><%:Buffered%></td><td id="membuff">-</td></tr>
587 <% if swapinfo.total > 0 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>
598 <fieldset class="cbi-section">
599 <legend><%:Network%></legend>
601 <table width="100%" cellspacing="10">
602 <tr><td width="33%" style="vertical-align:top"><%:IPv4 WAN Status%></td><td>
604 <td id="wan4_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td>
605 <td id="wan4_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></td>
608 <% if has_ipv6 then %>
609 <tr><td width="33%" style="vertical-align:top"><%:IPv6 WAN Status%></td><td>
611 <td id="wan6_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td>
612 <td id="wan6_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></td>
616 <tr><td width="33%"><%:Active Connections%></td><td id="conns">-</td></tr>
620 <% if has_dhcp then %>
621 <fieldset class="cbi-section">
622 <legend><%:DHCP Leases%></legend>
624 <table class="cbi-section-table" id="lease_status_table">
625 <tr class="cbi-section-table-titles">
626 <th class="cbi-section-table-cell"><%:Hostname%></th>
627 <th class="cbi-section-table-cell"><%:IPv4-Address%></th>
628 <th class="cbi-section-table-cell"><%:MAC-Address%></th>
629 <th class="cbi-section-table-cell"><%:Leasetime remaining%></th>
631 <tr class="cbi-section-table-row">
632 <td colspan="4"><em><br /><%:Collecting data...%></em></td>
637 <fieldset class="cbi-section" style="display:none">
638 <legend><%:DHCPv6 Leases%></legend>
640 <table class="cbi-section-table" id="lease6_status_table">
641 <tr class="cbi-section-table-titles">
642 <th class="cbi-section-table-cell"><%:Hostname%></th>
643 <th class="cbi-section-table-cell"><%:IPv6-Address%></th>
644 <th class="cbi-section-table-cell"><%:DUID%></th>
645 <th class="cbi-section-table-cell"><%:Leasetime remaining%></th>
647 <tr class="cbi-section-table-row">
648 <td colspan="4"><em><br /><%:Collecting data...%></em></td>
654 <% if has_dsl then %>
655 <fieldset class="cbi-section">
656 <legend><%:ADSL%></legend>
657 <table width="100%" cellspacing="10">
658 <tr><td width="33%" style="vertical-align:top"><%:ADSL Status%></td><td>
660 <td id="dsl_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td>
661 <td id="dsl_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></td>
668 <% if has_wifi then %>
669 <fieldset class="cbi-section">
670 <legend><%:Wireless%></legend>
672 <table id="wifi_status_table" width="100%" cellspacing="10">
673 <tr><td><em><%:Collecting data...%></em></td></tr>
677 <fieldset class="cbi-section">
678 <legend><%:Associated Stations%></legend>
680 <table class="cbi-section-table" id="wifi_assoc_table">
681 <tr class="cbi-section-table-titles">
682 <th class="cbi-section-table-cell"> </th>
683 <th class="cbi-section-table-cell"><%:MAC-Address%></th>
684 <th class="cbi-section-table-cell"><%:Network%></th>
685 <th class="cbi-section-table-cell"><%:Signal%></th>
686 <th class="cbi-section-table-cell"><%:Noise%></th>
687 <th class="cbi-section-table-cell"><%:RX Rate%></th>
688 <th class="cbi-section-table-cell"><%:TX Rate%></th>
690 <tr class="cbi-section-table-row">
691 <td colspan="7"><em><br /><%:Collecting data...%></em></td>
701 local plugins = nixio.fs.dir(luci.util.libpath() .. "/view/admin_status/index")
704 for inc in plugins do
705 if inc:match("%.htm$") then
706 include("admin_status/index/" .. inc:gsub("%.htm$", ""))