Busybox: Upgrade to 1.21.1 (stable). lsof active.
[tomato.git] / release / src / router / www / status-data.jsx
blob9088bf5c68d6ced7fffed9ff443d9530b7a75f3d
1 /*
2         Tomato GUI
3         Copyright (C) 2006-2010 Jonathan Zarate
4         http://www.polarcloud.com/tomato/
6         For use with Tomato Firmware only.
7         No part of this file may be used without permission.
8 */
10 //<% nvram("ppp_get_ip,pptp_server_ip,router_name,wan_domain,wan_gateway,wan_gateway_get,wan_get_domain,wan_hostname,wan_hwaddr,wan_ipaddr,wan_netmask,wan_proto,wan_run_mtu,et0macaddr,lan_proto,lan_ipaddr,dhcp_start,dhcp_num,dhcpd_startip,dhcpd_endip,lan_netmask,wl_security_mode,wl_crypto,wl_mode,wl_wds_enable,wl_hwaddr,wl_net_mode,wl_radio,wl_channel,lan_gateway,wl_ssid,wl_closed,t_model_name,t_features,pptp_dhcp,dhcp1_start,dhcp1_num,dhcpd1_startip,dhcpd1_endip,dhcp2_start,dhcp2_num,dhcpd2_startip,dhcpd2_endip,dhcp3_start,dhcp3_num,dhcpd3_startip,dhcpd3_endip,lan1_proto,lan1_ipaddr,lan1_netmask,lan2_proto,lan2_ipaddr,lan2_netmask,lan3_proto,lan3_ipaddr,lan3_netmask,lan_ifname,lan1_ifname,lan2_ifname,lan3_ifname,lan_ifnames,lan1_ifnames,lan2_ifnames,lan3_ifnames,wan_ifnames,wan_ipaddr_buf,lan_state"); %>
11 //<% uptime(); %>
12 //<% sysinfo(); %>
13 //<% wlstats(1); %>
15 stats = { };
17 do {
18         var a, b, i;
19         var xifs = ['wan', 'lan', 'lan1', 'lan2', 'lan3'];
20         stats.lan_desc = (nvram.lan_state & 2) ? 1 : 0;
21         if (typeof(last_wan_proto) == 'undefined') {
22                 last_wan_proto = nvram.wan_proto;
23         }
24         else if (last_wan_proto != nvram.wan_proto) {
25                 reloadPage();
26         }
28         stats.flashsize = sysinfo.flashsize+' MB';
29         stats.cpumhz = sysinfo.cpuclk+' MHz';
30         stats.systemtype = sysinfo.systemtype;
31         stats.cpuload = ((sysinfo.loads[0] / 65536.0).toFixed(2) + '<small> / </small> ' +
32                 (sysinfo.loads[1] / 65536.0).toFixed(2) + '<small> / </small>' +
33                 (sysinfo.loads[2] / 65536.0).toFixed(2));
34         stats.freqcpu = nvram.clkfreq;
35         stats.uptime = sysinfo.uptime_s;
37         var total_jiffies = 0;
38         var jiffylist = sysinfo.jiffies.split(' ');
39         for (i=0; i < jiffylist.length; ++i) {
40                 total_jiffies += parseInt(jiffylist[i]);
41         }
42         var diff_idle = jiffylist[3] - lastjiffiesidle;
43         var diff_total = total_jiffies - lastjiffiestotal;
44         lastjiffiesusage = (1000*(diff_total-diff_idle)/diff_total)/10;
46         lastjiffiestotal = total_jiffies;
47         lastjiffiesidle = jiffylist[3];
49         stats.cpupercent = lastjiffiesusage.toFixed(2) + '%';
51         a = sysinfo.totalram;
52         b = sysinfo.totalfreeram;
53         stats.memory = scaleSize(a) + ' / ' + scaleSize(b) + ' <small>(' + (b / a * 100.0).toFixed(2) + '%)</small>';
54         if (sysinfo.totalswap > 0) {
55                 a = sysinfo.totalswap;
56                 b = sysinfo.freeswap;
57                 stats.swap = scaleSize(a) + ' / ' + scaleSize(b) + ' <small>(' + (b / a * 100.0).toFixed(2) + '%)</small>';
58         } else
59                 stats.swap = '';
61         stats.time = '<% time(); %>';
62         stats.wanup = '<% wanup(); %>' == '1';
63         stats.wanprebuf = nvram.wan_ipaddr_buf; //Victek
64         stats.wanuptime = '<% link_uptime(); %>';
65         stats.wanlease = '<% dhcpc_time(); %>';
67         //<% dns(); %>
68         stats.dns = dns.join(', ');
70         stats.wanip = nvram.wan_ipaddr;
71         stats.wannetmask = nvram.wan_netmask;
72         stats.wangateway = nvram.wan_gateway_get;
73         if (stats.wangateway == '0.0.0.0' || stats.wangateway == '')
74                 stats.wangateway = nvram.wan_gateway;
76         switch (nvram.wan_proto) {
77         case 'pptp':
78         case 'l2tp':
79                 if (stats.wanup) {
80                         stats.wanip = nvram.ppp_get_ip;
81                         if (nvram.pptp_dhcp == '1') {
82                                 if (nvram.wan_ipaddr != '' && nvram.wan_ipaddr != '0.0.0.0' && nvram.wan_ipaddr != stats.wanip)
83                                         stats.wanip += '&nbsp;&nbsp;<small>(DHCP: ' + nvram.wan_ipaddr + ')</small>';
84                                 if (nvram.wan_gateway != '' && nvram.wan_gateway != '0.0.0.0' && nvram.wan_gateway != stats.wangateway)
85                                         stats.wangateway += '&nbsp;&nbsp;<small>(DHCP: ' + nvram.wan_gateway + ')</small>';
86                         }
87                         if (stats.wannetmask == '0.0.0.0')
88                                 stats.wannetmask = '255.255.255.255';
89                 }
90                 else {
91                         if (nvram.wan_proto == 'pptp')
92                                 stats.wangateway = nvram.pptp_server_ip;
93                 }
94                 break;
95         default:
96                 if (!stats.wanup) {
97                         stats.wanip = '0.0.0.0';
98                         stats.wannetmask = '0.0.0.0';
99                         stats.wangateway = '0.0.0.0';
100                 }
101         }
103 /* IPV6-BEGIN */
104         stats.ip6_wan = ((typeof(sysinfo.ip6_wan) != 'undefined') ? sysinfo.ip6_wan : '') + '';
105         stats.ip6_lan = ((typeof(sysinfo.ip6_lan) != 'undefined') ? sysinfo.ip6_lan : '') + ''
106         stats.ip6_lan_ll = ((typeof(sysinfo.ip6_lan_ll) != 'undefined') ? sysinfo.ip6_lan_ll : '') + ''
107 /* IPV6-END */
109         stats.wanstatus = '<% wanstatus(); %>';
110         if (stats.wanstatus != 'Connected') stats.wanstatus = '<b>' + stats.wanstatus + ' <% link_starttime(); %></b>';
112         stats.channel = [];
113         stats.interference = [];
114         stats.qual = [];
116         for (var uidx = 0; uidx < wl_ifaces.length; ++uidx) {
117                 u = wl_unit(uidx);
119                 a = i = wlstats[uidx].channel * 1;
120                 if (i < 0) i = -i;
121                 stats.channel.push('<a href="tools-survey.asp">' + ((i) ? i + '' : 'Auto') +
122                         ((wlstats[uidx].mhz) ? ' - ' + (wlstats[uidx].mhz / 1000.0).toFixed(3) + ' <small>GHz</small>' : '') + '</a>' +
123                         ((a < 0) ? ' <small>(scanning...)</small>' : ''));
124                 stats.interference.push((wlstats[uidx].intf >= 0) ? ((wlstats[uidx].intf) ? 'Severe' : 'Acceptable') : '');
126                 a = wlstats[uidx].nbw * 1;
127                 wlstats[uidx].nbw = (a > 0) ? (a + ' <small>MHz</small>') : 'Auto';
129                 if (wlstats[uidx].radio) {
130                         a = wlstats[uidx].rate * 1;
131                         if (a > 0)
132                                 wlstats[uidx].rate = Math.floor(a / 2) + ((a & 1) ? '.5' : '') + ' <small>Mbps</small>';
133                         else
134                                 wlstats[uidx].rate = '-';
136                         if (wlstats[uidx].client) {
137                                 if (wlstats[uidx].rssi == 0) a = 0;
138                                         else a = MAX(wlstats[uidx].rssi - wlstats[uidx].noise, 0);
139                                 stats.qual.push(a + ' <img src="bar' + MIN(MAX(Math.floor(a / 10), 1), 6) + '.gif">');
140                         }
141                         else {
142                                 stats.qual.push('');
143                         }
144                         wlstats[uidx].noise += ' <small>dBm</small>';
145                         wlstats[uidx].rssi += ' <small>dBm</small>';
146                 }
147                 else {
148                         wlstats[uidx].rate = '';
149                         wlstats[uidx].noise = '';
150                         wlstats[uidx].rssi = '';
151                         stats.qual.push('');
152                 }
154                 if (wl_ifaces[uidx][6] != 1) {
155                         wlstats[uidx].ifstatus = '<b>Down</b>';
156                 } else {
157                         wlstats[uidx].ifstatus = 'Up';
158                         for (i = 0; i < xifs.length ; ++i) {
159                                 if ((nvram[xifs[i] + '_ifnames']).indexOf(wl_ifaces[uidx][0]) >= 0) {
160                                         wlstats[uidx].ifstatus = wlstats[uidx].ifstatus + ' (' + xifs[i].toUpperCase() + ')';
161                                         break;
162                                 }
163                         }
164                 }
165         }
166 } while (0);