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'],[4096,'PPLive/UUSee'],[256,'SoulSeek'],[512,'Waste'],[1024,'WinMX']
87 ,[2048,'XDCC'],[8192,'Xunlei/QQCyclone']
91 var dowNames
= ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
95 var cg
= new TomatoGrid();
97 cg
.verifyFields = function(row
, quiet
) {
98 var f
= fields
.getAll(row
)[0];
99 if (v_mac(f
, true)) return true;
100 if (_v_iptaddr(f
, true, false, true, true)) return true;
102 ferror
.set(f
, 'Invalid MAC address or IP address/range', quiet
);
106 cg
.setup = function() {
109 this.init('res-comp-grid', 'sort', 500, [ { type
: 'text', maxlen
: 32 } ] );
110 this.headerSet(['MAC / IP Address']);
111 this.showNewEditor();
112 this.resetNewEditor();
114 if (rule
[5] == '~') return; // wireless disable rule
118 a
= rule
[5].split('>');
119 for (i
= 0; i
< a
.length
; ++i
) {
120 if (!a
[i
].length
) continue;
125 cg
.insertData(-1, [a
[i
]]);
132 a
.value
= ex
? 2 : 1;
140 var bpg
= new TomatoGrid();
142 bpg
.verifyFields = function(row
, quiet
) {
143 var f
= fields
.getAll(row
);
145 this.enDiFields(row
);
147 if ((f
[5].selectedIndex
!= 0) && ((!v_length(f
[6], quiet
, 1)) || (!_v_iptaddr(f
[6], quiet
, false, true, true)))) return 0;
148 if ((f
[1].selectedIndex
!= 0) && (!v_iptport(f
[2], quiet
))) return 0;
150 if ((f
[1].selectedIndex
== 0) && (f
[3].selectedIndex
== 0) && (f
[4].selectedIndex
== 0) && (f
[5].selectedIndex
== 0)) {
151 var m
= 'Please enter a specific address or port, or select an application match';
152 ferror
.set(f
[3], m
, 1);
153 ferror
.set(f
[4], m
, 1);
154 ferror
.set(f
[5], m
, 1);
155 ferror
.set(f
[1], m
, quiet
);
167 bpg
.dataToView = function(data
) {
171 if (data
[5] != 0) s
= ((data
[5] == 1) ? 'To ' : 'From ') + data
[6] + ', ';
173 if (data
[0] <= -2) s
+= (s
.length
? 'a' : 'A') + 'ny protocol';
174 else if (data
[0] == -1) s
+= 'TCP/UDP';
175 else if (data
[0] >= 0) s
+= protocols
[data
[0]] || data
[0];
178 if (data
[1] == 'd') s
+= ', dst port ';
179 else if (data
[1] == 's') s
+= ', src port ';
180 else if (data
[1] == 'x') s
+= ', port ';
181 else s
+= ', all ports';
182 if (data
[1] != 'a') s
+= data
[2].replace(/:/g
, '-');
186 for (i
= 0; i
< ipp2p
.length
; ++i
) {
187 if (data
[3] == ipp2p
[i
][0]) {
188 s
+= ', IPP2P: ' + ipp2p
[i
][1];
193 else if (data
[4] != '') {
194 s
+= ', L7: ' + data
[4];
200 bpg
.fieldValuesToData = function(row
) {
201 var f
= fields
.getAll(row
);
202 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
];
205 bpg
.resetNewEditor = function() {
206 var f
= fields
.getAll(this.newEditor
);
207 f
[0].selectedIndex
= 0;
208 f
[1].selectedIndex
= 0;
210 f
[3].selectedIndex
= 0;
211 f
[4].selectedIndex
= 0;
212 f
[5].selectedIndex
= 0;
214 this.enDiFields(this.newEditor
);
215 ferror
.clearAll(fields
.getAll(this.newEditor
));
218 bpg
._createEditor
= bpg
.createEditor
;
219 bpg
.createEditor = function(which
, rowIndex
, source
) {
220 var row
= this._createEditor(which
, rowIndex
, source
);
221 if (which
== 'edit') this.enDiFields(row
);
225 bpg
.enDiFields = function(row
) {
227 var f
= fields
.getAll(row
);
230 x
= ((x
!= -1) && (x
!= 6) && (x
!= 17));
232 if (f
[1].selectedIndex
== 0) x
= 1;
234 f
[3].disabled
= (f
[4].selectedIndex
!= 0);
235 f
[4].disabled
= (f
[3].selectedIndex
!= 0);
236 f
[6].disabled
= (f
[5].selectedIndex
== 0);
239 bpg
.setup = function() {
240 var a
, i
, r
, count
, protos
;
242 protos
= [[-2, 'Any Protocol'],[-1,'TCP/UDP'],[6,'TCP'],[17,'UDP']];
243 for (i
= 0; i
< 256; ++i
) {
244 if ((i
!= 6) && (i
!= 17)) protos
.push([i
, protocols
[i
] || i
]);
247 this.init('res-bp-grid', 'sort', 500, [ { multi
: [
248 { type
: 'select', prefix
: '<div class="box1">', suffix
: '</div>', options
: protos
},
249 { type
: 'select', prefix
: '<div class="box2">', suffix
: '</div>',
250 options
: [['a','Any Port'],['d','Dst Port'],['s','Src Port'],['x','Src or Dst']] },
251 { type
: 'text', prefix
: '<div class="box3">', suffix
: '</div>', maxlen
: 32 },
252 { type
: 'select', prefix
: '<div class="box4">', suffix
: '</div>', options
: ipp2p
},
253 { type
: 'select', prefix
: '<div class="box5">', suffix
: '</div>', options
: layer7
},
254 { type
: 'select', prefix
: '<div class="box6">', suffix
: '</div>',
255 options
: [[0,'Any Address'],[1,'Dst IP'],[2,'Src IP']] },
256 { type
: 'text', prefix
: '<div class="box7">', suffix
: '</div>', maxlen
: 64 }
258 this.headerSet(['Rules']);
259 this.showNewEditor();
260 this.resetNewEditor();
263 // ---- proto<dir<port<ipp2p<layer7[<addr_type<addr]
265 a
= rule
[6].split('>');
266 for (i
= 0; i
< a
.length
; ++i
) {
269 // ---- fixup for backward compatibility
274 r
[2] = r
[2].replace(/:/g
, '-');
275 this.insertData(-1, r
);
284 function verifyFields(focused
, quiet
)
290 elem
.display(PR('_f_sched_begin'), !E('_f_sched_allday').checked
);
291 elem
.display(PR('_f_sched_sun'), !E('_f_sched_everyday').checked
);
293 b
= E('rt_norm').checked
;
294 elem
.display(PR('_f_comp_all'), PR('_f_block_all'), b
);
296 elem
.display(PR('res-comp-grid'), b
&& E('_f_comp_all').value
!= 0);
297 elem
.display(PR('res-bp-grid'), PR('_f_block_http'), PR('_f_activex'), b
&& !E('_f_block_all').checked
);
299 ferror
.clear('_f_comp_all');
301 e
= E('_f_block_http');
302 e
.value
= e
.value
.replace(/[|"']/g, ' ');
303 if (!v_length(e
, quiet
, 0, 2048 - 16)) return 0;
306 e
.value
= e
.value
.replace(/\|/g, '_');
307 if (!v_length(e
, quiet
, 1)) return 0;
314 document
.location
= 'restrict.asp';
319 if (!confirm('Delete this rule?')) return;
321 E('delete-button').disabled
= 1;
324 e
.name
= 'rrule' + rruleN
;
331 if (!verifyFields(null, false)) return;
332 if ((cg
.isEditing()) || (bpg
.isEditing())) return;
334 var a
, b
, e
, s
, n
, data
;
337 data
.push(E('_f_enabled').checked
? '1' : '0');
338 if (E('_f_sched_allday').checked
) data
.push(-1, -1);
339 else data
.push(E('_f_sched_begin').value
, E('_f_sched_end').value
);
341 if (E('_f_sched_everyday').checked
) {
346 for (i
= 0; i
< 7; ++i
) {
347 if (E('_f_sched_' + dowNames
[i
].toLowerCase()).checked
) n
|= (1 << i
);
349 if (n
== 0) n
= 0x7F;
353 if (E('rt_norm').checked
) {
354 e
= E('_f_comp_all');
358 ferror
.set(e
, 'No MAC or IP address was specified', 0);
361 if (e
.value
== 2) a
.unshift('!');
362 data
.push(a
.join('>'));
368 if (E('_f_block_all').checked
) {
369 data
.push('', '', '0');
373 a
= bpg
.getAllData();
376 for (i
= 0; i
< a
.length
; ++i
) {
377 a
[i
][2] = a
[i
][2].replace(/-/g
, ':');
378 b
.push(a
[i
].join('<'));
380 data
.push(b
.join('>'));
382 a
= E('_f_block_http').value
.replace(/\r+/g, ' ').replace(/\n+/g, '\n').replace(/ +/g, ' ').replace(/^\s
+|\s
+$/g
, '');
387 if (E('_f_activex').checked
) n
= 1;
388 if (E('_f_flash').checked
) n
|= 2;
389 if (E('_f_java').checked
) n
|= 4;
392 if (((check
+ n
) == 0) && (data
[0] == 1)) {
393 alert('Please specify what items should be blocked.');
400 data
.push('', '', '', '0');
403 data
.push(E('_f_desc').value
);
404 data
= data
.join('|');
406 if (data
.length
>= 8192) {
407 alert('This rule is too big. Please reduce by ' + (data
.length
- 8192) + ' characters.');
412 e
.name
= 'rrule' + rruleN
;
415 E('delete-button').disabled
= 1;
432 E('_f_block_all').checked
= (count
== 0) && (rule
[7].search(/[^\s\r\n]/) == -1) && (rule
[8] == 0);
433 verifyFields(null, 1);
437 <body onload='init()'
>
438 <form name='_fom' id='_fom' method='post' action='tomato.cgi'
>
439 <table id='container' cellspacing=
0>
440 <tr><td colspan=
2 id='header'
>
441 <div class='title'
>Tomato
</div>
442 <div class='version'
>Version <%
version() %></div>
444 <tr id='body'
><td id='navi'
><script type='text/javascript'
>navi()</script></td>
446 <div id='ident'
><%
ident(); %></div>
450 <input type='hidden' name='_nextpage' value='restrict.asp'
>
451 <input type='hidden' name='_service' value='restrict-restart'
>
452 <input type='hidden' name='rruleNN' id='_rrule' value=''
>
454 <div class='section-title'
>Access Restriction
</div>
455 <div class='section'
>
456 <script type='text/javascript'
>
457 W('<div style="float:right"><small>'+ 'ID: ' + rruleN
.pad(2) + '</small> </div><br>');
459 for (i
= 0; i
< 1440; i
+= 15) tm
.push([i
, timeString(i
)]);
461 createFieldTable('', [
462 { title
: 'Enabled', name
: 'f_enabled', type
: 'checkbox', value
: rule
[1] == '1' },
463 { title
: 'Description', name
: 'f_desc', type
: 'text', maxlen
: 32, size
: 35, value
: rule
[9] },
464 { title
: 'Schedule', multi
: [
465 { name
: 'f_sched_allday', type
: 'checkbox', suffix
: ' All Day ', value
: (rule
[2] < 0) || (rule
[3] < 0) },
466 { name
: 'f_sched_everyday', type
: 'checkbox', suffix
: ' Everyday', value
: (rule
[4] & 0x7F) == 0x7F } ] },
467 { title
: 'Time', indent
: 2, multi
: [
468 { name
: 'f_sched_begin', type
: 'select', options
: tm
, value
: (rule
[2] < 0) ? 0 : rule
[2], suffix
: ' - ' },
469 { name
: 'f_sched_end', type
: 'select', options
: tm
, value
: (rule
[3] < 0) ? 0 : rule
[3] } ] },
470 { title
: 'Days', indent
: 2, multi
: [
471 { name
: 'f_sched_sun', type
: 'checkbox', suffix
: ' Sun ', value
: (rule
[4] & 1) },
472 { name
: 'f_sched_mon', type
: 'checkbox', suffix
: ' Mon ', value
: (rule
[4] & (1 << 1)) },
473 { name
: 'f_sched_tue', type
: 'checkbox', suffix
: ' Tue ', value
: (rule
[4] & (1 << 2)) },
474 { name
: 'f_sched_wed', type
: 'checkbox', suffix
: ' Wed ', value
: (rule
[4] & (1 << 3)) },
475 { name
: 'f_sched_thu', type
: 'checkbox', suffix
: ' Thu ', value
: (rule
[4] & (1 << 4)) },
476 { name
: 'f_sched_fri', type
: 'checkbox', suffix
: ' Fri ', value
: (rule
[4] & (1 << 5)) },
477 { name
: 'f_sched_sat', type
: 'checkbox', suffix
: ' Sat', value
: (rule
[4] & (1 << 6)) } ] },
478 { title
: 'Type', name
: 'f_type', id
: 'rt_norm', type
: 'radio', suffix
: ' Normal Access Restriction', value
: (rule
[5] != '~') },
479 { title
: '', name
: 'f_type', id
: 'rt_wl', type
: 'radio', suffix
: ' Disable Wireless', value
: (rule
[5] == '~') },
480 { title
: 'Applies To', name
: 'f_comp_all', type
: 'select', options
: [[0,'All Computers / Devices'],[1,'The Following...'],[2,'All Except...']], value
: 0 },
481 { title
: ' ', text
: '<table class="tomato-grid" cellspacing=1 id="res-comp-grid"></table>' },
482 { title
: 'Blocked Resources', name
: 'f_block_all', type
: 'checkbox', suffix
: ' Block All Internet Access', value
: 0 },
483 { title
: 'Port /<br>Application', indent
: 2, text
: '<table class="tomato-grid" cellspacing=1 id="res-bp-grid"></table>' },
484 { title
: 'HTTP Request', indent
: 2, name
: 'f_block_http', type
: 'textarea', value
: rule
[7] },
485 { title
: 'HTTP Requested Files', indent
: 2, multi
: [
486 { name
: 'f_activex', type
: 'checkbox', suffix
: ' ActiveX (ocx, cab) ', value
: (rule
[8] & 1) },
487 { name
: 'f_flash', type
: 'checkbox', suffix
: ' Flash (swf) ', value
: (rule
[8] & 2) },
488 { name
: 'f_java', type
: 'checkbox', suffix
: ' Java (class, jar) ', value
: (rule
[8] & 4) } ] }
496 <tr><td id='footer' colspan=
2>
497 <span id='footer-msg'
></span>
498 <input type='button' value='Delete...' id='delete-button' onclick='remove()'
>
500 <input type='button' value='Save' id='save-button' onclick='save()'
>
501 <input type='button' value='Cancel' id='cancel-button' onclick='cancel()'
>
506 <script type='text/javascript'
>earlyInit();</script>