modules/admin-full: rework index page
[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 if luci.http.formvalue("status") == "1" then
18 local ntm = require "luci.model.network".init()
19 local dr4 = luci.sys.net.defaultroute()
20 local dr6 = luci.sys.net.defaultroute6()
21 local wan, wan6
22
23 if dr4 and dr4.device then
24 wan = ntm:get_interface(dr4.device)
25 wan = wan and wan:get_network()
26 end
27
28 if dr6 and dr6.device then
29 wan6 = ntm:get_interface(dr6.device)
30 wan6 = wan6 and wan6:get_network()
31 end
32
33 local _, _, memtotal, memcached, membuffers, memfree = luci.sys.sysinfo()
34
35 local conn_count = tonumber((
36 luci.sys.exec("wc -l /proc/net/nf_conntrack") or
37 luci.sys.exec("wc -l /proc/net/ip_conntrack") or
38 ""):match("%d+")) or 0
39
40 local conn_max = tonumber((
41 luci.sys.exec("sysctl net.nf_conntrack_max") or
42 luci.sys.exec("sysctl net.ipv4.netfilter.ip_conntrack_max") or
43 ""):match("%d+")) or 4096
44
45 local rv = {
46 uptime = luci.sys.uptime(),
47 localtime = os.date(),
48 loadavg = { luci.sys.loadavg() },
49 memtotal = memtotal,
50 memcached = memcached,
51 membuffers = membuffers,
52 memfree = memfree,
53 connmax = conn_max,
54 conncount = conn_count
55 }
56
57 if wan then
58 rv.wan = {
59 ipaddr = wan:ipaddr(),
60 gwaddr = wan:gwaddr(),
61 netmask = wan:netmask(),
62 dns = wan:dnsaddrs(),
63 expires = wan:expires(),
64 uptime = wan:uptime(),
65 proto = wan:proto(),
66 ifname = wan:ifname(),
67 link = wan:adminlink()
68 }
69 end
70
71 if wan6 then
72 rv.wan6 = {
73 ip6addr = wan6:ip6addr(),
74 gw6addr = wan6:gw6addr(),
75 dns = wan6:dns6addrs(),
76 uptime = wan6:uptime(),
77 ifname = wan6:ifname(),
78 link = wan6:adminlink()
79 }
80 end
81
82 luci.http.prepare_content("application/json")
83 luci.http.write_json(rv)
84
85 return
86 end
87
88 local system, model, _, _, _, _, bogomips = luci.sys.sysinfo()
89 -%>
90
91 <%+header%>
92
93 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
94 <script type="text/javascript">//<![CDATA[
95 function progressbar(v, m)
96 {
97 var vn = parseInt(v) || 0;
98 var mn = parseInt(m) || 100;
99 var pc = Math.floor((100 / mn) * vn);
100
101 return String.format(
102 '<div style="width:200px; position:relative; border:1px solid #999999">' +
103 '<div style="background-color:#CCCCCC; width:%d%%; height:15px">' +
104 '<div style="position:absolute; left:0; top:0; text-align:center; width:100%%; color:#000000">' +
105 '<small>%d / %d (%d%%)</small>' +
106 '</div>' +
107 '</div>' +
108 '</div>', pc, v, m, pc
109 );
110 }
111
112 var iwxhr = new XHR();
113 var wifidevs = <%=luci.http.write_json(netdevs)%>;
114 var arptable = <%=luci.http.write_json(arpcache)%>;
115
116 var update_status = function() {
117 iwxhr.get('<%=REQUEST_URI%>', { status: 1 },
118 function(x, info)
119 {
120 var si = document.getElementById('wan4_i');
121 var ss = document.getElementById('wan4_s');
122 var ifc = info.wan;
123
124 if (ifc && ifc.ifname && ifc.proto != 'none')
125 {
126 var s = String.format(
127 '<strong><%:Type%>: </strong>%s<br />' +
128 '<strong><%:Address%>: </strong>%s<br />' +
129 '<strong><%:Netmask%>: </strong>%s<br />' +
130 '<strong><%:Gateway%>: </strong>%s<br />',
131 ifc.proto,
132 (ifc.ipaddr) ? ifc.ipaddr : '0.0.0.0',
133 (ifc.netmask != ifc.ipaddr) ? ifc.netmask : '255.255.255.255',
134 (ifc.gwaddr) ? ifc.gwaddr : '0.0.0.0'
135 );
136
137 for (var i = 0; i < ifc.dns.length; i++)
138 {
139 s += String.format(
140 '<strong><%:DNS%> %d: </strong>%s<br />',
141 i + 1, ifc.dns[i]
142 );
143 }
144
145 if (ifc.expires > -1)
146 {
147 s += String.format(
148 '<strong><%:Expires%>: </strong>%t<br />',
149 ifc.expires
150 );
151 }
152
153 if (ifc.uptime > 0)
154 {
155 s += String.format(
156 '<strong><%:Connected%>: </strong>%t<br />',
157 ifc.uptime
158 );
159 }
160
161 ss.innerHTML = String.format('<small>%s</small>', s);
162 si.innerHTML = String.format(
163 '<a href="%s"><img src="<%=resource%>/icons/ethernet.png" /></a>' +
164 '<br /><small>%s</small>', ifc.link, ifc.ifname
165 );
166 }
167 else
168 {
169 si.innerHTML = '<img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small>';
170 ss.innerHTML = '<em>Not connected</em>';
171 }
172
173 var si6 = document.getElementById('wan6_i');
174 var ss6 = document.getElementById('wan6_s');
175 var ifc6 = info.wan6;
176
177 if (ifc6 && ifc6.ifname && ifc6.proto != 'none')
178 {
179 var s = String.format(
180 '<strong><%:Address%>: </strong>%s<br />' +
181 '<strong><%:Gateway%>: </strong>%s<br />',
182 (ifc6.ip6addr) ? ifc6.ip6addr : '::',
183 (ifc6.gw6addr) ? ifc6.gw6addr : '::'
184 );
185
186 for (var i = 0; i < ifc6.dns.length; i++)
187 {
188 s += String.format(
189 '<strong><%:DNS%> %d: </strong>%s<br />',
190 i + 1, ifc6.dns[i]
191 );
192 }
193
194 if (ifc6.uptime > 0)
195 {
196 s += String.format(
197 '<strong><%:Connected%>: </strong>%t<br />',
198 ifc6.uptime
199 );
200 }
201
202 ss6.innerHTML = String.format('<small>%s</small>', s);
203 si6.innerHTML = String.format(
204 '<a href="%s"><img src="<%=resource%>/icons/ethernet.png" /></a>' +
205 '<br /><small>%s</small>', ifc6.link, ifc6.ifname
206 );
207 }
208 else
209 {
210 si6.innerHTML = '<img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small>';
211 ss6.innerHTML = '<em>Not connected</em>';
212 }
213
214 var e;
215
216 if (e = document.getElementById('localtime'))
217 e.innerHTML = info.localtime;
218
219 if (e = document.getElementById('uptime'))
220 e.innerHTML = String.format('%t', info.uptime);
221
222 if (e = document.getElementById('loadavg'))
223 e.innerHTML = String.format('%.02f, %.02f, %.02f',
224 info.loadavg[0], info.loadavg[1], info.loadavg[2]);
225
226 if (e = document.getElementById('memtotal'))
227 e.innerHTML = progressbar(
228 (info.memfree + info.membuffers + info.memcached) + " kB",
229 info.memtotal + " kB"
230 );
231
232 if (e = document.getElementById('memfree'))
233 e.innerHTML = progressbar(
234 info.memfree + " kB", info.memtotal + " kB"
235 );
236
237 if (e = document.getElementById('memcache'))
238 e.innerHTML = progressbar(
239 info.memcached + " kB", info.memtotal + " kB"
240 );
241
242 if (e = document.getElementById('membuff'))
243 e.innerHTML = progressbar(
244 info.membuffers + " kB", info.memtotal + " kB"
245 );
246
247 if (e = document.getElementById('conns'))
248 e.innerHTML = progressbar(
249 info.conncount + " kB", info.connmax + " kB"
250 );
251
252 window.setTimeout(update_status, 5000);
253 }
254 )
255 };
256
257 update_status();
258 //]]></script>
259
260 <h2><a id="content" name="content"><%:Status%></a></h2>
261
262 <fieldset class="cbi-section">
263 <legend><%:System%></legend>
264
265 <table width="100%" cellspacing="10">
266 <tr><td width="33%"><%:Router Name%></td><td><%=luci.sys.hostname() or "?"%></td></tr>
267 <tr><td width="33%"><%:Router Model%></td><td><%=pcdata(model or "?")%></td></tr>
268 <tr><td width="33%"><%:Firmware Version%></td><td>
269 <%=pcdata(luci.version.distname)%> <%=pcdata(luci.version.distversion)%> /
270 <%=pcdata(luci.version.luciname)%> <%=pcdata(luci.version.luciversion)%>
271 </td></tr>
272 <tr><td width="33%"><%:Kernel%></td><td><%=luci.sys.exec("uname -r")%></td></tr>
273 <tr><td width="33%"><%:Local Time%></td><td id="localtime">-</td></tr>
274 <tr><td width="33%"><%:Uptime%></td><td id="uptime">-</td></tr>
275 <tr><td width="33%"><%:Load Average%></td><td id="loadavg">-</td></tr>
276 </table>
277 </fieldset>
278
279 <fieldset class="cbi-section">
280 <legend><%:CPU%></legend>
281
282 <table width="100%" cellspacing="10">
283 <tr><td width="33%"><%:CPU Model%></td><td><%=system or "?" %></td></tr>
284 <tr><td width="33%"><%:CPU Speed%></td><td><%=math.floor((bogomips + 5) / 10) * 10 %> MHz</td></tr>
285 </table>
286 </fieldset>
287
288 <fieldset class="cbi-section">
289 <legend><%:Memory%></legend>
290
291 <table width="100%" cellspacing="10">
292 <tr><td width="33%"><%:Total Available%></td><td id="memtotal">-</td></tr>
293 <tr><td width="33%"><%:Free%></td><td id="memfree">-</td></tr>
294 <tr><td width="33%"><%:Cached%></td><td id="memcache">-</td></tr>
295 <tr><td width="33%"><%:Buffered%></td><td id="membuff">-</td></tr>
296 </table>
297 </fieldset>
298
299 <fieldset class="cbi-section">
300 <legend><%:Network%></legend>
301
302 <table width="100%" cellspacing="10">
303 <tr><td width="33%" style="vertical-align:top"><%:IPv4 WAN Status%></td><td>
304 <table><tr>
305 <td id="wan4_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td>
306 <td id="wan4_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></td>
307 </tr></table>
308 </td></tr>
309 <tr><td width="33%" style="vertical-align:top"><%:IPv6 WAN Status%></td><td>
310 <table><tr>
311 <td id="wan6_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td>
312 <td id="wan6_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></td>
313 </tr></table>
314 </td></tr>
315 <tr><td width="33%"><%:Active IP Connections%></td><td id="conns">-</td></tr>
316 </table>
317 </fieldset>
318
319 <%+footer%>