luci-0.11: merge outstanding trunk changes
[project/luci.git] / modules / admin-full / luasrc / view / admin_status / index.htm
1 <%#
2 LuCI - Lua Configuration Interface
3 Copyright 2008 Steven Barth <steven@midlink.org>
4 Copyright 2008-2011 Jo-Philipp Wich <xm@subsignal.org>
5
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
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 -%>
13
14 <%
15 require "luci.fs"
16 require "luci.tools.status"
17
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
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()
27
28 local _, _, memtotal, memcached, membuffers, memfree = luci.sys.sysinfo()
29
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
34
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
39
40 local rv = {
41 uptime = luci.sys.uptime(),
42 localtime = os.date(),
43 loadavg = { luci.sys.loadavg() },
44 memtotal = memtotal,
45 memcached = memcached,
46 membuffers = membuffers,
47 memfree = memfree,
48 connmax = conn_max,
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()
53 }
54
55 if wan then
56 rv.wan = {
57 ipaddr = wan:ipaddr(),
58 gwaddr = wan:gwaddr(),
59 netmask = wan:netmask(),
60 dns = wan:dnsaddrs(),
61 expires = wan:expires(),
62 uptime = wan:uptime(),
63 proto = wan:proto(),
64 ifname = wan:ifname(),
65 link = wan:adminlink()
66 }
67 end
68
69 if wan6 then
70 rv.wan6 = {
71 ip6addr = wan6:ip6addr(),
72 gw6addr = wan6:gw6addr(),
73 dns = wan6:dns6addrs(),
74 uptime = wan6:uptime(),
75 ifname = wan6:ifname(),
76 link = wan6:adminlink()
77 }
78 end
79
80 luci.http.prepare_content("application/json")
81 luci.http.write_json(rv)
82
83 return
84 end
85
86 local system, model = luci.sys.sysinfo()
87 -%>
88
89 <%+header%>
90
91 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
92 <script type="text/javascript">//<![CDATA[
93 function progressbar(v, m)
94 {
95 var vn = parseInt(v) || 0;
96 var mn = parseInt(m) || 100;
97 var pc = Math.floor((100 / mn) * vn);
98
99 return String.format(
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>' +
104 '</div>' +
105 '</div>' +
106 '</div>', pc, v, m, pc
107 );
108 }
109
110 var wifidevs = <%=luci.http.write_json(netdevs)%>;
111 var arptable = <%=luci.http.write_json(arpcache)%>;
112
113 XHR.poll(5, '<%=REQUEST_URI%>', { status: 1 },
114 function(x, info)
115 {
116 var si = document.getElementById('wan4_i');
117 var ss = document.getElementById('wan4_s');
118 var ifc = info.wan;
119
120 if (ifc && ifc.ifname && ifc.proto != 'none')
121 {
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 />',
127 ifc.proto,
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'
131 );
132
133 for (var i = 0; i < ifc.dns.length; i++)
134 {
135 s += String.format(
136 '<strong><%:DNS%> %d: </strong>%s<br />',
137 i + 1, ifc.dns[i]
138 );
139 }
140
141 if (ifc.expires > -1)
142 {
143 s += String.format(
144 '<strong><%:Expires%>: </strong>%t<br />',
145 ifc.expires
146 );
147 }
148
149 if (ifc.uptime > 0)
150 {
151 s += String.format(
152 '<strong><%:Connected%>: </strong>%t<br />',
153 ifc.uptime
154 );
155 }
156
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>',
161 ifc.link, ifc.ifname
162 );
163 }
164 else
165 {
166 si.innerHTML = '<img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small>';
167 ss.innerHTML = '<em><%:Not connected%></em>';
168 }
169
170 <% if has_ipv6 then %>
171 var si6 = document.getElementById('wan6_i');
172 var ss6 = document.getElementById('wan6_s');
173 var ifc6 = info.wan6;
174
175 if (ifc6 && ifc6.ifname && ifc6.proto != 'none')
176 {
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 : '::'
182 );
183
184 for (var i = 0; i < ifc6.dns.length; i++)
185 {
186 s += String.format(
187 '<strong><%:DNS%> %d: </strong>%s<br />',
188 i + 1, ifc6.dns[i]
189 );
190 }
191
192 if (ifc6.uptime > 0)
193 {
194 s += String.format(
195 '<strong><%:Connected%>: </strong>%t<br />',
196 ifc6.uptime
197 );
198 }
199
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
205 );
206 }
207 else
208 {
209 si6.innerHTML = '<img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small>';
210 ss6.innerHTML = '<em><%:Not connected%></em>';
211 }
212 <% end %>
213
214 <% if has_dhcp then %>
215 var ls = document.getElementById('lease_status_table');
216 if (ls)
217 {
218 /* clear all rows */
219 while( ls.rows.length > 1 )
220 ls.rows[0].parentNode.deleteRow(1);
221
222 for( var i = 0; i < info.leases.length; i++ )
223 {
224 var timestr;
225
226 if (info.leases[i].expires <= 0)
227 timestr = '<em><%:expired%></em>';
228 else
229 timestr = String.format('%t', info.leases[i].expires);
230
231 var tr = ls.rows[0].parentNode.insertRow(-1);
232 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
233
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;
238 }
239
240 if( ls.rows.length == 1 )
241 {
242 var tr = ls.rows[0].parentNode.insertRow(-1);
243 tr.className = 'cbi-section-table-row';
244
245 var td = tr.insertCell(-1);
246 td.colSpan = 4;
247 td.innerHTML = '<em><br /><%:There are no active leases.%></em>';
248 }
249 }
250
251 var ls6 = document.getElementById('lease6_status_table');
252 if (ls6 && info.leases6)
253 {
254 ls6.parentNode.style.display = 'block';
255
256 /* clear all rows */
257 while( ls6.rows.length > 1 )
258 ls6.rows[0].parentNode.deleteRow(1);
259
260 for( var i = 0; i < info.leases6.length; i++ )
261 {
262 var timestr;
263
264 if (info.leases6[i].expires <= 0)
265 timestr = '<em><%:expired%></em>';
266 else
267 timestr = String.format('%t', info.leases6[i].expires);
268
269 var tr = ls6.rows[0].parentNode.insertRow(-1);
270 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
271
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;
276 }
277
278 if( ls6.rows.length == 1 )
279 {
280 var tr = ls6.rows[0].parentNode.insertRow(-1);
281 tr.className = 'cbi-section-table-row';
282
283 var td = tr.insertCell(-1);
284 td.colSpan = 4;
285 td.innerHTML = '<em><br /><%:There are no active leases.%></em>';
286 }
287 }
288 <% end %>
289
290 <% if has_wifi then %>
291 var assoclist = [ ];
292
293 var ws = document.getElementById('wifi_status_table');
294 if (ws)
295 {
296 var wsbody = ws.rows[0].parentNode;
297 while (ws.rows.length > 0)
298 wsbody.deleteRow(0);
299
300 for (var didx = 0; didx < info.wifinets.length; didx++)
301 {
302 var dev = info.wifinets[didx];
303
304 var tr = wsbody.insertRow(-1);
305 var td;
306
307 td = tr.insertCell(-1);
308 td.width = "33%";
309 td.innerHTML = dev.name;
310 td.style.verticalAlign = "top";
311
312 td = tr.insertCell(-1);
313
314 var s = '';
315
316 for (var nidx = 0; nidx < dev.networks.length; nidx++)
317 {
318 var net = dev.networks[nidx];
319 var is_assoc = (net.bssid != '00:00:00:00:00:00' && net.channel);
320
321 var icon;
322 if (!is_assoc)
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";
332 else
333 icon = "<%=resource%>/icons/signal-75-100.png";
334
335 s += String.format(
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,
345 net.quality,
346 net.link, net.ssid,
347 net.mode,
348 net.channel, net.frequency,
349 net.bitrate || '?'
350 );
351
352 if (is_assoc)
353 {
354 s += String.format(
355 '<strong><%:BSSID%>:</strong> %s<br />' +
356 '<strong><%:Encryption%>:</strong> %s',
357 net.bssid,
358 net.encryption
359 );
360 }
361 else
362 {
363 s += '<em><%:Wireless is disabled or not associated%></em>';
364 }
365
366 s += '</small></td></tr></table>';
367
368 for (var bssid in net.assoclist)
369 {
370 assoclist.push({
371 bssid: bssid,
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,
380 link: net.link,
381 name: net.name
382 });
383 }
384 }
385
386 if (!s)
387 s = '<em><%:No information available%></em>';
388
389 td.innerHTML = s;
390 }
391 }
392
393 var ac = document.getElementById('wifi_assoc_table');
394 if (ac)
395 {
396 /* clear all rows */
397 while( ac.rows.length > 1 )
398 ac.rows[0].parentNode.deleteRow(1);
399
400 assoclist.sort(function(a, b) {
401 return (a.name == b.name)
402 ? (a.bssid < b.bssid)
403 : (a.name > b.name )
404 ;
405 });
406
407 for( var i = 0; i < assoclist.length; i++ )
408 {
409 var tr = ac.rows[0].parentNode.insertRow(-1);
410 tr.className = 'cbi-section-table-row cbi-rowstyle-' + (1 + (i % 2));
411
412 var icon;
413 var q = (-1 * (assoclist[i].noise - assoclist[i].signal)) / 5;
414 if (q < 1)
415 icon = "<%=resource%>/icons/signal-0.png";
416 else if (q < 2)
417 icon = "<%=resource%>/icons/signal-0-25.png";
418 else if (q < 3)
419 icon = "<%=resource%>/icons/signal-25-50.png";
420 else if (q < 4)
421 icon = "<%=resource%>/icons/signal-50-75.png";
422 else
423 icon = "<%=resource%>/icons/signal-75-100.png";
424
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
428 );
429
430 tr.insertCell(-1).innerHTML = assoclist[i].bssid;
431
432 tr.insertCell(-1).innerHTML = String.format(
433 '<a href="%s">%s</a>',
434 assoclist[i].link,
435 '%h'.format(assoclist[i].name).nobr()
436 );
437
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();
440
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()
444 ;
445
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()
449 ;
450 }
451
452 if (ac.rows.length == 1)
453 {
454 var tr = ac.rows[0].parentNode.insertRow(-1);
455 tr.className = 'cbi-section-table-row';
456
457 var td = tr.insertCell(-1);
458 td.colSpan = 7;
459 td.innerHTML = '<br /><em><%:No information available%></em>';
460 }
461 }
462 <% end %>
463
464 var e;
465
466 if (e = document.getElementById('localtime'))
467 e.innerHTML = info.localtime;
468
469 if (e = document.getElementById('uptime'))
470 e.innerHTML = String.format('%t', info.uptime);
471
472 if (e = document.getElementById('loadavg'))
473 e.innerHTML = String.format('%.02f, %.02f, %.02f',
474 info.loadavg[0], info.loadavg[1], info.loadavg[2]);
475
476 if (e = document.getElementById('memtotal'))
477 e.innerHTML = progressbar(
478 (info.memfree + info.membuffers + info.memcached) + " <%:kB%>",
479 info.memtotal + " <%:kB%>"
480 );
481
482 if (e = document.getElementById('memfree'))
483 e.innerHTML = progressbar(
484 info.memfree + " <%:kB%>", info.memtotal + " <%:kB%>"
485 );
486
487 if (e = document.getElementById('memcache'))
488 e.innerHTML = progressbar(
489 info.memcached + " <%:kB%>", info.memtotal + " <%:kB%>"
490 );
491
492 if (e = document.getElementById('membuff'))
493 e.innerHTML = progressbar(
494 info.membuffers + " <%:kB%>", info.memtotal + " <%:kB%>"
495 );
496
497 if (e = document.getElementById('conns'))
498 e.innerHTML = progressbar(info.conncount, info.connmax);
499
500 }
501 );
502 //]]></script>
503
504 <h2><a id="content" name="content"><%:Status%></a></h2>
505
506 <fieldset class="cbi-section">
507 <legend><%:System%></legend>
508
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)%>)
515 </td></tr>
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>
520 </table>
521 </fieldset>
522
523 <fieldset class="cbi-section">
524 <legend><%:Memory%></legend>
525
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>
531 </table>
532 </fieldset>
533
534 <fieldset class="cbi-section">
535 <legend><%:Network%></legend>
536
537 <table width="100%" cellspacing="10">
538 <tr><td width="33%" style="vertical-align:top"><%:IPv4 WAN Status%></td><td>
539 <table><tr>
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>
542 </tr></table>
543 </td></tr>
544 <% if has_ipv6 then %>
545 <tr><td width="33%" style="vertical-align:top"><%:IPv6 WAN Status%></td><td>
546 <table><tr>
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>
549 </tr></table>
550 </td></tr>
551 <% end %>
552 <tr><td width="33%"><%:Active Connections%></td><td id="conns">-</td></tr>
553 </table>
554 </fieldset>
555
556 <% if has_dhcp then %>
557 <fieldset class="cbi-section">
558 <legend><%:DHCP Leases%></legend>
559
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>
566 </tr>
567 <tr class="cbi-section-table-row">
568 <td colspan="4"><em><br /><%:Collecting data...%></em></td>
569 </tr>
570 </table>
571 </fieldset>
572
573 <fieldset class="cbi-section" style="display:none">
574 <legend><%:DHCPv6 Leases%></legend>
575
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>
582 </tr>
583 <tr class="cbi-section-table-row">
584 <td colspan="4"><em><br /><%:Collecting data...%></em></td>
585 </tr>
586 </table>
587 </fieldset>
588 <% end %>
589
590 <% if has_wifi then %>
591 <fieldset class="cbi-section">
592 <legend><%:Wireless%></legend>
593
594 <table id="wifi_status_table" width="100%" cellspacing="10">
595 <tr><td><em><%:Collecting data...%></em></td></tr>
596 </table>
597 </fieldset>
598
599 <fieldset class="cbi-section">
600 <legend><%:Associated Stations%></legend>
601
602 <table class="cbi-section-table" id="wifi_assoc_table">
603 <tr class="cbi-section-table-titles">
604 <th class="cbi-section-table-cell">&#160;</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>
611 </tr>
612 <tr class="cbi-section-table-row">
613 <td colspan="7"><em><br /><%:Collecting data...%></em></td>
614 </tr>
615 </table>
616 </fieldset>
617 <% end %>
618
619 <%-
620 require "luci.util"
621 require "nixio.fs"
622
623 local plugins = nixio.fs.dir(luci.util.libpath() .. "/view/admin_status/index")
624 if plugins then
625 local inc
626 for inc in plugins do
627 if inc:match("%.htm$") then
628 include("admin_status/index/" .. inc:gsub("%.htm$", ""))
629 end
630 end
631 end
632 -%>
633
634 <%+footer%>