Merge pull request #1818 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 util = require "luci.util"
10         local stat = require "luci.tools.status"
11         local ver = require "luci.version"
12
13         local has_ipv6 = fs.access("/proc/net/ipv6_route")
14         local has_dhcp = fs.access("/etc/config/dhcp")
15         local has_wifi = ((fs.stat("/etc/config/wireless", "size") or 0) > 0)
16
17         local sysinfo = luci.util.ubus("system", "info") or { }
18         local boardinfo = luci.util.ubus("system", "board") or { }
19         local unameinfo = nixio.uname() or { }
20
21         local meminfo = sysinfo.memory or {
22                 total = 0,
23                 free = 0,
24                 buffered = 0,
25                 shared = 0
26         }
27
28         local swapinfo = sysinfo.swap or {
29                 total = 0,
30                 free = 0
31         }
32
33         local has_dsl = fs.access("/etc/init.d/dsl_control")
34
35         if luci.http.formvalue("status") == "1" then
36                 local ntm = require "luci.model.network".init()
37                 local wan = ntm:get_wannet()
38                 local wan6 = ntm:get_wan6net()
39
40                 local conn_count = tonumber(
41                         fs.readfile("/proc/sys/net/netfilter/nf_conntrack_count") or "") or 0
42
43                 local conn_max = tonumber(luci.sys.exec(
44                         "sysctl -n -e net.nf_conntrack_max net.ipv4.netfilter.ip_conntrack_max"
45                 ):match("%d+")) or 4096
46
47                 local rv = {
48                         uptime     = sysinfo.uptime or 0,
49                         localtime  = os.date(),
50                         loadavg    = sysinfo.load or { 0, 0, 0 },
51                         memory     = meminfo,
52                         swap       = swapinfo,
53                         connmax    = conn_max,
54                         conncount  = conn_count,
55                         leases     = stat.dhcp_leases(),
56                         leases6    = stat.dhcp6_leases(),
57                         wifinets   = stat.wifi_networks()
58                 }
59
60                 if wan then
61                         rv.wan = {
62                                 ipaddr  = wan:ipaddr(),
63                                 gwaddr  = wan:gwaddr(),
64                                 netmask = wan:netmask(),
65                                 dns     = wan:dnsaddrs(),
66                                 expires = wan:expires(),
67                                 uptime  = wan:uptime(),
68                                 proto   = wan:proto(),
69                                 ifname  = wan:ifname(),
70                                 link    = wan:adminlink()
71                         }
72                 end
73
74                 if wan6 then
75                         rv.wan6 = {
76                                 ip6addr   = wan6:ip6addr(),
77                                 gw6addr   = wan6:gw6addr(),
78                                 dns       = wan6:dns6addrs(),
79                                 ip6prefix = wan6:ip6prefix(),
80                                 uptime    = wan6:uptime(),
81                                 proto     = wan6:proto(),
82                                 ifname    = wan6:ifname(),
83                                 link      = wan6:adminlink()
84                         }
85                 end
86
87                 if has_dsl then
88                         local dsl_stat = luci.sys.exec("/etc/init.d/dsl_control lucistat")
89                         local dsl_func = loadstring(dsl_stat)
90                         if dsl_func then
91                                 rv.dsl = dsl_func()
92                         end
93                 end
94
95                 luci.http.prepare_content("application/json")
96                 luci.http.write_json(rv)
97
98                 return
99         elseif luci.http.formvalue("hosts") == "1" then
100                 luci.http.prepare_content("application/json")
101                 luci.http.write_json(luci.sys.net.host_hints())
102
103                 return
104         end
105 -%>
106
107 <%+header%>
108
109 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
110 <script type="text/javascript">//<![CDATA[
111         function progressbar(v, m)
112         {
113                 var vn = parseInt(v) || 0;
114                 var mn = parseInt(m) || 100;
115                 var pc = Math.floor((100 / mn) * vn);
116
117                 return String.format(
118                         '<div style="width:200px; position:relative; border:1px solid #999999">' +
119                                 '<div style="background-color:#CCCCCC; width:%d%%; height:15px">' +
120                                         '<div style="position:absolute; left:0; top:0; text-align:center; width:100%%; color:#000000">' +
121                                                 '<small>%s / %s (%d%%)</small>' +
122                                         '</div>' +
123                                 '</div>' +
124                         '</div>', pc, v, m, pc
125                 );
126         }
127
128         function wifirate(bss, rx) {
129                 var p = rx ? 'rx_' : 'tx_',
130                     s = '%.1f <%:Mbit/s%>, %d<%:MHz%>'
131                                         .format(bss[p+'rate'] / 1000, bss[p+'mhz']),
132                     ht = bss[p+'ht'], vht = bss[p+'vht'],
133                         mhz = bss[p+'mhz'], nss = bss[p+'nss'],
134                         mcs = bss[p+'mcs'], sgi = bss[p+'short_gi'];
135
136                 if (ht || vht) {
137                         if (vht) s += ', VHT-MCS %d'.format(mcs);
138                         if (nss) s += ', VHT-NSS %d'.format(nss);
139                         if (ht)  s += ', MCS %s'.format(mcs);
140                         if (sgi) s += ', <%:Short GI%>';
141                 }
142
143                 return s;
144         }
145
146         function duid2mac(duid) {
147                 // DUID-LLT / Ethernet
148                 if (duid.length === 28 && duid.substr(0, 8) === '00010001')
149                         return duid.substr(16).replace(/(..)(?=..)/g, '$1:').toUpperCase();
150
151                 // DUID-LL / Ethernet
152                 if (duid.length === 20 && duid.substr(0, 8) === '00030001')
153                         return duid.substr(8).replace(/(..)(?=..)/g, '$1:').toUpperCase();
154
155                 return null;
156         }
157
158         var npoll = 1;
159         var hosts = <%=luci.http.write_json(luci.sys.net.host_hints())%>;
160
161         function updateHosts() {
162                 XHR.get('<%=REQUEST_URI%>', { hosts: 1 }, function(x, data) {
163                         hosts = data;
164                 });
165         }
166
167         XHR.poll(5, '<%=REQUEST_URI%>', { status: 1 },
168                 function(x, info)
169                 {
170                         if (!(npoll++ % 5))
171                                 updateHosts();
172
173                         var si = document.getElementById('wan4_i');
174                         var ss = document.getElementById('wan4_s');
175                         var ifc = info.wan;
176
177                         if (ifc && ifc.ifname && ifc.proto != 'none')
178                         {
179                                 var s = String.format(
180                                         '<strong><%:Type%>: </strong>%s<br />' +
181                                         '<strong><%:Address%>: </strong>%s<br />' +
182                                         '<strong><%:Netmask%>: </strong>%s<br />' +
183                                         '<strong><%:Gateway%>: </strong>%s<br />',
184                                                 ifc.proto,
185                                                 (ifc.ipaddr) ? ifc.ipaddr : '0.0.0.0',
186                                                 (ifc.netmask && ifc.netmask != ifc.ipaddr) ? ifc.netmask : '255.255.255.255',
187                                                 (ifc.gwaddr) ? ifc.gwaddr : '0.0.0.0'
188                                 );
189
190                                 for (var i = 0; i < ifc.dns.length; i++)
191                                 {
192                                         s += String.format(
193                                                 '<strong><%:DNS%> %d: </strong>%s<br />',
194                                                 i + 1, ifc.dns[i]
195                                         );
196                                 }
197
198                                 if (ifc.expires > -1)
199                                 {
200                                         s += String.format(
201                                                 '<strong><%:Expires%>: </strong>%t<br />',
202                                                 ifc.expires
203                                         );
204                                 }
205
206                                 if (ifc.uptime > 0)
207                                 {
208                                         s += String.format(
209                                                 '<strong><%:Connected%>: </strong>%t<br />',
210                                                 ifc.uptime
211                                         );
212                                 }
213
214                                 ss.innerHTML = String.format('<small>%s</small>', s);
215                                 si.innerHTML = String.format(
216                                         '<img src="<%=resource%>/icons/ethernet.png" />' +
217                                         '<br /><small><a href="%s">%s</a></small>',
218                                                 ifc.link, ifc.ifname
219                                 );
220                         }
221                         else
222                         {
223                                 si.innerHTML = '<img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small>';
224                                 ss.innerHTML = '<em><%:Not connected%></em>';
225                         }
226
227                         <% if has_ipv6 then %>
228                         var si6 = document.getElementById('wan6_i');
229                         var ss6 = document.getElementById('wan6_s');
230                         var ifc6 = info.wan6;
231
232                         if (ifc6 && ifc6.ifname && ifc6.proto != 'none')
233                         {
234                                 var s = String.format(
235                                         '<strong><%:Type%>: </strong>%s%s<br />',
236                                                 ifc6.proto, (ifc6.ip6prefix) ? '-pd' : ''
237                                 );
238                                 
239                                 if (!ifc6.ip6prefix)
240                                 {
241                                         s += String.format(
242                                                 '<strong><%:Address%>: </strong>%s<br />',
243                                                 (ifc6.ip6addr) ? ifc6.ip6addr : '::'
244                                         );
245                                 }
246                                 else
247                                 {
248                                         s += String.format(
249                                                 '<strong><%:Prefix Delegated%>: </strong>%s<br />',
250                                                 ifc6.ip6prefix
251                                         );
252                                         if (ifc6.ip6addr)
253                                         {
254                                                 s += String.format(
255                                                         '<strong><%:Address%>: </strong>%s<br />',
256                                                         ifc6.ip6addr
257                                                 );
258                                         }
259                                 }
260
261                                 s += String.format(
262                                         '<strong><%:Gateway%>: </strong>%s<br />',
263                                                 (ifc6.gw6addr) ? ifc6.gw6addr : '::'
264                                 );
265
266                                 for (var i = 0; i < ifc6.dns.length; i++)
267                                 {
268                                         s += String.format(
269                                                 '<strong><%:DNS%> %d: </strong>%s<br />',
270                                                 i + 1, ifc6.dns[i]
271                                         );
272                                 }
273
274                                 if (ifc6.uptime > 0)
275                                 {
276                                         s += String.format(
277                                                 '<strong><%:Connected%>: </strong>%t<br />',
278                                                 ifc6.uptime
279                                         );
280                                 }
281
282                                 ss6.innerHTML = String.format('<small>%s</small>', s);
283                                 si6.innerHTML = String.format(
284                                         '<img src="<%=resource%>/icons/ethernet.png" />' +
285                                         '<br /><small><a href="%s">%s</a></small>',
286                                                 ifc6.link, ifc6.ifname
287                                 );
288                         }
289                         else
290                         {
291                                 si6.innerHTML = '<img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small>';
292                                 ss6.innerHTML = '<em><%:Not connected%></em>';
293                         }
294                         <% end %>
295
296                         <% if has_dsl then %>
297                                 var dsl_i = document.getElementById('dsl_i');
298                                 var dsl_s = document.getElementById('dsl_s');
299
300                                 var s = String.format(
301                                         '<strong><%:Status%>: </strong>%s<br />' +
302                                         '<strong><%:Line State%>: </strong>%s [0x%x]<br />' +
303                                         '<strong><%:Line Mode%>: </strong>%s<br />' +
304                                         '<strong><%:Annex%>: </strong>%s<br />' +
305                                         '<strong><%:Profile%>: </strong>%s<br />' +
306                                         '<strong><%:Data Rate%>: </strong>%s/s / %s/s<br />' +
307                                         '<strong><%:Max. Attainable Data Rate (ATTNDR)%>: </strong>%s/s / %s/s<br />' +
308                                         '<strong><%:Latency%>: </strong>%s / %s<br />' +
309                                         '<strong><%:Line Attenuation (LATN)%>: </strong>%s dB / %s dB<br />' +
310                                         '<strong><%:Signal Attenuation (SATN)%>: </strong>%s dB / %s dB<br />' +
311                                         '<strong><%:Noise Margin (SNR)%>: </strong>%s dB / %s dB<br />' +
312                                         '<strong><%:Aggregate Transmit Power(ACTATP)%>: </strong>%s dB / %s dB<br />' +
313                                         '<strong><%:Forward Error Correction Seconds (FECS)%>: </strong>%s / %s<br />' +
314                                         '<strong><%:Errored seconds (ES)%>: </strong>%s / %s<br />' +
315                                         '<strong><%:Severely Errored Seconds (SES)%>: </strong>%s / %s<br />' +
316                                         '<strong><%:Loss of Signal Seconds (LOSS)%>: </strong>%s / %s<br />' +
317                                         '<strong><%:Unavailable Seconds (UAS)%>: </strong>%s / %s<br />' +
318                                         '<strong><%:Header Error Code Errors (HEC)%>: </strong>%s / %s<br />' +
319                                         '<strong><%:Non Pre-emtive CRC errors (CRC_P)%>: </strong>%s / %s<br />' +
320                                         '<strong><%:Pre-emtive CRC errors (CRCP_P)%>: </strong>%s / %s<br />' +
321                                         '<strong><%:Line Uptime%>: </strong>%s<br />' +
322                                         '<strong><%:ATU-C System Vendor ID%>: </strong>%s<br />' +
323                                         '<strong><%:Power Management Mode%>: </strong>%s<br />',
324                                                 info.dsl.line_state, info.dsl.line_state_detail,
325                                                 info.dsl.line_state_num,
326                                                 info.dsl.line_mode_s,
327                                                 info.dsl.annex_s,
328                                                 info.dsl.profile_s,
329                                                 info.dsl.data_rate_down_s, info.dsl.data_rate_up_s,
330                                                 info.dsl.max_data_rate_down_s, info.dsl.max_data_rate_up_s,
331                                                 info.dsl.latency_num_down, info.dsl.latency_num_up,
332                                                 info.dsl.line_attenuation_down, info.dsl.line_attenuation_up,
333                                                 info.dsl.signal_attenuation_down, info.dsl.signal_attenuation_up,
334                                                 info.dsl.noise_margin_down, info.dsl.noise_margin_up,
335                                                 info.dsl.actatp_down, info.dsl.actatp_up,
336                                                 info.dsl.errors_fec_near, info.dsl.errors_fec_far,
337                                                 info.dsl.errors_es_near, info.dsl.errors_es_far,
338                                                 info.dsl.errors_ses_near, info.dsl.errors_ses_far,
339                                                 info.dsl.errors_loss_near, info.dsl.errors_loss_far,
340                                                 info.dsl.errors_uas_near, info.dsl.errors_uas_far,
341                                                 info.dsl.errors_hec_near, info.dsl.errors_hec_far,
342                                                 info.dsl.errors_crc_p_near, info.dsl.errors_crc_p_far,
343                                                 info.dsl.errors_crcp_p_near, info.dsl.errors_crcp_p_far,
344                                                 info.dsl.line_uptime_s,
345                                                 info.dsl.atuc_vendor_id,
346                                                 info.dsl.power_mode_s
347                                 );
348
349                                 dsl_s.innerHTML = String.format('<small>%s</small>', s);
350                                 dsl_i.innerHTML = String.format(
351                                         '<img src="<%=resource%>/icons/ethernet.png" />' +
352                                         '<br /><small>DSL</small>'
353                                 );
354                         <% end %>
355
356                         <% if has_dhcp then %>
357                         var ls = document.getElementById('lease_status_table');
358                         if (ls)
359                         {
360                                 /* clear all rows */
361                                 while( ls.rows.length > 1 )
362                                         ls.rows[0].parentNode.deleteRow(1);
363
364                                 for( var i = 0; i < info.leases.length; i++ )
365                                 {
366                                         var timestr;
367
368                                         if (info.leases[i].expires === false)
369                                                 timestr = '<em><%:unlimited%></em>';
370                                         else if (info.leases[i].expires <= 0)
371                                                 timestr = '<em><%:expired%></em>';
372                                         else
373                                                 timestr = String.format('%t', info.leases[i].expires);
374
375                                         var tr = ls.rows[0].parentNode.insertRow(-1);
376                                                 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
377
378                                         tr.insertCell(-1).innerHTML = info.leases[i].hostname ? info.leases[i].hostname : '?';
379                                         tr.insertCell(-1).innerHTML = info.leases[i].ipaddr;
380                                         tr.insertCell(-1).innerHTML = info.leases[i].macaddr;
381                                         tr.insertCell(-1).innerHTML = timestr;
382                                 }
383
384                                 if( ls.rows.length == 1 )
385                                 {
386                                         var tr = ls.rows[0].parentNode.insertRow(-1);
387                                                 tr.className = 'cbi-section-table-row';
388
389                                         var td = tr.insertCell(-1);
390                                                 td.colSpan = 4;
391                                                 td.innerHTML = '<em><br /><%:There are no active leases.%></em>';
392                                 }
393                         }
394
395                         var ls6 = document.getElementById('lease6_status_table');
396                         if (ls6 && info.leases6)
397                         {
398                                 ls6.parentNode.style.display = 'block';
399
400                                 /* clear all rows */
401                                 while( ls6.rows.length > 1 )
402                                         ls6.rows[0].parentNode.deleteRow(1);
403
404                                 for( var i = 0; i < info.leases6.length; i++ )
405                                 {
406                                         var timestr;
407
408                                         if (info.leases6[i].expires === false)
409                                                 timestr = '<em><%:unlimited%></em>';
410                                         else if (info.leases6[i].expires <= 0)
411                                                 timestr = '<em><%:expired%></em>';
412                                         else
413                                                 timestr = String.format('%t', info.leases6[i].expires);
414
415                                         var tr = ls6.rows[0].parentNode.insertRow(-1);
416                                                 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
417
418                                         var host = hosts[duid2mac(info.leases6[i].duid)];
419                                         if (!info.leases6[i].hostname)
420                                                 tr.insertCell(-1).innerHTML =
421                                                         (host && (host.name || host.ipv4 || host.ipv6))
422                                                                 ? '<div style="max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space: nowrap">? (%h)</div>'.format(host.name || host.ipv4 || host.ipv6)
423                                                                 : '?';
424                                         else
425                                                 tr.insertCell(-1).innerHTML =
426                                                         (host && host.name && info.leases6[i].hostname != host.name)
427                                                                 ? '<div style="max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space: nowrap">%h (%h)</div>'.format(info.leases6[i].hostname, host.name)
428                                                                 : info.leases6[i].hostname;
429
430                                         tr.insertCell(-1).innerHTML = info.leases6[i].ip6addr;
431                                         tr.insertCell(-1).innerHTML = info.leases6[i].duid;
432                                         tr.insertCell(-1).innerHTML = timestr;
433                                 }
434
435                                 if( ls6.rows.length == 1 )
436                                 {
437                                         var tr = ls6.rows[0].parentNode.insertRow(-1);
438                                                 tr.className = 'cbi-section-table-row';
439
440                                         var td = tr.insertCell(-1);
441                                                 td.colSpan = 4;
442                                                 td.innerHTML = '<em><br /><%:There are no active leases.%></em>';
443                                 }
444                         }
445                         <% end %>
446
447                         <% if has_wifi then %>
448                         var assoclist = [ ];
449
450                         var ws = document.getElementById('wifi_status_table');
451                         if (ws)
452                         {
453                                 var wsbody = ws.rows[0].parentNode;
454                                 while (ws.rows.length > 0)
455                                         wsbody.deleteRow(0);
456
457                                 for (var didx = 0; didx < info.wifinets.length; didx++)
458                                 {
459                                         var dev = info.wifinets[didx];
460
461                                         var tr = wsbody.insertRow(-1);
462                                         var td;
463
464                                         td = tr.insertCell(-1);
465                                         td.width     = "33%";
466                                         td.innerHTML = dev.name;
467                                         td.style.verticalAlign = "top";
468
469                                         td = tr.insertCell(-1);
470
471                                         var s = '';
472
473                                         for (var nidx = 0; nidx < dev.networks.length; nidx++)
474                                         {
475                                                 var net = dev.networks[nidx];
476                                                 var is_assoc = (net.bssid != '00:00:00:00:00:00' && net.channel && !net.disabled);
477
478                                                 var icon;
479                                                 if (!is_assoc)
480                                                         icon = "<%=resource%>/icons/signal-none.png";
481                                                 else if (net.quality == 0)
482                                                         icon = "<%=resource%>/icons/signal-0.png";
483                                                 else if (net.quality < 25)
484                                                         icon = "<%=resource%>/icons/signal-0-25.png";
485                                                 else if (net.quality < 50)
486                                                         icon = "<%=resource%>/icons/signal-25-50.png";
487                                                 else if (net.quality < 75)
488                                                         icon = "<%=resource%>/icons/signal-50-75.png";
489                                                 else
490                                                         icon = "<%=resource%>/icons/signal-75-100.png";
491
492                                                 s += String.format(
493                                                         '<table><tr><td style="text-align:center; width:32px; padding:3px">' +
494                                                                 '<img src="%s" title="<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" />' +
495                                                                 '<br /><small>%d%%</small>' +
496                                                         '</td><td style="text-align:left; padding:3px"><small>' +
497                                                                 '<strong><%:SSID%>:</strong> <a href="%s">%h</a><br />' +
498                                                                 '<strong><%:Mode%>:</strong> %s<br />' +
499                                                                 '<strong><%:Channel%>:</strong> %d (%.3f <%:GHz%>)<br />' +
500                                                                 '<strong><%:Bitrate%>:</strong> %s <%:Mbit/s%><br />',
501                                                                 icon, net.signal, net.noise,
502                                                                 net.quality,
503                                                                 net.link, net.ssid || '?',
504                                                                 net.mode,
505                                                                 net.channel, net.frequency,
506                                                                 net.bitrate || '?'
507                                                 );
508
509                                                 if (is_assoc)
510                                                 {
511                                                         s += String.format(
512                                                                 '<strong><%:BSSID%>:</strong> %s<br />' +
513                                                                 '<strong><%:Encryption%>:</strong> %s',
514                                                                         net.bssid || '?',
515                                                                         net.encryption
516                                                         );
517                                                 }
518                                                 else
519                                                 {
520                                                         s += '<em><%:Wireless is disabled or not associated%></em>';
521                                                 }
522
523                                                 s += '</small></td></tr></table>';
524
525                                                 for (var bssid in net.assoclist)
526                                                 {
527                                                         var bss = net.assoclist[bssid];
528
529                                                         bss.bssid  = bssid;
530                                                         bss.link   = net.link;
531                                                         bss.name   = net.name;
532                                                         bss.ifname = net.ifname;
533                                                         bss.radio  = dev.name;
534
535                                                         assoclist.push(bss);
536                                                 }
537                                         }
538
539                                         if (!s)
540                                                 s = '<em><%:No information available%></em>';
541
542                                         td.innerHTML = s;
543                                 }
544                         }
545
546                         var ac = document.getElementById('wifi_assoc_table');
547                         if (ac)
548                         {
549                                 /* clear all rows */
550                                 while( ac.rows.length > 1 )
551                                         ac.rows[0].parentNode.deleteRow(1);
552
553                                 assoclist.sort(function(a, b) {
554                                         return (a.name == b.name)
555                                                 ? (a.bssid < b.bssid)
556                                                 : (a.name  > b.name )
557                                         ;
558                                 });
559
560                                 for( var i = 0; i < assoclist.length; i++ )
561                                 {
562                                         var tr = ac.rows[0].parentNode.insertRow(-1);
563                                                 tr.className = 'cbi-section-table-row cbi-rowstyle-' + (1 + (i % 2));
564
565                                         var icon;
566                                         var q = (-1 * (assoclist[i].noise - assoclist[i].signal)) / 5;
567                                         if (q < 1)
568                                                 icon = "<%=resource%>/icons/signal-0.png";
569                                         else if (q < 2)
570                                                 icon = "<%=resource%>/icons/signal-0-25.png";
571                                         else if (q < 3)
572                                                 icon = "<%=resource%>/icons/signal-25-50.png";
573                                         else if (q < 4)
574                                                 icon = "<%=resource%>/icons/signal-50-75.png";
575                                         else
576                                                 icon = "<%=resource%>/icons/signal-75-100.png";
577
578                                         tr.insertCell(-1).innerHTML = String.format(
579                                                 '<span class="ifacebadge" title="%q"><img src="<%=resource%>/icons/wifi.png" /> %h</span>',
580                                                 assoclist[i].radio, assoclist[i].ifname
581                                         );
582
583                                         tr.insertCell(-1).innerHTML = String.format(
584                                                 '<a href="%s">%s</a>',
585                                                         assoclist[i].link,
586                                                         '%h'.format(assoclist[i].name).nobr()
587                                         );
588
589                                         tr.insertCell(-1).innerHTML = assoclist[i].bssid;
590
591                                         var host = hosts[assoclist[i].bssid];
592                                         if (host)
593                                                 tr.insertCell(-1).innerHTML = String.format(
594                                                         '<div style="max-width:200px;overflow:hidden;text-overflow:ellipsis">%s</div>',
595                                                         ((host.name && (host.ipv4 || host.ipv6))
596                                                                 ? '%h (%s)'.format(host.name, host.ipv4 || host.ipv6)
597                                                                 : '%h'.format(host.name || host.ipv4 || host.ipv6)).nobr()
598                                                 );
599                                         else
600                                                 tr.insertCell(-1).innerHTML = '?';
601
602                                         tr.insertCell(-1).innerHTML = String.format(
603                                                 '<span class="ifacebadge" title="<%:Signal%>: %d <%:dBm%> / <%:Noise%>: %d <%:dBm%> / <%:SNR%>: %d"><img src="%s" /> %d / %d <%:dBm%></span>',
604                                                 assoclist[i].signal, assoclist[i].noise, assoclist[i].signal - assoclist[i].noise,
605                                                 icon,
606                                                 assoclist[i].signal, assoclist[i].noise
607                                         );
608
609                                         tr.insertCell(-1).innerHTML = wifirate(assoclist[i], true).nobr() + '<br />' + wifirate(assoclist[i], false).nobr();
610                                 }
611
612                                 if (ac.rows.length == 1)
613                                 {
614                                         var tr = ac.rows[0].parentNode.insertRow(-1);
615                                                 tr.className = 'cbi-section-table-row';
616
617                                         var td = tr.insertCell(-1);
618                                                 td.colSpan = 7;
619                                                 td.innerHTML = '<br /><em><%:No information available%></em>';
620                                 }
621                         }
622                         <% end %>
623
624                         var e;
625
626                         if (e = document.getElementById('localtime'))
627                                 e.innerHTML = info.localtime;
628
629                         if (e = document.getElementById('uptime'))
630                                 e.innerHTML = String.format('%t', info.uptime);
631
632                         if (e = document.getElementById('loadavg'))
633                                 e.innerHTML = String.format(
634                                         '%.02f, %.02f, %.02f',
635                                         info.loadavg[0] / 65535.0,
636                                         info.loadavg[1] / 65535.0,
637                                         info.loadavg[2] / 65535.0
638                                 );
639
640                         if (e = document.getElementById('memtotal'))
641                                 e.innerHTML = progressbar(
642                                         ((info.memory.free + info.memory.buffered) / 1024) + " <%:kB%>",
643                                         (info.memory.total / 1024) + " <%:kB%>"
644                                 );
645
646                         if (e = document.getElementById('memfree'))
647                                 e.innerHTML = progressbar(
648                                         (info.memory.free / 1024) + " <%:kB%>",
649                                         (info.memory.total / 1024) + " <%:kB%>"
650                                 );
651
652                         if (e = document.getElementById('membuff'))
653                                 e.innerHTML = progressbar(
654                                         (info.memory.buffered / 1024) + " <%:kB%>",
655                                         (info.memory.total / 1024) + " <%:kB%>"
656                                 );
657
658                         if (e = document.getElementById('swaptotal'))
659                                 e.innerHTML = progressbar(
660                                         (info.swap.free / 1024) + " <%:kB%>",
661                                         (info.swap.total / 1024) + " <%:kB%>"
662                                 );
663
664                         if (e = document.getElementById('swapfree'))
665                                 e.innerHTML = progressbar(
666                                         (info.swap.free / 1024) + " <%:kB%>",
667                                         (info.swap.total / 1024) + " <%:kB%>"
668                                 );
669
670                         if (e = document.getElementById('conns'))
671                                 e.innerHTML = progressbar(info.conncount, info.connmax);
672
673                 }
674         );
675 //]]></script>
676
677 <h2 name="content"><%:Status%></h2>
678
679 <fieldset class="cbi-section">
680         <legend><%:System%></legend>
681
682         <table width="100%" cellspacing="10">
683                 <tr><td width="33%"><%:Hostname%></td><td><%=luci.sys.hostname() or "?"%></td></tr>
684                 <tr><td width="33%"><%:Model%></td><td><%=pcdata(boardinfo.model or boardinfo.system or "?")%></td></tr>
685                 <tr><td width="33%"><%:Firmware Version%></td><td>
686                         <%=pcdata(ver.distname)%> <%=pcdata(ver.distversion)%> /
687                         <%=pcdata(ver.luciname)%> (<%=pcdata(ver.luciversion)%>)
688                 </td></tr>
689                 <tr><td width="33%"><%:Kernel Version%></td><td><%=unameinfo.release or "?"%></td></tr>
690                 <tr><td width="33%"><%:Local Time%></td><td id="localtime">-</td></tr>
691                 <tr><td width="33%"><%:Uptime%></td><td id="uptime">-</td></tr>
692                 <tr><td width="33%"><%:Load Average%></td><td id="loadavg">-</td></tr>
693         </table>
694 </fieldset>
695
696 <fieldset class="cbi-section">
697         <legend><%:Memory%></legend>
698
699         <table width="100%" cellspacing="10">
700                 <tr><td width="33%"><%:Total Available%></td><td id="memtotal">-</td></tr>
701                 <tr><td width="33%"><%:Free%></td><td id="memfree">-</td></tr>
702                 <tr><td width="33%"><%:Buffered%></td><td id="membuff">-</td></tr>
703         </table>
704 </fieldset>
705
706 <% if swapinfo.total > 0 then %>
707 <fieldset class="cbi-section">
708         <legend><%:Swap%></legend>
709
710         <table width="100%" cellspacing="10">
711                 <tr><td width="33%"><%:Total Available%></td><td id="swaptotal">-</td></tr>
712                 <tr><td width="33%"><%:Free%></td><td id="swapfree">-</td></tr>
713         </table>
714 </fieldset>
715 <% end %>
716
717 <fieldset class="cbi-section">
718         <legend><%:Network%></legend>
719
720         <table width="100%" cellspacing="10">
721                 <tr><td width="33%" style="vertical-align:top"><%:IPv4 WAN Status%></td><td>
722                         <table><tr>
723                                 <td id="wan4_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td>
724                                 <td id="wan4_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></td>
725                         </tr></table>
726                 </td></tr>
727                 <% if has_ipv6 then %>
728                 <tr><td width="33%" style="vertical-align:top"><%:IPv6 WAN Status%></td><td>
729                         <table><tr>
730                                 <td id="wan6_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td>
731                                 <td id="wan6_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></td>
732                         </tr></table>
733                 </td></tr>
734                 <% end %>
735                 <tr><td width="33%"><%:Active Connections%></td><td id="conns">-</td></tr>
736         </table>
737 </fieldset>
738
739 <% if has_dhcp then %>
740 <fieldset class="cbi-section">
741         <legend><%:DHCP Leases%></legend>
742
743         <table class="cbi-section-table" id="lease_status_table">
744                 <tr class="cbi-section-table-titles">
745                         <th class="cbi-section-table-cell"><%:Hostname%></th>
746                         <th class="cbi-section-table-cell"><%:IPv4-Address%></th>
747                         <th class="cbi-section-table-cell"><%:MAC-Address%></th>
748                         <th class="cbi-section-table-cell"><%:Leasetime remaining%></th>
749                 </tr>
750                 <tr class="cbi-section-table-row">
751                         <td colspan="4"><em><br /><%:Collecting data...%></em></td>
752                 </tr>
753         </table>
754 </fieldset>
755
756 <fieldset class="cbi-section" style="display:none">
757         <legend><%:DHCPv6 Leases%></legend>
758
759         <table class="cbi-section-table" id="lease6_status_table">
760                 <tr class="cbi-section-table-titles">
761                         <th class="cbi-section-table-cell"><%:Host%></th>
762                         <th class="cbi-section-table-cell"><%:IPv6-Address%></th>
763                         <th class="cbi-section-table-cell"><%:DUID%></th>
764                         <th class="cbi-section-table-cell"><%:Leasetime remaining%></th>
765                 </tr>
766                 <tr class="cbi-section-table-row">
767                         <td colspan="4"><em><br /><%:Collecting data...%></em></td>
768                 </tr>
769         </table>
770 </fieldset>
771 <% end %>
772
773 <% if has_dsl then %>
774 <fieldset class="cbi-section">
775        <legend><%:DSL%></legend>
776        <table width="100%" cellspacing="10">
777                <tr><td width="33%" style="vertical-align:top"><%:DSL Status%></td><td>
778                        <table><tr>
779                                <td id="dsl_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td>
780                                <td id="dsl_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></td>
781                        </tr></table>
782                </td></tr>
783        </table>
784 </fieldset>
785 <% end %>
786
787 <% if has_wifi then %>
788 <fieldset class="cbi-section">
789         <legend><%:Wireless%></legend>
790
791         <table id="wifi_status_table" width="100%" cellspacing="10">
792                 <tr><td><em><%:Collecting data...%></em></td></tr>
793         </table>
794 </fieldset>
795
796 <fieldset class="cbi-section">
797         <legend><%:Associated Stations%></legend>
798
799         <table class="cbi-section-table valign-middle" id="wifi_assoc_table">
800                 <tr class="cbi-section-table-titles">
801                         <th class="cbi-section-table-cell">&#160;</th>
802                         <th class="cbi-section-table-cell"><%:Network%></th>
803                         <th class="cbi-section-table-cell"><%:MAC-Address%></th>
804                         <th class="cbi-section-table-cell"><%:Host%></th>
805                         <th class="cbi-section-table-cell"><%:Signal%> / <%:Noise%></th>
806                         <th class="cbi-section-table-cell"><%:RX Rate%> / <%:TX Rate%></th>
807                 </tr>
808                 <tr class="cbi-section-table-row">
809                         <td colspan="6"><em><br /><%:Collecting data...%></em></td>
810                 </tr>
811         </table>
812 </fieldset>
813 <% end %>
814
815 <%-
816         local incdir = util.libpath() .. "/view/admin_status/index/"
817         if fs.access(incdir) then
818                 local inc
819                 for inc in fs.dir(incdir) do
820                         if inc:match("%.htm$") then
821                                 include("admin_status/index/" .. inc:gsub("%.htm$", ""))
822                         end
823                 end
824         end
825 -%>
826
827 <%+footer%>