Merge branch 'tomato-RT' into tomato-1.28-Toastman-RT
[tomato.git] / release / src / router / www / status-data.jsx
blob2489a82c0b77e38ad9db549466dc9d2fb0b8e81e
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 */
11 //<% nvram("l2tp_get_ip,ppp_get_ac,pptp_get_ip,pptp_server_ip,router_name,clkfreq,wan_ipaddr_buf,wan_domain,wan_gateway,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,security_mode2,wl_crypto,wl_mode,wds_enable,wl0_hwaddr,wl_net_mode,wl_radio,wl_channel,lan_gateway,wl_ssid,t_model_name,t_features"); %>
13 //<% uptime(); %>
14 //<% sysinfo(); %>
15 //<% wlradio(); %>
17 stats = { };
19 do {
20         var a, b, i;
22         if (typeof(last_wan_proto) == 'undefined') {
23                 last_wan_proto = nvram.wan_proto;
24         }
25         else if (last_wan_proto != nvram.wan_proto) {
26                 reloadPage();
27         }
29         stats.cpuload = ((sysinfo.loads[0] / 65536.0).toFixed(2) + '<small> / </small> ' +
30                 (sysinfo.loads[1] / 65536.0).toFixed(2) + '<small> / </small>' +
31                 (sysinfo.loads[2] / 65536.0).toFixed(2));
32         stats.freqcpu = nvram.clkfreq;
33         stats.uptime = sysinfo.uptime_s;
35         a = sysinfo.totalram;
36         b = sysinfo.totalfreeram;
37         stats.memory = scaleSize(a) + ' / ' + scaleSize(b) + ' <small>(' + (b / a * 100.0).toFixed(2) + '%)</small>';
38         if (sysinfo.totalswap > 0) {
39                 a = sysinfo.totalswap;
40                 b = sysinfo.freeswap;
41                 stats.swap = scaleSize(a) + ' / ' + scaleSize(b) + ' <small>(' + (b / a * 100.0).toFixed(2) + '%)</small>';
42         } else
43                 stats.swap = '';
45         stats.time = '<% time(); %>';
46         stats.wanup = '<% wanup(); %>' == '1';
47         stats.wanprebuf = nvram.wan_ipaddr_buf;
48         stats.wanuptime = '<% link_uptime(); %>';
49         stats.wanlease = '<% dhcpc_time(); %>';
51         //<% dns(); %>
52         stats.dns = dns.join(', ');
54         stats.wanip = nvram.wan_ipaddr;
55         stats.wannetmask = nvram.wan_netmask;
56         stats.wangateway = nvram.wan_gateway;
57         stats.ispconid = nvram.ppp_get_ac; //Victek
59         switch (nvram.wan_proto) {
60         case 'pptp':
61         case 'l2tp':
62                 if (stats.wanup) {
63                         stats.wanip = nvram.ppp_get_ip;
64                         if (nvram.wan_ipaddr != '' && nvram.wan_ipaddr != '0.0.0.0' && nvram.wan_ipaddr != nvram.ppp_get_ip)
65                                 stats.wanip += ' <small>(DHCP: ' + nvram.wan_ipaddr + ')</small>';
66                         if (stats.wannetmask == '0.0.0.0')
67                                 stats.wannetmask = '255.255.255.255';
68                 }
69                 else {
70                         if (nvram.wan_proto == 'pptp')
71                                 stats.wangateway = nvram.pptp_server_ip;
72                 }
73                 break;
74         default:
75                 if (!stats.wanup) {
76                         stats.wanip = '0.0.0.0';
77                         stats.wannetmask = '0.0.0.0';
78                         stats.wangateway = '0.0.0.0';
79                 }
80         }
82         stats.wanstatus = '<% wanstatus(); %>';
83         if (stats.wanstatus != 'Connected') stats.wanstatus = '<b>' + stats.wanstatus + '</b>';
85         // <% wlchannel(); %>
86         a = i = wlchaninfo[0] * 1;
87         if (i < 0) i = -i;
88         stats.channel = '<a href="tools-survey.asp">' + ((i) ? i + '' : 'Auto') +
89                 ((wlchaninfo[1]) ? ' - ' + (wlchaninfo[1] / 1000.0).toFixed(3) + ' <small>GHz</small>' : '') + '</a>' +
90                 ((a < 0) ? ' <small>(scanning...)</small>' : '');
91         stats.interference = (wlchaninfo[2] >= 0) ? ((wlchaninfo[2]) ? 'Severe' : 'Acceptable') : '';
93         a = '<% wlnbw(); %>' * 1;
94         if (a > 0)
95                 stats.nbw = a + ' <small>MHz</small>';
96         else
97                 stats.nbw = 'Auto';
99         wlcrssi = wlnoise = stats.qual = stats.rate = '';
100         isClient = ((nvram.wl_mode == 'wet') || (nvram.wl_mode == 'sta'));
101         if (wlradio) {
102                 a = '<% wlrate(); %>' * 1;
103                 if (a > 0)
104                         stats.rate = Math.floor(a / 2) + ((a & 1) ? '.5' : '') + ' <small>Mbps</small>';
105                 if (isClient) {
106                         //<% wlnoise(); %>
107                         //<% wlcrssi(); %>
108                         if (wlcrssi == 0) a = 0;
109                                 else a = MAX(wlcrssi - wlnoise, 0);
110                         stats.qual = a + ' <img src="bar' + MIN(MAX(Math.floor(a / 10), 1), 6) + '.gif">';
111                 }
112                 wlnoise += ' <small>dBm</small>';
113                 wlcrssi += ' <small>dBm</small>';
114         }
115 } while (0);