e54ee9a9a3ad1b201810e27af73015c02c7fd3e7
[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 $Id$
13
14 -%>
15
16 <%
17 require "luci.fs"
18 require "luci.tools.status"
19
20 local has_ipv6 = luci.fs.access("/proc/net/ipv6_route")
21 local has_dhcp = luci.fs.access("/etc/config/dhcp")
22 local has_wifi = luci.fs.stat("/etc/config/wireless")
23 has_wifi = has_wifi and has_wifi.size > 0
24
25 if luci.http.formvalue("status") == "1" then
26 local ntm = require "luci.model.network".init()
27 local dr4 = luci.sys.net.defaultroute()
28 local dr6 = luci.sys.net.defaultroute6()
29 local wan, wan6
30
31 if dr4 and dr4.device then
32 wan = ntm:get_interface(dr4.device)
33 wan = wan and wan:get_network()
34 end
35
36 if dr6 and dr6.device then
37 wan6 = ntm:get_interface(dr6.device)
38 wan6 = wan6 and wan6:get_network()
39 end
40
41 local _, _, memtotal, memcached, membuffers, memfree = luci.sys.sysinfo()
42
43 local conn_count = tonumber((
44 luci.sys.exec("wc -l /proc/net/nf_conntrack") or
45 luci.sys.exec("wc -l /proc/net/ip_conntrack") or
46 ""):match("%d+")) or 0
47
48 local conn_max = tonumber((
49 luci.sys.exec("sysctl net.nf_conntrack_max") or
50 luci.sys.exec("sysctl net.ipv4.netfilter.ip_conntrack_max") or
51 ""):match("%d+")) or 4096
52
53 local rv = {
54 uptime = luci.sys.uptime(),
55 localtime = os.date(),
56 loadavg = { luci.sys.loadavg() },
57 memtotal = memtotal,
58 memcached = memcached,
59 membuffers = membuffers,
60 memfree = memfree,
61 connmax = conn_max,
62 conncount = conn_count,
63 leases = luci.tools.status.dhcp_leases(),
64 wifinets = luci.tools.status.wifi_networks()
65 }
66
67 if wan then
68 rv.wan = {
69 ipaddr = wan:ipaddr(),
70 gwaddr = wan:gwaddr(),
71 netmask = wan:netmask(),
72 dns = wan:dnsaddrs(),
73 expires = wan:expires(),
74 uptime = wan:uptime(),
75 proto = wan:proto(),
76 ifname = wan:ifname(),
77 link = wan:adminlink()
78 }
79 end
80
81 if wan6 then
82 rv.wan6 = {
83 ip6addr = wan6:ip6addr(),
84 gw6addr = wan6:gw6addr(),
85 dns = wan6:dns6addrs(),
86 uptime = wan6:uptime(),
87 ifname = wan6:ifname(),
88 link = wan6:adminlink()
89 }
90 end
91
92 luci.http.prepare_content("application/json")
93 luci.http.write_json(rv)
94
95 return
96 end
97
98 local system, model = luci.sys.sysinfo()
99 -%>
100
101 <%+header%>
102
103 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
104 <script type="text/javascript">//<![CDATA[
105 function progressbar(v, m)
106 {
107 var vn = parseInt(v) || 0;
108 var mn = parseInt(m) || 100;
109 var pc = Math.floor((100 / mn) * vn);
110
111 return String.format(
112 '<div style="width:200px; position:relative; border:1px solid #999999">' +
113 '<div style="background-color:#CCCCCC; width:%d%%; height:15px">' +
114 '<div style="position:absolute; left:0; top:0; text-align:center; width:100%%; color:#000000">' +
115 '<small>%s / %s (%d%%)</small>' +
116 '</div>' +
117 '</div>' +
118 '</div>', pc, v, m, pc
119 );
120 }
121
122 var wifidevs = <%=luci.http.write_json(netdevs)%>;
123 var arptable = <%=luci.http.write_json(arpcache)%>;
124
125 XHR.poll(5, '<%=REQUEST_URI%>', { status: 1 },
126 function(x, info)
127 {
128 var si = document.getElementById('wan4_i');
129 var ss = document.getElementById('wan4_s');
130 var ifc = info.wan;
131
132 if (ifc && ifc.ifname && ifc.proto != 'none')
133 {
134 var s = String.format(
135 '<strong><%:Type%>: </strong>%s<br />' +
136 '<strong><%:Address%>: </strong>%s<br />' +
137 '<strong><%:Netmask%>: </strong>%s<br />' +
138 '<strong><%:Gateway%>: </strong>%s<br />',
139 ifc.proto,
140 (ifc.ipaddr) ? ifc.ipaddr : '0.0.0.0',
141 (ifc.netmask && ifc.netmask != ifc.ipaddr) ? ifc.netmask : '255.255.255.255',
142 (ifc.gwaddr) ? ifc.gwaddr : '0.0.0.0'
143 );
144
145 for (var i = 0; i < ifc.dns.length; i++)
146 {
147 s += String.format(
148 '<strong><%:DNS%> %d: </strong>%s<br />',
149 i + 1, ifc.dns[i]
150 );
151 }
152
153 if (ifc.expires > -1)
154 {
155 s += String.format(
156 '<strong><%:Expires%>: </strong>%t<br />',
157 ifc.expires
158 );
159 }
160
161 if (ifc.uptime > 0)
162 {
163 s += String.format(
164 '<strong><%:Connected%>: </strong>%t<br />',
165 ifc.uptime
166 );
167 }
168
169 ss.innerHTML = String.format('<small>%s</small>', s);
170 si.innerHTML = String.format(
171 '<img src="<%=resource%>/icons/ethernet.png" />' +
172 '<br /><small><a href="%s">%s</a></small>',
173 ifc.link, ifc.ifname
174 );
175 }
176 else
177 {
178 si.innerHTML = '<img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small>';
179 ss.innerHTML = '<em>Not connected</em>';
180 }
181
182 <% if has_ipv6 then %>
183 var si6 = document.getElementById('wan6_i');
184 var ss6 = document.getElementById('wan6_s');
185 var ifc6 = info.wan6;
186
187 if (ifc6 && ifc6.ifname && ifc6.proto != 'none')
188 {
189 var s = String.format(
190 '<strong><%:Address%>: </strong>%s<br />' +
191 '<strong><%:Gateway%>: </strong>%s<br />',
192 (ifc6.ip6addr) ? ifc6.ip6addr : '::',
193 (ifc6.gw6addr) ? ifc6.gw6addr : '::'
194 );
195
196 for (var i = 0; i < ifc6.dns.length; i++)
197 {
198 s += String.format(
199 '<strong><%:DNS%> %d: </strong>%s<br />',
200 i + 1, ifc6.dns[i]
201 );
202 }
203
204 if (ifc6.uptime > 0)
205 {
206 s += String.format(
207 '<strong><%:Connected%>: </strong>%t<br />',
208 ifc6.uptime
209 );
210 }
211
212 ss6.innerHTML = String.format('<small>%s</small>', s);
213 si6.innerHTML = String.format(
214 '<img src="<%=resource%>/icons/ethernet.png" />' +
215 '<br /><small><a href="%s">%s</a></small>',
216 ifc6.link, ifc6.ifname
217 );
218 }
219 else
220 {
221 si6.innerHTML = '<img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small>';
222 ss6.innerHTML = '<em>Not connected</em>';
223 }
224 <% end %>
225
226 <% if has_dhcp then %>
227 var ls = document.getElementById('lease_status_table');
228 if (ls)
229 {
230 /* clear all rows */
231 while( ls.rows.length > 1 )
232 ls.rows[0].parentNode.deleteRow(1);
233
234 for( var i = 0; i < info.leases.length; i++ )
235 {
236 var timestr;
237
238 if (info.leases[i].expires <= 0)
239 timestr = '<em><%:expired%></em>';
240 else
241 timestr = String.format('%t', info.leases[i].expires);
242
243 var tr = ls.rows[0].parentNode.insertRow(-1);
244 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
245
246 tr.insertCell(-1).innerHTML = info.leases[i].hostname ? info.leases[i].hostname : '?';
247 tr.insertCell(-1).innerHTML = info.leases[i].ipaddr;
248 tr.insertCell(-1).innerHTML = info.leases[i].macaddr;
249 tr.insertCell(-1).innerHTML = timestr;
250 }
251
252 if( ls.rows.length == 1 )
253 {
254 var tr = ls.rows[0].parentNode.insertRow(-1);
255 tr.className = 'cbi-section-table-row';
256
257 var td = tr.insertCell(-1);
258 td.colSpan = 4;
259 td.innerHTML = '<em><br /><%:There are no active leases.%></em>';
260 }
261 }
262 <% end %>
263
264 <% if has_wifi then %>
265 var assoclist = [ ];
266
267 var ws = document.getElementById('wifi_status_table');
268 if (ws)
269 {
270 var wsbody = ws.rows[0].parentNode;
271 while (ws.rows.length > 0)
272 wsbody.deleteRow(0);
273
274 for (var didx = 0; didx < info.wifinets.length; didx++)
275 {
276 var dev = info.wifinets[didx];
277
278 var tr = wsbody.insertRow(-1);
279 var td;
280
281 td = tr.insertCell(-1);
282 td.width = "33%";
283 td.innerHTML = dev.name;
284 td.style.verticalAlign = "top";
285
286 td = tr.insertCell(-1);
287
288 var s = '';
289
290 for (var nidx = 0; nidx < dev.networks.length; nidx++)
291 {
292 var net = dev.networks[nidx];
293 var is_assoc = (net.bssid != '00:00:00:00:00:00' && net.channel);
294
295 var icon;
296 if (!is_assoc)
297 icon = "<%=resource%>/icons/signal-none.png";
298 else if (net.quality == 0)
299 icon = "<%=resource%>/icons/signal-0.png";
300 else if (net.quality < 25)
301 icon = "<%=resource%>/icons/signal-0-25.png";
302 else if (net.quality < 50)
303 icon = "<%=resource%>/icons/signal-25-50.png";
304 else if (net.quality < 75)
305 icon = "<%=resource%>/icons/signal-50-75.png";
306 else
307 icon = "<%=resource%>/icons/signal-75-100.png";
308
309 s += String.format(
310 '<table><tr><td style="text-align:center; width:32px; padding:3px">' +
311 '<img src="%s" title="<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" />' +
312 '<br /><small>%d%%</small>' +
313 '</td><td style="text-align:left; padding:3px"><small>' +
314 '<strong><%:SSID%>:</strong> <a href="%s">%h</a><br />' +
315 '<strong><%:Mode%>:</strong> %s<br />' +
316 '<strong><%:Channel%>:</strong> %d (%.2f GHz)<br />' +
317 '<strong><%:Bitrate%>:</strong> %s Mb/s<br />',
318 icon, net.signal, net.noise,
319 net.quality,
320 net.link, net.ssid,
321 net.mode,
322 net.channel, net.frequency,
323 net.bitrate || '?'
324 );
325
326 if (is_assoc)
327 {
328 s += String.format(
329 '<strong><%:BSSID%>:</strong> %s<br />' +
330 '<strong><%:Encryption%>:</strong> %s',
331 net.bssid,
332 net.encryption
333 );
334 }
335 else
336 {
337 s += '<em><%:Wireless is disabled or not associated%></em>';
338 }
339
340 s += '</small></td></tr></table>';
341
342 for (var bssid in net.assoclist)
343 {
344 assoclist.push({
345 bssid: bssid,
346 signal: net.assoclist[bssid].signal,
347 noise: net.assoclist[bssid].noise,
348 rx_rate: net.assoclist[bssid].rx_rate,
349 rx_mcs: net.assoclist[bssid].rx_mcs,
350 rx_40mhz: net.assoclist[bssid].rx_40mhz,
351 tx_rate: net.assoclist[bssid].tx_rate,
352 tx_mcs: net.assoclist[bssid].tx_mcs,
353 tx_40mhz: net.assoclist[bssid].tx_40mhz,
354 link: net.link,
355 name: net.name
356 });
357 }
358 }
359
360 if (!s)
361 s = '<em><%:No information available%></em>';
362
363 td.innerHTML = s;
364 }
365 }
366
367 var ac = document.getElementById('wifi_assoc_table');
368 if (ac)
369 {
370 /* clear all rows */
371 while( ac.rows.length > 1 )
372 ac.rows[0].parentNode.deleteRow(1);
373
374 assoclist.sort(function(a, b) {
375 return (a.name == b.name)
376 ? (a.bssid < b.bssid)
377 : (a.name > b.name )
378 ;
379 });
380
381 for( var i = 0; i < assoclist.length; i++ )
382 {
383 var tr = ac.rows[0].parentNode.insertRow(-1);
384 tr.className = 'cbi-section-table-row cbi-rowstyle-' + (1 + (i % 2));
385
386 var icon;
387 var q = (-1 * (assoclist[i].noise - assoclist[i].signal)) / 5;
388 if (q < 1)
389 icon = "<%=resource%>/icons/signal-0.png";
390 else if (q < 2)
391 icon = "<%=resource%>/icons/signal-0-25.png";
392 else if (q < 3)
393 icon = "<%=resource%>/icons/signal-25-50.png";
394 else if (q < 4)
395 icon = "<%=resource%>/icons/signal-50-75.png";
396 else
397 icon = "<%=resource%>/icons/signal-75-100.png";
398
399 tr.insertCell(-1).innerHTML = String.format(
400 '<img src="%s" title="<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" />',
401 icon, assoclist[i].signal, assoclist[i].noise
402 );
403
404 tr.insertCell(-1).innerHTML = assoclist[i].bssid;
405
406 tr.insertCell(-1).innerHTML = String.format(
407 '<a href="%s">%h</a>',
408 assoclist[i].link,
409 assoclist[i].name
410 );
411
412 tr.insertCell(-1).innerHTML = String.format('%d dBm', assoclist[i].signal);
413 tr.insertCell(-1).innerHTML = String.format('%d dBm', assoclist[i].noise);
414
415 tr.insertCell(-1).innerHTML = (assoclist[i].rx_mcs > -1)
416 ? String.format('%.1f Mbit/s, MCS %d, %dMHz', assoclist[i].rx_rate / 1000, assoclist[i].rx_mcs, assoclist[i].rx_40mhz ? 40 : 20)
417 : String.format('%.1f Mbit/s', assoclist[i].rx_rate / 1000)
418 ;
419
420 tr.insertCell(-1).innerHTML = (assoclist[i].tx_mcs > -1)
421 ? String.format('%.1f Mbit/s, MCS %d, %dMHz', assoclist[i].tx_rate / 1000, assoclist[i].tx_mcs, assoclist[i].tx_40mhz ? 40 : 20)
422 : String.format('%.1f Mbit/s', assoclist[i].tx_rate / 1000)
423 ;
424 }
425
426 if (ac.rows.length == 1)
427 {
428 var tr = ac.rows[0].parentNode.insertRow(-1);
429 tr.className = 'cbi-section-table-row';
430
431 var td = tr.insertCell(-1);
432 td.colSpan = 7;
433 td.innerHTML = '<br /><em><%:No information available%></em>';
434 }
435 }
436 <% end %>
437
438 var e;
439
440 if (e = document.getElementById('localtime'))
441 e.innerHTML = info.localtime;
442
443 if (e = document.getElementById('uptime'))
444 e.innerHTML = String.format('%t', info.uptime);
445
446 if (e = document.getElementById('loadavg'))
447 e.innerHTML = String.format('%.02f, %.02f, %.02f',
448 info.loadavg[0], info.loadavg[1], info.loadavg[2]);
449
450 if (e = document.getElementById('memtotal'))
451 e.innerHTML = progressbar(
452 (info.memfree + info.membuffers + info.memcached) + " kB",
453 info.memtotal + " kB"
454 );
455
456 if (e = document.getElementById('memfree'))
457 e.innerHTML = progressbar(
458 info.memfree + " kB", info.memtotal + " kB"
459 );
460
461 if (e = document.getElementById('memcache'))
462 e.innerHTML = progressbar(
463 info.memcached + " kB", info.memtotal + " kB"
464 );
465
466 if (e = document.getElementById('membuff'))
467 e.innerHTML = progressbar(
468 info.membuffers + " kB", info.memtotal + " kB"
469 );
470
471 if (e = document.getElementById('conns'))
472 e.innerHTML = progressbar(info.conncount, info.connmax);
473
474 }
475 );
476 //]]></script>
477
478 <h2><a id="content" name="content"><%:Status%></a></h2>
479
480 <fieldset class="cbi-section">
481 <legend><%:System%></legend>
482
483 <table width="100%" cellspacing="10">
484 <tr><td width="33%"><%:Router Name%></td><td><%=luci.sys.hostname() or "?"%></td></tr>
485 <tr><td width="33%"><%:Router Model%></td><td><%=pcdata(model or "?")%></td></tr>
486 <tr><td width="33%"><%:Firmware Version%></td><td>
487 <%=pcdata(luci.version.distname)%> <%=pcdata(luci.version.distversion)%> /
488 <%=pcdata(luci.version.luciname)%> (<%=pcdata(luci.version.luciversion)%>)
489 </td></tr>
490 <tr><td width="33%"><%:Kernel Version%></td><td><%=luci.sys.exec("uname -r")%></td></tr>
491 <tr><td width="33%"><%:Local Time%></td><td id="localtime">-</td></tr>
492 <tr><td width="33%"><%:Uptime%></td><td id="uptime">-</td></tr>
493 <tr><td width="33%"><%:Load Average%></td><td id="loadavg">-</td></tr>
494 </table>
495 </fieldset>
496
497 <fieldset class="cbi-section">
498 <legend><%:Memory%></legend>
499
500 <table width="100%" cellspacing="10">
501 <tr><td width="33%"><%:Total Available%></td><td id="memtotal">-</td></tr>
502 <tr><td width="33%"><%:Free%></td><td id="memfree">-</td></tr>
503 <tr><td width="33%"><%:Cached%></td><td id="memcache">-</td></tr>
504 <tr><td width="33%"><%:Buffered%></td><td id="membuff">-</td></tr>
505 </table>
506 </fieldset>
507
508 <fieldset class="cbi-section">
509 <legend><%:Network%></legend>
510
511 <table width="100%" cellspacing="10">
512 <tr><td width="33%" style="vertical-align:top"><%:IPv4 WAN Status%></td><td>
513 <table><tr>
514 <td id="wan4_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td>
515 <td id="wan4_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></td>
516 </tr></table>
517 </td></tr>
518 <% if has_ipv6 then %>
519 <tr><td width="33%" style="vertical-align:top"><%:IPv6 WAN Status%></td><td>
520 <table><tr>
521 <td id="wan6_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td>
522 <td id="wan6_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></td>
523 </tr></table>
524 </td></tr>
525 <% end %>
526 <tr><td width="33%"><%:Active Connections%></td><td id="conns">-</td></tr>
527 </table>
528 </fieldset>
529
530 <% if has_dhcp then %>
531 <fieldset class="cbi-section">
532 <legend><%:DHCP Leases%></legend>
533
534 <table class="cbi-section-table" id="lease_status_table">
535 <tr class="cbi-section-table-titles">
536 <th class="cbi-section-table-cell"><%:Hostname%></th>
537 <th class="cbi-section-table-cell"><%:IPv4-Address%></th>
538 <th class="cbi-section-table-cell"><%:MAC-Address%></th>
539 <th class="cbi-section-table-cell"><%:Leasetime remaining%></th>
540 </tr>
541 <tr class="cbi-section-table-row">
542 <td colspan="4"><em><br /><%:Collecting data...%></em></td>
543 </tr>
544 </table>
545 </fieldset>
546 <% end %>
547
548 <% if has_wifi then %>
549 <fieldset class="cbi-section">
550 <legend><%:Wireless%></legend>
551
552 <table id="wifi_status_table" width="100%" cellspacing="10">
553 <tr><td><em><%:Collecting data...%></em></td></tr>
554 </table>
555 </fieldset>
556
557 <fieldset class="cbi-section">
558 <legend><%:Associated Stations%></legend>
559
560 <table class="cbi-section-table" id="wifi_assoc_table">
561 <tr class="cbi-section-table-titles">
562 <th class="cbi-section-table-cell">&#160;</th>
563 <th class="cbi-section-table-cell"><%:MAC-Address%></th>
564 <th class="cbi-section-table-cell"><%:Network%></th>
565 <th class="cbi-section-table-cell"><%:Signal%></th>
566 <th class="cbi-section-table-cell"><%:Noise%></th>
567 <th class="cbi-section-table-cell"><%:RX Rate%></th>
568 <th class="cbi-section-table-cell"><%:TX Rate%></th>
569 </tr>
570 <tr class="cbi-section-table-row">
571 <td colspan="7"><em><br /><%:Collecting data...%></em></td>
572 </tr>
573 </table>
574 </fieldset>
575 <% end %>
576
577 <%-
578 require "luci.util"
579 require "nixio.fs"
580
581 local plugins = nixio.fs.dir(luci.util.libpath() .. "/view/admin_status/index")
582 if plugins then
583 local inc
584 for inc in plugins do
585 if inc:match("%.htm$") then
586 include("admin_status/index/" .. inc:gsub("%.htm$", ""))
587 end
588 end
589 end
590 -%>
591
592 <%+footer%>