cosmetics
[tomato.git] / release / src / router / www / restrict-edit.asp
blobbaccab5b153a2401c7d858ed60dab103714d3c47
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(); %>] Edit Access Restrictions</title>
15 <link rel='stylesheet' type='text/css' href='tomato.css'>
16 <link rel='stylesheet' type='text/css' href='color.css'>
17 <script type='text/javascript' src='tomato.js'></script>
18 <script type='text/javascript' src='protocols.js'></script>
20 <!-- / / / -->
22 <style type='text/css'>
23 #res-comp-grid {
24 width: 60%;
26 #res-bp-grid .box1, #res-bp-grid .box2 {
27 width: 20%;
28 float: left;
30 #res-bp-grid .box3 {
31 width: 60%;
32 float: left;
34 #res-bp-grid .box4 {
35 width: 30%;
36 float: left;
37 clear: left;
38 padding-top: 2px;
40 #res-bp-grid .box5 {
41 width: 70%;
42 float: left;
43 padding-top: 2px;
45 #res-bp-grid .box6 {
46 width: 30%;
47 float: left;
48 padding-top: 2px;
50 #res-bp-grid .box7 {
51 width: 70%;
52 float: left;
53 padding-top: 2px;
56 textarea {
57 width: 99%;
58 height: 20em;
60 </style>
62 <script type='text/javascript' src='debug.js'></script>
64 <script type='text/javascript'>
65 // <% nvram(''); %> // http_id
67 // {enable}|{begin_mins}|{end_mins}|{dow}|{comp[<comp]}|{rules<rules[...]>}|{http[ ...]}|{http_file}|{desc}
68 // <% rrule(); %>
69 if ((rule = rrule.match(/^(\d+)\|(-?\d+)\|(-?\d+)\|(\d+)\|(.*?)\|(.*?)\|([^|]*?)\|(\d+)\|(.*)$/m)) == null) {
70 rule = ['', 1, 1380, 240, 31, '', '', '', 0, 'New Rule ' + (rruleN + 1)];
72 rule[2] *= 1;
73 rule[3] *= 1;
74 rule[4] *= 1;
75 rule[8] *= 1;
77 // <% layer7(); %>
78 layer7.sort();
79 for (i = 0; i < layer7.length; ++i)
80 layer7[i] = [layer7[i],layer7[i]];
81 layer7.unshift(['', 'Layer 7 (disabled)']);
83 var ipp2p = [
84 [0,'IPP2P (disabled)'],[0xFFFF,'All IPP2P Filters'],[1,'AppleJuice'],[2,'Ares'],[4,'BitTorrent'],[8,'Direct Connect'],
85 [16,'eDonkey'],[32,'Gnutella'],[64,'Kazaa'],[128,'Mute'],[256,'SoulSeek'],[512,'Waste'],[1024,'WinMX'],[2048,'XDCC']];
87 var dowNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
91 var cg = new TomatoGrid();
93 cg.verifyFields = function(row, quiet) {
94 var f = fields.getAll(row)[0];
95 if (v_mac(f, true)) return true;
96 if (_v_iptaddr(f, true, false, true, true)) return true;
98 ferror.set(f, 'Invalid MAC address or IP address/range', quiet);
99 return false;
102 cg.setup = function() {
103 var a, i, count, ex;
105 this.init('res-comp-grid', 'sort', 500, [ { type: 'text', maxlen: 32 } ] );
106 this.headerSet(['MAC / IP Address']);
107 this.showNewEditor();
108 this.resetNewEditor();
110 if (rule[5] == '~') return; // wireless disable rule
112 ex = 0;
113 count = 0;
114 a = rule[5].split('>');
115 for (i = 0; i < a.length; ++i) {
116 if (!a[i].length) continue;
117 if (a[i] == '!') {
118 ex = 1;
120 else {
121 cg.insertData(-1, [a[i]]);
122 ++count;
126 a = E('_f_comp_all')
127 if (count) {
128 a.value = ex ? 2 : 1;
130 else {
131 a.value = 0;
136 var bpg = new TomatoGrid();
138 bpg.verifyFields = function(row, quiet) {
139 var f = fields.getAll(row);
140 ferror.clearAll(f);
141 this.enDiFields(row);
143 if ((f[5].selectedIndex != 0) && ((!v_length(f[6], quiet, 1)) || (!_v_iptaddr(f[6], quiet, false, true, true)))) return 0;
144 if ((f[1].selectedIndex != 0) && (!v_iptport(f[2], quiet))) return 0;
146 if ((f[1].selectedIndex == 0) && (f[3].selectedIndex == 0) && (f[4].selectedIndex == 0) && (f[5].selectedIndex == 0)) {
147 var m = 'Please enter a specific address or port, or select an application match';
148 ferror.set(f[3], m, 1);
149 ferror.set(f[4], m, 1);
150 ferror.set(f[5], m, 1);
151 ferror.set(f[1], m, quiet);
152 return 0;
155 ferror.clear(f[1]);
156 ferror.clear(f[3]);
157 ferror.clear(f[4]);
158 ferror.clear(f[5]);
159 ferror.clear(f[6]);
160 return 1;
163 bpg.dataToView = function(data) {
164 var s, i;
166 s = '';
167 if (data[5] != 0) s = ((data[5] == 1) ? 'To ' : 'From ') + data[6] + ', ';
169 if (data[0] <= -2) s += (s.length ? 'a' : 'A') + 'ny protocol';
170 else if (data[0] == -1) s += 'TCP/UDP';
171 else if (data[0] >= 0) s += protocols[data[0]] || data[0];
173 if (data[0] >= -1) {
174 if (data[1] == 'd') s += ', dst port ';
175 else if (data[1] == 's') s += ', src port ';
176 else if (data[1] == 'x') s += ', port ';
177 else s += ', all ports';
178 if (data[1] != 'a') s += data[2].replace(/:/g, '-');
181 if (data[3] != 0) {
182 for (i = 0; i < ipp2p.length; ++i) {
183 if (data[3] == ipp2p[i][0]) {
184 s += ', IPP2P: ' + ipp2p[i][1];
185 break;
189 else if (data[4] != '') {
190 s += ', L7: ' + data[4];
193 return [s];
196 bpg.fieldValuesToData = function(row) {
197 var f = fields.getAll(row);
198 return [f[0].value, f[1].value, (f[1].selectedIndex == 0) ? '' : f[2].value, f[3].value, f[4].value, f[5].value, (f[5].selectedIndex == 0) ? '' : f[6].value];
201 bpg.resetNewEditor = function() {
202 var f = fields.getAll(this.newEditor);
203 f[0].selectedIndex = 0;
204 f[1].selectedIndex = 0;
205 f[2].value = '';
206 f[3].selectedIndex = 0;
207 f[4].selectedIndex = 0;
208 f[5].selectedIndex = 0;
209 f[6].value = '';
210 this.enDiFields(this.newEditor);
211 ferror.clearAll(fields.getAll(this.newEditor));
214 bpg._createEditor = bpg.createEditor;
215 bpg.createEditor = function(which, rowIndex, source) {
216 var row = this._createEditor(which, rowIndex, source);
217 if (which == 'edit') this.enDiFields(row);
218 return row;
221 bpg.enDiFields = function(row) {
222 var x;
223 var f = fields.getAll(row);
225 x = f[0].value;
226 x = ((x != -1) && (x != 6) && (x != 17));
227 f[1].disabled = x;
228 if (f[1].selectedIndex == 0) x = 1;
229 f[2].disabled = x;
230 f[3].disabled = (f[4].selectedIndex != 0);
231 f[4].disabled = (f[3].selectedIndex != 0);
232 f[6].disabled = (f[5].selectedIndex == 0);
235 bpg.setup = function() {
236 var a, i, r, count, protos;
238 protos = [[-2, 'Any Protocol'],[-1,'TCP/UDP'],[6,'TCP'],[17,'UDP']];
239 for (i = 0; i < 256; ++i) {
240 if ((i != 6) && (i != 17)) protos.push([i, protocols[i] || i]);
243 this.init('res-bp-grid', 'sort', 500, [ { multi: [
244 { type: 'select', prefix: '<div class="box1">', suffix: '</div>', options: protos },
245 { type: 'select', prefix: '<div class="box2">', suffix: '</div>',
246 options: [['a','Any Port'],['d','Dst Port'],['s','Src Port'],['x','Src or Dst']] },
247 { type: 'text', prefix: '<div class="box3">', suffix: '</div>', maxlen: 32 },
248 { type: 'select', prefix: '<div class="box4">', suffix: '</div>', options: ipp2p },
249 { type: 'select', prefix: '<div class="box5">', suffix: '</div>', options: layer7 },
250 { type: 'select', prefix: '<div class="box6">', suffix: '</div>',
251 options: [[0,'Any Address'],[1,'Dst IP'],[2,'Src IP']] },
252 { type: 'text', prefix: '<div class="box7">', suffix: '</div>', maxlen: 64 }
253 ] } ] );
254 this.headerSet(['Rules']);
255 this.showNewEditor();
256 this.resetNewEditor();
257 count = 0;
259 // ---- proto<dir<port<ipp2p<layer7[<addr_type<addr]
261 a = rule[6].split('>');
262 for (i = 0; i < a.length; ++i) {
263 r = a[i].split('<');
264 if (r.length == 5) {
265 // ---- fixup for backward compatibility
266 r.push('0');
267 r.push('');
269 if (r.length == 7) {
270 r[2] = r[2].replace(/:/g, '-');
271 this.insertData(-1, r);
272 ++count;
275 return count;
280 function verifyFields(focused, quiet)
282 var b, e;
284 tgHideIcons();
286 elem.display(PR('_f_sched_begin'), !E('_f_sched_allday').checked);
287 elem.display(PR('_f_sched_sun'), !E('_f_sched_everyday').checked);
289 b = E('rt_norm').checked;
290 elem.display(PR('_f_comp_all'), PR('_f_block_all'), b);
292 elem.display(PR('res-comp-grid'), b && E('_f_comp_all').value != 0);
293 elem.display(PR('res-bp-grid'), PR('_f_block_http'), PR('_f_activex'), b && !E('_f_block_all').checked);
295 ferror.clear('_f_comp_all');
297 e = E('_f_block_http');
298 e.value = e.value.replace(/[|"']/g, ' ');
299 if (!v_length(e, quiet, 0, 2048 - 16)) return 0;
301 e = E('_f_desc');
302 e.value = e.value.replace(/\|/g, '_');
303 if (!v_length(e, quiet, 1)) return 0;
305 return 1;
308 function cancel()
310 document.location = 'restrict.asp';
313 function remove()
315 if (!confirm('Delete this rule?')) return;
317 E('delete-button').disabled = 1;
319 e = E('_rrule');
320 e.name = 'rrule' + rruleN;
321 e.value = '';
322 form.submit('_fom');
325 function save()
327 if (!verifyFields(null, false)) return;
328 if ((cg.isEditing()) || (bpg.isEditing())) return;
330 var a, b, e, s, n, data;
332 data = [];
333 data.push(E('_f_enabled').checked ? '1' : '0');
334 if (E('_f_sched_allday').checked) data.push(-1, -1);
335 else data.push(E('_f_sched_begin').value, E('_f_sched_end').value);
337 if (E('_f_sched_everyday').checked) {
338 n = 0x7F;
340 else {
341 n = 0;
342 for (i = 0; i < 7; ++i) {
343 if (E('_f_sched_' + dowNames[i].toLowerCase()).checked) n |= (1 << i);
345 if (n == 0) n = 0x7F;
347 data.push(n);
349 if (E('rt_norm').checked) {
350 e = E('_f_comp_all');
351 if (e.value != 0) {
352 a = cg.getAllData();
353 if (a.length == 0) {
354 ferror.set(e, 'No MAC or IP address was specified', 0);
355 return;
357 if (e.value == 2) a.unshift('!');
358 data.push(a.join('>'));
360 else {
361 data.push('');
364 if (E('_f_block_all').checked) {
365 data.push('', '', '0');
367 else {
368 var check = 0;
369 a = bpg.getAllData();
370 check += a.length;
371 b = [];
372 for (i = 0; i < a.length; ++i) {
373 a[i][2] = a[i][2].replace(/-/g, ':');
374 b.push(a[i].join('<'));
376 data.push(b.join('>'));
378 a = E('_f_block_http').value.replace(/\r+/g, ' ').replace(/\n+/g, '\n').replace(/ +/g, ' ').replace(/^\s+|\s+$/g, '');
379 check += a.length;
380 data.push(a);
382 n = 0;
383 if (E('_f_activex').checked) n = 1;
384 if (E('_f_flash').checked) n |= 2;
385 if (E('_f_java').checked) n |= 4;
386 data.push(n);
388 if (((check + n) == 0) && (data[0] == 1)) {
389 alert('Please specify what items should be blocked.');
390 return;
394 else {
395 data.push('~');
396 data.push('', '', '', '0');
399 data.push(E('_f_desc').value);
400 data = data.join('|');
402 if (data.length >= 8192) {
403 alert('This rule is too big. Please reduce by ' + (data.length - 8192) + ' characters.');
404 return;
407 e = E('_rrule');
408 e.name = 'rrule' + rruleN;
409 e.value = data;
411 E('delete-button').disabled = 1;
412 form.submit('_fom');
415 function init()
417 cg.recolor();
418 bpg.recolor();
421 function earlyInit()
423 var count;
425 cg.setup();
427 count = bpg.setup();
428 E('_f_block_all').checked = (count == 0) && (rule[7].search(/[^\s\r\n]/) == -1) && (rule[8] == 0);
429 verifyFields(null, 1);
431 </script>
432 </head>
433 <body onload='init()'>
434 <form name='_fom' id='_fom' method='post' action='tomato.cgi'>
435 <table id='container' cellspacing=0>
436 <tr><td colspan=2 id='header'>
437 <div class='title'>Tomato</div>
438 <div class='version'>Version <% version() %></div>
439 </td></tr>
440 <tr id='body'><td id='navi'><script type='text/javascript'>navi()</script></td>
441 <td id='content'>
442 <div id='ident'><% ident(); %></div>
444 <!-- / / / -->
446 <input type='hidden' name='_nextpage' value='restrict.asp'>
447 <input type='hidden' name='_service' value='restrict-restart'>
448 <input type='hidden' name='rruleNN' id='_rrule' value=''>
450 <div class='section-title'>Access Restriction</div>
451 <div class='section'>
452 <script type='text/javascript'>
453 W('<div style="float:right"><small>'+ 'ID: ' + rruleN.pad(2) + '</small>&nbsp;</div><br>');
454 tm = [];
455 for (i = 0; i < 1440; i += 15) tm.push([i, timeString(i)]);
457 createFieldTable('', [
458 { title: 'Enabled', name: 'f_enabled', type: 'checkbox', value: rule[1] == '1' },
459 { title: 'Description', name: 'f_desc', type: 'text', maxlen: 32, size: 35, value: rule[9] },
460 { title: 'Schedule', multi: [
461 { name: 'f_sched_allday', type: 'checkbox', suffix: ' All Day &nbsp; ', value: (rule[2] < 0) || (rule[3] < 0) },
462 { name: 'f_sched_everyday', type: 'checkbox', suffix: ' Everyday', value: (rule[4] & 0x7F) == 0x7F } ] },
463 { title: 'Time', indent: 2, multi: [
464 { name: 'f_sched_begin', type: 'select', options: tm, value: (rule[2] < 0) ? 0 : rule[2], suffix: ' - ' },
465 { name: 'f_sched_end', type: 'select', options: tm, value: (rule[3] < 0) ? 0 : rule[3] } ] },
466 { title: 'Days', indent: 2, multi: [
467 { name: 'f_sched_sun', type: 'checkbox', suffix: ' Sun &nbsp; ', value: (rule[4] & 1) },
468 { name: 'f_sched_mon', type: 'checkbox', suffix: ' Mon &nbsp; ', value: (rule[4] & (1 << 1)) },
469 { name: 'f_sched_tue', type: 'checkbox', suffix: ' Tue &nbsp; ', value: (rule[4] & (1 << 2)) },
470 { name: 'f_sched_wed', type: 'checkbox', suffix: ' Wed &nbsp; ', value: (rule[4] & (1 << 3)) },
471 { name: 'f_sched_thu', type: 'checkbox', suffix: ' Thu &nbsp; ', value: (rule[4] & (1 << 4)) },
472 { name: 'f_sched_fri', type: 'checkbox', suffix: ' Fri &nbsp; ', value: (rule[4] & (1 << 5)) },
473 { name: 'f_sched_sat', type: 'checkbox', suffix: ' Sat', value: (rule[4] & (1 << 6)) } ] },
474 { title: 'Type', name: 'f_type', id: 'rt_norm', type: 'radio', suffix: ' Normal Access Restriction', value: (rule[5] != '~') },
475 { title: '', name: 'f_type', id: 'rt_wl', type: 'radio', suffix: ' Disable Wireless', value: (rule[5] == '~') },
476 { title: 'Applies To', name: 'f_comp_all', type: 'select', options: [[0,'All Computers / Devices'],[1,'The Following...'],[2,'All Except...']], value: 0 },
477 { title: '&nbsp;', text: '<table class="tomato-grid" cellspacing=1 id="res-comp-grid"></table>' },
478 { title: 'Blocked Resources', name: 'f_block_all', type: 'checkbox', suffix: ' Block All Internet Access', value: 0 },
479 { title: 'Port /<br>Application', indent: 2, text: '<table class="tomato-grid" cellspacing=1 id="res-bp-grid"></table>' },
480 { title: 'HTTP Request', indent: 2, name: 'f_block_http', type: 'textarea', value: rule[7] },
481 { title: 'HTTP Requested Files', indent: 2, multi: [
482 { name: 'f_activex', type: 'checkbox', suffix: ' ActiveX (ocx, cab) &nbsp;&nbsp;', value: (rule[8] & 1) },
483 { name: 'f_flash', type: 'checkbox', suffix: ' Flash (swf) &nbsp;&nbsp;', value: (rule[8] & 2) },
484 { name: 'f_java', type: 'checkbox', suffix: ' Java (class, jar) &nbsp;&nbsp;', value: (rule[8] & 4) } ] }
486 </script>
487 </div>
489 <!-- / / / -->
491 </td></tr>
492 <tr><td id='footer' colspan=2>
493 <span id='footer-msg'></span>
494 <input type='button' value='Delete...' id='delete-button' onclick='remove()'>
495 &nbsp;
496 <input type='button' value='Save' id='save-button' onclick='save()'>
497 <input type='button' value='Cancel' id='cancel-button' onclick='cancel()'>
498 </td></tr>
499 </table>
500 <br><br>
501 </form>
502 <script type='text/javascript'>earlyInit();</script>
503 </body>
504 </html>