PageRenderTime 47ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/release/src/router/www/ipt-monthly.asp

https://gitlab.com/envieidoc/tomato
ASP | 494 lines | 415 code | 77 blank | 2 comment | 85 complexity | b2737e5b0d082e0bfc68c262a6c9eaf1 MD5 | raw file
  1. <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0//EN'>
  2. <!--
  3. Tomato GUI
  4. Copyright (C) 2006-2010 Jonathan Zarate
  5. http://www.polarcloud.com/tomato/
  6. IP Traffic enhancements
  7. Copyright (C) 2011 Augusto Bott
  8. http://code.google.com/p/tomato-sdhc-vlan/
  9. For use with Tomato Firmware only.
  10. No part of this file may be used without permission.
  11. -->
  12. <html>
  13. <head>
  14. <meta http-equiv='content-type' content='text/html;charset=utf-8'>
  15. <meta name='robots' content='noindex,nofollow'>
  16. <title>[<% ident(); %>] IP Traffic: Monthly History</title>
  17. <link rel='stylesheet' type='text/css' href='tomato.css'>
  18. <% css(); %>
  19. <script type='text/javascript' src='tomato.js'></script>
  20. <!-- / / / -->
  21. <style type='text/css'>
  22. #monthly-grid .co3,
  23. #monthly-grid .co4,
  24. #monthly-grid .co5 {
  25. text-align: right;
  26. }
  27. </style>
  28. <!-- / / / -->
  29. <script type='text/javascript' src='debug.js'></script>
  30. <script type='text/javascript' src='bwm-hist.js'></script>
  31. <script type='text/javascript' src='bwm-common.js'></script>
  32. <script type='text/javascript' src='interfaces.js'></script>
  33. <script type='text/javascript'>
  34. // <% nvram("wan_ifname,lan_ifname,wl_ifname,wan_proto,wan_iface,web_svg,cstats_enable,cstats_colors,dhcpd_static,lan_ipaddr,lan_netmask,lan1_ipaddr,lan1_netmask,lan2_ipaddr,lan2_netmask,lan3_ipaddr,lan3_netmask"); %>
  35. // <% devlist(); %>
  36. try {
  37. // <% ipt_bandwidth("monthly"); %>
  38. }
  39. catch (ex) {
  40. monthly_history = [];
  41. }
  42. cstats_busy = 0;
  43. if (typeof(monthly_history) == 'undefined') {
  44. monthly_history = [];
  45. cstats_busy = 1;
  46. }
  47. var filterip = [];
  48. var filteripe = [];
  49. var filteripe_before = [];
  50. var dateFormat = -1;
  51. var scale = -1;
  52. hostnamecache = [];
  53. function genData() {
  54. var w, i, h, t;
  55. w = window.open('', 'tomato_ipt_data_d');
  56. w.document.writeln('<pre>');
  57. for (i = 0; i < monthly_history.length; ++i) {
  58. h = monthly_history[i];
  59. t = getYMD(h[0]);
  60. w.document.writeln([t[0], t[1] + 1, h[1], h[2], h[3]].join(','));
  61. }
  62. w.document.writeln('</pre>');
  63. w.document.close();
  64. }
  65. function getYMD(n) {
  66. // [y,m,d]
  67. return [(((n >> 16) & 0xFF) + 1900), ((n >>> 8) & 0xFF), (n & 0xFF)];
  68. }
  69. var dg = new TomatoGrid();
  70. dg.setup = function() {
  71. this.init('monthly-grid', 'sort');
  72. this.headerSet(['Date', 'Host', 'Download', 'Upload', 'Total']);
  73. }
  74. function redraw() {
  75. var i, b, d;
  76. var fskip;
  77. var tx = 0;
  78. var rx = 0;
  79. var hostslisted = [];
  80. var subnetslisted = [];
  81. if (monthly_history.length > 0) {
  82. dg.removeAllData();
  83. for (i = 0; i < monthly_history.length; ++i) {
  84. fskip=0;
  85. b = monthly_history[i];
  86. if (E('_f_ignorezeroes').checked)
  87. if ((b[2] < 1) || (b[3] < 1))
  88. continue;
  89. if (E('_f_begin_date').value.toString() != '0') {
  90. if (b[0] < E('_f_begin_date').value)
  91. continue;
  92. }
  93. if (E('_f_end_date').value.toString() != '0') {
  94. if (b[0] > E('_f_end_date').value)
  95. continue;
  96. }
  97. if (filteripe.length>0) {
  98. fskip = 0;
  99. for (var x = 0; x < filteripe.length; ++x) {
  100. if (b[1] == filteripe[x]){
  101. fskip=1;
  102. break;
  103. }
  104. }
  105. if (fskip == 1) continue;
  106. }
  107. if (filterip.length>0) {
  108. fskip = 1;
  109. for (var x = 0; x < filterip.length; ++x) {
  110. if (b[1] == filterip[x]){
  111. fskip=0;
  112. break;
  113. }
  114. }
  115. if (fskip == 1) continue;
  116. }
  117. if ((b[1] == getNetworkAddress(nvram.lan_ipaddr,nvram.lan_netmask)) ||
  118. (b[1] == getNetworkAddress(nvram.lan1_ipaddr,nvram.lan1_netmask)) ||
  119. (b[1] == getNetworkAddress(nvram.lan2_ipaddr,nvram.lan2_netmask)) ||
  120. (b[1] == getNetworkAddress(nvram.lan3_ipaddr,nvram.lan3_netmask))) {
  121. if(E('_f_subnet').checked == 0) {
  122. continue;
  123. } else {
  124. subnetslisted.push(b[1]);
  125. }
  126. } else {
  127. hostslisted.push(b[1]);
  128. rx += b[2];
  129. tx += b[3];
  130. }
  131. if (hostslisted.length > 0) {
  132. hostslisted.sort();
  133. for (var j = 1; j < hostslisted.length; j++ ) {
  134. if (hostslisted[j] === hostslisted[j - 1]) {
  135. hostslisted.splice(j--, 1);
  136. }
  137. }
  138. }
  139. if (subnetslisted.length > 0) {
  140. subnetslisted.sort();
  141. for (var j = 1; j < subnetslisted.length; j++ ) {
  142. if (subnetslisted[j] === subnetslisted[j - 1]) {
  143. subnetslisted.splice(j--, 1);
  144. }
  145. }
  146. }
  147. var h = b[1];
  148. if (E('_f_hostnames').checked) {
  149. if(hostnamecache[b[1]] != null) {
  150. h = hostnamecache[b[1]] + ((b[1].indexOf(':') != -1) ? '<br>' : ' ') + '<small>(' + b[1] + ')</small>';
  151. }
  152. }
  153. if (E('_f_shortcuts').checked) {
  154. h = h + '<br><small>';
  155. h = h + '<a href="javascript:viewQosDetail(' + i + ')" title="View QoS Details">[qosdetails]</a>';
  156. h = h + '<a href="javascript:viewQosCTrates(' + i + ')" title="View transfer rates per connection">[qosrates]</a>';
  157. h = h + '<a href="javascript:viewIptDetail(' + i + ')" title="View real-time IP Traffic for this address">[iptraf]</a>';
  158. h = h + '<a href="javascript:addExcludeList(' + i + ')" title="Filter out this address">[hide]</a>';
  159. h = h + '</small>';
  160. }
  161. var ymd = getYMD(b[0]);
  162. d = [ymText(ymd[0], ymd[1]), h, rescale(b[2]), rescale(b[3]), rescale(b[2]+b[3])];
  163. dg.insertData(-1, d);
  164. }
  165. dg.resort();
  166. dg.recolor();
  167. dg.footerSet([
  168. 'Total',
  169. ('<small><i>(' +
  170. (((hostslisted.length > 0) || (subnetslisted.length > 0)) ?
  171. ((hostslisted.length > 0) ? (hostslisted.length + ' hosts') : '') +
  172. (((hostslisted.length > 0) && (subnetslisted.length > 0)) ? ', ' : '') +
  173. ((subnetslisted.length > 0) ? (subnetslisted.length + ' subnets') : '')
  174. : 'no data') +
  175. ')</i></small>'),
  176. rescale(rx),
  177. rescale(tx),
  178. rescale(rx+tx)]);
  179. }
  180. }
  181. function popupWindow(v) {
  182. window.open(v, '', 'width=1000,height=600,toolbar=no,menubar=no,scrollbars=yes,resizable=yes');
  183. }
  184. function viewQosDetail(n) {
  185. cookie.set('qos_filterip', [monthly_history[n][1]], 1);
  186. popupWindow('qos-detailed.asp');
  187. }
  188. function viewQosCTrates(n) {
  189. cookie.set('qos_filterip', [monthly_history[n][1]], 1);
  190. popupWindow('qos-ctrate.asp');
  191. }
  192. function viewIptDetail(n) {
  193. cookie.set('ipt_filterip', [monthly_history[n][1]], 1);
  194. popupWindow('ipt-details.asp');
  195. }
  196. function addExcludeList(n) {
  197. if (E('_f_filter_ipe').value.length<6) {
  198. E('_f_filter_ipe').value = monthly_history[n][1];
  199. } else {
  200. if (E('_f_filter_ipe').value.indexOf(monthly_history[n][1]) < 0) {
  201. E('_f_filter_ipe').value = E('_f_filter_ipe').value + ',' + monthly_history[n][1];
  202. }
  203. }
  204. dofilter();
  205. }
  206. dg.dataToView = function(data) {
  207. return(data);
  208. }
  209. dg.sortCompare = function(a, b) {
  210. var col = this.sortColumn;
  211. var da = a.getRowData();
  212. var db = b.getRowData();
  213. var r = 0;
  214. switch (col) {
  215. case 0: // Date
  216. r = cmpText(da[col], db[col]);
  217. break;
  218. case 1: // Hostname
  219. r = cmpIP(da[col], db[col]);
  220. if (r == 0)
  221. r = cmpText(da[col], db[col]);
  222. break;
  223. case 2: // Download
  224. case 3: // Upload
  225. case 4: // Total
  226. r = cmpFloat(da[col].replace(/,/g,""), db[col].replace(/,/g,""));
  227. break;
  228. }
  229. return this.sortAscending ? r : -r;
  230. }
  231. function init_filter_dates() {
  232. var dates = [];
  233. if (monthly_history.length > 0) {
  234. for (var i = 0; i < monthly_history.length; ++i) {
  235. dates.push('0x' + monthly_history[i][0].toString(16));
  236. }
  237. if (dates.length > 0) {
  238. dates.sort();
  239. for (var j = 1; j < dates.length; j++ ) {
  240. if (dates[j] === dates[j - 1]) {
  241. dates.splice(j--, 1);
  242. }
  243. }
  244. }
  245. }
  246. var b = E('_f_begin_date');
  247. var e = E('_f_end_date');
  248. var d = new Date();
  249. for (var i = 0; i < dates.length; ++i) {
  250. var ymd = getYMD(dates[i]);
  251. b.options[i+1] = new Option(ymText(ymd[0], ymd[1]), dates[i], false, ((ymd[0]==d.getFullYear()) && (ymd[1]==d.getMonth()) ) );
  252. e.options[i+1] = new Option(ymText(ymd[0], ymd[1]), dates[i], false, ((ymd[0]==d.getFullYear()) && (ymd[1]==d.getMonth()) ) );
  253. }
  254. }
  255. function update_filter_dates(b) {
  256. for (var i = 0; i < b.options.length; ++i) {
  257. if(b.options[i].value.toString() != '0') {
  258. var ymd = getYMD(b.options[i].value);
  259. b.options[i].text = ymText(ymd[0], ymd[1]);
  260. }
  261. }
  262. }
  263. function init() {
  264. if (nvram.cstats_enable != '1') return;
  265. var c;
  266. init_filter_dates();
  267. populateCache();
  268. if ((c = '<% cgi_get("ipt_filterip"); %>') != '') {
  269. if (c.length>6) {
  270. E('_f_begin_date').value = 0;
  271. E('_f_end_date').value = 0;
  272. E('_f_filter_ip').value = c;
  273. filterip = c.split(',');
  274. }
  275. }
  276. if ((c = cookie.get('ipt_filterip')) != null) {
  277. cookie.set('ipt_filterip', '', 0);
  278. if (c.length>6) {
  279. E('_f_begin_date').value = 0;
  280. E('_f_end_date').value = 0;
  281. E('_f_filter_ip').value = E('_f_filter_ip').value + ((E('_f_filter_ip').value.length > 0) ? ',' : '') + c;
  282. filterip.push(c.split(','));
  283. }
  284. }
  285. if ((c = cookie.get('ipt_addr_hidden')) != null) {
  286. if (c.length>6) {
  287. E('_f_filter_ipe').value = c;
  288. filteripe = c.split(',');
  289. }
  290. }
  291. filteripe_before = filteripe;
  292. dateFormat = fixInt(cookie.get('ipt_history_dafm'), 0, 3, 0);
  293. E('_f_dafm').value = dateFormat;
  294. scale = fixInt(cookie.get('ipt_history_scale'), 0, 2, 0);
  295. E('_f_scale').value = scale;
  296. E('_f_subnet').checked = (((c = cookie.get('ipt_history_subnet')) != null) && (c == '1'));
  297. E('_f_hostnames').checked = (((c = cookie.get('ipt_history_hostnames')) != null) && (c == '1'));
  298. E('_f_shortcuts').checked = (((c = cookie.get('ipt_history_shortcuts')) != null) && (c == '1'));
  299. E('_f_ignorezeroes').checked = (((c = cookie.get('ipt_history_ignorezeroes')) != null) && (c == '1'));
  300. if (((c = cookie.get('ipt_history_options_vis')) != null) && (c == '1')) {
  301. toggleVisibility("options");
  302. }
  303. dg.setup();
  304. redraw();
  305. }
  306. function toggleVisibility(whichone) {
  307. if(E('sesdiv' + whichone).style.display=='') {
  308. E('sesdiv' + whichone).style.display='none';
  309. E('sesdiv' + whichone + 'showhide').innerHTML='(Click here to show)';
  310. cookie.set('ipt_history_' + whichone + '_vis', 0);
  311. } else {
  312. E('sesdiv' + whichone).style.display='';
  313. E('sesdiv' + whichone + 'showhide').innerHTML='(Click here to hide)';
  314. cookie.set('ipt_history_' + whichone + '_vis', 1);
  315. }
  316. }
  317. function dofilter() {
  318. var i;
  319. if (E('_f_filter_ip').value.length>0) {
  320. filterip = E('_f_filter_ip').value.split(',');
  321. for (i = 0; i < filterip.length; ++i) {
  322. if ((filterip[i] = fixIP(filterip[i])) == null) {
  323. filterip.splice(i,1);
  324. }
  325. }
  326. E('_f_filter_ip').value = (filterip.length > 0) ? filterip.join(',') : '';
  327. } else {
  328. filterip = [];
  329. }
  330. if (E('_f_filter_ipe').value.length>0) {
  331. filteripe = E('_f_filter_ipe').value.split(',');
  332. for (i = 0; i < filteripe.length; ++i) {
  333. if ((filteripe[i] = fixIP(filteripe[i])) == null) {
  334. filteripe.splice(i,1);
  335. }
  336. }
  337. E('_f_filter_ipe').value = (filteripe.length > 0) ? filteripe.join(',') : '';
  338. } else {
  339. filteripe = [];
  340. }
  341. if (filteripe_before != filteripe) {
  342. cookie.set('ipt_addr_hidden', (filteripe.length > 0) ? filteripe.join(',') : '', 1);
  343. filteripe_before = filteripe;
  344. }
  345. redraw();
  346. }
  347. function verifyFields(focused, quiet) {
  348. dateFormat = E('_f_dafm').value * 1;
  349. cookie.set('ipt_history_dafm', E('_f_dafm').value, 31);
  350. scale = E('_f_scale').value * 1;
  351. cookie.set('ipt_history_scale', E('_f_scale').value, 2);
  352. // cookie.set('ipt_history_subnet', (E('_f_subnet').checked ? '1' : '0'), 1);
  353. cookie.set('ipt_history_hostnames', (E('_f_hostnames').checked ? '1' : '0'), 1);
  354. cookie.set('ipt_history_shortcuts', (E('_f_shortcuts').checked ? '1' : '0'), 1);
  355. cookie.set('ipt_history_ignorezeroes', (E('_f_ignorezeroes').checked ? '1' : '0'), 1);
  356. update_filter_dates(E('_f_begin_date'));
  357. update_filter_dates(E('_f_end_date'));
  358. if ((E('_f_begin_date').value > E('_f_end_date').value) && ( E('_f_end_date').value != '0')) {
  359. var tmp = E('_f_begin_date').value;
  360. E('_f_begin_date').value = E('_f_end_date').value;
  361. E('_f_end_date').value = tmp;
  362. }
  363. dofilter();
  364. return 1;
  365. }
  366. </script>
  367. </head>
  368. <body onload='init()'>
  369. <form>
  370. <table id='container' cellspacing=0>
  371. <tr><td colspan=2 id='header'>
  372. <div class='title'>Tomato</div>
  373. <div class='version'>Version <% version(); %></div>
  374. </td></tr>
  375. <tr id='body'><td id='navi'><script type='text/javascript'>navi()</script></td>
  376. <td id='content'>
  377. <div id='ident'><% ident(); %></div>
  378. <!-- / / / -->
  379. <div id='cstats'>
  380. <div class='section-title'>IP Traffic Monthly History</div>
  381. <div class='section'>
  382. <table id='monthly-grid' class='tomato-grid' cellspacing=0 style='height:auto'></table>
  383. </div>
  384. <div class='section-title'>Options <small><i><a href='javascript:toggleVisibility("options");'><span id='sesdivoptionsshowhide'>(Click here to show)</span></a></i></small></div>
  385. <div class='section' id='sesdivoptions' style='display:none'>
  386. <script type='text/javascript'>
  387. var c;
  388. c = [];
  389. c.push({ title: 'List only these IPs', name: 'f_filter_ip', size: 50, maxlen: 255, type: 'text', suffix: ' <small>(Comma separated list)</small>' });
  390. c.push({ title: 'Exclude these IPs', name: 'f_filter_ipe', size: 50, maxlen: 255, type: 'text', suffix: ' <small>(Comma separated list)</small>' });
  391. c.push({ title: 'Date Range', multi: [ { name: 'f_begin_date', type: 'select', options: [['0', 'Any']], suffix: ' - ' }, { name: 'f_end_date', type: 'select', options: [['0', 'Any']] } ] } );
  392. c.push({ title: 'Date Format', name: 'f_dafm', type: 'select', options: [['0', 'yyyy-mm'], ['1', 'mm-yyyy'], ['2', 'mmm, yyyy'], ['3', 'mm.yyyy']] });
  393. c.push({ title: 'Scale', name: 'f_scale', type: 'select', options: [['0', 'KB'], ['1', 'MB'], ['2', 'GB']] });
  394. c.push({ title: 'Show subnet totals', name: 'f_subnet', type: 'checkbox', suffix: ' <small>(Not considered when calculating total traffic on the last line)</small>' });
  395. c.push({ title: 'Hide IPs without traffic', name: 'f_ignorezeroes', type: 'checkbox' });
  396. c.push({ title: 'Show known hostnames', name: 'f_hostnames', type: 'checkbox' });
  397. c.push({ title: 'Show shortcuts', name: 'f_shortcuts', type: 'checkbox' });
  398. createFieldTable('',c);
  399. </script>
  400. <div style="float:right;text-align:right">
  401. &raquo; <a href="javascript:genData()">Data</a>
  402. <br>
  403. &raquo; <a href="admin-iptraffic.asp">Configure</a>
  404. </div>
  405. </div>
  406. </div>
  407. <br>
  408. <script type='text/javascript'>checkCstats();</script>
  409. <!-- / / / -->
  410. </td></tr>
  411. <tr><td id='footer' colspan=2>
  412. <input type='button' value='Refresh' onclick='reloadPage()'>
  413. </td></tr>
  414. </table>
  415. </form>
  416. </body>
  417. </html>