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
15 local fs = require "nixio.fs"
16 local util = require "luci.util"
17 local stat = require "luci.tools.status"
18 local ver = require "luci.version"
20 local has_ipv6 = fs.access("/proc/net/ipv6_route")
21 local has_dhcp = fs.access("/etc/config/dhcp")
22 local has_wifi = ((fs.stat("/etc/config/wireless", "size") or 0) > 0)
24 local sysinfo = luci.util.ubus("system", "info") or { }
25 local boardinfo = luci.util.ubus("system", "board") or { }
26 local unameinfo = nixio.uname() or { }
28 local meminfo = sysinfo.memory or {
35 local swapinfo = sysinfo.swap or {
40 local has_dsl = fs.access("/etc/init.d/dsl_control")
42 if luci.http.formvalue("status") == "1" then
43 local ntm = require "luci.model.network".init()
44 local wan = ntm:get_wannet()
45 local wan6 = ntm:get_wan6net()
47 local conn_count = tonumber((
48 luci.sys.exec("wc -l /proc/net/nf_conntrack") or
49 luci.sys.exec("wc -l /proc/net/ip_conntrack") or
50 ""):match("%d+")) or 0
52 local conn_max = tonumber((
53 luci.sys.exec("sysctl net.nf_conntrack_max") or
54 luci.sys.exec("sysctl net.ipv4.netfilter.ip_conntrack_max") or
55 ""):match("%d+")) or 4096
58 uptime = sysinfo.uptime or 0,
59 localtime = os.date(),
60 loadavg = sysinfo.load or { 0, 0, 0 },
64 conncount = conn_count,
65 leases = stat.dhcp_leases(),
66 leases6 = stat.dhcp6_leases(),
67 wifinets = stat.wifi_networks()
72 ipaddr = wan:ipaddr(),
73 gwaddr = wan:gwaddr(),
74 netmask = wan:netmask(),
76 expires = wan:expires(),
77 uptime = wan:uptime(),
79 ifname = wan:ifname(),
80 link = wan:adminlink()
86 ip6addr = wan6:ip6addr(),
87 gw6addr = wan6:gw6addr(),
88 dns = wan6:dns6addrs(),
89 uptime = wan6:uptime(),
90 ifname = wan6:ifname(),
91 link = wan6:adminlink()
96 local dsl_stat = luci.sys.exec("/etc/init.d/dsl_control lucistat")
97 local dsl_func = loadstring(dsl_stat)
101 luci.http.prepare_content("application/json")
102 luci.http.write_json(rv)
110 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
111 <script type="text/javascript">//<![CDATA[
112 function progressbar(v, m)
114 var vn = parseInt(v) || 0;
115 var mn = parseInt(m) || 100;
116 var pc = Math.floor((100 / mn) * vn);
118 return String.format(
119 '<div style="width:200px; position:relative; border:1px solid #999999">' +
120 '<div style="background-color:#CCCCCC; width:%d%%; height:15px">' +
121 '<div style="position:absolute; left:0; top:0; text-align:center; width:100%%; color:#000000">' +
122 '<small>%s / %s (%d%%)</small>' +
125 '</div>', pc, v, m, pc
129 var wifidevs = <%=luci.http.write_json(netdevs)%>;
130 var arptable = <%=luci.http.write_json(arpcache)%>;
132 XHR.poll(5, '<%=REQUEST_URI%>', { status: 1 },
135 var si = document.getElementById('wan4_i');
136 var ss = document.getElementById('wan4_s');
139 if (ifc && ifc.ifname && ifc.proto != 'none')
141 var s = String.format(
142 '<strong><%:Type%>: </strong>%s<br />' +
143 '<strong><%:Address%>: </strong>%s<br />' +
144 '<strong><%:Netmask%>: </strong>%s<br />' +
145 '<strong><%:Gateway%>: </strong>%s<br />',
147 (ifc.ipaddr) ? ifc.ipaddr : '0.0.0.0',
148 (ifc.netmask && ifc.netmask != ifc.ipaddr) ? ifc.netmask : '255.255.255.255',
149 (ifc.gwaddr) ? ifc.gwaddr : '0.0.0.0'
152 for (var i = 0; i < ifc.dns.length; i++)
155 '<strong><%:DNS%> %d: </strong>%s<br />',
160 if (ifc.expires > -1)
163 '<strong><%:Expires%>: </strong>%t<br />',
171 '<strong><%:Connected%>: </strong>%t<br />',
176 ss.innerHTML = String.format('<small>%s</small>', s);
177 si.innerHTML = String.format(
178 '<img src="<%=resource%>/icons/ethernet.png" />' +
179 '<br /><small><a href="%s">%s</a></small>',
185 si.innerHTML = '<img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small>';
186 ss.innerHTML = '<em><%:Not connected%></em>';
189 <% if has_ipv6 then %>
190 var si6 = document.getElementById('wan6_i');
191 var ss6 = document.getElementById('wan6_s');
192 var ifc6 = info.wan6;
194 if (ifc6 && ifc6.ifname && ifc6.proto != 'none')
196 var s = String.format(
197 '<strong><%:Address%>: </strong>%s<br />' +
198 '<strong><%:Gateway%>: </strong>%s<br />',
199 (ifc6.ip6addr) ? ifc6.ip6addr : '::',
200 (ifc6.gw6addr) ? ifc6.gw6addr : '::'
203 for (var i = 0; i < ifc6.dns.length; i++)
206 '<strong><%:DNS%> %d: </strong>%s<br />',
214 '<strong><%:Connected%>: </strong>%t<br />',
219 ss6.innerHTML = String.format('<small>%s</small>', s);
220 si6.innerHTML = String.format(
221 '<img src="<%=resource%>/icons/ethernet.png" />' +
222 '<br /><small><a href="%s">%s</a></small>',
223 ifc6.link, ifc6.ifname
228 si6.innerHTML = '<img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small>';
229 ss6.innerHTML = '<em><%:Not connected%></em>';
233 <% if has_dsl then %>
234 var dsl_i = document.getElementById('dsl_i');
235 var dsl_s = document.getElementById('dsl_s');
237 var s = String.format(
238 '<strong><%:Status%>: </strong>%s<br />' +
239 '<strong><%:Line State%>: </strong>%s [0x%x]<br />' +
240 '<strong><%:Line Speed%>: </strong>%s/s / %s/s<br />' +
241 '<strong><%:Line Attenuation%>: </strong>%s dB / %s dB<br />' +
242 '<strong><%:Noise Margin%>: </strong>%s dB / %s dB<br />',
243 info.dsl.line_state, info.dsl.line_state_detail,
244 info.dsl.line_state_num,
245 info.dsl.data_rate_down_s, info.dsl.data_rate_up_s,
246 info.dsl.line_attenuation_down, info.dsl.line_attenuation_up,
247 info.dsl.noise_margin_down, info.dsl.noise_margin_up
250 dsl_s.innerHTML = String.format('<small>%s</small>', s);
251 dsl_i.innerHTML = String.format(
252 '<img src="<%=resource%>/icons/ethernet.png" />' +
253 '<br /><small>ADSL</small>'
257 <% if has_dhcp then %>
258 var ls = document.getElementById('lease_status_table');
262 while( ls.rows.length > 1 )
263 ls.rows[0].parentNode.deleteRow(1);
265 for( var i = 0; i < info.leases.length; i++ )
269 if (info.leases[i].expires <= 0)
270 timestr = '<em><%:expired%></em>';
272 timestr = String.format('%t', info.leases[i].expires);
274 var tr = ls.rows[0].parentNode.insertRow(-1);
275 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
277 tr.insertCell(-1).innerHTML = info.leases[i].hostname ? info.leases[i].hostname : '?';
278 tr.insertCell(-1).innerHTML = info.leases[i].ipaddr;
279 tr.insertCell(-1).innerHTML = info.leases[i].macaddr;
280 tr.insertCell(-1).innerHTML = timestr;
283 if( ls.rows.length == 1 )
285 var tr = ls.rows[0].parentNode.insertRow(-1);
286 tr.className = 'cbi-section-table-row';
288 var td = tr.insertCell(-1);
290 td.innerHTML = '<em><br /><%:There are no active leases.%></em>';
294 var ls6 = document.getElementById('lease6_status_table');
295 if (ls6 && info.leases6)
297 ls6.parentNode.style.display = 'block';
300 while( ls6.rows.length > 1 )
301 ls6.rows[0].parentNode.deleteRow(1);
303 for( var i = 0; i < info.leases6.length; i++ )
307 if (info.leases6[i].expires <= 0)
308 timestr = '<em><%:expired%></em>';
310 timestr = String.format('%t', info.leases6[i].expires);
312 var tr = ls6.rows[0].parentNode.insertRow(-1);
313 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
315 tr.insertCell(-1).innerHTML = info.leases6[i].hostname ? info.leases6[i].hostname : '?';
316 tr.insertCell(-1).innerHTML = info.leases6[i].ip6addr;
317 tr.insertCell(-1).innerHTML = info.leases6[i].duid;
318 tr.insertCell(-1).innerHTML = timestr;
321 if( ls6.rows.length == 1 )
323 var tr = ls6.rows[0].parentNode.insertRow(-1);
324 tr.className = 'cbi-section-table-row';
326 var td = tr.insertCell(-1);
328 td.innerHTML = '<em><br /><%:There are no active leases.%></em>';
333 <% if has_wifi then %>
336 var ws = document.getElementById('wifi_status_table');
339 var wsbody = ws.rows[0].parentNode;
340 while (ws.rows.length > 0)
343 for (var didx = 0; didx < info.wifinets.length; didx++)
345 var dev = info.wifinets[didx];
347 var tr = wsbody.insertRow(-1);
350 td = tr.insertCell(-1);
352 td.innerHTML = dev.name;
353 td.style.verticalAlign = "top";
355 td = tr.insertCell(-1);
359 for (var nidx = 0; nidx < dev.networks.length; nidx++)
361 var net = dev.networks[nidx];
362 var is_assoc = (net.bssid != '00:00:00:00:00:00' && net.channel);
366 icon = "<%=resource%>/icons/signal-none.png";
367 else if (net.quality == 0)
368 icon = "<%=resource%>/icons/signal-0.png";
369 else if (net.quality < 25)
370 icon = "<%=resource%>/icons/signal-0-25.png";
371 else if (net.quality < 50)
372 icon = "<%=resource%>/icons/signal-25-50.png";
373 else if (net.quality < 75)
374 icon = "<%=resource%>/icons/signal-50-75.png";
376 icon = "<%=resource%>/icons/signal-75-100.png";
379 '<table><tr><td style="text-align:center; width:32px; padding:3px">' +
380 '<img src="%s" title="<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" />' +
381 '<br /><small>%d%%</small>' +
382 '</td><td style="text-align:left; padding:3px"><small>' +
383 '<strong><%:SSID%>:</strong> <a href="%s">%h</a><br />' +
384 '<strong><%:Mode%>:</strong> %s<br />' +
385 '<strong><%:Channel%>:</strong> %d (%.3f <%:GHz%>)<br />' +
386 '<strong><%:Bitrate%>:</strong> %s <%:Mbit/s%><br />',
387 icon, net.signal, net.noise,
391 net.channel, net.frequency,
398 '<strong><%:BSSID%>:</strong> %s<br />' +
399 '<strong><%:Encryption%>:</strong> %s',
406 s += '<em><%:Wireless is disabled or not associated%></em>';
409 s += '</small></td></tr></table>';
411 for (var bssid in net.assoclist)
415 signal: net.assoclist[bssid].signal,
416 noise: net.assoclist[bssid].noise,
417 rx_rate: net.assoclist[bssid].rx_rate,
418 rx_mcs: net.assoclist[bssid].rx_mcs,
419 rx_40mhz: net.assoclist[bssid].rx_40mhz,
420 tx_rate: net.assoclist[bssid].tx_rate,
421 tx_mcs: net.assoclist[bssid].tx_mcs,
422 tx_40mhz: net.assoclist[bssid].tx_40mhz,
430 s = '<em><%:No information available%></em>';
436 var ac = document.getElementById('wifi_assoc_table');
440 while( ac.rows.length > 1 )
441 ac.rows[0].parentNode.deleteRow(1);
443 assoclist.sort(function(a, b) {
444 return (a.name == b.name)
445 ? (a.bssid < b.bssid)
450 for( var i = 0; i < assoclist.length; i++ )
452 var tr = ac.rows[0].parentNode.insertRow(-1);
453 tr.className = 'cbi-section-table-row cbi-rowstyle-' + (1 + (i % 2));
456 var q = (-1 * (assoclist[i].noise - assoclist[i].signal)) / 5;
458 icon = "<%=resource%>/icons/signal-0.png";
460 icon = "<%=resource%>/icons/signal-0-25.png";
462 icon = "<%=resource%>/icons/signal-25-50.png";
464 icon = "<%=resource%>/icons/signal-50-75.png";
466 icon = "<%=resource%>/icons/signal-75-100.png";
468 tr.insertCell(-1).innerHTML = String.format(
469 '<img src="%s" title="<%:Signal%>: %d <%:dBm%> / <%:Noise%>: %d <%:dBm%>" />',
470 icon, assoclist[i].signal, assoclist[i].noise
473 tr.insertCell(-1).innerHTML = assoclist[i].bssid;
475 tr.insertCell(-1).innerHTML = String.format(
476 '<a href="%s">%s</a>',
478 '%h'.format(assoclist[i].name).nobr()
481 tr.insertCell(-1).innerHTML = String.format('%d <%:dBm%>', assoclist[i].signal).nobr();
482 tr.insertCell(-1).innerHTML = String.format('%d <%:dBm%>', assoclist[i].noise).nobr();
484 tr.insertCell(-1).innerHTML = (assoclist[i].rx_mcs > -1)
485 ? 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()
486 : String.format('%.1f <%:Mbit/s%>', assoclist[i].rx_rate / 1000).nobr()
489 tr.insertCell(-1).innerHTML = (assoclist[i].tx_mcs > -1)
490 ? 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()
491 : String.format('%.1f <%:Mbit/s%>', assoclist[i].tx_rate / 1000).nobr()
495 if (ac.rows.length == 1)
497 var tr = ac.rows[0].parentNode.insertRow(-1);
498 tr.className = 'cbi-section-table-row';
500 var td = tr.insertCell(-1);
502 td.innerHTML = '<br /><em><%:No information available%></em>';
509 if (e = document.getElementById('localtime'))
510 e.innerHTML = info.localtime;
512 if (e = document.getElementById('uptime'))
513 e.innerHTML = String.format('%t', info.uptime);
515 if (e = document.getElementById('loadavg'))
516 e.innerHTML = String.format(
517 '%.02f, %.02f, %.02f',
518 info.loadavg[0] / 65535.0,
519 info.loadavg[1] / 65535.0,
520 info.loadavg[2] / 65535.0
523 if (e = document.getElementById('memtotal'))
524 e.innerHTML = progressbar(
525 ((info.memory.free + info.memory.buffered) / 1024) + " <%:kB%>",
526 (info.memory.total / 1024) + " <%:kB%>"
529 if (e = document.getElementById('memfree'))
530 e.innerHTML = progressbar(
531 (info.memory.free / 1024) + " <%:kB%>",
532 (info.memory.total / 1024) + " <%:kB%>"
535 if (e = document.getElementById('membuff'))
536 e.innerHTML = progressbar(
537 (info.memory.buffered / 1024) + " <%:kB%>",
538 (info.memory.total / 1024) + " <%:kB%>"
541 if (e = document.getElementById('swaptotal'))
542 e.innerHTML = progressbar(
543 (info.swap.free / 1024) + " <%:kB%>",
544 (info.swap.total / 1024) + " <%:kB%>"
547 if (e = document.getElementById('swapfree'))
548 e.innerHTML = progressbar(
549 (info.swap.free / 1024) + " <%:kB%>",
550 (info.swap.total / 1024) + " <%:kB%>"
553 if (e = document.getElementById('conns'))
554 e.innerHTML = progressbar(info.conncount, info.connmax);
560 <h2><a id="content" name="content"><%:Status%></a></h2>
562 <fieldset class="cbi-section">
563 <legend><%:System%></legend>
565 <table width="100%" cellspacing="10">
566 <tr><td width="33%"><%:Hostname%></td><td><%=luci.sys.hostname() or "?"%></td></tr>
567 <tr><td width="33%"><%:Model%></td><td><%=pcdata(boardinfo.model or boardinfo.system or "?")%></td></tr>
568 <tr><td width="33%"><%:Firmware Version%></td><td>
569 <%=pcdata(ver.distname)%> <%=pcdata(ver.distversion)%> /
570 <%=pcdata(ver.luciname)%> (<%=pcdata(ver.luciversion)%>)
572 <tr><td width="33%"><%:Kernel Version%></td><td><%=unameinfo.release or "?"%></td></tr>
573 <tr><td width="33%"><%:Local Time%></td><td id="localtime">-</td></tr>
574 <tr><td width="33%"><%:Uptime%></td><td id="uptime">-</td></tr>
575 <tr><td width="33%"><%:Load Average%></td><td id="loadavg">-</td></tr>
579 <fieldset class="cbi-section">
580 <legend><%:Memory%></legend>
582 <table width="100%" cellspacing="10">
583 <tr><td width="33%"><%:Total Available%></td><td id="memtotal">-</td></tr>
584 <tr><td width="33%"><%:Free%></td><td id="memfree">-</td></tr>
585 <tr><td width="33%"><%:Buffered%></td><td id="membuff">-</td></tr>
589 <% if swapinfo.total > 0 then %>
590 <fieldset class="cbi-section">
591 <legend><%:Swap%></legend>
593 <table width="100%" cellspacing="10">
594 <tr><td width="33%"><%:Total Available%></td><td id="swaptotal">-</td></tr>
595 <tr><td width="33%"><%:Free%></td><td id="swapfree">-</td></tr>
600 <fieldset class="cbi-section">
601 <legend><%:Network%></legend>
603 <table width="100%" cellspacing="10">
604 <tr><td width="33%" style="vertical-align:top"><%:IPv4 WAN Status%></td><td>
606 <td id="wan4_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td>
607 <td id="wan4_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></td>
610 <% if has_ipv6 then %>
611 <tr><td width="33%" style="vertical-align:top"><%:IPv6 WAN Status%></td><td>
613 <td id="wan6_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td>
614 <td id="wan6_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></td>
618 <tr><td width="33%"><%:Active Connections%></td><td id="conns">-</td></tr>
622 <% if has_dhcp then %>
623 <fieldset class="cbi-section">
624 <legend><%:DHCP Leases%></legend>
626 <table class="cbi-section-table" id="lease_status_table">
627 <tr class="cbi-section-table-titles">
628 <th class="cbi-section-table-cell"><%:Hostname%></th>
629 <th class="cbi-section-table-cell"><%:IPv4-Address%></th>
630 <th class="cbi-section-table-cell"><%:MAC-Address%></th>
631 <th class="cbi-section-table-cell"><%:Leasetime remaining%></th>
633 <tr class="cbi-section-table-row">
634 <td colspan="4"><em><br /><%:Collecting data...%></em></td>
639 <fieldset class="cbi-section" style="display:none">
640 <legend><%:DHCPv6 Leases%></legend>
642 <table class="cbi-section-table" id="lease6_status_table">
643 <tr class="cbi-section-table-titles">
644 <th class="cbi-section-table-cell"><%:Hostname%></th>
645 <th class="cbi-section-table-cell"><%:IPv6-Address%></th>
646 <th class="cbi-section-table-cell"><%:DUID%></th>
647 <th class="cbi-section-table-cell"><%:Leasetime remaining%></th>
649 <tr class="cbi-section-table-row">
650 <td colspan="4"><em><br /><%:Collecting data...%></em></td>
656 <% if has_dsl then %>
657 <fieldset class="cbi-section">
658 <legend><%:ADSL%></legend>
659 <table width="100%" cellspacing="10">
660 <tr><td width="33%" style="vertical-align:top"><%:ADSL Status%></td><td>
662 <td id="dsl_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td>
663 <td id="dsl_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></td>
670 <% if has_wifi then %>
671 <fieldset class="cbi-section">
672 <legend><%:Wireless%></legend>
674 <table id="wifi_status_table" width="100%" cellspacing="10">
675 <tr><td><em><%:Collecting data...%></em></td></tr>
679 <fieldset class="cbi-section">
680 <legend><%:Associated Stations%></legend>
682 <table class="cbi-section-table" id="wifi_assoc_table">
683 <tr class="cbi-section-table-titles">
684 <th class="cbi-section-table-cell"> </th>
685 <th class="cbi-section-table-cell"><%:MAC-Address%></th>
686 <th class="cbi-section-table-cell"><%:Network%></th>
687 <th class="cbi-section-table-cell"><%:Signal%></th>
688 <th class="cbi-section-table-cell"><%:Noise%></th>
689 <th class="cbi-section-table-cell"><%:RX Rate%></th>
690 <th class="cbi-section-table-cell"><%:TX Rate%></th>
692 <tr class="cbi-section-table-row">
693 <td colspan="7"><em><br /><%:Collecting data...%></em></td>
700 local incdir = util.libpath() .. "/view/admin_status/index/"
701 if fs.access(incdir) then
703 for inc in fs.dir(incdir) do
704 if inc:match("%.htm$") then
705 include("admin_status/index/" .. inc:gsub("%.htm$", ""))