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 if luci.http.formvalue("status") == "1" then
24 local ntm = require "luci.model.network".init()
25 local wan = ntm:get_wannet()
26 local wan6 = ntm:get_wan6net()
28 local _, _, memtotal, memcached, membuffers, memfree = luci.sys.sysinfo()
30 local conn_count = tonumber((
31 luci.sys.exec("wc -l /proc/net/nf_conntrack") or
32 luci.sys.exec("wc -l /proc/net/ip_conntrack") or
33 ""):match("%d+")) or 0
35 local conn_max = tonumber((
36 luci.sys.exec("sysctl net.nf_conntrack_max") or
37 luci.sys.exec("sysctl net.ipv4.netfilter.ip_conntrack_max") or
38 ""):match("%d+")) or 4096
41 uptime = luci.sys.uptime(),
42 localtime = os.date(),
43 loadavg = { luci.sys.loadavg() },
45 memcached = memcached,
46 membuffers = membuffers,
49 conncount = conn_count,
50 leases = luci.tools.status.dhcp_leases(),
51 leases6 = luci.tools.status.dhcp6_leases(),
52 wifinets = luci.tools.status.wifi_networks()
57 ipaddr = wan:ipaddr(),
58 gwaddr = wan:gwaddr(),
59 netmask = wan:netmask(),
61 expires = wan:expires(),
62 uptime = wan:uptime(),
64 ifname = wan:ifname(),
65 link = wan:adminlink()
71 ip6addr = wan6:ip6addr(),
72 gw6addr = wan6:gw6addr(),
73 dns = wan6:dns6addrs(),
74 uptime = wan6:uptime(),
75 ifname = wan6:ifname(),
76 link = wan6:adminlink()
80 luci.http.prepare_content("application/json")
81 luci.http.write_json(rv)
86 local system, model = luci.sys.sysinfo()
91 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
92 <script type="text/javascript">//<![CDATA[
93 function progressbar(v, m)
95 var vn = parseInt(v) || 0;
96 var mn = parseInt(m) || 100;
97 var pc = Math.floor((100 / mn) * vn);
100 '<div style="width:200px; position:relative; border:1px solid #999999">' +
101 '<div style="background-color:#CCCCCC; width:%d%%; height:15px">' +
102 '<div style="position:absolute; left:0; top:0; text-align:center; width:100%%; color:#000000">' +
103 '<small>%s / %s (%d%%)</small>' +
106 '</div>', pc, v, m, pc
110 var wifidevs = <%=luci.http.write_json(netdevs)%>;
111 var arptable = <%=luci.http.write_json(arpcache)%>;
113 XHR.poll(5, '<%=REQUEST_URI%>', { status: 1 },
116 var si = document.getElementById('wan4_i');
117 var ss = document.getElementById('wan4_s');
120 if (ifc && ifc.ifname && ifc.proto != 'none')
122 var s = String.format(
123 '<strong><%:Type%>: </strong>%s<br />' +
124 '<strong><%:Address%>: </strong>%s<br />' +
125 '<strong><%:Netmask%>: </strong>%s<br />' +
126 '<strong><%:Gateway%>: </strong>%s<br />',
128 (ifc.ipaddr) ? ifc.ipaddr : '0.0.0.0',
129 (ifc.netmask && ifc.netmask != ifc.ipaddr) ? ifc.netmask : '255.255.255.255',
130 (ifc.gwaddr) ? ifc.gwaddr : '0.0.0.0'
133 for (var i = 0; i < ifc.dns.length; i++)
136 '<strong><%:DNS%> %d: </strong>%s<br />',
141 if (ifc.expires > -1)
144 '<strong><%:Expires%>: </strong>%t<br />',
152 '<strong><%:Connected%>: </strong>%t<br />',
157 ss.innerHTML = String.format('<small>%s</small>', s);
158 si.innerHTML = String.format(
159 '<img src="<%=resource%>/icons/ethernet.png" />' +
160 '<br /><small><a href="%s">%s</a></small>',
166 si.innerHTML = '<img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small>';
167 ss.innerHTML = '<em><%:Not connected%></em>';
170 <% if has_ipv6 then %>
171 var si6 = document.getElementById('wan6_i');
172 var ss6 = document.getElementById('wan6_s');
173 var ifc6 = info.wan6;
175 if (ifc6 && ifc6.ifname && ifc6.proto != 'none')
177 var s = String.format(
178 '<strong><%:Address%>: </strong>%s<br />' +
179 '<strong><%:Gateway%>: </strong>%s<br />',
180 (ifc6.ip6addr) ? ifc6.ip6addr : '::',
181 (ifc6.gw6addr) ? ifc6.gw6addr : '::'
184 for (var i = 0; i < ifc6.dns.length; i++)
187 '<strong><%:DNS%> %d: </strong>%s<br />',
195 '<strong><%:Connected%>: </strong>%t<br />',
200 ss6.innerHTML = String.format('<small>%s</small>', s);
201 si6.innerHTML = String.format(
202 '<img src="<%=resource%>/icons/ethernet.png" />' +
203 '<br /><small><a href="%s">%s</a></small>',
204 ifc6.link, ifc6.ifname
209 si6.innerHTML = '<img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small>';
210 ss6.innerHTML = '<em><%:Not connected%></em>';
214 <% if has_dhcp then %>
215 var ls = document.getElementById('lease_status_table');
219 while( ls.rows.length > 1 )
220 ls.rows[0].parentNode.deleteRow(1);
222 for( var i = 0; i < info.leases.length; i++ )
226 if (info.leases[i].expires <= 0)
227 timestr = '<em><%:expired%></em>';
229 timestr = String.format('%t', info.leases[i].expires);
231 var tr = ls.rows[0].parentNode.insertRow(-1);
232 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
234 tr.insertCell(-1).innerHTML = info.leases[i].hostname ? info.leases[i].hostname : '?';
235 tr.insertCell(-1).innerHTML = info.leases[i].ipaddr;
236 tr.insertCell(-1).innerHTML = info.leases[i].macaddr;
237 tr.insertCell(-1).innerHTML = timestr;
240 if( ls.rows.length == 1 )
242 var tr = ls.rows[0].parentNode.insertRow(-1);
243 tr.className = 'cbi-section-table-row';
245 var td = tr.insertCell(-1);
247 td.innerHTML = '<em><br /><%:There are no active leases.%></em>';
251 var ls6 = document.getElementById('lease6_status_table');
252 if (ls6 && info.leases6)
254 ls6.parentNode.style.display = 'block';
257 while( ls6.rows.length > 1 )
258 ls6.rows[0].parentNode.deleteRow(1);
260 for( var i = 0; i < info.leases6.length; i++ )
264 if (info.leases6[i].expires <= 0)
265 timestr = '<em><%:expired%></em>';
267 timestr = String.format('%t', info.leases6[i].expires);
269 var tr = ls6.rows[0].parentNode.insertRow(-1);
270 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
272 tr.insertCell(-1).innerHTML = info.leases6[i].hostname ? info.leases6[i].hostname : '?';
273 tr.insertCell(-1).innerHTML = info.leases6[i].ip6addr;
274 tr.insertCell(-1).innerHTML = info.leases6[i].duid;
275 tr.insertCell(-1).innerHTML = timestr;
278 if( ls6.rows.length == 1 )
280 var tr = ls6.rows[0].parentNode.insertRow(-1);
281 tr.className = 'cbi-section-table-row';
283 var td = tr.insertCell(-1);
285 td.innerHTML = '<em><br /><%:There are no active leases.%></em>';
290 <% if has_wifi then %>
293 var ws = document.getElementById('wifi_status_table');
296 var wsbody = ws.rows[0].parentNode;
297 while (ws.rows.length > 0)
300 for (var didx = 0; didx < info.wifinets.length; didx++)
302 var dev = info.wifinets[didx];
304 var tr = wsbody.insertRow(-1);
307 td = tr.insertCell(-1);
309 td.innerHTML = dev.name;
310 td.style.verticalAlign = "top";
312 td = tr.insertCell(-1);
316 for (var nidx = 0; nidx < dev.networks.length; nidx++)
318 var net = dev.networks[nidx];
319 var is_assoc = (net.bssid != '00:00:00:00:00:00' && net.channel);
323 icon = "<%=resource%>/icons/signal-none.png";
324 else if (net.quality == 0)
325 icon = "<%=resource%>/icons/signal-0.png";
326 else if (net.quality < 25)
327 icon = "<%=resource%>/icons/signal-0-25.png";
328 else if (net.quality < 50)
329 icon = "<%=resource%>/icons/signal-25-50.png";
330 else if (net.quality < 75)
331 icon = "<%=resource%>/icons/signal-50-75.png";
333 icon = "<%=resource%>/icons/signal-75-100.png";
336 '<table><tr><td style="text-align:center; width:32px; padding:3px">' +
337 '<img src="%s" title="<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" />' +
338 '<br /><small>%d%%</small>' +
339 '</td><td style="text-align:left; padding:3px"><small>' +
340 '<strong><%:SSID%>:</strong> <a href="%s">%h</a><br />' +
341 '<strong><%:Mode%>:</strong> %s<br />' +
342 '<strong><%:Channel%>:</strong> %d (%.3f <%:GHz%>)<br />' +
343 '<strong><%:Bitrate%>:</strong> %s <%:Mbit/s%><br />',
344 icon, net.signal, net.noise,
348 net.channel, net.frequency,
355 '<strong><%:BSSID%>:</strong> %s<br />' +
356 '<strong><%:Encryption%>:</strong> %s',
363 s += '<em><%:Wireless is disabled or not associated%></em>';
366 s += '</small></td></tr></table>';
368 for (var bssid in net.assoclist)
372 signal: net.assoclist[bssid].signal,
373 noise: net.assoclist[bssid].noise,
374 rx_rate: net.assoclist[bssid].rx_rate,
375 rx_mcs: net.assoclist[bssid].rx_mcs,
376 rx_40mhz: net.assoclist[bssid].rx_40mhz,
377 tx_rate: net.assoclist[bssid].tx_rate,
378 tx_mcs: net.assoclist[bssid].tx_mcs,
379 tx_40mhz: net.assoclist[bssid].tx_40mhz,
387 s = '<em><%:No information available%></em>';
393 var ac = document.getElementById('wifi_assoc_table');
397 while( ac.rows.length > 1 )
398 ac.rows[0].parentNode.deleteRow(1);
400 assoclist.sort(function(a, b) {
401 return (a.name == b.name)
402 ? (a.bssid < b.bssid)
407 for( var i = 0; i < assoclist.length; i++ )
409 var tr = ac.rows[0].parentNode.insertRow(-1);
410 tr.className = 'cbi-section-table-row cbi-rowstyle-' + (1 + (i % 2));
413 var q = (-1 * (assoclist[i].noise - assoclist[i].signal)) / 5;
415 icon = "<%=resource%>/icons/signal-0.png";
417 icon = "<%=resource%>/icons/signal-0-25.png";
419 icon = "<%=resource%>/icons/signal-25-50.png";
421 icon = "<%=resource%>/icons/signal-50-75.png";
423 icon = "<%=resource%>/icons/signal-75-100.png";
425 tr.insertCell(-1).innerHTML = String.format(
426 '<img src="%s" title="<%:Signal%>: %d <%:dBm%> / <%:Noise%>: %d <%:dBm%>" />',
427 icon, assoclist[i].signal, assoclist[i].noise
430 tr.insertCell(-1).innerHTML = assoclist[i].bssid;
432 tr.insertCell(-1).innerHTML = String.format(
433 '<a href="%s">%s</a>',
435 '%h'.format(assoclist[i].name).nobr()
438 tr.insertCell(-1).innerHTML = String.format('%d <%:dBm%>', assoclist[i].signal).nobr();
439 tr.insertCell(-1).innerHTML = String.format('%d <%:dBm%>', assoclist[i].noise).nobr();
441 tr.insertCell(-1).innerHTML = (assoclist[i].rx_mcs > -1)
442 ? 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()
443 : String.format('%.1f <%:Mbit/s%>', assoclist[i].rx_rate / 1000).nobr()
446 tr.insertCell(-1).innerHTML = (assoclist[i].tx_mcs > -1)
447 ? 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()
448 : String.format('%.1f <%:Mbit/s%>', assoclist[i].tx_rate / 1000).nobr()
452 if (ac.rows.length == 1)
454 var tr = ac.rows[0].parentNode.insertRow(-1);
455 tr.className = 'cbi-section-table-row';
457 var td = tr.insertCell(-1);
459 td.innerHTML = '<br /><em><%:No information available%></em>';
466 if (e = document.getElementById('localtime'))
467 e.innerHTML = info.localtime;
469 if (e = document.getElementById('uptime'))
470 e.innerHTML = String.format('%t', info.uptime);
472 if (e = document.getElementById('loadavg'))
473 e.innerHTML = String.format('%.02f, %.02f, %.02f',
474 info.loadavg[0], info.loadavg[1], info.loadavg[2]);
476 if (e = document.getElementById('memtotal'))
477 e.innerHTML = progressbar(
478 (info.memfree + info.membuffers + info.memcached) + " <%:kB%>",
479 info.memtotal + " <%:kB%>"
482 if (e = document.getElementById('memfree'))
483 e.innerHTML = progressbar(
484 info.memfree + " <%:kB%>", info.memtotal + " <%:kB%>"
487 if (e = document.getElementById('memcache'))
488 e.innerHTML = progressbar(
489 info.memcached + " <%:kB%>", info.memtotal + " <%:kB%>"
492 if (e = document.getElementById('membuff'))
493 e.innerHTML = progressbar(
494 info.membuffers + " <%:kB%>", info.memtotal + " <%:kB%>"
497 if (e = document.getElementById('conns'))
498 e.innerHTML = progressbar(info.conncount, info.connmax);
504 <h2><a id="content" name="content"><%:Status%></a></h2>
506 <fieldset class="cbi-section">
507 <legend><%:System%></legend>
509 <table width="100%" cellspacing="10">
510 <tr><td width="33%"><%:Router Name%></td><td><%=luci.sys.hostname() or "?"%></td></tr>
511 <tr><td width="33%"><%:Router Model%></td><td><%=pcdata(model or "?")%></td></tr>
512 <tr><td width="33%"><%:Firmware Version%></td><td>
513 <%=pcdata(luci.version.distname)%> <%=pcdata(luci.version.distversion)%> /
514 <%=pcdata(luci.version.luciname)%> (<%=pcdata(luci.version.luciversion)%>)
516 <tr><td width="33%"><%:Kernel Version%></td><td><%=luci.sys.exec("uname -r")%></td></tr>
517 <tr><td width="33%"><%:Local Time%></td><td id="localtime">-</td></tr>
518 <tr><td width="33%"><%:Uptime%></td><td id="uptime">-</td></tr>
519 <tr><td width="33%"><%:Load Average%></td><td id="loadavg">-</td></tr>
523 <fieldset class="cbi-section">
524 <legend><%:Memory%></legend>
526 <table width="100%" cellspacing="10">
527 <tr><td width="33%"><%:Total Available%></td><td id="memtotal">-</td></tr>
528 <tr><td width="33%"><%:Free%></td><td id="memfree">-</td></tr>
529 <tr><td width="33%"><%:Cached%></td><td id="memcache">-</td></tr>
530 <tr><td width="33%"><%:Buffered%></td><td id="membuff">-</td></tr>
534 <fieldset class="cbi-section">
535 <legend><%:Network%></legend>
537 <table width="100%" cellspacing="10">
538 <tr><td width="33%" style="vertical-align:top"><%:IPv4 WAN Status%></td><td>
540 <td id="wan4_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td>
541 <td id="wan4_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></td>
544 <% if has_ipv6 then %>
545 <tr><td width="33%" style="vertical-align:top"><%:IPv6 WAN Status%></td><td>
547 <td id="wan6_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td>
548 <td id="wan6_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></td>
552 <tr><td width="33%"><%:Active Connections%></td><td id="conns">-</td></tr>
556 <% if has_dhcp then %>
557 <fieldset class="cbi-section">
558 <legend><%:DHCP Leases%></legend>
560 <table class="cbi-section-table" id="lease_status_table">
561 <tr class="cbi-section-table-titles">
562 <th class="cbi-section-table-cell"><%:Hostname%></th>
563 <th class="cbi-section-table-cell"><%:IPv4-Address%></th>
564 <th class="cbi-section-table-cell"><%:MAC-Address%></th>
565 <th class="cbi-section-table-cell"><%:Leasetime remaining%></th>
567 <tr class="cbi-section-table-row">
568 <td colspan="4"><em><br /><%:Collecting data...%></em></td>
573 <fieldset class="cbi-section" style="display:none">
574 <legend><%:DHCPv6 Leases%></legend>
576 <table class="cbi-section-table" id="lease6_status_table">
577 <tr class="cbi-section-table-titles">
578 <th class="cbi-section-table-cell"><%:Hostname%></th>
579 <th class="cbi-section-table-cell"><%:IPv6-Address%></th>
580 <th class="cbi-section-table-cell"><%:DUID%></th>
581 <th class="cbi-section-table-cell"><%:Leasetime remaining%></th>
583 <tr class="cbi-section-table-row">
584 <td colspan="4"><em><br /><%:Collecting data...%></em></td>
590 <% if has_wifi then %>
591 <fieldset class="cbi-section">
592 <legend><%:Wireless%></legend>
594 <table id="wifi_status_table" width="100%" cellspacing="10">
595 <tr><td><em><%:Collecting data...%></em></td></tr>
599 <fieldset class="cbi-section">
600 <legend><%:Associated Stations%></legend>
602 <table class="cbi-section-table" id="wifi_assoc_table">
603 <tr class="cbi-section-table-titles">
604 <th class="cbi-section-table-cell"> </th>
605 <th class="cbi-section-table-cell"><%:MAC-Address%></th>
606 <th class="cbi-section-table-cell"><%:Network%></th>
607 <th class="cbi-section-table-cell"><%:Signal%></th>
608 <th class="cbi-section-table-cell"><%:Noise%></th>
609 <th class="cbi-section-table-cell"><%:RX Rate%></th>
610 <th class="cbi-section-table-cell"><%:TX Rate%></th>
612 <tr class="cbi-section-table-row">
613 <td colspan="7"><em><br /><%:Collecting data...%></em></td>
623 local plugins = nixio.fs.dir(luci.util.libpath() .. "/view/admin_status/index")
626 for inc in plugins do
627 if inc:match("%.htm$") then
628 include("admin_status/index/" .. inc:gsub("%.htm$", ""))