1 <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML
4.0//EN'
>
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.
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>
22 <style type='text/css'
>
26 #res-bp-grid .box1
, #res-bp-grid
.box2
{
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}
69 if ((rule
= rrule
.match(/^(\d+)\|(-?\d+)\|(-?\d+)\|(\d+)\|(.*?)\|(.*?)\|([^|]*?)\|(\d+)\|(.*)$/m)) == null) {
70 rule
= ['', 1, 1380, 240, 31, '', '', '', 0, 'New Rule ' + (rruleN
+ 1)];
79 for (i
= 0; i
< layer7
.length
; ++i
)
80 layer7
[i
] = [layer7
[i
],layer7
[i
]];
81 layer7
.unshift(['', 'Layer 7 (disabled)']);
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
);
102 cg
.setup = function() {
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
114 a
= rule
[5].split('>');
115 for (i
= 0; i
< a
.length
; ++i
) {
116 if (!a
[i
].length
) continue;
121 cg
.insertData(-1, [a
[i
]]);
128 a
.value
= ex
? 2 : 1;
136 var bpg
= new TomatoGrid();
138 bpg
.verifyFields = function(row
, quiet
) {
139 var f
= fields
.getAll(row
);
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
);
163 bpg
.dataToView = function(data
) {
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];
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
, '-');
182 for (i
= 0; i
< ipp2p
.length
; ++i
) {
183 if (data
[3] == ipp2p
[i
][0]) {
184 s
+= ', IPP2P: ' + ipp2p
[i
][1];
189 else if (data
[4] != '') {
190 s
+= ', L7: ' + data
[4];
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;
206 f
[3].selectedIndex
= 0;
207 f
[4].selectedIndex
= 0;
208 f
[5].selectedIndex
= 0;
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
);
221 bpg
.enDiFields = function(row
) {
223 var f
= fields
.getAll(row
);
226 x
= ((x
!= -1) && (x
!= 6) && (x
!= 17));
228 if (f
[1].selectedIndex
== 0) x
= 1;
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 }
254 this.headerSet(['Rules']);
255 this.showNewEditor();
256 this.resetNewEditor();
259 // ---- proto<dir<port<ipp2p<layer7[<addr_type<addr]
261 a
= rule
[6].split('>');
262 for (i
= 0; i
< a
.length
; ++i
) {
265 // ---- fixup for backward compatibility
270 r
[2] = r
[2].replace(/:/g
, '-');
271 this.insertData(-1, r
);
280 function verifyFields(focused
, quiet
)
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;
302 e
.value
= e
.value
.replace(/\|/g, '_');
303 if (!v_length(e
, quiet
, 1)) return 0;
310 document
.location
= 'restrict.asp';
315 if (!confirm('Delete this rule?')) return;
317 E('delete-button').disabled
= 1;
320 e
.name
= 'rrule' + rruleN
;
327 if (!verifyFields(null, false)) return;
328 if ((cg
.isEditing()) || (bpg
.isEditing())) return;
330 var a
, b
, e
, s
, n
, 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
) {
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;
349 if (E('rt_norm').checked
) {
350 e
= E('_f_comp_all');
354 ferror
.set(e
, 'No MAC or IP address was specified', 0);
357 if (e
.value
== 2) a
.unshift('!');
358 data
.push(a
.join('>'));
364 if (E('_f_block_all').checked
) {
365 data
.push('', '', '0');
369 a
= bpg
.getAllData();
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
, '');
383 if (E('_f_activex').checked
) n
= 1;
384 if (E('_f_flash').checked
) n
|= 2;
385 if (E('_f_java').checked
) n
|= 4;
388 if (((check
+ n
) == 0) && (data
[0] == 1)) {
389 alert('Please specify what items should be blocked.');
396 data
.push('', '', '', '0');
399 data
.push(E('_f_desc').value
);
400 data
= data
.join('|');
402 if (data
.length
>= 2048) {
403 alert('This rule is too big. Please reduce by ' + (data
.length
- 2048) + ' characters.');
408 e
.name
= 'rrule' + rruleN
;
411 E('delete-button').disabled
= 1;
428 E('_f_block_all').checked
= (count
== 0) && (rule
[7].search(/[^\s\r\n]/) == -1) && (rule
[8] == 0);
429 verifyFields(null, 1);
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>
440 <tr id='body'
><td id='navi'
><script type='text/javascript'
>navi()</script></td>
442 <div id='ident'
><%
ident(); %></div>
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> </div><br>');
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 ', 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 ', value
: (rule
[4] & 1) },
468 { name
: 'f_sched_mon', type
: 'checkbox', suffix
: ' Mon ', value
: (rule
[4] & (1 << 1)) },
469 { name
: 'f_sched_tue', type
: 'checkbox', suffix
: ' Tue ', value
: (rule
[4] & (1 << 2)) },
470 { name
: 'f_sched_wed', type
: 'checkbox', suffix
: ' Wed ', value
: (rule
[4] & (1 << 3)) },
471 { name
: 'f_sched_thu', type
: 'checkbox', suffix
: ' Thu ', value
: (rule
[4] & (1 << 4)) },
472 { name
: 'f_sched_fri', type
: 'checkbox', suffix
: ' Fri ', 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
: ' ', 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) ', value
: (rule
[8] & 1) },
483 { name
: 'f_flash', type
: 'checkbox', suffix
: ' Flash (swf) ', value
: (rule
[8] & 2) },
484 { name
: 'f_java', type
: 'checkbox', suffix
: ' Java (class, jar) ', value
: (rule
[8] & 4) } ] }
492 <tr><td id='footer' colspan=
2>
493 <span id='footer-msg'
></span>
494 <input type='button' value='Delete...' id='delete-button' onclick='remove()'
>
496 <input type='button' value='Save' id='save-button' onclick='save()'
>
497 <input type='button' value='Cancel' id='cancel-button' onclick='cancel()'
>
502 <script type='text/javascript'
>earlyInit();</script>