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.
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"
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)
18 local sysinfo = luci.util.ubus(
"system",
"info") or { }
19 local boardinfo = luci.util.ubus(
"system",
"board") or { }
20 local unameinfo = nixio.uname() or { }
22 local meminfo = sysinfo.memory or {
29 local swapinfo = sysinfo.swap or {
34 local has_dsl = fs.access(
"/etc/init.d/dsl_control")
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()
41 local conn_count = tonumber(
42 fs.readfile(
"/proc/sys/net/netfilter/nf_conntrack_count") or
"") or
0
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
49 uptime = sysinfo.uptime or
0,
50 localtime = os.date(),
51 loadavg = sysinfo.load or {
0,
0,
0 },
55 conncount = conn_count,
56 wifinets = stat.wifi_networks()
60 local dev = wan:get_interface()
61 local link = dev and ipc.link(dev:name())
63 ipaddr = wan:ipaddr(),
64 gwaddr = wan:gwaddr(),
65 netmask = wan:netmask(),
67 expires = wan:expires(),
68 uptime = wan:uptime(),
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
81 local dev = wan6:get_interface()
82 local link = dev and ipc.link(dev:name())
84 ip6addr = wan6:ip6addr(),
85 gw6addr = wan6:gw6addr(),
86 dns = wan6:dns6addrs(),
87 ip6prefix = wan6:ip6prefix(),
88 uptime = wan6:uptime(),
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
101 local dsl_stat = luci.sys.exec(
"/etc/init.d/dsl_control lucistat")
102 local dsl_func = loadstring(dsl_stat)
108 luci.http.prepare_content(
"application/json")
109 luci.http.write_json(rv)
117 <script type=
"text/javascript" src=
"<%=resource%>/cbi.js"></script>
118 <script type=
"text/javascript">//<![CDATA[
119 function progressbar(v, m)
121 var vn = parseInt(v) ||
0;
122 var mn = parseInt(m) ||
100;
123 var pc = Math.floor((
100 / mn) * vn);
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>' +
132 '
</div>', pc, v, m, pc
136 function labelList(items, offset) {
139 for (var i = offset ||
0; i < items.length; i +=
2) {
140 var label = items[i],
143 if (value === undefined || value === null)
147 rv.push(E('strong', [label, ': ']));
149 rv.push(value, E('br'));
155 function renderBox(title, active, childs) {
156 childs = childs || [];
157 childs.unshift(E('span', labelList(arguments,
3)));
159 return E('div', { class: 'ifacebox' }, [
160 E('div', { class: 'ifacebox-head center ' + (active ? 'active' : '') },
162 E('div', { class: 'ifacebox-body left' }, childs)
166 function renderBadge(icon, title) {
167 return E('span', { class: 'ifacebadge' }, [
168 E('img', { src: icon, title: title || '' }),
169 E('span', labelList(arguments,
2))
173 XHR.poll(
5, '<%=REQUEST_URI%
>', { status:
1 },
176 var us = document.getElementById('upstream_status_table');
178 while (us.lastElementChild)
179 us.removeChild(us.lastElementChild);
181 var ifc = info.wan || {};
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));
202 <% if has_ipv6 then %
>
203 var ifc6 = info.wan6 || {};
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));
224 <% if has_dsl then %
>
225 var dsl_i = document.getElementById('dsl_i');
226 var dsl_s = document.getElementById('dsl_s');
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,
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
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>'
284 <% if has_wifi then %
>
285 var ws = document.getElementById('wifi_status_table');
288 while (ws.lastElementChild)
289 ws.removeChild(ws.lastElementChild);
291 for (var didx =
0; didx < info.wifinets.length; didx++)
293 var dev = info.wifinets[didx];
294 var net0 = (dev.networks && dev.networks[
0]) ? dev.networks[
0] : {};
297 for (var nidx =
0; nidx < dev.networks.length; nidx++)
299 var net = dev.networks[nidx];
300 var is_assoc = (net.bssid != '
00:
00:
00:
00:
00:
00' && net.channel && !net.disabled);
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";
314 icon =
"<%=resource%>/icons/signal-75-100.png";
316 vifs.push(renderBadge(
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%
>')));
327 ws.appendChild(renderBox(
328 dev.device, dev.up || net0.up,
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) : '-'));
335 if (!ws.lastElementChild)
336 ws.appendChild(E('
<em><%:No information available%
></em>'));
342 if (e = document.getElementById('localtime'))
343 e.innerHTML = info.localtime;
345 if (e = document.getElementById('uptime'))
346 e.innerHTML = String.format('%t', info.uptime);
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
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%>"
362 if (e = document.getElementById('memfree'))
363 e.innerHTML = progressbar(
364 (info.memory.free /
1024) +
" <%:kB%>",
365 (info.memory.total /
1024) +
" <%:kB%>"
368 if (e = document.getElementById('membuff'))
369 e.innerHTML = progressbar(
370 (info.memory.buffered /
1024) +
" <%:kB%>",
371 (info.memory.total /
1024) +
" <%:kB%>"
374 if (e = document.getElementById('swaptotal'))
375 e.innerHTML = progressbar(
376 (info.swap.free /
1024) +
" <%:kB%>",
377 (info.swap.total /
1024) +
" <%:kB%>"
380 if (e = document.getElementById('swapfree'))
381 e.innerHTML = progressbar(
382 (info.swap.free /
1024) +
" <%:kB%>",
383 (info.swap.total /
1024) +
" <%:kB%>"
386 if (e = document.getElementById('conns'))
387 e.innerHTML = progressbar(info.conncount, info.connmax);
393 <h2 name=
"content"><%:Status%
></h2>
395 <div class=
"cbi-section">
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)%
>)
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>
413 <div class=
"cbi-section">
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>
423 <% if swapinfo.total
> 0 then %
>
424 <div class=
"cbi-section">
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>
434 <div class=
"cbi-section">
435 <h3><%:Network%
></h3>
437 <div id=
"upstream_status_table" class=
"network-status-table">
438 <em><%:Collecting data...%
></em>
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>
448 include(
"admin_network/lease_status")
452 <% if has_dsl then %
>
453 <div class=
"cbi-section">
456 <div class=
"table" width=
"100%">
458 <div class=
"td left" width=
"33%" style=
"vertical-align:top"><%:DSL Status%
></div>
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>
472 <% if has_wifi then %
>
473 <div class=
"cbi-section">
474 <h3><%:Wireless%
></h3>
476 <div id=
"wifi_status_table" class=
"network-status-table">
477 <em><%:Collecting data...%
></em>
481 <div class=
"cbi-section">
482 <h3><%:Associated Stations%
></h3>
484 <%+admin_network/wifi_assoclist%
>
489 local incdir = util.libpath() ..
"/view/admin_status/index/"
490 if fs.access(incdir) then
492 for inc in fs.dir(incdir) do
493 if inc:match(
"%.htm$") then
494 include(
"admin_status/index/" .. inc:gsub(
"%.htm$",
""))