2 LuCI - Lua Configuration Interface
3 Copyright
2008 Steven Barth
<steven@midlink.org
>
4 Copyright
2008-
2011 Jo-Philipp Wich
<xm@subsignal.org
>
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
10 http://www.apache.org/licenses/LICENSE-
2.0
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()
23 if dr4 and dr4.device then
24 wan = ntm:get_interface(dr4.device)
25 wan = wan and wan:get_network()
28 if dr6 and dr6.device then
29 wan6 = ntm:get_interface(dr6.device)
30 wan6 = wan6 and wan6:get_network()
33 local _, _, memtotal, memcached, membuffers, memfree = luci.sys.sysinfo()
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
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
46 uptime = luci.sys.uptime(),
47 localtime = os.date(),
48 loadavg = { luci.sys.loadavg() },
50 memcached = memcached,
51 membuffers = membuffers,
54 conncount = conn_count
59 ipaddr = wan:ipaddr(),
60 gwaddr = wan:gwaddr(),
61 netmask = wan:netmask(),
63 expires = wan:expires(),
64 uptime = wan:uptime(),
66 ifname = wan:ifname(),
67 link = wan:adminlink()
73 ip6addr = wan6:ip6addr(),
74 gw6addr = wan6:gw6addr(),
75 dns = wan6:dns6addrs(),
76 uptime = wan6:uptime(),
77 ifname = wan6:ifname(),
78 link = wan6:adminlink()
82 luci.http.prepare_content(
"application/json")
83 luci.http.write_json(rv)
88 local system, model = luci.sys.sysinfo()
93 <script type=
"text/javascript" src=
"<%=resource%>/cbi.js"></script>
94 <script type=
"text/javascript">//<![CDATA[
95 function progressbar(v, m)
97 var vn = parseInt(v) ||
0;
98 var mn = parseInt(m) ||
100;
99 var pc = Math.floor((
100 / mn) * vn);
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>' +
108 '
</div>', pc, v, m, pc
112 var iwxhr = new XHR();
113 var wifidevs = <%=luci.http.write_json(netdevs)%
>;
114 var arptable = <%=luci.http.write_json(arpcache)%
>;
116 var update_status = function() {
117 iwxhr.get('<%=REQUEST_URI%
>', { status:
1 },
120 var si = document.getElementById('wan4_i');
121 var ss = document.getElementById('wan4_s');
124 if (ifc && ifc.ifname && ifc.proto != 'none')
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 />',
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'
137 for (var i =
0; i < ifc.dns.length; i++)
140 '
<strong><%:DNS%
> %d:
</strong>%s
<br />',
145 if (ifc.expires
> -
1)
148 '
<strong><%:Expires%
>:
</strong>%t
<br />',
156 '
<strong><%:Connected%
>:
</strong>%t
<br />',
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
169 si.innerHTML = '
<img src=
"<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?
</small>';
170 ss.innerHTML = '
<em>Not connected
</em>';
173 var si6 = document.getElementById('wan6_i');
174 var ss6 = document.getElementById('wan6_s');
175 var ifc6 = info.wan6;
177 if (ifc6 && ifc6.ifname && ifc6.proto != 'none')
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 : '::'
186 for (var i =
0; i < ifc6.dns.length; i++)
189 '
<strong><%:DNS%
> %d:
</strong>%s
<br />',
197 '
<strong><%:Connected%
>:
</strong>%t
<br />',
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
210 si6.innerHTML = '
<img src=
"<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?
</small>';
211 ss6.innerHTML = '
<em>Not connected
</em>';
216 if (e = document.getElementById('localtime'))
217 e.innerHTML = info.localtime;
219 if (e = document.getElementById('uptime'))
220 e.innerHTML = String.format('%t', info.uptime);
222 if (e = document.getElementById('loadavg'))
223 e.innerHTML = String.format('%
.02f, %
.02f, %
.02f',
224 info.loadavg[
0], info.loadavg[
1], info.loadavg[
2]);
226 if (e = document.getElementById('memtotal'))
227 e.innerHTML = progressbar(
228 (info.memfree + info.membuffers + info.memcached) +
" kB",
229 info.memtotal +
" kB"
232 if (e = document.getElementById('memfree'))
233 e.innerHTML = progressbar(
234 info.memfree +
" kB", info.memtotal +
" kB"
237 if (e = document.getElementById('memcache'))
238 e.innerHTML = progressbar(
239 info.memcached +
" kB", info.memtotal +
" kB"
242 if (e = document.getElementById('membuff'))
243 e.innerHTML = progressbar(
244 info.membuffers +
" kB", info.memtotal +
" kB"
247 if (e = document.getElementById('conns'))
248 e.innerHTML = progressbar(
249 info.conncount +
" kB", info.connmax +
" kB"
252 window.setTimeout(update_status,
5000);
260 <h2><a id=
"content" name=
"content"><%:Status%
></a></h2>
262 <fieldset class=
"cbi-section">
263 <legend><%:System%
></legend>
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)%
>
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>
279 <fieldset class=
"cbi-section">
280 <legend><%:Memory%
></legend>
282 <table width=
"100%" cellspacing=
"10">
283 <tr><td width=
"33%"><%:Total Available%
></td><td id=
"memtotal">-
</td></tr>
284 <tr><td width=
"33%"><%:Free%
></td><td id=
"memfree">-
</td></tr>
285 <tr><td width=
"33%"><%:Cached%
></td><td id=
"memcache">-
</td></tr>
286 <tr><td width=
"33%"><%:Buffered%
></td><td id=
"membuff">-
</td></tr>
290 <fieldset class=
"cbi-section">
291 <legend><%:Network%
></legend>
293 <table width=
"100%" cellspacing=
"10">
294 <tr><td width=
"33%" style=
"vertical-align:top"><%:IPv4 WAN Status%
></td><td>
296 <td id=
"wan4_i" style=
"width:16px; text-align:center; padding:3px"><img src=
"<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?
</small></td>
297 <td id=
"wan4_s" style=
"vertical-align:middle; padding: 3px"><em><%:Collecting data...%
></em></td>
300 <tr><td width=
"33%" style=
"vertical-align:top"><%:IPv6 WAN Status%
></td><td>
302 <td id=
"wan6_i" style=
"width:16px; text-align:center; padding:3px"><img src=
"<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?
</small></td>
303 <td id=
"wan6_s" style=
"vertical-align:middle; padding: 3px"><em><%:Collecting data...%
></em></td>
306 <tr><td width=
"33%"><%:Active IP Connections%
></td><td id=
"conns">-
</td></tr>