Merge branch 'VLAN-MultiSSID' into Teaman-ND
[tomato.git] / release / src / router / www / status-data.jsx
blob689491dfd53919403168147f2527f87ea4df5370
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"); %>
11 //<% uptime(); %>
12 //<% sysinfo(); %>
13 //<% wlstats(1); %>
15 stats = { };
17 do {
18         var a, b, i;
19         var xifs = ['wan', 'lan', 'lan1', 'lan2', 'lan3'];
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.cpuload = ((sysinfo.loads[0] / 65536.0).toFixed(2) + '<small> / </small> ' +
29                 (sysinfo.loads[1] / 65536.0).toFixed(2) + '<small> / </small>' +
30                 (sysinfo.loads[2] / 65536.0).toFixed(2));
31         stats.uptime = sysinfo.uptime_s;
33         var total_jiffies = 0;
34         var jiffylist = sysinfo.jiffies.split(' ');
35         for (i=0; i < jiffylist.length; ++i) {
36                 total_jiffies += parseInt(jiffylist[i]);
37         }
38         var diff_idle = jiffylist[3] - lastjiffiesidle;
39         var diff_total = total_jiffies - lastjiffiestotal;
40         lastjiffiesusage = (1000*(diff_total-diff_idle)/diff_total)/10;
42         lastjiffiestotal = total_jiffies;
43         lastjiffiesidle = jiffylist[3];
45         stats.cpupercent = lastjiffiesusage.toFixed(2) + '%';
47         a = sysinfo.totalram;
48         b = sysinfo.totalfreeram;
49         stats.memory = scaleSize(a) + ' / ' + scaleSize(b) + ' <small>(' + (b / a * 100.0).toFixed(2) + '%)</small>';
50         if (sysinfo.totalswap > 0) {
51                 a = sysinfo.totalswap;
52                 b = sysinfo.freeswap;
53                 stats.swap = scaleSize(a) + ' / ' + scaleSize(b) + ' <small>(' + (b / a * 100.0).toFixed(2) + '%)</small>';
54         } else
55                 stats.swap = '';
57         stats.time = '<% time(); %>';
58         stats.wanup = '<% wanup(); %>' == '1';
59         stats.wanuptime = '<% link_uptime(); %>';
60         stats.wanlease = '<% dhcpc_time(); %>';
62         //<% dns(); %>
63         stats.dns = dns.join(', ');
65         stats.wanip = nvram.wan_ipaddr;
66         stats.wannetmask = nvram.wan_netmask;
67         stats.wangateway = nvram.wan_gateway_get;
68         if (stats.wangateway == '0.0.0.0' || stats.wangateway == '')
69                 stats.wangateway = nvram.wan_gateway;
71         switch (nvram.wan_proto) {
72         case 'pptp':
73         case 'l2tp':
74                 if (stats.wanup) {
75                         stats.wanip = nvram.ppp_get_ip;
76                         if (nvram.pptp_dhcp == '1') {
77                                 if (nvram.wan_ipaddr != '' && nvram.wan_ipaddr != '0.0.0.0' && nvram.wan_ipaddr != stats.wanip)
78                                         stats.wanip += '&nbsp;&nbsp;<small>(DHCP: ' + nvram.wan_ipaddr + ')</small>';
79                                 if (nvram.wan_gateway != '' && nvram.wan_gateway != '0.0.0.0' && nvram.wan_gateway != stats.wangateway)
80                                         stats.wangateway += '&nbsp;&nbsp;<small>(DHCP: ' + nvram.wan_gateway + ')</small>';
81                         }
82                         if (stats.wannetmask == '0.0.0.0')
83                                 stats.wannetmask = '255.255.255.255';
84                 }
85                 else {
86                         if (nvram.wan_proto == 'pptp')
87                                 stats.wangateway = nvram.pptp_server_ip;
88                 }
89                 break;
90         default:
91                 if (!stats.wanup) {
92                         stats.wanip = '0.0.0.0';
93                         stats.wannetmask = '0.0.0.0';
94                         stats.wangateway = '0.0.0.0';
95                 }
96         }
98 /* IPV6-BEGIN */
99         stats.ip6_wan = ((typeof(sysinfo.ip6_wan) != 'undefined') ? sysinfo.ip6_wan : '') + '';
100         stats.ip6_lan = ((typeof(sysinfo.ip6_lan) != 'undefined') ? sysinfo.ip6_lan : '') + ''
101         stats.ip6_lan_ll = ((typeof(sysinfo.ip6_lan_ll) != 'undefined') ? sysinfo.ip6_lan_ll : '') + ''
102 /* IPV6-END */
104         stats.wanstatus = '<% wanstatus(); %>';
105         if (stats.wanstatus != 'Connected') stats.wanstatus = '<b>' + stats.wanstatus + '</b>';
107         stats.channel = [];
108         stats.interference = [];
109         stats.qual = [];
111         for (var uidx = 0; uidx < wl_ifaces.length; ++uidx) {
112                 u = wl_unit(uidx);
114                 a = i = wlstats[uidx].channel * 1;
115                 if (i < 0) i = -i;
116                 stats.channel.push('<a href="tools-survey.asp">' + ((i) ? i + '' : 'Auto') +
117                         ((wlstats[uidx].mhz) ? ' - ' + (wlstats[uidx].mhz / 1000.0).toFixed(3) + ' <small>GHz</small>' : '') + '</a>' +
118                         ((a < 0) ? ' <small>(scanning...)</small>' : ''));
119                 stats.interference.push((wlstats[uidx].intf >= 0) ? ((wlstats[uidx].intf) ? 'Severe' : 'Acceptable') : '');
121                 a = wlstats[uidx].nbw * 1;
122                 wlstats[uidx].nbw = (a > 0) ? (a + ' <small>MHz</small>') : 'Auto';
124                 if (wlstats[uidx].radio) {
125                         a = wlstats[uidx].rate * 1;
126                         if (a > 0)
127                                 wlstats[uidx].rate = Math.floor(a / 2) + ((a & 1) ? '.5' : '') + ' <small>Mbps</small>';
128                         else
129                                 wlstats[uidx].rate = '-';
131                         if (wlstats[uidx].client) {
132                                 if (wlstats[uidx].rssi == 0) a = 0;
133                                         else a = MAX(wlstats[uidx].rssi - wlstats[uidx].noise, 0);
134                                 stats.qual.push(a + ' <img src="bar' + MIN(MAX(Math.floor(a / 10), 1), 6) + '.gif">');
135                         }
136                         else {
137                                 stats.qual.push('');
138                         }
139                         wlstats[uidx].noise += ' <small>dBm</small>';
140                         wlstats[uidx].rssi += ' <small>dBm</small>';
141                 }
142                 else {
143                         wlstats[uidx].rate = '';
144                         wlstats[uidx].noise = '';
145                         wlstats[uidx].rssi = '';
146                         stats.qual.push('');
147                 }
149                 if (wl_ifaces[uidx][6] != 1) {
150                         wlstats[uidx].ifstatus = '<b>Down</b>';
151                 } else {
152                         wlstats[uidx].ifstatus = 'Up';
153                         for (i = 0; i < xifs.length ; ++i) {
154                                 if ((nvram[xifs[i] + '_ifnames']).indexOf(wl_ifaces[uidx][0]) >= 0) {
155                                         wlstats[uidx].ifstatus = wlstats[uidx].ifstatus + ' (' + xifs[i].toUpperCase() + ')';
156                                         break;
157                                 }
158                         }
159                 }
160         }
161 } while (0);