PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/release/src/router/www/js/status-data.jsx

https://gitlab.com/envieidoc/advancedtomato2
JSX | 137 lines | 124 code | 6 blank | 7 comment | 54 complexity | b5a99ecaed374777b0ded7f61ec1f5d5 MD5 | raw file
  1. //<% nvram("at_update,ppp_get_ip,pptp_server_ip,router_name,t_model_name,wan_ipaddr_buf,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,tomatoanon_enable,tomatoanon_answer,lan_desc"); %>
  2. //<% uptime(); %>
  3. //<% sysinfo(); %>
  4. //<% wlstats(1); %>
  5. stats = { };
  6. do {
  7. var a, b, i;
  8. var xifs = ['wan', 'lan', 'lan1', 'lan2', 'lan3'];
  9. stats.anon_enable = nvram.tomatoanon_enable;
  10. stats.anon_answer = nvram.tomatoanon_answer;
  11. stats.lan_desc = nvram.lan_desc;
  12. if (typeof(last_wan_proto) == 'undefined') {
  13. last_wan_proto = nvram.wan_proto;
  14. }
  15. else if (last_wan_proto != nvram.wan_proto) {
  16. reloadPage();
  17. }
  18. stats.flashsize = sysinfo.flashsize+'MB';
  19. stats.cpumhz = sysinfo.cpuclk+'MHz';
  20. stats.systemtype = sysinfo.systemtype;
  21. stats.cpuload = ((sysinfo.loads[0] / 65536.0).toFixed(2) + '<small> / </small> ' +
  22. (sysinfo.loads[1] / 65536.0).toFixed(2) + '<small> / </small>' +
  23. (sysinfo.loads[2] / 65536.0).toFixed(2));
  24. stats.uptime = sysinfo.uptime_s;
  25. stats.wlsense = sysinfo.wlsense;
  26. a = sysinfo.totalram;
  27. b = sysinfo.totalfreeram;
  28. stats.memory = scaleSize(a - b) + ' <small>/</small> ' + scaleSize(a) + ' (' + ((a - b) / a * 100.0).toFixed(2) + '%)';
  29. stats.memoryperc = ((a-b) / a * 100.0).toFixed(2) + '%';
  30. if (sysinfo.totalswap > 0) {
  31. a = sysinfo.totalswap;
  32. b = sysinfo.freeswap;
  33. stats.swap = scaleSize(a - b) + ' <small>/</small> ' + scaleSize(a) + ' (' + ((a - b) / a * 100.0).toFixed(2) + '%)';
  34. stats.swapperc = ((a - b) / a * 100.0).toFixed(2) + '%';
  35. } else
  36. stats.swap = '';
  37. stats.time = '<% time(); %>';
  38. stats.wanup = '<% wanup(); %>' == '1';
  39. stats.wanprebuf = nvram.wan_ipaddr_buf;
  40. stats.wanuptime = '<% link_uptime(); %>';
  41. stats.wanlease = '<% dhcpc_time(); %>';
  42. stats.routermodel = nvram.t_model_name;
  43. //<% dns(); %>
  44. stats.dns = dns.join(', ');
  45. stats.wanip = nvram.wan_ipaddr;
  46. stats.wannetmask = nvram.wan_netmask;
  47. stats.wangateway = nvram.wan_gateway_get;
  48. if (stats.wangateway == '0.0.0.0' || stats.wangateway == '')
  49. stats.wangateway = nvram.wan_gateway;
  50. switch (nvram.wan_proto) {
  51. case 'pptp':
  52. case 'l2tp':
  53. if (stats.wanup) {
  54. stats.wanip = nvram.ppp_get_ip;
  55. if (nvram.pptp_dhcp == '1') {
  56. if (nvram.wan_ipaddr != '' && nvram.wan_ipaddr != '0.0.0.0' && nvram.wan_ipaddr != stats.wanip)
  57. stats.wanip += '&nbsp;&nbsp;<small>(DHCP: ' + nvram.wan_ipaddr + ')</small>';
  58. if (nvram.wan_gateway != '' && nvram.wan_gateway != '0.0.0.0' && nvram.wan_gateway != stats.wangateway)
  59. stats.wangateway += '&nbsp;&nbsp;<small>(DHCP: ' + nvram.wan_gateway + ')</small>';
  60. }
  61. if (stats.wannetmask == '0.0.0.0')
  62. stats.wannetmask = '255.255.255.255';
  63. }
  64. else {
  65. if (nvram.wan_proto == 'pptp')
  66. stats.wangateway = nvram.pptp_server_ip;
  67. }
  68. break;
  69. default:
  70. if (!stats.wanup) {
  71. stats.wanip = '0.0.0.0';
  72. stats.wannetmask = '0.0.0.0';
  73. stats.wangateway = '0.0.0.0';
  74. }
  75. }
  76. /* IPV6-BEGIN */
  77. stats.ip6_wan = ((typeof(sysinfo.ip6_wan) != 'undefined') ? sysinfo.ip6_wan : '') + '';
  78. stats.ip6_lan = ((typeof(sysinfo.ip6_lan) != 'undefined') ? sysinfo.ip6_lan : '') + '';
  79. stats.ip6_lan_ll = ((typeof(sysinfo.ip6_lan_ll) != 'undefined') ? sysinfo.ip6_lan_ll : '') + '';
  80. /* IPV6-END */
  81. stats.wanstatus = '<% wanstatus(); %>';
  82. if (stats.wanstatus != 'Connected') stats.wanstatus = '<b>' + stats.wanstatus + '</b>';
  83. stats.channel = [];
  84. stats.interference = [];
  85. stats.qual = [];
  86. for (var uidx = 0; uidx < wl_ifaces.length; ++uidx) {
  87. u = wl_unit(uidx);
  88. a = i = wlstats[uidx].channel * 1;
  89. if (i < 0) i = -i;
  90. stats.channel.push('<a class="ajaxload" href="#tools-survey.asp">' + ((i) ? i + '' : 'Auto') +
  91. ((wlstats[uidx].mhz) ? ' - ' + (wlstats[uidx].mhz / 1000.0).toFixed(3) + ' <small>GHz</small>' : '') + '</a>' +
  92. ((a < 0) ? ' <small>(scanning...)</small>' : ''));
  93. stats.interference.push((wlstats[uidx].intf >= 0) ? ((wlstats[uidx].intf) ? 'Severe' : 'Acceptable') : '');
  94. a = wlstats[uidx].nbw * 1;
  95. wlstats[uidx].nbw = (a > 0) ? (a + ' <small>MHz</small>') : 'Auto';
  96. if (wlstats[uidx].radio) {
  97. a = wlstats[uidx].rate * 1;
  98. if (a > 0)
  99. wlstats[uidx].rate = Math.floor(a / 2) + ((a & 1) ? '.5' : '') + ' <small>Mbps</small>';
  100. else
  101. wlstats[uidx].rate = '-';
  102. if (wlstats[uidx].client) {
  103. if (wlstats[uidx].rssi == 0) a = 0;
  104. else a = MAX(wlstats[uidx].rssi - wlstats[uidx].noise, 0);
  105. stats.qual.push(a + ' <i class="icon-wifi-' + MIN(MAX(Math.floor(a / 10), 1), 3) + '"></i>');
  106. }
  107. else {
  108. stats.qual.push('');
  109. }
  110. wlstats[uidx].noise += ' <small>dBm</small>';
  111. wlstats[uidx].rssi += ' <small>dBm</small>';
  112. }
  113. else {
  114. wlstats[uidx].rate = '';
  115. wlstats[uidx].noise = '';
  116. wlstats[uidx].rssi = '';
  117. stats.qual.push('');
  118. }
  119. if (wl_ifaces[uidx][6] != 1) {
  120. wlstats[uidx].ifstatus = '<b>Down</b>';
  121. } else {
  122. wlstats[uidx].ifstatus = 'Up';
  123. for (i = 0; i < xifs.length ; ++i) {
  124. if ((nvram[xifs[i] + '_ifnames']).indexOf(wl_ifaces[uidx][0]) >= 0) {
  125. wlstats[uidx].ifstatus = wlstats[uidx].ifstatus + ' (' + xifs[i].toUpperCase() + ')';
  126. break;
  127. }
  128. }
  129. }
  130. }
  131. } while (0);