Busybox: Upgrade to 1.21.1 (stable). lsof active.
[tomato.git] / release / src / router / www / admin-iptraffic.asp
blobca0469af69e970ce72ad0ce69e11acfe21e9a541
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/
7 For use with Tomato Firmware only.
8 No part of this file may be used without permission.
9 -->
10 <html>
11 <head>
12 <meta http-equiv='content-type' content='text/html;charset=utf-8'>
13 <meta name='robots' content='noindex,nofollow'>
14 <title>[<% ident(); %>] Admin: IP Traffic Monitoring</title>
15 <link rel='stylesheet' type='text/css' href='tomato.css'>
16 <% css(); %>
17 <script type='text/javascript' src='tomato.js'></script>
19 <!-- / / / -->
20 <style type='text/css'>
21 textarea {
22 width: 98%;
23 height: 15em;
25 </style>
27 <script type='text/javascript' src='debug.js'></script>
29 <script type='text/javascript'>
31 // <% nvram("cstats_enable,cstats_path,cstats_stime,cstats_offset,cstats_exclude,cstats_include,cstats_sshut,et0macaddr,cifs1,cifs2,jffs2_on,cstats_bak,cstats_all,cstats_labels"); %>
33 function fix(name)
35 var i;
36 if (((i = name.lastIndexOf('/')) > 0) || ((i = name.lastIndexOf('\\')) > 0))
37 name = name.substring(i + 1, name.length);
38 return name;
41 function backupNameChanged()
43 if (location.href.match(/^(http.+?\/.+\/)/)) {
44 E('backup-link').href = RegExp.$1 + 'ipt/' + fix(E('backup-name').value) + '.gz?_http_id=' + nvram.http_id;
48 function backupButton()
50 var name;
52 name = fix(E('backup-name').value);
53 if (name.length <= 1) {
54 alert('Invalid filename');
55 return;
57 location.href = 'ipt/' + name + '.gz?_http_id=' + nvram.http_id;
60 function restoreButton()
62 var fom;
63 var name;
64 var i;
66 name = fix(E('restore-name').value);
67 name = name.toLowerCase();
68 if ((name.length <= 3) || (name.substring(name.length - 3, name.length).toLowerCase() != '.gz')) {
69 alert('Incorrect filename. Expecting a ".gz" file.');
70 return;
72 if (!confirm('Restore data from ' + name + '?')) return;
74 E('restore-button').disabled = 1;
75 fields.disableAll(E('config-section'), 1);
76 fields.disableAll(E('backup-section'), 1);
77 fields.disableAll(E('footer'), 1);
79 E('restore-form').submit();
82 function getPath()
84 var s = E('_f_loc').value;
85 return (s == '*user') ? E('_f_user').value : s;
88 function verifyFields(focused, quiet)
90 var b, v;
91 var path;
92 var eLoc, eUser, eTime, eOfs;
93 var bak;
94 var eInc, eExc, eAll, eBak, eLab;
96 eLoc = E('_f_loc');
97 eUser = E('_f_user');
98 eTime = E('_cstats_stime');
99 eOfs = E('_cstats_offset');
101 eInc = E('_cstats_include');
102 eExc = E('_cstats_exclude');
103 eAll = E('_f_all');
104 eBak = E('_f_bak');
106 eLab = E('_cstats_labels');
108 b = !E('_f_cstats_enable').checked;
109 eLoc.disabled = b;
110 eUser.disabled = b;
111 eTime.disabled = b;
112 eOfs.disabled = b;
113 eInc.disabled = b;
114 eExc.disabled = b;
115 eAll.disabled = b;
116 eBak.disabled = b;
117 eLab.disabled = b;
118 E('_f_new').disabled = b;
119 E('_f_sshut').disabled = b;
120 E('backup-button').disabled = b;
121 E('backup-name').disabled = b;
122 E('restore-button').disabled = b;
123 E('restore-name').disabled = b;
124 ferror.clear(eLoc);
125 ferror.clear(eUser);
126 ferror.clear(eOfs);
127 if (b) return 1;
129 eInc.disabled = eAll.checked;
131 path = getPath();
132 E('newmsg').style.visibility = ((nvram.cstats_path != path) && (path != '*nvram') && (path != '')) ? 'visible' : 'hidden';
134 bak = 0;
135 v = eLoc.value;
136 b = (v == '*user');
137 elem.display(eUser, b);
138 if (b) {
139 if (!v_length(eUser, quiet, 2)) return 0;
140 if (path.substr(0, 1) != '/') {
141 ferror.set(eUser, 'Please start at the / root directory.', quiet);
142 return 0;
145 else if (v == '/jffs/') {
146 if (nvram.jffs2_on != '1') {
147 ferror.set(eLoc, 'JFFS2 is not enabled.', quiet);
148 return 0;
151 else if (v.match(/^\/cifs(1|2)\/$/)) {
152 if (nvram['cifs' + RegExp.$1].substr(0, 1) != '1') {
153 ferror.set(eLoc, 'CIFS #' + RegExp.$1 + ' is not enabled.', quiet);
154 return 0;
157 else {
158 bak = 1;
161 E('_f_bak').disabled = bak;
163 return v_range(eOfs, quiet, 1, 31);
166 function save()
168 var fom, path, en, e, aj;
170 if (!verifyFields(null, false)) return;
172 aj = 1;
173 en = E('_f_cstats_enable').checked;
174 fom = E('_fom');
175 fom._service.value = 'cstats-restart';
176 if (en) {
177 path = getPath();
178 if (((E('_cstats_stime').value * 1) <= 48) &&
179 ((path == '*nvram') || (path == '/jffs/'))) {
180 if (!confirm('Frequent saving to NVRAM or JFFS2 is not recommended. Continue anyway?')) return;
182 if ((nvram.cstats_path != path) && (fom.cstats_path.value != path) && (path != '') && (path != '*nvram') &&
183 (path.substr(path.length - 1, 1) != '/')) {
184 if (!confirm('Note: ' + path + ' will be treated as a file. If this is a directory, please use a trailing /. Continue anyway?')) return;
186 fom.cstats_path.value = path;
188 if (E('_f_new').checked) {
189 fom._service.value = 'cstatsnew-restart';
190 aj = 0;
194 fom.cstats_path.disabled = !en;
195 fom.cstats_enable.value = en ? 1 : 0;
196 fom.cstats_sshut.value = E('_f_sshut').checked ? 1 : 0;
197 fom.cstats_bak.value = E('_f_bak').checked ? 1 : 0;
198 fom.cstats_all.value = E('_f_all').checked ? 1 : 0;
200 e = E('_cstats_exclude');
201 e.value = e.value.replace(/\s+/g, ',').replace(/,+/g, ',');
203 e = E('_cstats_include');
204 e.value = e.value.replace(/\s+/g, ',').replace(/,+/g, ',');
206 fields.disableAll(E('backup-section'), 1);
207 fields.disableAll(E('restore-section'), 1);
208 form.submit(fom, aj);
209 if (en) {
210 fields.disableAll(E('backup-section'), 0);
211 fields.disableAll(E('restore-section'), 0);
215 function init()
217 backupNameChanged();
218 var c;
219 if (((c = cookie.get('admin_iptraffic_notes_vis')) != null) && (c == '1')) toggleVisibility("notes");
222 function toggleVisibility(whichone) {
223 if (E('sesdiv_' + whichone).style.display == '') {
224 E('sesdiv_' + whichone).style.display = 'none';
225 E('sesdiv_' + whichone + '_showhide').innerHTML = '(Click here to show)';
226 cookie.set('admin_iptraffic_' + whichone + '_vis', 0);
227 } else {
228 E('sesdiv_' + whichone).style.display='';
229 E('sesdiv_' + whichone + '_showhide').innerHTML = '(Click here to hide)';
230 cookie.set('admin_iptraffic_' + whichone + '_vis', 1);
233 </script>
235 </head>
236 <body onload="init()">
237 <table id='container' cellspacing=0>
238 <tr><td colspan=2 id='header'>
239 <div class='title'>Tomato</div>
240 <div class='version'>Version <% version(); %></div>
241 </td></tr>
242 <tr id='body'><td id='navi'><script type='text/javascript'>navi()</script></td>
243 <td id='content'>
244 <div id='ident'><% ident(); %></div>
246 <!-- / / / -->
248 <div class='section-title'>IP Traffic Monitoring</div>
249 <div class='section' id='config-section'>
250 <form id='_fom' method='post' action='tomato.cgi'>
251 <input type='hidden' name='_nextpage' value='admin-iptraffic.asp'>
252 <input type='hidden' name='_service' value='cstats-restart'>
253 <input type='hidden' name='cstats_enable'>
254 <input type='hidden' name='cstats_path'>
255 <input type='hidden' name='cstats_sshut'>
256 <input type='hidden' name='cstats_bak'>
257 <input type='hidden' name='cstats_all'>
259 <script type='text/javascript'>
260 switch (nvram.cstats_path) {
261 case '':
262 case '*nvram':
263 case '/jffs/':
264 case '/cifs1/':
265 case '/cifs2/':
266 loc = nvram.cstats_path;
267 break;
268 default:
269 loc = '*user';
270 break;
272 createFieldTable('', [
273 { title: 'Enable', name: 'f_cstats_enable', type: 'checkbox', value: nvram.cstats_enable == '1' },
274 { title: 'Save History Location', multi: [
275 /* REMOVE-BEGIN
276 // { name: 'f_loc', type: 'select', options: [['','RAM (Temporary)'],['*nvram','NVRAM'],['/jffs/','JFFS2'],['/cifs1/','CIFS 1'],['/cifs2/','CIFS 2'],['*user','Custom Path']], value: loc },
277 REMOVE-END */
278 { name: 'f_loc', type: 'select', options: [['','RAM (Temporary)'],['/jffs/','JFFS2'],['/cifs1/','CIFS 1'],['/cifs2/','CIFS 2'],['*user','Custom Path']], value: loc },
279 { name: 'f_user', type: 'text', maxlen: 48, size: 50, value: nvram.cstats_path }
280 ] },
281 { title: 'Save Frequency', indent: 2, name: 'cstats_stime', type: 'select', value: nvram.cstats_stime, options: [
282 [1,'Every Hour'],[2,'Every 2 Hours'],[3,'Every 3 Hours'],[4,'Every 4 Hours'],[5,'Every 5 Hours'],[6,'Every 6 Hours'],
283 [9,'Every 9 Hours'],[12,'Every 12 Hours'],[24,'Every 24 Hours'],[48,'Every 2 Days'],[72,'Every 3 Days'],[96,'Every 4 Days'],
284 [120,'Every 5 Days'],[144,'Every 6 Days'],[168,'Every Week']] },
285 { title: 'Save On Shutdown', indent: 2, name: 'f_sshut', type: 'checkbox', value: nvram.cstats_sshut == '1' },
286 { title: 'Create New File<br><small>(Reset Data)</small>', indent: 2, name: 'f_new', type: 'checkbox', value: 0,
287 suffix: ' &nbsp; <b id="newmsg" style="visibility:hidden"><small>(note: enable if this is a new file)</small></b>' },
288 { title: 'Create Backups', indent: 2, name: 'f_bak', type: 'checkbox', value: nvram.cstats_bak == '1' },
289 { title: 'First Day Of The Month', name: 'cstats_offset', type: 'text', value: nvram.cstats_offset, maxlen: 2, size: 4 },
290 { title: 'Excluded IPs', name: 'cstats_exclude', type: 'text', value: nvram.cstats_exclude, maxlen: 512, size: 50, suffix: '&nbsp;<small>(comma separated list)</small>' },
291 { title: 'Included IPs', name: 'cstats_include', type: 'text', value: nvram.cstats_include, maxlen: 2048, size: 50, suffix: '&nbsp;<small>(comma separated list)</small>' },
292 { title: 'Enable Auto-Discovery', name: 'f_all', type: 'checkbox', value: nvram.cstats_all == '1', suffix: '&nbsp;<small>(automatically include new IPs in monitoring as soon as any traffic is detected)</small>' },
293 { title: 'Labels on graphics', name: 'cstats_labels', type: 'select', value: nvram.cstats_stime, options: [[0,'Show known hostnames and IPs'],[1,'Prefer to show only known hostnames, otherwise show IPs'],[2,'Show only IPs']], value: nvram.cstats_labels }
295 </script>
296 </form>
297 </div>
299 <br>
301 <div class='section-title'>Backup</div>
302 <div class='section' id='backup-section'>
303 <form>
304 <script type='text/javascript'>
305 W("<input type='text' size='40' maxlength='64' id='backup-name' name='backup_name' onchange='backupNameChanged()' value='tomato_cstats_" + nvram.et0macaddr.replace(/:/g, '').toLowerCase() + "'>");
306 </script>
307 .gz &nbsp;
308 <input type='button' name='f_backup_button' id='backup-button' onclick='backupButton()' value='Backup'>
309 </form>
310 <a href='' id='backup-link'>Link</a>
311 </div>
312 <br>
314 <div class='section-title'>Restore</div>
315 <div class='section' id='restore-section'>
316 <form id='restore-form' method='post' action='ipt/restore.cgi?_http_id=<% nv(http_id); %>' encType='multipart/form-data'>
317 <input type='file' size='40' id='restore-name' name='restore_name'>
318 <input type='button' name='f_restore_button' id='restore-button' value='Restore' onclick='restoreButton()'>
319 <br>
320 </form>
321 </div>
323 <!-- / / / -->
325 <div class='section-title'>Notes <small><i><a href='javascript:toggleVisibility("notes");'><span id='sesdiv_notes_showhide'>(Click here to show)</span></a></i></small></div>
326 <div class='section' id='sesdiv_notes' style='display:none'>
327 <ul>
328 <li>IP Traffic is about monitoring <i>IPv4</i> network traffic flowing <i>through</i> the router.</li>
329 <li>Check your <a href=basic-network.asp>LAN Settings</a> before enabling this feature: any/all LAN interfaces must have a netmask with at least 16 bits set (255.255.0.0).</li>
330 <li>Monitoring of larger subnets is not supported.</li>
331 </ul>
333 <small>
334 <ul>
335 <li><b>Other relevant notes/hints:</b>
336 <ul>
337 <li>Before enabling this feature, please check your <a href=basic-network.asp>LAN Settings</a> and make sure the netmask on any/all of your LAN bridges has been configured properly (i.e. netmask with at least 16 bits set or "255.255.0.0").</li>
338 <li>Although technically supported, it's not actually recommended having IP Traffic monitoring enabled with subnets larger than/the equivalent of a class C network (i.e. netmask with at least 24 bits set or "255.255.255.0").</li>
339 <li>IP Traffic monitoring keeps track of data/packets that would be either <i>coming from/leaving</i> or <i>going to/arriving</i> IPs on LAN interfaces/subnets.</li>
340 <li>As a rule of thumb, this means keeping track of network/data packets being forwarded from/to LAN interfaces as a result of some kind of routing (or NAT) and would exclude any/all data/packets being exchanged between devices reachable/within the same LAN interface (i.e. on the same IP subnet/LAN bridge, even if packets are actually being forwarded from/to wired/wireless/different interfaces through the router).</li>
341 <!-- VLAN-BEGIN -->
342 <li>Network traffic/communications flowing from/to/between different LAN bridges/subnets will be tracked/accounted separately/accordingly ("twice", as in: number of bytes/packets <i>coming from</i> the first LAN bridge and (the same) number of bytes/packets <i>going to</i> the second LAN bridge).</li>
343 <!-- VLAN-END -->
344 </ul>
345 </ul>
347 </div>
349 <!-- / / / -->
351 </td></tr>
352 <tr><td id='footer' colspan=2>
353 <form>
354 <span id='footer-msg'></span>
355 <input type='button' value='Save' id='save-button' onclick='save()'>
356 <input type='button' value='Cancel' id='cancel-button' onclick='javascript:reloadPage();'>
357 </form>
358 </div>
359 </td></tr>
360 </table>
361 <script type='text/javascript'>verifyFields(null, 1);</script>
362 </body>
363 </html>