Merge pull request #1924 from dibdot/lxc_fix
[project/luci.git] / modules / luci-mod-admin-full / luasrc / view / admin_status / index.htm
1 <%#
2 Copyright 2008 Steven Barth <steven@midlink.org>
3 Copyright 2008-2011 Jo-Philipp Wich <jow@openwrt.org>
4 Licensed to the public under the Apache License 2.0.
5 -%>
6
7 <%
8 local fs = require "nixio.fs"
9 local ipc = require "luci.ip"
10 local util = require "luci.util"
11 local stat = require "luci.tools.status"
12 local ver = require "luci.version"
13
14 local has_ipv6 = fs.access("/proc/net/ipv6_route")
15 local has_dhcp = fs.access("/etc/config/dhcp")
16 local has_wifi = ((fs.stat("/etc/config/wireless", "size") or 0) > 0)
17
18 local sysinfo = luci.util.ubus("system", "info") or { }
19 local boardinfo = luci.util.ubus("system", "board") or { }
20 local unameinfo = nixio.uname() or { }
21
22 local meminfo = sysinfo.memory or {
23 total = 0,
24 free = 0,
25 buffered = 0,
26 shared = 0
27 }
28
29 local swapinfo = sysinfo.swap or {
30 total = 0,
31 free = 0
32 }
33
34 local has_dsl = fs.access("/etc/init.d/dsl_control")
35
36 if luci.http.formvalue("status") == "1" then
37 local ntm = require "luci.model.network".init()
38 local wan = ntm:get_wannet()
39 local wan6 = ntm:get_wan6net()
40
41 local conn_count = tonumber(
42 fs.readfile("/proc/sys/net/netfilter/nf_conntrack_count") or "") or 0
43
44 local conn_max = tonumber(luci.sys.exec(
45 "sysctl -n -e net.nf_conntrack_max net.ipv4.netfilter.ip_conntrack_max"
46 ):match("%d+")) or 4096
47
48 local rv = {
49 uptime = sysinfo.uptime or 0,
50 localtime = os.date(),
51 loadavg = sysinfo.load or { 0, 0, 0 },
52 memory = meminfo,
53 swap = swapinfo,
54 connmax = conn_max,
55 conncount = conn_count,
56 wifinets = stat.wifi_networks()
57 }
58
59 if wan then
60 local dev = wan:get_interface()
61 local link = dev and ipc.link(dev:name())
62 rv.wan = {
63 ipaddr = wan:ipaddr(),
64 gwaddr = wan:gwaddr(),
65 netmask = wan:netmask(),
66 dns = wan:dnsaddrs(),
67 expires = wan:expires(),
68 uptime = wan:uptime(),
69 proto = wan:proto(),
70 i18n = wan:get_i18n(),
71 ifname = wan:ifname(),
72 link = wan:adminlink(),
73 mac = dev and dev:mac(),
74 type = dev and dev:type(),
75 name = dev and dev:get_i18n(),
76 ether = link and link.type == 1
77 }
78 end
79
80 if wan6 then
81 local dev = wan6:get_interface()
82 local link = dev and ipc.link(dev:name())
83 rv.wan6 = {
84 ip6addr = wan6:ip6addr(),
85 gw6addr = wan6:gw6addr(),
86 dns = wan6:dns6addrs(),
87 ip6prefix = wan6:ip6prefix(),
88 uptime = wan6:uptime(),
89 proto = wan6:proto(),
90 i18n = wan6:get_i18n(),
91 ifname = wan6:ifname(),
92 link = wan6:adminlink(),
93 mac = dev and dev:mac(),
94 type = dev and dev:type(),
95 name = dev and dev:get_i18n(),
96 ether = link and link.type == 1
97 }
98 end
99
100 if has_dsl then
101 local dsl_stat = luci.sys.exec("/etc/init.d/dsl_control lucistat")
102 local dsl_func = loadstring(dsl_stat)
103 if dsl_func then
104 rv.dsl = dsl_func()
105 end
106 end
107
108 luci.http.prepare_content("application/json")
109 luci.http.write_json(rv)
110
111 return
112 end
113 -%>
114
115 <%+header%>
116
117 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
118 <script type="text/javascript">//<![CDATA[
119 function progressbar(v, m)
120 {
121 var vn = parseInt(v) || 0;
122 var mn = parseInt(m) || 100;
123 var pc = Math.floor((100 / mn) * vn);
124
125 return String.format(
126 '<div style="width:100%%; max-width:200px; position:relative; border:1px solid #999999">' +
127 '<div style="background-color:#CCCCCC; width:%d%%; height:15px">' +
128 '<div style="position:absolute; left:0; top:0; text-align:center; width:100%%; color:#000000">' +
129 '<small>%s / %s (%d%%)</small>' +
130 '</div>' +
131 '</div>' +
132 '</div>', pc, v, m, pc
133 );
134 }
135
136 function labelList(items, offset) {
137 var rv = [ ];
138
139 for (var i = offset || 0; i < items.length; i += 2) {
140 var label = items[i],
141 value = items[i+1];
142
143 if (value === undefined || value === null)
144 continue;
145
146 if (label)
147 rv.push(E('strong', [label, ': ']));
148
149 rv.push(value, E('br'));
150 }
151
152 return rv;
153 }
154
155 function renderBox(title, active, childs) {
156 childs = childs || [];
157 childs.unshift(E('span', labelList(arguments, 3)));
158
159 return E('div', { class: 'ifacebox' }, [
160 E('div', { class: 'ifacebox-head center ' + (active ? 'active' : '') },
161 E('strong', title)),
162 E('div', { class: 'ifacebox-body left' }, childs)
163 ]);
164 }
165
166 function renderBadge(icon, title) {
167 return E('span', { class: 'ifacebadge' }, [
168 E('img', { src: icon, title: title || '' }),
169 E('span', labelList(arguments, 2))
170 ]);
171 }
172
173 XHR.poll(5, '<%=REQUEST_URI%>', { status: 1 },
174 function(x, info)
175 {
176 var us = document.getElementById('upstream_status_table');
177
178 while (us.lastElementChild)
179 us.removeChild(us.lastElementChild);
180
181 var ifc = info.wan || {};
182
183 us.appendChild(renderBox(
184 '<%:IPv4 Upstream%>',
185 (ifc.ifname && ifc.proto != 'none'),
186 [ E('div', {}, renderBadge(
187 '<%=resource%>/icons/%s.png'.format((ifc && ifc.type) ? ifc.type : 'ethernet_disabled'), null,
188 '<%:Device%>', ifc ? (ifc.name || ifc.ifname || '-') : '-',
189 '<%:MAC-Address%>', (ifc && ifc.ether) ? ifc.mac : null)) ],
190 '<%:Protocol%>', ifc.i18n || E('em', '<%:Not connected%>'),
191 '<%:Address%>', (ifc.ipaddr) ? ifc.ipaddr : '0.0.0.0',
192 '<%:Netmask%>', (ifc.netmask && ifc.netmask != ifc.ipaddr) ? ifc.netmask : '255.255.255.255',
193 '<%:Gateway%>', (ifc.gwaddr) ? ifc.gwaddr : '0.0.0.0',
194 '<%:DNS%> 1', (ifc.dns) ? ifc.dns[0] : null,
195 '<%:DNS%> 2', (ifc.dns) ? ifc.dns[1] : null,
196 '<%:DNS%> 3', (ifc.dns) ? ifc.dns[2] : null,
197 '<%:DNS%> 4', (ifc.dns) ? ifc.dns[3] : null,
198 '<%:DNS%> 5', (ifc.dns) ? ifc.dns[4] : null,
199 '<%:Expires%>', (ifc.expires > -1) ? '%t'.format(ifc.expires) : null,
200 '<%:Connected%>', (ifc.uptime > 0) ? '%t'.format(ifc.uptime) : null));
201
202 <% if has_ipv6 then %>
203 var ifc6 = info.wan6 || {};
204
205 us.appendChild(renderBox(
206 '<%:IPv6 Upstream%>',
207 (ifc6.ifname && ifc6.proto != 'none'),
208 [ E('div', {}, renderBadge(
209 '<%=resource%>/icons/%s.png'.format(ifc6.type || 'ethernet_disabled'), null,
210 '<%:Device%>', ifc6 ? (ifc6.name || ifc6.ifname || '-') : '-',
211 '<%:MAC-Address%>', (ifc6 && ifc6.ether) ? ifc6.mac : null)) ],
212 '<%:Protocol%>', ifc6.i18n ? (ifc6.i18n + (ifc6.proto === 'dhcp' && ifc6.ip6prefix ? '-PD' : '')) : E('em', '<%:Not connected%>'),
213 '<%:Prefix Delegated%>', ifc6.ip6prefix,
214 '<%:Address%>', (ifc6.ip6prefix) ? (ifc6.ip6addr || null) : (ifc6.ipaddr || '::'),
215 '<%:Gateway%>', (ifc6.gw6addr) ? ifc6.gw6addr : '::',
216 '<%:DNS%> 1', (ifc6.dns) ? ifc6.dns[0] : null,
217 '<%:DNS%> 2', (ifc6.dns) ? ifc6.dns[1] : null,
218 '<%:DNS%> 3', (ifc6.dns) ? ifc6.dns[2] : null,
219 '<%:DNS%> 4', (ifc6.dns) ? ifc6.dns[3] : null,
220 '<%:DNS%> 5', (ifc6.dns) ? ifc6.dns[4] : null,
221 '<%:Connected%>', (ifc6.uptime > 0) ? '%t'.format(ifc6.uptime) : null));
222 <% end %>
223
224 <% if has_dsl then %>
225 var dsl_i = document.getElementById('dsl_i');
226 var dsl_s = document.getElementById('dsl_s');
227
228 var s = String.format(
229 '<strong><%:Status%>: </strong>%s<br />' +
230 '<strong><%:Line State%>: </strong>%s [0x%x]<br />' +
231 '<strong><%:Line Mode%>: </strong>%s<br />' +
232 '<strong><%:Annex%>: </strong>%s<br />' +
233 '<strong><%:Profile%>: </strong>%s<br />' +
234 '<strong><%:Data Rate%>: </strong>%s/s / %s/s<br />' +
235 '<strong><%:Max. Attainable Data Rate (ATTNDR)%>: </strong>%s/s / %s/s<br />' +
236 '<strong><%:Latency%>: </strong>%s / %s<br />' +
237 '<strong><%:Line Attenuation (LATN)%>: </strong>%s dB / %s dB<br />' +
238 '<strong><%:Signal Attenuation (SATN)%>: </strong>%s dB / %s dB<br />' +
239 '<strong><%:Noise Margin (SNR)%>: </strong>%s dB / %s dB<br />' +
240 '<strong><%:Aggregate Transmit Power(ACTATP)%>: </strong>%s dB / %s dB<br />' +
241 '<strong><%:Forward Error Correction Seconds (FECS)%>: </strong>%s / %s<br />' +
242 '<strong><%:Errored seconds (ES)%>: </strong>%s / %s<br />' +
243 '<strong><%:Severely Errored Seconds (SES)%>: </strong>%s / %s<br />' +
244 '<strong><%:Loss of Signal Seconds (LOSS)%>: </strong>%s / %s<br />' +
245 '<strong><%:Unavailable Seconds (UAS)%>: </strong>%s / %s<br />' +
246 '<strong><%:Header Error Code Errors (HEC)%>: </strong>%s / %s<br />' +
247 '<strong><%:Non Pre-emtive CRC errors (CRC_P)%>: </strong>%s / %s<br />' +
248 '<strong><%:Pre-emtive CRC errors (CRCP_P)%>: </strong>%s / %s<br />' +
249 '<strong><%:Line Uptime%>: </strong>%s<br />' +
250 '<strong><%:ATU-C System Vendor ID%>: </strong>%s<br />' +
251 '<strong><%:Power Management Mode%>: </strong>%s<br />',
252 info.dsl.line_state, info.dsl.line_state_detail,
253 info.dsl.line_state_num,
254 info.dsl.line_mode_s,
255 info.dsl.annex_s,
256 info.dsl.profile_s,
257 info.dsl.data_rate_down_s, info.dsl.data_rate_up_s,
258 info.dsl.max_data_rate_down_s, info.dsl.max_data_rate_up_s,
259 info.dsl.latency_num_down, info.dsl.latency_num_up,
260 info.dsl.line_attenuation_down, info.dsl.line_attenuation_up,
261 info.dsl.signal_attenuation_down, info.dsl.signal_attenuation_up,
262 info.dsl.noise_margin_down, info.dsl.noise_margin_up,
263 info.dsl.actatp_down, info.dsl.actatp_up,
264 info.dsl.errors_fec_near, info.dsl.errors_fec_far,
265 info.dsl.errors_es_near, info.dsl.errors_es_far,
266 info.dsl.errors_ses_near, info.dsl.errors_ses_far,
267 info.dsl.errors_loss_near, info.dsl.errors_loss_far,
268 info.dsl.errors_uas_near, info.dsl.errors_uas_far,
269 info.dsl.errors_hec_near, info.dsl.errors_hec_far,
270 info.dsl.errors_crc_p_near, info.dsl.errors_crc_p_far,
271 info.dsl.errors_crcp_p_near, info.dsl.errors_crcp_p_far,
272 info.dsl.line_uptime_s,
273 info.dsl.atuc_vendor_id,
274 info.dsl.power_mode_s
275 );
276
277 dsl_s.innerHTML = String.format('<small>%s</small>', s);
278 dsl_i.innerHTML = String.format(
279 '<img src="<%=resource%>/icons/ethernet.png" />' +
280 '<br /><small>DSL</small>'
281 );
282 <% end %>
283
284 <% if has_wifi then %>
285 var ws = document.getElementById('wifi_status_table');
286 if (ws)
287 {
288 while (ws.lastElementChild)
289 ws.removeChild(ws.lastElementChild);
290
291 for (var didx = 0; didx < info.wifinets.length; didx++)
292 {
293 var dev = info.wifinets[didx];
294 var net0 = (dev.networks && dev.networks[0]) ? dev.networks[0] : {};
295 var vifs = [];
296
297 for (var nidx = 0; nidx < dev.networks.length; nidx++)
298 {
299 var net = dev.networks[nidx];
300 var is_assoc = (net.bssid != '00:00:00:00:00:00' && net.channel && !net.disabled);
301
302 var icon;
303 if (!is_assoc)
304 icon = "<%=resource%>/icons/signal-none.png";
305 else if (net.quality == 0)
306 icon = "<%=resource%>/icons/signal-0.png";
307 else if (net.quality < 25)
308 icon = "<%=resource%>/icons/signal-0-25.png";
309 else if (net.quality < 50)
310 icon = "<%=resource%>/icons/signal-25-50.png";
311 else if (net.quality < 75)
312 icon = "<%=resource%>/icons/signal-50-75.png";
313 else
314 icon = "<%=resource%>/icons/signal-75-100.png";
315
316 vifs.push(renderBadge(
317 icon,
318 '<%:Signal%>: %d dBm / <%:Quality%>: %d%%'.format(net.signal, net.quality),
319 '<%:SSID%>', E('a', { href: net.link }, [ net.ssid || '?' ]),
320 '<%:Mode%>', net.mode,
321 '<%:BSSID%>', is_assoc ? (net.bssid || '-') : null,
322 '<%:Encryption%>', is_assoc ? net.encryption : null,
323 '<%:Associations%>', is_assoc ? (net.num_assoc || '-') : null,
324 null, is_assoc ? null : E('em', '<%:Wireless is disabled or not associated%>')));
325 }
326
327 ws.appendChild(renderBox(
328 dev.device, dev.up || net0.up,
329 [ E('div', vifs) ],
330 '<%:Type%>', dev.name.replace(/^Generic | Wireless Controller .+$/g, ''),
331 '<%:Channel%>', net0.channel ? '%d (%.3f <%:GHz%>)'.format(net0.channel, net0.frequency) : '-',
332 '<%:Bitrate%>', net0.bitrate ? '%d <%:Mbit/s%>'.format(net0.bitrate) : '-'));
333 }
334
335 if (!ws.lastElementChild)
336 ws.appendChild(E('<em><%:No information available%></em>'));
337 }
338 <% end %>
339
340 var e;
341
342 if (e = document.getElementById('localtime'))
343 e.innerHTML = info.localtime;
344
345 if (e = document.getElementById('uptime'))
346 e.innerHTML = String.format('%t', info.uptime);
347
348 if (e = document.getElementById('loadavg'))
349 e.innerHTML = String.format(
350 '%.02f, %.02f, %.02f',
351 info.loadavg[0] / 65535.0,
352 info.loadavg[1] / 65535.0,
353 info.loadavg[2] / 65535.0
354 );
355
356 if (e = document.getElementById('memtotal'))
357 e.innerHTML = progressbar(
358 ((info.memory.free + info.memory.buffered) / 1024) + " <%:kB%>",
359 (info.memory.total / 1024) + " <%:kB%>"
360 );
361
362 if (e = document.getElementById('memfree'))
363 e.innerHTML = progressbar(
364 (info.memory.free / 1024) + " <%:kB%>",
365 (info.memory.total / 1024) + " <%:kB%>"
366 );
367
368 if (e = document.getElementById('membuff'))
369 e.innerHTML = progressbar(
370 (info.memory.buffered / 1024) + " <%:kB%>",
371 (info.memory.total / 1024) + " <%:kB%>"
372 );
373
374 if (e = document.getElementById('swaptotal'))
375 e.innerHTML = progressbar(
376 (info.swap.free / 1024) + " <%:kB%>",
377 (info.swap.total / 1024) + " <%:kB%>"
378 );
379
380 if (e = document.getElementById('swapfree'))
381 e.innerHTML = progressbar(
382 (info.swap.free / 1024) + " <%:kB%>",
383 (info.swap.total / 1024) + " <%:kB%>"
384 );
385
386 if (e = document.getElementById('conns'))
387 e.innerHTML = progressbar(info.conncount, info.connmax);
388
389 }
390 );
391 //]]></script>
392
393 <h2 name="content"><%:Status%></h2>
394
395 <div class="cbi-section">
396 <h3><%:System%></h3>
397
398 <div class="table" width="100%">
399 <div class="tr"><div class="td left" width="33%"><%:Hostname%></div><div class="td left"><%=luci.sys.hostname() or "?"%></div></div>
400 <div class="tr"><div class="td left" width="33%"><%:Model%></div><div class="td left"><%=pcdata(boardinfo.model or "?")%></div></div>
401 <div class="tr"><div class="td left" width="33%"><%:Architecture%></div><div class="td left"><%=pcdata(boardinfo.system or "?")%></div></div>
402 <div class="tr"><div class="td left" width="33%"><%:Firmware Version%></div><div class="td left">
403 <%=pcdata(ver.distname)%> <%=pcdata(ver.distversion)%> /
404 <%=pcdata(ver.luciname)%> (<%=pcdata(ver.luciversion)%>)
405 </div></div>
406 <div class="tr"><div class="td left" width="33%"><%:Kernel Version%></div><div class="td left"><%=unameinfo.release or "?"%></div></div>
407 <div class="tr"><div class="td left" width="33%"><%:Local Time%></div><div class="td left" id="localtime">-</div></div>
408 <div class="tr"><div class="td left" width="33%"><%:Uptime%></div><div class="td left" id="uptime">-</div></div>
409 <div class="tr"><div class="td left" width="33%"><%:Load Average%></div><div class="td left" id="loadavg">-</div></div>
410 </div>
411 </div>
412
413 <div class="cbi-section">
414 <h3><%:Memory%></h3>
415
416 <div class="table" width="100%">
417 <div class="tr"><div class="td left" width="33%"><%:Total Available%></div><div class="td left" id="memtotal">-</div></div>
418 <div class="tr"><div class="td left" width="33%"><%:Free%></div><div class="td left" id="memfree">-</div></div>
419 <div class="tr"><div class="td left" width="33%"><%:Buffered%></div><div class="td left" id="membuff">-</div></div>
420 </div>
421 </div>
422
423 <% if swapinfo.total > 0 then %>
424 <div class="cbi-section">
425 <h3><%:Swap%></h3>
426
427 <div class="table" width="100%">
428 <div class="tr"><div class="td left" width="33%"><%:Total Available%></div><div class="td left" id="swaptotal">-</div></div>
429 <div class="tr"><div class="td left" width="33%"><%:Free%></div><div class="td left" id="swapfree">-</div></div>
430 </div>
431 </div>
432 <% end %>
433
434 <div class="cbi-section">
435 <h3><%:Network%></h3>
436
437 <div id="upstream_status_table" class="network-status-table">
438 <em><%:Collecting data...%></em>
439 </div>
440
441 <div class="table" width="100%">
442 <div class="tr"><div class="td left" width="33%"><%:Active Connections%></div><div class="td left" id="conns">-</div></div>
443 </div>
444 </div>
445
446 <%
447 if has_dhcp then
448 include("admin_network/lease_status")
449 end
450 %>
451
452 <% if has_dsl then %>
453 <div class="cbi-section">
454 <h3><%:DSL%></h3>
455
456 <div class="table" width="100%">
457 <div class="tr">
458 <div class="td left" width="33%" style="vertical-align:top"><%:DSL Status%></div>
459 <div class="td">
460 <div class="table">
461 <div class="tr">
462 <div class="td" id="dsl_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></div>
463 <div class="td left" id="dsl_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></div>
464 </div>
465 </div>
466 </div>
467 </div>
468 </div>
469 </div>
470 <% end %>
471
472 <% if has_wifi then %>
473 <div class="cbi-section">
474 <h3><%:Wireless%></h3>
475
476 <div id="wifi_status_table" class="network-status-table">
477 <em><%:Collecting data...%></em>
478 </div>
479 </div>
480
481 <div class="cbi-section">
482 <h3><%:Associated Stations%></h3>
483
484 <%+admin_network/wifi_assoclist%>
485 </div>
486 <% end %>
487
488 <%-
489 local incdir = util.libpath() .. "/view/admin_status/index/"
490 if fs.access(incdir) then
491 local inc
492 for inc in fs.dir(incdir) do
493 if inc:match("%.htm$") then
494 include("admin_status/index/" .. inc:gsub("%.htm$", ""))
495 end
496 end
497 end
498 -%>
499
500 <%+footer%>