Tomato 1.28
[tomato/tomato-null.git] / release / src / router / www / restrict-edit.asp
blob1f89764fe35a8b8e2f07f68d5dd6d79613ce2dc6
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>
19 <!-- / / / -->
21 <style type='text/css'>
22 #res-comp-grid {
23 width: 60%;
25 #res-bp-grid .box1, #res-bp-grid .box2 {
26 width: 20%;
27 float: left;
29 #res-bp-grid .box3 {
30 width: 60%;
31 float: left;
33 #res-bp-grid .box4 {
34 width: 30%;
35 float: left;
36 clear: left;
37 padding-top: 2px;
39 #res-bp-grid .box5 {
40 width: 70%;
41 float: left;
42 padding-top: 2px;
45 textarea {
46 width: 99%;
47 height: 20em;
49 </style>
51 <script type='text/javascript' src='debug.js'></script>
53 <script type='text/javascript'>
54 // <% nvram(''); %> // http_id
56 // {enable}|{begin_mins}|{end_mins}|{dow}|{comp[<comp]}|{rules<rules[...]>}|{http[ ...]}|{http_file}|{desc}
57 // <% rrule(); %>
58 if ((rule = rrule.match(/^(\d+)\|(-?\d+)\|(-?\d+)\|(\d+)\|(.*?)\|(.*?)\|([^|]*?)\|(\d+)\|(.*)$/m)) == null) {
59 rule = ['', 1, 1380, 240, 31, '', '', '', 0, 'New Rule ' + (rruleN + 1)];
61 rule[2] *= 1;
62 rule[3] *= 1;
63 rule[4] *= 1;
64 rule[8] *= 1;
66 // <% layer7(); %>
67 layer7.sort();
68 for (i = 0; i < layer7.length; ++i)
69 layer7[i] = [layer7[i],layer7[i]];
70 layer7.unshift(['', 'Layer 7 (disabled)']);
72 var ipp2p = [
73 [0,'IPP2P (disabled)'],[0xFFFF,'All IPP2P Filters'],[1,'AppleJuice'],[2,'Ares'],[4,'BitTorrent'],[8,'Direct Connect'],
74 [16,'eDonkey'],[32,'Gnutella'],[64,'Kazaa'],[128,'Mute'],[256,'SoulSeek'],[512,'Waste'],[1024,'WinMX'],[2048,'XDCC']];
76 var dowNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
80 var cg = new TomatoGrid();
82 cg.verifyFields = function(row, quiet) {
83 var f = fields.getAll(row)[0];
84 if (v_mac(f, true)) return true;
85 if (v_iptip(f, true)) return true;
86 ferror.set(f, 'Invalid MAC address or IP address/range', quiet);
87 return false;
90 cg.setup = function() {
91 var a, i, count, ex;
93 this.init('res-comp-grid', 'sort', 50, [ { type: 'text', maxlen: 32 } ] );
94 this.headerSet(['MAC / IP Address']);
95 this.showNewEditor();
96 this.resetNewEditor();
98 if (rule[5] == '~') return; // wireless disable rule
100 ex = 0;
101 count = 0;
102 a = rule[5].split('>');
103 for (i = 0; i < a.length; ++i) {
104 if (!a[i].length) continue;
105 if (a[i] == '!') {
106 ex = 1;
108 else {
109 cg.insertData(-1, [a[i]]);
110 ++count;
114 a = E('_f_comp_all')
115 if (count) {
116 a.value = ex ? 2 : 1;
118 else {
119 a.value = 0;
124 var bpg = new TomatoGrid();
126 bpg.verifyFields = function(row, quiet) {
127 var f = fields.getAll(row);
128 ferror.clearAll(f);
129 this.enDiFields(row);
130 if ((f[1].selectedIndex != 0) && (!v_iptport(f[2], quiet))) return 0;
131 if ((f[1].selectedIndex == 0) && (f[3].selectedIndex == 0) && (f[4].selectedIndex == 0)) {
132 var m = 'Please enter a specific port or select an application match';
133 ferror.set(f[3], m, 1);
134 ferror.set(f[4], m, 1);
135 ferror.set(f[1], m, quiet);
136 return 0;
138 ferror.clear(f[1]);
139 return 1;
142 bpg.dataToView = function(data) {
143 var s, i;
144 if (data[0] == 6) s = 'TCP';
145 else if (data[0] == 17) s = 'UDP';
146 else s = 'TCP/UDP';
147 if (data[1] == 'd') s += ', dst port ';
148 else if (data[1] == 's') s += ', src port ';
149 else if (data[1] == 'x') s += ', port ';
150 if (data[1] != 'a') s += data[2];
151 if (data[3] != 0) {
152 for (i = 0; i < ipp2p.length; ++i) {
153 if (data[3] == ipp2p[i][0]) {
154 s += ', IPP2P: ' + ipp2p[i][1];
155 break;
159 else if (data[4] != '') {
160 s += ', L7: ' + data[4];
162 return [s];
165 bpg.fieldValuesToData = function(row) {
166 var f = fields.getAll(row);
167 return [f[0].value, f[1].value, (f[1].selectedIndex == 0) ? '' : f[2].value, f[3].value, f[4].value];
170 bpg.resetNewEditor = function() {
171 var f = fields.getAll(this.newEditor);
172 f[0].selectedIndex = 0;
173 f[1].selectedIndex = 0;
174 f[2].value = '';
175 f[3].selectedIndex = 0;
176 f[4].selectedIndex = 0;
177 this.enDiFields(this.newEditor);
178 ferror.clearAll(fields.getAll(this.newEditor));
181 bpg._createEditor = bpg.createEditor;
182 bpg.createEditor = function(which, rowIndex, source) {
183 var row = this._createEditor(which, rowIndex, source);
184 if (which == 'edit') this.enDiFields(row);
185 return row;
188 bpg.enDiFields = function(row) {
189 var f = fields.getAll(row);
190 f[2].disabled = (f[1].selectedIndex == 0);
191 f[3].disabled = (f[4].selectedIndex != 0);
192 f[4].disabled = (f[3].selectedIndex != 0);
195 bpg.setup = function() {
196 var a, i, r, count;
198 this.init('res-bp-grid', 'sort', 50, [ { multi: [
199 { type: 'select', prefix: '<div class="box1">', suffix: '</div>',options: [[-1, 'TCP/UDP'], [6, 'TCP'], [17, 'UDP']] },
200 { type: 'select', prefix: '<div class="box2">', suffix: '</div>',
201 options: [['a','Any Port'],['d','Dst Port'],['s','Src Port'],['x','Src or Dst']] },
202 { type: 'text', prefix: '<div class="box3">', suffix: '</div>', maxlen: 32 },
203 { type: 'select', prefix: '<div class="box4">', suffix: '</div>', options: ipp2p },
204 { type: 'select', prefix: '<div class="box5">', suffix: '</div>', options: layer7 }
205 ] } ] );
206 this.headerSet(['Rules']);
207 this.showNewEditor();
208 this.resetNewEditor();
209 count = 0;
210 a = rule[6].split('>');
211 for (i = 0; i < a.length; ++i) {
212 if ((r = a[i].match(/^(-?\d+)<(.)<(.*?)<(.*?)<(.*?)$/)) != null) {
213 r[3] = r[3].replace(/:/g, '-')
214 this.insertData(-1, r.slice(1, r.length));
215 ++count;
218 return count;
223 function verifyFields(focused, quiet)
225 var b, e;
227 tgHideIcons();
229 elem.display(PR('_f_sched_begin'), !E('_f_sched_allday').checked);
230 elem.display(PR('_f_sched_sun'), !E('_f_sched_everyday').checked);
232 b = E('rt_norm').checked;
233 elem.display(PR('_f_comp_all'), PR('_f_block_all'), b);
235 elem.display(PR('res-comp-grid'), b && E('_f_comp_all').value != 0);
236 elem.display(PR('res-bp-grid'), PR('_f_block_http'), PR('_f_activex'), b && !E('_f_block_all').checked);
238 ferror.clear('_f_comp_all');
240 e = E('_f_block_http');
241 e.value = e.value.replace(/[|"']/g, ' ');
242 if (!v_length(e, quiet, 0, 2048 - 16)) return 0;
244 e = E('_f_desc');
245 e.value = e.value.replace(/\|/g, '_');
246 if (!v_length(e, quiet, 1)) return 0;
248 return 1;
251 function cancel()
253 document.location = 'restrict.asp';
256 function remove()
258 if (!confirm('Delete this rule?')) return;
260 E('delete-button').disabled = 1;
262 e = E('_rrule');
263 e.name = 'rrule' + rruleN;
264 e.value = '';
265 form.submit('_fom');
268 function save()
270 if (!verifyFields(null, false)) return;
271 if ((cg.isEditing()) || (bpg.isEditing())) return;
273 var a, b, e, s, n, data;
275 data = [];
276 data.push(E('_f_enabled').checked ? '1' : '0');
277 if (E('_f_sched_allday').checked) data.push(-1, -1);
278 else data.push(E('_f_sched_begin').value, E('_f_sched_end').value);
280 if (E('_f_sched_everyday').checked) {
281 n = 0x7F;
283 else {
284 n = 0;
285 for (i = 0; i < 7; ++i) {
286 if (E('_f_sched_' + dowNames[i].toLowerCase()).checked) n |= (1 << i);
288 if (n == 0) n = 0x7F;
290 data.push(n);
292 if (E('rt_norm').checked) {
293 e = E('_f_comp_all');
294 if (e.value != 0) {
295 a = cg.getAllData();
296 if (a.length == 0) {
297 ferror.set(e, 'No MAC or IP address was specified', 0);
298 return;
300 if (e.value == 2) a.unshift('!');
301 data.push(a.join('>'));
303 else {
304 data.push('');
307 if (E('_f_block_all').checked) {
308 data.push('', '', '0');
310 else {
311 var check = 0;
312 a = bpg.getAllData();
313 check += a.length;
314 b = [];
315 for (i = 0; i < a.length; ++i) {
316 a[i][2] = a[i][2].replace(/-/g, ':');
317 b.push(a[i].join('<'));
319 data.push(b.join('>'));
321 a = E('_f_block_http').value.replace(/\r+/g, ' ').replace(/\n+/g, '\n').replace(/ +/g, ' ').replace(/^\s+|\s+$/g, '');
322 check += a.length;
323 data.push(a);
325 n = 0;
326 if (E('_f_activex').checked) n = 1;
327 if (E('_f_flash').checked) n |= 2;
328 if (E('_f_java').checked) n |= 4;
329 data.push(n);
331 if (((check + n) == 0) && (data[0] == 1)) {
332 alert('Please specify what items should be blocked.');
333 return;
337 else {
338 data.push('~');
339 data.push('', '', '', '0');
342 data.push(E('_f_desc').value);
343 data = data.join('|');
345 if (data.length >= 2048) {
346 alert('This rule is too big. Please reduce by ' + (data.length - 2048) + ' characters.');
347 return;
350 e = E('_rrule');
351 e.name = 'rrule' + rruleN;
352 e.value = data;
354 E('delete-button').disabled = 1;
355 form.submit('_fom');
358 function init()
360 cg.recolor();
361 bpg.recolor();
364 function earlyInit()
366 var count;
368 cg.setup();
370 count = bpg.setup();
371 E('_f_block_all').checked = (count == 0) && (rule[7].search(/[^\s\r\n]/) == -1) && (rule[8] == 0);
372 verifyFields(null, 1);
374 </script>
375 </head>
376 <body onload='init()'>
377 <form name='_fom' id='_fom' method='post' action='tomato.cgi'>
378 <table id='container' cellspacing=0>
379 <tr><td colspan=2 id='header'>
380 <div class='title'>Tomato</div>
381 <div class='version'>Version <% version() %></div>
382 </td></tr>
383 <tr id='body'><td id='navi'><script type='text/javascript'>navi()</script></td>
384 <td id='content'>
385 <div id='ident'><% ident(); %></div>
387 <!-- / / / -->
389 <input type='hidden' name='_nextpage' value='restrict.asp'>
390 <input type='hidden' name='_service' value='restrict-restart'>
391 <input type='hidden' name='rruleNN' id='_rrule' value=''>
393 <div class='section-title'>Access Restriction</div>
394 <div class='section'>
395 <script type='text/javascript'>
396 W('<div style="float:right"><small>'+ 'ID: ' + rruleN.pad(2) + '</small>&nbsp;</div><br>');
397 tm = [];
398 for (i = 0; i < 1440; i += 15) tm.push([i, timeString(i)]);
400 createFieldTable('', [
401 { title: 'Enabled', name: 'f_enabled', type: 'checkbox', value: rule[1] == '1' },
402 { title: 'Description', name: 'f_desc', type: 'text', maxlen: 32, size: 35, value: rule[9] },
403 { title: 'Schedule', multi: [
404 { name: 'f_sched_allday', type: 'checkbox', suffix: ' All Day &nbsp; ', value: (rule[2] < 0) || (rule[3] < 0) },
405 { name: 'f_sched_everyday', type: 'checkbox', suffix: ' Everyday', value: (rule[4] & 0x7F) == 0x7F } ] },
406 { title: 'Time', indent: 2, multi: [
407 { name: 'f_sched_begin', type: 'select', options: tm, value: (rule[2] < 0) ? 0 : rule[2], suffix: ' - ' },
408 { name: 'f_sched_end', type: 'select', options: tm, value: (rule[3] < 0) ? 0 : rule[3] } ] },
409 { title: 'Days', indent: 2, multi: [
410 { name: 'f_sched_sun', type: 'checkbox', suffix: ' Sun &nbsp; ', value: (rule[4] & 1) },
411 { name: 'f_sched_mon', type: 'checkbox', suffix: ' Mon &nbsp; ', value: (rule[4] & (1 << 1)) },
412 { name: 'f_sched_tue', type: 'checkbox', suffix: ' Tue &nbsp; ', value: (rule[4] & (1 << 2)) },
413 { name: 'f_sched_wed', type: 'checkbox', suffix: ' Wed &nbsp; ', value: (rule[4] & (1 << 3)) },
414 { name: 'f_sched_thu', type: 'checkbox', suffix: ' Thu &nbsp; ', value: (rule[4] & (1 << 4)) },
415 { name: 'f_sched_fri', type: 'checkbox', suffix: ' Fri &nbsp; ', value: (rule[4] & (1 << 5)) },
416 { name: 'f_sched_sat', type: 'checkbox', suffix: ' Sat', value: (rule[4] & (1 << 6)) } ] },
417 { title: 'Type', name: 'f_type', id: 'rt_norm', type: 'radio', suffix: ' Normal Access Restriction', value: (rule[5] != '~') },
418 { title: '', name: 'f_type', id: 'rt_wl', type: 'radio', suffix: ' Disable Wireless', value: (rule[5] == '~') },
419 { title: 'Applies To', name: 'f_comp_all', type: 'select', options: [[0,'All Computers / Devices'],[1,'The Following...'],[2,'All Except...']], value: 0 },
420 { title: '&nbsp;', text: '<table class="tomato-grid" cellspacing=1 id="res-comp-grid"></table>' },
421 { title: 'Blocked Resources', name: 'f_block_all', type: 'checkbox', suffix: ' Block All Internet Access', value: 0 },
422 { title: 'Port /<br>Application', indent: 2, text: '<table class="tomato-grid" cellspacing=1 id="res-bp-grid"></table>' },
423 { title: 'HTTP Request', indent: 2, name: 'f_block_http', type: 'textarea', value: rule[7] },
424 { title: 'HTTP Requested Files', indent: 2, multi: [
425 { name: 'f_activex', type: 'checkbox', suffix: ' ActiveX (ocx, cab) &nbsp;&nbsp;', value: (rule[8] & 1) },
426 { name: 'f_flash', type: 'checkbox', suffix: ' Flash (swf) &nbsp;&nbsp;', value: (rule[8] & 2) },
427 { name: 'f_java', type: 'checkbox', suffix: ' Java (class, jar) &nbsp;&nbsp;', value: (rule[8] & 4) } ] }
429 </script>
430 </div>
432 <!-- / / / -->
434 </td></tr>
435 <tr><td id='footer' colspan=2>
436 <span id='footer-msg'></span>
437 <input type='button' value='Delete...' id='delete-button' onclick='remove()'>
438 &nbsp;
439 <input type='button' value='Save' id='save-button' onclick='save()'>
440 <input type='button' value='Cancel' id='cancel-button' onclick='cancel()'>
441 </td></tr>
442 </table>
443 <br><br>
444 </form>
445 <script type='text/javascript'>earlyInit();</script>
446 </body>
447 </html>