Fixes bug #0000697 added example for blacklist
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / urlfilter.cgi
CommitLineData
10e4f239 1#!/usr/bin/perl
70df8302
MT
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
a4883c68 5# Copyright (C) 2005-2010 IPFire Team #
70df8302
MT
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
10e4f239
MT
21
22use strict;
23
24# enable only the following on debugging purpose
cb5e9c6c
CS
25#use warnings;
26#use CGI::Carp 'fatalsToBrowser';
10e4f239
MT
27
28use File::Copy;
29use IO::Socket;
30
31require '/var/ipfire/general-functions.pl';
32require "${General::swroot}/lang.pl";
33require "${General::swroot}/header.pl";
34
1465b127 35my $http_port='81';
10e4f239
MT
36my %netsettings=();
37my %mainsettings=();
38my %proxysettings=();
39my %filtersettings=();
10e4f239
MT
40my %tcsettings=();
41my %uqsettings=();
42my %besettings=();
43my %updatesettings=();
44my %checked=();
45my %selected=();
46my $id=0;
47my $line='';
48my $i=0;
49my $n=0;
50my $time='';
51my $filesize;
52my $category='';
53my $section='';
54my $blacklist='';
55my $blistbackup='';
56
57my $changed = 'no';
58my $tcfile = "${General::swroot}/urlfilter/timeconst";
59my $uqfile = "${General::swroot}/urlfilter/userquota";
60my $dbdir = "${General::swroot}/urlfilter/blacklists";
61my $editdir = "${General::swroot}/urlfilter/editor";
e9007fef 62my $repository = "/var/urlrepo";
10e4f239
MT
63my $hintcolour = '#FFFFCC';
64
65my $sourceurlfile = "${General::swroot}/urlfilter/autoupdate/autoupdate.urls";
66my $updconffile = "${General::swroot}/urlfilter/autoupdate/autoupdate.conf";
67my $updflagfile = "${General::swroot}/urlfilter/blacklists/.autoupdate.last";
10e4f239
MT
68
69my $errormessage='';
70my $updatemessage='';
71my $restoremessage='';
72my $buttontext='';
73my $source_name='';
74my $source_url='';
75my $blacklistage=0;
76
77my @repositorylist=();
78my @repositoryfiles=();
79my @categories=();
80my @selectedcategories=();
81my @filtergroups=();
82my @tclist=();
83my @uqlist=();
84my @source_urllist=();
1465b127 85my @clients=();
10e4f239
MT
86my @temp=();
87
88my $lastslashpos=0;
89
90my $toggle='';
91my $gif='';
92my $led='';
93my $ldesc='';
94my $gdesc='';
95
96if (! -d $dbdir) { mkdir("$dbdir"); }
97if (! -e $tcfile) { system("touch $tcfile"); }
98if (! -e $uqfile) { system("touch $uqfile"); }
99if (! -e $sourceurlfile) { system("touch $sourceurlfile"); }
100
101&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
102&General::readhash("${General::swroot}/main/settings", \%mainsettings);
103&General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
104
105&readblockcategories;
106
107open(FILE, $tcfile);
108@tclist = <FILE>;
109close(FILE);
110open(FILE, $uqfile);
111@uqlist = <FILE>;
112close(FILE);
113open(FILE, $sourceurlfile);
114@source_urllist = <FILE>;
115close(FILE);
116
117$filtersettings{'ENABLE_CUSTOM_BLACKLIST'} = 'off';
118$filtersettings{'ENABLE_CUSTOM_WHITELIST'} = 'off';
119$filtersettings{'ENABLE_CUSTOM_EXPRESSIONS'} = 'off';
120$filtersettings{'BLOCK_EXECUTABLES'} = 'off';
121$filtersettings{'BLOCK_AUDIO-VIDEO'} = 'off';
122$filtersettings{'BLOCK_ARCHIVES'} = 'off';
123$filtersettings{'ENABLE_REWRITE'} = 'off';
124$filtersettings{'UNFILTERED_CLIENTS'} = '';
125$filtersettings{'BANNED_CLIENTS'} = '';
126$filtersettings{'SHOW_CATEGORY'} = 'off';
127$filtersettings{'SHOW_URL'} = 'off';
128$filtersettings{'SHOW_IP'} = 'off';
129$filtersettings{'ENABLE_DNSERROR'} = 'off';
130$filtersettings{'ENABLE_JPEG'} = 'off';
131$filtersettings{'REDIRECT_PAGE'} = '';
132$filtersettings{'MSG_TEXT_1'} = '';
133$filtersettings{'MSG_TEXT_2'} = '';
134$filtersettings{'MSG_TEXT_3'} = '';
135$filtersettings{'ENABLE_EXPR_LISTS'} = 'off';
136$filtersettings{'BLOCK_IP_ADDR'} = 'off';
137$filtersettings{'BLOCK_ALL'} = 'off';
138$filtersettings{'ENABLE_EMPTY_ADS'} = 'off';
139$filtersettings{'ENABLE_GLOBAL_WHITELIST'} = 'off';
140$filtersettings{'ENABLE_SAFESEARCH'} = 'off';
141$filtersettings{'ENABLE_LOG'} = 'off';
142$filtersettings{'ENABLE_USERNAME_LOG'} = 'off';
143$filtersettings{'ENABLE_CATEGORY_LOG'} = 'off';
10e4f239
MT
144$filtersettings{'ENABLE_AUTOUPDATE'} = 'off';
145
146$filtersettings{'ACTION'} = '';
147$filtersettings{'VALID'} = '';
148
149&Header::getcgihash(\%filtersettings);
150&Header::getcgihash(\%tcsettings);
151&Header::getcgihash(\%uqsettings);
152&Header::getcgihash(\%besettings);
153
154if (($filtersettings{'ACTION'} eq $Lang::tr{'save'}) ||
155 ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter save and restart'}) ||
156 ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter upload file'}) ||
157 ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter remove file'}) ||
10e4f239
MT
158 ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter upload blacklist'}) ||
159 ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter backup'}) ||
160 ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter restore'}))
1465b127
MT
161{
162
163 @clients = split(/\n/,$filtersettings{'UNFILTERED_CLIENTS'});
164 foreach (@clients)
165 {
166 s/^\s+//g; s/\s+$//g; s/\s+-\s+/-/g; s/\s+/ /g; s/\n//g;
167 if (/.*-.*-.*/) { $errormessage = $Lang::tr{'urlfilter invalid ip or mask error'}; }
168 @temp = split(/-/);
169 foreach (@temp) { unless ((&General::validipormask($_)) || (&General::validipandmask($_))) { $errormessage = $Lang::tr{'urlfilter invalid ip or mask error'}; } }
170 }
171 @clients = split(/\n/,$filtersettings{'BANNED_CLIENTS'});
172 foreach (@clients)
173 {
174 s/^\s+//g; s/\s+$//g; s/\s+-\s+/-/g; s/\s+/ /g; s/\n//g;
175 if (/.*-.*-.*/) { $errormessage = $Lang::tr{'urlfilter invalid ip or mask error'}; }
176 @temp = split(/-/);
177 foreach (@temp) { unless ((&General::validipormask($_)) || (&General::validipandmask($_))) { $errormessage = $Lang::tr{'urlfilter invalid ip or mask error'}; } }
178 }
179 if ($errormessage) { goto ERROR; }
180
10e4f239
MT
181 if ((!($filtersettings{'REDIRECT_PAGE'} eq '')) && (!($filtersettings{'REDIRECT_PAGE'} =~ /^https?:\/\//)))
182 {
183 $filtersettings{'REDIRECT_PAGE'} = "http://".$filtersettings{'REDIRECT_PAGE'};
184 }
185
186 if ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter remove file'})
187 {
188 if (-e "$repository/$filtersettings{'ID'}") { unlink("$repository/$filtersettings{'ID'}"); }
189 $filtersettings{'ACTION'} = $Lang::tr{'urlfilter manage repository'};
190 }
191
192 if ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter upload file'})
193 {
194 &Header::getcgihash(\%filtersettings, {'wantfile' => 1, 'filevar' => 'UPLOADFILE'});
195
196 $filtersettings{'ACTION'} = $Lang::tr{'urlfilter manage repository'};
197 $_ = $filtersettings{'UPLOADFILE'};
198 tr/\\/\//;
199 $_ = substr($_,rindex($_,"/")+1);
200 if ($_) {
201 if (copy($filtersettings{'UPLOADFILE'}, "$repository/$_") != 1)
202 {
203 $errormessage = $!;
204 goto ERROR;
205 }
206 }
207
208 }
1465b127 209
10e4f239
MT
210 if ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter upload blacklist'})
211 {
212 &Header::getcgihash(\%filtersettings, {'wantfile' => 1, 'filevar' => 'UPDATEFILE'});
213
214 if (!($filtersettings{'UPDATEFILE'} =~ /.tar.gz$/))
215 {
216 $errormessage = $Lang::tr{'urlfilter wrong filetype'};
217 goto ERROR;
218 }
219
220 if (copy($filtersettings{'UPDATEFILE'}, "${General::swroot}/urlfilter/blacklists.tar.gz") != 1)
221 {
222 $errormessage = $!;
223 goto ERROR;
224 }
d47ad587 225
10e4f239
MT
226 if (!(-d "${General::swroot}/urlfilter/update")) { mkdir("${General::swroot}/urlfilter/update"); }
227
228 my $exitcode = system("/bin/tar --no-same-owner -xzf ${General::swroot}/urlfilter/blacklists.tar.gz -C ${General::swroot}/urlfilter/update");
d47ad587 229
10e4f239
MT
230 if ($exitcode > 0)
231 {
232 $errormessage = $Lang::tr{'urlfilter tar error'};
233 } else {
234
1465b127
MT
235 if (-d "${General::swroot}/urlfilter/update/BL")
236 {
237 system("mv ${General::swroot}/urlfilter/update/BL ${General::swroot}/urlfilter/update/blacklists");
238 }
239
10e4f239
MT
240 if (-d "${General::swroot}/urlfilter/update/category")
241 {
242 system("mv ${General::swroot}/urlfilter/update/category ${General::swroot}/urlfilter/update/blacklists");
243 }
244
245 if (!(-d "${General::swroot}/urlfilter/update/blacklists"))
246 {
247 $errormessage = $Lang::tr{'urlfilter invalid content'};
248 } else {
249 system("cp -r ${General::swroot}/urlfilter/update/blacklists/* $dbdir");
250
251 &readblockcategories;
252 &readcustomlists;
253
254 &writeconfigfile;
255
256 $updatemessage = $Lang::tr{'urlfilter upload success'};
257 system("${General::swroot}/urlfilter/bin/prebuild.pl &");
258 system("logger -t installpackage[urlfilter] \"URL filter blacklist - Blacklist update from local source completed\"");
259 }
260 }
261 if (-d "${General::swroot}/urlfilter/update") { system("rm -rf ${General::swroot}/urlfilter/update"); }
262 if (-e "${General::swroot}/urlfilter/blacklists.tar.gz") { unlink("${General::swroot}/urlfilter/blacklists.tar.gz"); }
263 if ($errormessage) { goto ERROR; }
264 }
265
266 if ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter backup'})
267 {
268 $blistbackup = ($filtersettings{'ENABLE_FULLBACKUP'} eq 'on') ? "blacklists" : "blacklists/custom";
269 if (system("/bin/tar -C ${General::swroot}/urlfilter -czf ${General::swroot}/urlfilter/backup.tar.gz settings timeconst userquota autoupdate $blistbackup"))
270 {
271 $errormessage = $Lang::tr{'urlfilter backup error'};
272 goto ERROR;
273 }
274 else
275 {
276 print "Content-type: application/gzip\n";
277 print "Content-length: ";
278 print (-s "${General::swroot}/urlfilter/backup.tar.gz");
279 print "\n";
280 print "Content-disposition: attachment; filename=urlfilter-backup.tar.gz\n\n";
281
282 open (FILE, "${General::swroot}/urlfilter/backup.tar.gz");
283 while (<FILE>) { print; }
284 close (FILE);
285
286 if (-e "${General::swroot}/urlfilter/backup.tar.gz") { unlink("${General::swroot}/urlfilter/backup.tar.gz"); }
287 exit;
288 }
289 }
290
291 if ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter restore'})
292 {
293 &Header::getcgihash(\%filtersettings, {'wantfile' => 1, 'filevar' => 'UPDATEFILE'});
294
295 if (!($filtersettings{'UPDATEFILE'} =~ /.tar.gz$/))
296 {
297 $errormessage = $Lang::tr{'urlfilter wrong filetype'};
298 goto ERROR;
299 }
300
301 if (!(-d "${General::swroot}/urlfilter/restore")) { mkdir("${General::swroot}/urlfilter/restore"); }
302
303 if (copy($filtersettings{'UPDATEFILE'}, "${General::swroot}/urlfilter/backup.tar.gz") != 1)
304 {
305 $errormessage = $!;
306 }
d47ad587 307
10e4f239
MT
308 my $exitcode = system("/bin/tar --no-same-owner --preserve-permissions -xzf ${General::swroot}/urlfilter/backup.tar.gz -C ${General::swroot}/urlfilter/restore");
309 if ($exitcode > 0)
310 {
311 $errormessage = $Lang::tr{'urlfilter tar error'};
312 } else {
313 if (!(-e "${General::swroot}/urlfilter/restore/settings"))
314 {
315 $errormessage = $Lang::tr{'urlfilter invalid restore file'};
316 } else {
317 system("cp -rp ${General::swroot}/urlfilter/restore/* ${General::swroot}/urlfilter/");
318 &readblockcategories;
319 &readcustomlists;
320 &writeconfigfile;
321
322 $restoremessage = $Lang::tr{'urlfilter restore success'};
323 }
324 }
325
326 if (-e "${General::swroot}/urlfilter/backup.tar.gz") { unlink("${General::swroot}/urlfilter/backup.tar.gz"); }
327 if (-d "${General::swroot}/urlfilter/restore") { system("rm -rf ${General::swroot}/urlfilter/restore"); }
328 if ($errormessage) { goto ERROR; }
329 }
330
331 if ($filtersettings{'ACTION'} eq $Lang::tr{'save'})
332 {
333 $filtersettings{'VALID'} = 'yes';
334 &savesettings;
335 }
336
337 if ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter save and restart'})
338 {
1465b127 339 if ((!(-e "${General::swroot}/proxy/enable")) && (!(-e "${General::swroot}/proxy/enable_blue")))
10e4f239
MT
340 {
341 $errormessage = $Lang::tr{'urlfilter web proxy service required'};
342 goto ERROR;
343 }
344 if (!($proxysettings{'ENABLE_FILTER'} eq 'on'))
345 {
346 $errormessage = $Lang::tr{'urlfilter not enabled'};
347 goto ERROR;
348 }
349
350 $filtersettings{'VALID'} = 'yes';
351 &savesettings;
352
7d3af7f7 353 system('/usr/local/bin/squidctrl restart >/dev/null 2>&1');
10e4f239 354 }
10e4f239
MT
355}
356
357if ($tcsettings{'ACTION'} eq $Lang::tr{'urlfilter set time constraints'}) { $tcsettings{'TCMODE'} = 'on'}
358
359if (($tcsettings{'MODE'} eq 'TIMECONSTRAINT') && ($tcsettings{'ACTION'} eq $Lang::tr{'add'}))
360{
361 $tcsettings{'TCMODE'}='on';
362
363 if (!$tcsettings{'DST'})
364 {
365 $errormessage=$Lang::tr{'urlfilter dst error'};
366 }
367
368 if (!$tcsettings{'SRC'})
369 {
370 $errormessage=$Lang::tr{'urlfilter src error'};
371 }
372
373 if (!($tcsettings{'TO_HOUR'}.$tcsettings{'TO_MINUTE'} gt $tcsettings{'FROM_HOUR'}.$tcsettings{'FROM_MINUTE'}))
374 {
375 $errormessage=$Lang::tr{'urlfilter timespace error'};
376 }
377
378 if (!(($tcsettings{'MON'} eq 'on') || ($tcsettings{'TUE'} eq 'on') || ($tcsettings{'WED'} eq 'on') || ($tcsettings{'THU'} eq 'on') || ($tcsettings{'FRI'} eq 'on') || ($tcsettings{'SAT'} eq 'on') || ($tcsettings{'SUN'} eq 'on')))
379 {
380 $errormessage=$Lang::tr{'urlfilter weekday error'};
381 }
382
383 if (!$errormessage)
384 {
1465b127
MT
385 # transform to pre1.8 client definitions
386 @clients = split(/\n/,$tcsettings{'SRC'});
387 undef $tcsettings{'SRC'};
388 foreach(@clients)
389 {
390 s/^\s+//g; s/\s+$//g; s/\s+-\s+/-/g; s/\s+/ /g; s/\n//g;
391 $tcsettings{'SRC'} .= "$_ ";
392 }
393 $tcsettings{'SRC'} =~ s/\s+$//;
394
10e4f239
MT
395 if ($tcsettings{'DST'} =~ /^any/) { $tcsettings{'DST'} = 'any'; }
396 if ($tcsettings{'ENABLERULE'} eq 'on') { $tcsettings{'ACTIVE'} = $tcsettings{'ENABLERULE'}; } else { $tcsettings{'ACTIVE'} = 'off'}
397
398 $tcsettings{'ENABLERULE'} = 'on';
399 if($tcsettings{'EDITING'} eq 'no') {
400 open(FILE,">>$tcfile");
401 flock FILE, 2;
402 print FILE "$tcsettings{'DEFINITION'},$tcsettings{'MON'},$tcsettings{'TUE'},$tcsettings{'WED'},$tcsettings{'THU'},$tcsettings{'FRI'},$tcsettings{'SAT'},$tcsettings{'SUN'},$tcsettings{'FROM_HOUR'},$tcsettings{'FROM_MINUTE'},$tcsettings{'TO_HOUR'},$tcsettings{'TO_MINUTE'},$tcsettings{'SRC'},$tcsettings{'DST'},$tcsettings{'ACCESS'},$tcsettings{'ACTIVE'},$tcsettings{'COMMENT'}\n";
403 } else {
404 open(FILE, ">$tcfile");
405 flock FILE, 2;
406 $id = 0;
407 foreach $line (@tclist)
408 {
409 $id++;
410 if ($tcsettings{'EDITING'} eq $id) {
411 print FILE "$tcsettings{'DEFINITION'},$tcsettings{'MON'},$tcsettings{'TUE'},$tcsettings{'WED'},$tcsettings{'THU'},$tcsettings{'FRI'},$tcsettings{'SAT'},$tcsettings{'SUN'},$tcsettings{'FROM_HOUR'},$tcsettings{'FROM_MINUTE'},$tcsettings{'TO_HOUR'},$tcsettings{'TO_MINUTE'},$tcsettings{'SRC'},$tcsettings{'DST'},$tcsettings{'ACCESS'},$tcsettings{'ACTIVE'},$tcsettings{'COMMENT'}\n";
412 } else { print FILE "$line"; }
413 }
414 }
415 close(FILE);
416 undef %tcsettings;
417 $tcsettings{'CHANGED'}='yes';
418 $tcsettings{'TCMODE'}='on';
419 $changed = 'yes';
420 } else {
421 if ($tcsettings{'EDITING'} ne 'no')
422 {
423 $tcsettings{'ACTION'} = $Lang::tr{'edit'};
424 $tcsettings{'ID'} = $tcsettings{'EDITING'};
425 }
426 }
427}
428
1465b127
MT
429if (($tcsettings{'MODE'} eq 'TIMECONSTRAINT') && ($tcsettings{'ACTION'} eq $Lang::tr{'urlfilter copy rule'}) && (!$errormessage))
430{
431 $id = 0;
432 foreach $line (@tclist)
433 {
434 $id++;
435 if ($tcsettings{'ID'} eq $id)
436 {
437 chomp($line);
438 @temp = split(/\,/,$line);
439 $tcsettings{'DEFINITION'} = $temp[0];
440 $tcsettings{'MON'} = $temp[1];
441 $tcsettings{'TUE'} = $temp[2];
442 $tcsettings{'WED'} = $temp[3];
443 $tcsettings{'THU'} = $temp[4];
444 $tcsettings{'FRI'} = $temp[5];
445 $tcsettings{'SAT'} = $temp[6];
446 $tcsettings{'SUN'} = $temp[7];
447 $tcsettings{'FROM_HOUR'} = $temp[8];
448 $tcsettings{'FROM_MINUTE'} = $temp[9];
449 $tcsettings{'TO_HOUR'} = $temp[10];
450 $tcsettings{'TO_MINUTE'} = $temp[11];
451 $tcsettings{'SRC'} = $temp[12];
452 $tcsettings{'DST'} = $temp[13];
453 $tcsettings{'ACCESS'} = $temp[14];
454 $tcsettings{'ENABLERULE'} = $temp[15];
455 $tcsettings{'COMMENT'} = $temp[16];
456 }
457 }
458 $tcsettings{'TCMODE'}='on';
459}
460
10e4f239
MT
461if (($tcsettings{'MODE'} eq 'TIMECONSTRAINT') && ($tcsettings{'ACTION'} eq $Lang::tr{'remove'}))
462{
463 $id = 0;
464 open(FILE, ">$tcfile");
465 flock FILE, 2;
466 foreach $line (@tclist)
467 {
468 $id++;
469 unless ($tcsettings{'ID'} eq $id) { print FILE "$line"; }
470 }
471 close(FILE);
472 $tcsettings{'CHANGED'}='yes';
473 $tcsettings{'TCMODE'}='on';
474}
475
476if (($tcsettings{'MODE'} eq 'TIMECONSTRAINT') && ($tcsettings{'ACTION'} eq $Lang::tr{'urlfilter restart'}))
477{
478 if (!($proxysettings{'ENABLE_FILTER'} eq 'on'))
479 {
480 $errormessage = $Lang::tr{'urlfilter not enabled'};
481 }
1465b127 482 if ((!(-e "${General::swroot}/proxy/enable")) && (!(-e "${General::swroot}/proxy/enable_blue")))
10e4f239
MT
483 {
484 $errormessage = $Lang::tr{'urlfilter web proxy service required'};
485 }
486
7d3af7f7 487 if (!$errormessage) { system('/usr/local/bin/squidctrl restart >/dev/null 2>&1'); }
10e4f239
MT
488 $tcsettings{'TCMODE'}='on';
489}
490
491if (($tcsettings{'MODE'} eq 'TIMECONSTRAINT') && ($tcsettings{'ACTION'} eq $Lang::tr{'toggle enable disable'}))
492{
493 open(FILE, ">$tcfile");
494 flock FILE, 2;
495 $id = 0;
496 foreach $line (@tclist)
497 {
498 $id++;
499 unless ($tcsettings{'ID'} eq $id) { print FILE "$line"; }
500 else
501 {
502 chomp($line);
503 @temp = split(/\,/,$line);
504 if ($temp[15] eq 'on') { $temp[15] = 'off'; } else { $temp[15] = 'on' }
505 print FILE "$temp[0],$temp[1],$temp[2],$temp[3],$temp[4],$temp[5],$temp[6],$temp[7],$temp[8],$temp[9],$temp[10],$temp[11],$temp[12],$temp[13],$temp[14],$temp[15],$temp[16]\n";
506 }
507 }
508 close(FILE);
509 $tcsettings{'CHANGED'}='yes';
510 $tcsettings{'TCMODE'}='on';
511}
512
10e4f239
MT
513if (($tcsettings{'MODE'} eq 'TIMECONSTRAINT') && ($tcsettings{'ACTION'} eq $Lang::tr{'edit'}) && (!$errormessage))
514{
515 $id = 0;
516 foreach $line (@tclist)
517 {
518 $id++;
519 if ($tcsettings{'ID'} eq $id)
520 {
521 chomp($line);
522 @temp = split(/\,/,$line);
523 $tcsettings{'DEFINITION'} = $temp[0];
524 $tcsettings{'MON'} = $temp[1];
525 $tcsettings{'TUE'} = $temp[2];
526 $tcsettings{'WED'} = $temp[3];
527 $tcsettings{'THU'} = $temp[4];
528 $tcsettings{'FRI'} = $temp[5];
529 $tcsettings{'SAT'} = $temp[6];
530 $tcsettings{'SUN'} = $temp[7];
531 $tcsettings{'FROM_HOUR'} = $temp[8];
532 $tcsettings{'FROM_MINUTE'} = $temp[9];
533 $tcsettings{'TO_HOUR'} = $temp[10];
534 $tcsettings{'TO_MINUTE'} = $temp[11];
535 $tcsettings{'SRC'} = $temp[12];
536 $tcsettings{'DST'} = $temp[13];
537 $tcsettings{'ACCESS'} = $temp[14];
538 $tcsettings{'ENABLERULE'} = $temp[15];
539 $tcsettings{'COMMENT'} = $temp[16];
540 }
541 }
542 $tcsettings{'TCMODE'}='on';
543}
544
1465b127
MT
545if ((!$errormessage) && (!($tcsettings{'ACTION'} eq $Lang::tr{'urlfilter copy rule'})) && (!($tcsettings{'ACTION'} eq $Lang::tr{'edit'}))) {
546 $tcsettings{'ENABLERULE'}='on';
547 $tcsettings{'TO_HOUR'}='24';
548}
549
10e4f239
MT
550if ($uqsettings{'ACTION'} eq $Lang::tr{'urlfilter set user quota'}) { $uqsettings{'UQMODE'} = 'on'}
551
552if (($uqsettings{'MODE'} eq 'USERQUOTA') && ($uqsettings{'ACTION'} eq $Lang::tr{'add'}))
553{
554 $uqsettings{'UQMODE'}='on';
555
556 if ((!($uqsettings{'TIME_QUOTA'} =~ /^\d+/)) || ($uqsettings{'TIME_QUOTA'} < '1'))
557 {
558 $errormessage=$Lang::tr{'urlfilter quota time error'};
559 }
560
561 @temp = split(/\n/,$uqsettings{'QUOTA_USERS'});
562 undef $uqsettings{'QUOTA_USERS'};
563 foreach (@temp)
564 {
565 s/^\s+//g; s/\s+$//g;
566 if ($_) { $uqsettings{'QUOTA_USERS'} .= $_."\n"; }
567 }
568
569 if ($uqsettings{'QUOTA_USERS'} eq '')
570 {
571 $errormessage=$Lang::tr{'urlfilter quota user error'};
572 }
573
574 $_ = $uqsettings{'QUOTA_USERS'};
575 chomp; s/\n/|/g;
576 my $quota_users = $_;
577
578 if ($uqsettings{'QUOTA_USERS'} =~ /\\/)
579 {
580 $errormessage=$Lang::tr{'urlfilter invalid user error'};
581 }
582
583 if (!$errormessage) {
584 if ($uqsettings{'ENABLEQUOTA'} eq 'on') { $uqsettings{'ACTIVE'} = $uqsettings{'ENABLEQUOTA'}; } else { $uqsettings{'ACTIVE'} = 'off'}
585
586 $uqsettings{'ENABLERULE'} = 'on';
587 if($uqsettings{'EDITING'} eq 'no') {
588 open(FILE,">>$uqfile");
589 flock FILE, 2;
590 print FILE "$uqsettings{'TIME_QUOTA'},$uqsettings{'SPORADIC'},$uqsettings{'RENEWAL'},$quota_users,$uqsettings{'ACTIVE'}\n";
591 } else {
592 open(FILE, ">$uqfile");
593 flock FILE, 2;
594 $id = 0;
595 foreach $line (@uqlist)
596 {
597 $id++;
598 if ($uqsettings{'EDITING'} eq $id) {
599 print FILE "$uqsettings{'TIME_QUOTA'},$uqsettings{'SPORADIC'},$uqsettings{'RENEWAL'},$quota_users,$uqsettings{'ACTIVE'}\n";
600 } else { print FILE "$line"; }
601 }
602 }
603 close(FILE);
604 undef %uqsettings;
605 $uqsettings{'CHANGED'}='yes';
606 $uqsettings{'MODE'}='USERQUOTA';
607 $uqsettings{'UQMODE'}='on';
608 $changed = 'yes';
609 } else {
610 if ($uqsettings{'EDITING'} ne 'no')
611 {
612 $uqsettings{'ACTION'} = $Lang::tr{'edit'};
613 $uqsettings{'ID'} = $uqsettings{'EDITING'};
614 }
615 }
616}
617
618if (($uqsettings{'MODE'} eq 'USERQUOTA') && ($uqsettings{'ACTION'} eq $Lang::tr{'remove'}))
619{
620 $id = 0;
621 open(FILE, ">$uqfile");
622 flock FILE, 2;
623 foreach $line (@uqlist)
624 {
625 $id++;
626 unless ($uqsettings{'ID'} eq $id) { print FILE "$line"; }
627 }
628 close(FILE);
629 $uqsettings{'CHANGED'}='yes';
630 $uqsettings{'UQMODE'}='on';
631}
632
633if (!$errormessage) {
634 $uqsettings{'ENABLEQUOTA'}='on';
635}
636
637if (($uqsettings{'MODE'} eq 'USERQUOTA') && ($uqsettings{'ACTION'} eq $Lang::tr{'edit'}) && (!$errormessage))
638{
639 $id = 0;
640 foreach $line (@uqlist)
641 {
642 $id++;
643 if ($uqsettings{'ID'} eq $id)
644 {
645 chomp($line);
646 @temp = split(/\,/,$line);
647 $uqsettings{'TIME_QUOTA'} = $temp[0];
648 $uqsettings{'SPORADIC'} = $temp[1];
649 $uqsettings{'RENEWAL'} = $temp[2];
650 $uqsettings{'QUOTA_USERS'} = $temp[3];
651 $uqsettings{'ENABLEQUOTA'} = $temp[4];
652 }
653 }
654 $uqsettings{'UQMODE'}='on';
655}
656
657if (($uqsettings{'MODE'} eq 'USERQUOTA') && ($uqsettings{'ACTION'} eq $Lang::tr{'toggle enable disable'}))
658{
659 open(FILE, ">$uqfile");
660 flock FILE, 2;
661 $id = 0;
662 foreach $line (@uqlist)
663 {
664 $id++;
665 unless ($uqsettings{'ID'} eq $id) { print FILE "$line"; }
666 else
667 {
668 chomp($line);
669 @temp = split(/\,/,$line);
670 if ($temp[4] eq 'on') { $temp[4] = 'off'; } else { $temp[4] = 'on' }
671 print FILE "$temp[0],$temp[1],$temp[2],$temp[3],$temp[4]\n";
672 }
673 }
674 close(FILE);
675 $uqsettings{'CHANGED'}='yes';
676 $uqsettings{'UQMODE'}='on';
677}
678
679if (($uqsettings{'MODE'} eq 'USERQUOTA') && ($uqsettings{'ACTION'} eq $Lang::tr{'urlfilter restart'}))
680{
681 if (!($proxysettings{'ENABLE_FILTER'} eq 'on'))
682 {
683 $errormessage = $Lang::tr{'urlfilter not enabled'};
684 }
1465b127 685 if ((!(-e "${General::swroot}/proxy/enable")) && (!(-e "${General::swroot}/proxy/enable_blue")))
10e4f239
MT
686 {
687 $errormessage = $Lang::tr{'urlfilter web proxy service required'};
688 }
689
7d3af7f7 690 if (!$errormessage) { system('/usr/local/bin/squidctrl restart >/dev/null 2>&1'); }
10e4f239
MT
691 $uqsettings{'UQMODE'}='on';
692}
693
694if ($besettings{'ACTION'} eq $Lang::tr{'urlfilter blacklist editor'}) { $besettings{'BEMODE'} = 'on'; }
695
696if ($besettings{'MODE'} eq 'BLACKLIST_EDITOR')
697{
698 @temp = split(/\n/,$besettings{'BE_DOMAINS'});
699 undef $besettings{'BE_DOMAINS'};
700 foreach (@temp)
701 {
702 s/^\s+//g; s/\s+$//g;
703 if ($_) { $besettings{'BE_DOMAINS'} .= $_."\n"; }
704 }
705 chomp($besettings{'BE_DOMAINS'});
706 @temp = split(/\n/,$besettings{'BE_URLS'});
707 undef $besettings{'BE_URLS'};
708 foreach (@temp)
709 {
710 s/^\s+//g; s/\s+$//g;
711 if ($_) { $besettings{'BE_URLS'} .= $_."\n"; }
712 }
713 chomp($besettings{'BE_URLS'});
714 @temp = split(/\n/,$besettings{'BE_EXPRESSIONS'});
715 undef $besettings{'BE_EXPRESSIONS'};
716 foreach (@temp)
717 {
718 s/^\s+//g; s/\s+$//g;
719 if ($_) { $besettings{'BE_EXPRESSIONS'} .= $_."\n"; }
720 }
721 chomp($besettings{'BE_EXPRESSIONS'});
722}
723
724if (($besettings{'ACTION'} eq $Lang::tr{'urlfilter load blacklist'}) && ($besettings{'MODE'} = 'BLACKLIST_EDITOR'))
725{
726 $besettings{'BEMODE'} = 'on';
727
728 $besettings{'BE_NAME'} = $besettings{'BE_BLACKLIST'};
729
730 delete $besettings{'BE_DOMAINS'};
731 delete $besettings{'BE_URLS'};
732 delete $besettings{'BE_EXPRESSIONS'};
733
734 if (-e "$dbdir/$besettings{'BE_NAME'}/domains")
735 {
736 open(FILE, "$dbdir/$besettings{'BE_NAME'}/domains");
737 while (<FILE>) { unless ($_ eq '\n') { $besettings{'BE_DOMAINS'} .= $_ } };
738 close FILE;
739 chomp($besettings{'BE_DOMAINS'});
740 }
741 if (-e "$dbdir/$besettings{'BE_NAME'}/urls")
742 {
743 open(FILE, "$dbdir/$besettings{'BE_NAME'}/urls");
744 while (<FILE>) { unless ($_ eq '\n') { $besettings{'BE_URLS'} .= $_ } };
745 close FILE;
746 chomp($besettings{'BE_URLS'});
747 }
748 if (-e "$dbdir/$besettings{'BE_NAME'}/expressions")
749 {
750 open(FILE, "$dbdir/$besettings{'BE_NAME'}/expressions");
751 while (<FILE>) { unless ($_ eq '\n') { $besettings{'BE_EXPRESSIONS'} .= $_ } };
752 close FILE;
753 chomp($besettings{'BE_EXPRESSIONS'});
754 }
755}
756
757if (($besettings{'ACTION'} eq $Lang::tr{'urlfilter import blacklist'}) && ($besettings{'MODE'} = 'BLACKLIST_EDITOR'))
758{
759 $besettings{'BEMODE'} = 'on';
760
761 &Header::getcgihash(\%besettings, {'wantfile' => 1, 'filevar' => 'IMPORTFILE'});
762
763 if (!($besettings{'IMPORTFILE'} =~ /.tar.gz$/))
764 {
765 $errormessage = $Lang::tr{'urlfilter wrong filetype'};
766 } else {
767 if (!-d "$editdir") { mkdir("$editdir"); }
768
769 if (copy($besettings{'IMPORTFILE'}, "$editdir/blacklist.tar.gz") != 1)
770 {
771 $errormessage = $!;
772 } else {
d47ad587 773
10e4f239
MT
774 my $exitcode = system("/bin/tar --no-same-owner --preserve-permissions -xzf $editdir/blacklist.tar.gz -C $editdir");
775 if ($exitcode > 0)
776 {
777 $errormessage = $Lang::tr{'urlfilter tar error'};
778 } else {
779 $i = 0;
780 foreach (<$editdir/blacklists/*>)
781 {
782 if (-d)
783 {
784 $i++;
785 $besettings{'BE_NAME'} = substr($_, rindex($_,"/")+1);
786 }
787 }
788
789 if (!($i == 1))
790 {
791 $errormessage = $Lang::tr{'urlfilter invalid import file'};
792 } else {
793 delete $besettings{'BE_DOMAINS'};
794 delete $besettings{'BE_URLS'};
795 delete $besettings{'BE_EXPRESSIONS'};
796
797 if (-e "$editdir/blacklists/$besettings{'BE_NAME'}/domains")
798 {
799 open(FILE, "$editdir/blacklists/$besettings{'BE_NAME'}/domains");
800 while (<FILE>) { unless ($_ eq '\n') { $besettings{'BE_DOMAINS'} .= $_ } };
801 close FILE;
802 chomp($besettings{'BE_DOMAINS'});
803 }
804 if (-e "$editdir/blacklists/$besettings{'BE_NAME'}/urls")
805 {
806 open(FILE, "$editdir/blacklists/$besettings{'BE_NAME'}/urls");
807 while (<FILE>) { unless ($_ eq '\n') { $besettings{'BE_URLS'} .= $_ } };
808 close FILE;
809 chomp($besettings{'BE_URLS'});
810 }
811 if (-e "$editdir/blacklists/$besettings{'BE_NAME'}/expressions")
812 {
813 open(FILE, "$editdir/blacklists/$besettings{'BE_NAME'}/expressions");
814 while (<FILE>) { unless ($_ eq '\n') { $besettings{'BE_EXPRESSIONS'} .= $_ } };
815 close FILE;
816 chomp($besettings{'BE_EXPRESSIONS'});
817 }
818 }
819 }
820
821 if (-d $editdir) { system("rm -rf $editdir"); }
822
823 }
824 }
825}
826
827if (($besettings{'ACTION'} eq $Lang::tr{'urlfilter export blacklist'}) && ($besettings{'MODE'} = 'BLACKLIST_EDITOR'))
828{
829 $besettings{'BEMODE'} = 'on';
830
831 if ($besettings{'BE_NAME'} eq '')
832 {
833 $errormessage = $Lang::tr{'urlfilter category name error'};
834 } elsif ($besettings{'BE_DOMAINS'} || $besettings{'BE_URLS'} || $besettings{'BE_EXPRESSIONS'}) {
835
836 $_ = $besettings{'BE_NAME'}; tr/A-Z/a-z/; $besettings{'BE_NAME'} = $_;
837
838 if (!(-d "$editdir")) { mkdir("$editdir"); }
839 if (!(-d "$editdir/blacklists")) { mkdir("$editdir/blacklists"); }
840 if (!(-d "$editdir/blacklists/$besettings{'BE_NAME'}")) { mkdir("$editdir/blacklists/$besettings{'BE_NAME'}"); }
841
842 open(FILE, ">$editdir/blacklists/$besettings{'BE_NAME'}/domains");
843 flock FILE, 2;
844 print FILE "$besettings{'BE_DOMAINS'}\n";
845 close FILE;
846 open(FILE, ">$editdir/blacklists/$besettings{'BE_NAME'}/urls");
847 flock FILE, 2;
848 print FILE "$besettings{'BE_URLS'}\n";
849 close FILE;
850 open(FILE, ">$editdir/blacklists/$besettings{'BE_NAME'}/expressions");
851 flock FILE, 2;
852 print FILE "$besettings{'BE_EXPRESSIONS'}\n";
853 close FILE;
854
855 if (system("/bin/tar -C $editdir -czf $editdir/$besettings{'BE_NAME'}.tar.gz blacklists"))
856 {
857 $errormessage = $Lang::tr{'urlfilter export error'};
858 }
859 else
860 {
861 print "Content-type: application/gzip\n";
862 print "Content-length: ";
863 print (-s "$editdir/$besettings{'BE_NAME'}.tar.gz");
864 print "\n";
865 print "Content-disposition: attachment; filename=$besettings{'BE_NAME'}.tar.gz\n\n";
866
867 open (FILE, "$editdir/$besettings{'BE_NAME'}.tar.gz");
868 while (<FILE>) { print; }
869 close (FILE);
870
871 if (-d $editdir) { system("rm -rf $editdir"); }
872 exit;
873 }
874 } else {
875 $errormessage = $Lang::tr{'urlfilter category data error'};
876 }
877}
878
879if (($besettings{'ACTION'} eq $Lang::tr{'urlfilter install blacklist'}) && ($besettings{'MODE'} = 'BLACKLIST_EDITOR'))
880{
881 $besettings{'BEMODE'} = 'on';
882
883 if ($besettings{'BE_NAME'} eq '')
884 {
885 $errormessage = $Lang::tr{'urlfilter category name error'};
886 } elsif ($besettings{'BE_DOMAINS'} || $besettings{'BE_URLS'} || $besettings{'BE_EXPRESSIONS'}) {
887
888 $_ = $besettings{'BE_NAME'}; tr/A-Z/a-z/; $besettings{'BE_NAME'} = $_;
889
890 if (!-d "$editdir") { mkdir("$editdir"); }
891
892 if (!-d "$dbdir/$besettings{'BE_NAME'}") { mkdir("$dbdir/$besettings{'BE_NAME'}"); }
893
894 if (-e "$dbdir/$besettings{'BE_NAME'}/domains") { unlink("$dbdir/$besettings{'BE_NAME'}/domains"); }
895 if ($besettings{'BE_DOMAINS'})
896 {
897 open(FILE, ">$dbdir/$besettings{'BE_NAME'}/domains");
898 flock FILE, 2;
899 print FILE "$besettings{'BE_DOMAINS'}\n";
900 close FILE;
901 }
902 if (-e "$dbdir/$besettings{'BE_NAME'}/urls") { unlink("$dbdir/$besettings{'BE_NAME'}/urls"); }
903 if ($besettings{'BE_URLS'})
904 {
905 open(FILE, ">$dbdir/$besettings{'BE_NAME'}/urls");
906 flock FILE, 2;
907 print FILE "$besettings{'BE_URLS'}\n";
908 close FILE;
909 }
910 if (-e "$dbdir/$besettings{'BE_NAME'}/expressions") { unlink("$dbdir/$besettings{'BE_NAME'}/expressions"); }
911 if ($besettings{'BE_EXPRESSIONS'})
912 {
913 open(FILE, ">$dbdir/$besettings{'BE_NAME'}/expressions");
914 flock FILE, 2;
915 print FILE "$besettings{'BE_EXPRESSIONS'}\n";
916 close FILE;
917 }
918
919 open(FILE, ">$editdir/install.conf");
920 flock FILE, 2;
921 print FILE "logdir /var/log/squidGuard\n";
922 print FILE "dbhome $dbdir/$besettings{'BE_NAME'}\n\n";
923 print FILE "dest $besettings{'BE_NAME'} {\n";
924 if ($besettings{'BE_DOMAINS'}) { print FILE " domainlist domains\n"; }
925 if ($besettings{'BE_URLS'}) { print FILE " urllist urls\n"; }
926 if ($besettings{'BE_EXPRESSIONS'}) { print FILE " expressions expressions\n"; }
927 print FILE "}\n\n";
928 print FILE "acl {\n";
929 print FILE " default {\n";
930 print FILE " pass none\n";
931 print FILE " }\n";
932 print FILE "}\n";
933 close FILE;
934
935 system("rm -f $dbdir/$besettings{'BE_NAME'}/*.db");
936 system("/usr/sbin/squidGuard -c $editdir/install.conf -C all");
937 system("chmod a+w $dbdir/$besettings{'BE_NAME'}/*.db");
938
939 &readblockcategories;
940 &readcustomlists;
941
942 &writeconfigfile;
943
7d3af7f7 944 system('/usr/local/bin/squidctrl restart >/dev/null 2>&1') unless ($besettings{'NORESTART'} eq 'on');
10e4f239
MT
945
946 if (-d $editdir) { system("rm -rf $editdir"); }
947 } else {
948 $errormessage = $Lang::tr{'urlfilter category data error'};
949 }
950}
951
952if ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter save schedule'})
953{
954 if (($filtersettings{'UPDATE_SOURCE'} eq 'custom') && ($filtersettings{'CUSTOM_UPDATE_URL'} eq ''))
955 {
956 $errormessage = $Lang::tr{'urlfilter custom url required'};
957 } else {
958 open (FILE, ">$updconffile");
959 print FILE "ENABLE_AUTOUPDATE=$filtersettings{'ENABLE_AUTOUPDATE'}\n";
960 print FILE "UPDATE_SCHEDULE=$filtersettings{'UPDATE_SCHEDULE'}\n";
961 print FILE "UPDATE_SOURCE=$filtersettings{'UPDATE_SOURCE'}\n";
962 print FILE "CUSTOM_UPDATE_URL=$filtersettings{'CUSTOM_UPDATE_URL'}\n";
963 close FILE;
964
10e4f239
MT
965
966 if (($filtersettings{'ENABLE_AUTOUPDATE'} eq 'on') && ($filtersettings{'UPDATE_SCHEDULE'} eq 'daily'))
967 {
a4883c68 968 system('/usr/local/bin/urlfilterctrl cron daily >/dev/null 2>&1');
10e4f239
MT
969 }
970
971 if (($filtersettings{'ENABLE_AUTOUPDATE'} eq 'on') && ($filtersettings{'UPDATE_SCHEDULE'} eq 'weekly'))
972 {
a4883c68 973 system('/usr/local/bin/urlfilterctrl cron weekly >/dev/null 2>&1');
10e4f239
MT
974 }
975
976 if (($filtersettings{'ENABLE_AUTOUPDATE'} eq 'on') && ($filtersettings{'UPDATE_SCHEDULE'} eq 'monthly'))
977 {
a4883c68 978 system('/usr/local/bin/urlfilterctrl cron monthly >/dev/null 2>&1');
10e4f239
MT
979 }
980 }
981}
982
983if ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter update now'})
984{
985 if ($filtersettings{'UPDATE_SOURCE'} eq 'custom')
986 {
987 if ($filtersettings{'CUSTOM_UPDATE_URL'} eq '')
988 {
989 $errormessage = $Lang::tr{'urlfilter custom url required'};
990 } else {
991 system("${General::swroot}/urlfilter/bin/autoupdate.pl $filtersettings{'CUSTOM_UPDATE_URL'} &");
992 }
993 } else {
994 system("${General::swroot}/urlfilter/bin/autoupdate.pl $filtersettings{'UPDATE_SOURCE'} &");
995 }
996}
997
998
999if (-e "${General::swroot}/urlfilter/settings") { &General::readhash("${General::swroot}/urlfilter/settings", \%filtersettings); }
1000
1001&readcustomlists;
1002
1465b127
MT
1003ERROR:
1004
1005if ($errormessage) { $filtersettings{'VALID'} = 'no'; }
1006
10e4f239
MT
1007$checked{'ENABLE_CUSTOM_BLACKLIST'}{'off'} = '';
1008$checked{'ENABLE_CUSTOM_BLACKLIST'}{'on'} = '';
1009$checked{'ENABLE_CUSTOM_BLACKLIST'}{$filtersettings{'ENABLE_CUSTOM_BLACKLIST'}} = "checked='checked'";
1010$checked{'ENABLE_CUSTOM_WHITELIST'}{'off'} = '';
1011$checked{'ENABLE_CUSTOM_WHITELIST'}{'on'} = '';
1012$checked{'ENABLE_CUSTOM_WHITELIST'}{$filtersettings{'ENABLE_CUSTOM_WHITELIST'}} = "checked='checked'";
1013$checked{'ENABLE_CUSTOM_EXPRESSIONS'}{'off'} = '';
1014$checked{'ENABLE_CUSTOM_EXPRESSIONS'}{'on'} = '';
1015$checked{'ENABLE_CUSTOM_EXPRESSIONS'}{$filtersettings{'ENABLE_CUSTOM_EXPRESSIONS'}} = "checked='checked'";
1016$checked{'BLOCK_EXECUTABLES'}{'off'} = '';
1017$checked{'BLOCK_EXECUTABLES'}{'on'} = '';
1018$checked{'BLOCK_EXECUTABLES'}{$filtersettings{'BLOCK_EXECUTABLES'}} = "checked='checked'";
1019$checked{'BLOCK_AUDIO-VIDEO'}{'off'} = '';
1020$checked{'BLOCK_AUDIO-VIDEO'}{'on'} = '';
1021$checked{'BLOCK_AUDIO-VIDEO'}{$filtersettings{'BLOCK_AUDIO-VIDEO'}} = "checked='checked'";
1022$checked{'BLOCK_ARCHIVES'}{'off'} = '';
1023$checked{'BLOCK_ARCHIVES'}{'on'} = '';
1024$checked{'BLOCK_ARCHIVES'}{$filtersettings{'BLOCK_ARCHIVES'}} = "checked='checked'";
1025$checked{'ENABLE_REWRITE'}{'off'} = '';
1026$checked{'ENABLE_REWRITE'}{'on'} = '';
1027$checked{'ENABLE_REWRITE'}{$filtersettings{'ENABLE_REWRITE'}} = "checked='checked'";
1028$checked{'SHOW_CATEGORY'}{'off'} = '';
1029$checked{'SHOW_CATEGORY'}{'on'} = '';
1030$checked{'SHOW_CATEGORY'}{$filtersettings{'SHOW_CATEGORY'}} = "checked='checked'";
1031$checked{'SHOW_URL'}{'off'} = '';
1032$checked{'SHOW_URL'}{'on'} = '';
1033$checked{'SHOW_URL'}{$filtersettings{'SHOW_URL'}} = "checked='checked'";
1034$checked{'SHOW_IP'}{'off'} = '';
1035$checked{'SHOW_IP'}{'on'} = '';
1036$checked{'SHOW_IP'}{$filtersettings{'SHOW_IP'}} = "checked='checked'";
1037$checked{'ENABLE_DNSERROR'}{'off'} = '';
1038$checked{'ENABLE_DNSERROR'}{'on'} = '';
1039$checked{'ENABLE_DNSERROR'}{$filtersettings{'ENABLE_DNSERROR'}} = "checked='checked'";
1040$checked{'ENABLE_JPEG'}{'off'} = '';
1041$checked{'ENABLE_JPEG'}{'on'} = '';
1042$checked{'ENABLE_JPEG'}{$filtersettings{'ENABLE_JPEG'}} = "checked='checked'";
1043$checked{'ENABLE_EXPR_LISTS'}{'off'} = '';
1044$checked{'ENABLE_EXPR_LISTS'}{'on'} = '';
1045$checked{'ENABLE_EXPR_LISTS'}{$filtersettings{'ENABLE_EXPR_LISTS'}} = "checked='checked'";
1046$checked{'BLOCK_IP_ADDR'}{'off'} = '';
1047$checked{'BLOCK_IP_ADDR'}{'on'} = '';
1048$checked{'BLOCK_IP_ADDR'}{$filtersettings{'BLOCK_IP_ADDR'}} = "checked='checked'";
1049$checked{'BLOCK_ALL'}{'off'} = '';
1050$checked{'BLOCK_ALL'}{'on'} = '';
1051$checked{'BLOCK_ALL'}{$filtersettings{'BLOCK_ALL'}} = "checked='checked'";
1052$checked{'ENABLE_EMPTY_ADS'}{'off'} = '';
1053$checked{'ENABLE_EMPTY_ADS'}{'on'} = '';
1054$checked{'ENABLE_EMPTY_ADS'}{$filtersettings{'ENABLE_EMPTY_ADS'}} = "checked='checked'";
1055$checked{'ENABLE_GLOBAL_WHITELIST'}{'off'} = '';
1056$checked{'ENABLE_GLOBAL_WHITELIST'}{'on'} = '';
1057$checked{'ENABLE_GLOBAL_WHITELIST'}{$filtersettings{'ENABLE_GLOBAL_WHITELIST'}} = "checked='checked'";
1058$checked{'ENABLE_SAFESEARCH'}{'off'} = '';
1059$checked{'ENABLE_SAFESEARCH'}{'on'} = '';
1060$checked{'ENABLE_SAFESEARCH'}{$filtersettings{'ENABLE_SAFESEARCH'}} = "checked='checked'";
1061$checked{'ENABLE_LOG'}{'off'} = '';
1062$checked{'ENABLE_LOG'}{'on'} = '';
1063$checked{'ENABLE_LOG'}{$filtersettings{'ENABLE_LOG'}} = "checked='checked'";
1064$checked{'ENABLE_USERNAME_LOG'}{'off'} = '';
1065$checked{'ENABLE_USERNAME_LOG'}{'on'} = '';
1066$checked{'ENABLE_USERNAME_LOG'}{$filtersettings{'ENABLE_USERNAME_LOG'}} = "checked='checked'";
1067$checked{'ENABLE_CATEGORY_LOG'}{'off'} = '';
1068$checked{'ENABLE_CATEGORY_LOG'}{'on'} = '';
1069$checked{'ENABLE_CATEGORY_LOG'}{$filtersettings{'ENABLE_CATEGORY_LOG'}} = "checked='checked'";
1070
1071foreach $category (@filtergroups) {
1072 $checked{$category}{'off'} = '';
1073 $checked{$category}{'on'} = '';
1074 $checked{$category}{$filtersettings{$category}} = "checked='checked'";
1075}
1076
1077$selected{'DEFINITION'}{$tcsettings{'DEFINITION'}} = "selected='selected'";
1078$selected{'FROM_HOUR'}{$tcsettings{'FROM_HOUR'}} = "selected='selected'";
1079$selected{'FROM_MINUTE'}{$tcsettings{'FROM_MINUTE'}} = "selected='selected'";
1080$selected{'TO_HOUR'}{$tcsettings{'TO_HOUR'}} = "selected='selected'";
1081$selected{'TO_MINUTE'}{$tcsettings{'TO_MINUTE'}} = "selected='selected'";
1082
1083@selectedcategories = split(/\|/,$tcsettings{'DST'});
1084foreach (@selectedcategories)
1085{
1086 $selected{'DST'}{$_} = "selected='selected'";
1087}
1088
1089$selected{'ACCESS'}{$tcsettings{'ACCESS'}} = "selected='selected'";
1090
1091$checked{'ENABLERULE'}{'off'} = '';
1092$checked{'ENABLERULE'}{'on'} = '';
1093$checked{'ENABLERULE'}{$tcsettings{'ENABLERULE'}} = "checked='checked'";
1094$checked{'MON'}{'off'} = '';
1095$checked{'MON'}{'on'} = '';
1096$checked{'MON'}{$tcsettings{'MON'}} = "checked='checked'";
1097$checked{'TUE'}{'off'} = '';
1098$checked{'TUE'}{'on'} = '';
1099$checked{'TUE'}{$tcsettings{'TUE'}} = "checked='checked'";
1100$checked{'WED'}{'off'} = '';
1101$checked{'WED'}{'on'} = '';
1102$checked{'WED'}{$tcsettings{'WED'}} = "checked='checked'";
1103$checked{'THU'}{'off'} = '';
1104$checked{'THU'}{'on'} = '';
1105$checked{'THU'}{$tcsettings{'THU'}} = "checked='checked'";
1106$checked{'FRI'}{'off'} = '';
1107$checked{'FRI'}{'on'} = '';
1108$checked{'FRI'}{$tcsettings{'FRI'}} = "checked='checked'";
1109$checked{'SAT'}{'off'} = '';
1110$checked{'SAT'}{'on'} = '';
1111$checked{'SAT'}{$tcsettings{'SAT'}} = "checked='checked'";
1112$checked{'SUN'}{'off'} = '';
1113$checked{'SUN'}{'on'} = '';
1114$checked{'SUN'}{$tcsettings{'SUN'}} = "checked='checked'";
1115
1116$selected{'SPORADIC'}{$uqsettings{'SPORADIC'}} = "selected='selected'";
1117$selected{'RENEWAL'} {$uqsettings{'RENEWAL'}} = "selected='selected'";
1118
1119$checked{'ENABLEQUOTA'}{'off'} = '';
1120$checked{'ENABLEQUOTA'}{'on'} = '';
1121$checked{'ENABLEQUOTA'}{$uqsettings{'ENABLEQUOTA'}} = "checked='checked'";
1122
1123$selected{'BE_BLACKLIST'}{$besettings{'BE_BLACKLIST'}} = "selected='selected'";
1124
1125
1126&Header::showhttpheaders();
1127
1128&Header::openpage($Lang::tr{'urlfilter configuration'}, 1, '');
1129
1130&Header::openbigbox('100%', 'left', '', $errormessage);
1131
1132if ($errormessage) {
1133 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
1134 print "<font class='base'>$errormessage&nbsp;</font>\n";
1135 &Header::closebox();
1136} elsif (($tcsettings{'CHANGED'} eq 'yes') || ($uqsettings{'CHANGED'} eq 'yes') ) {
1137 &writeconfigfile;
1138 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
1139 &Header::openbox('100%', 'left', "$Lang::tr{'urlfilter restart notification'}:");
1140 print "<class name='base'>$Lang::tr{'urlfilter restart message'}\n";
1141 if ($uqsettings{'MODE'} eq 'USERQUOTA') { print "<p><class name='base'>$Lang::tr{'urlfilter quota restart message'}\n"; }
1142 print "</class>\n";
1143 print "<p><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter restart'}' />";
1144 if ($tcsettings{'MODE'} eq 'TIMECONSTRAINT') { print "<input type='hidden' name='MODE' value='TIMECONSTRAINT' />"; }
1145 if ($uqsettings{'MODE'} eq 'USERQUOTA') { print "<input type='hidden' name='MODE' value='USERQUOTA' />"; }
1146 &Header::closebox();
1147 print "</form>\n";
1148}
1149
1150if ($restoremessage) {
1151 &Header::openbox('100%', 'left', "$Lang::tr{'urlfilter restore results'}:");
1152 print "<class name='base'>$restoremessage\n";
1153 print "&nbsp;</class>\n";
1154 &Header::closebox();
1155}
1156
1157if ((!$tcsettings{'TCMODE'}) && (!$uqsettings{'UQMODE'}) && (!$besettings{'BEMODE'})) {
1158
1159if (!($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter manage repository'})) {
1160
1161#==========================================================
1162#
1163# Section: Main Configuration
1164#
1165#==========================================================
1166
1167print "<form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'>\n";
1168
1169&Header::openbox('100%', 'left', "$Lang::tr{'urlfilter filter settings'}:");
1170print <<END
1171<table width='100%'>
1172<tr>
1173 <td colspan='4'><b>$Lang::tr{'urlfilter block categories'}</b></td>
1174</tr>
1175END
1176;
1177
1178if (@categories == 0) {
1179print <<END
1180<tr>
1181 <td><i>$Lang::tr{'urlfilter no categories'}</i></td>
1182 <td>&nbsp;</td>
1183 <td>&nbsp;</td>
1184 <td>&nbsp;</td>
1185</tr>
1186
1187END
1188;
1189}
1190
1191for ($n=0; $n<=@categories; $n = $n + $i) {
1192 for ($i=0; $i<=3; $i++) {
1193 if ($i eq 0) { print "<tr>\n"; }
1194 if (($n+$i) < @categories) {
1195 print "<td width='15%'>@categories[$n+$i]:<\/td>\n";
1196 print "<td width='10%'><input type='checkbox' name=@filtergroups[$n+$i] $checked{@filtergroups[$n+$i]}{'on'} /></td>\n";
1197 }
1198 if ($i eq 3) { print "<\/tr>\n"; }
1199 }
1200}
1201
1202print <<END
1203</table>
1204<hr size='1'>
1205<table width='100%'>
1206<tr>
1207 <td><b>$Lang::tr{'urlfilter custom blacklist'}</b></td>
1208 <td>&nbsp;</td>
1209 <td>&nbsp;</td>
1210 <td>&nbsp;</td>
1211</tr>
1212<tr>
1213 <td colspan='2'>$Lang::tr{'urlfilter blocked domains'}&nbsp;<img src='/blob.gif' alt='*' /></td>
1214 <td colspan='2'>$Lang::tr{'urlfilter blocked urls'}&nbsp;<img src='/blob.gif' alt='*' /></td>
1215</tr>
97c3590c
JPT
1216<tr>
1217 <td colspan='2'>$Lang::tr{'urlfilter example'}</td>
1218 <td colspan='2'>$Lang::tr{'urlfilter example ads'}</td>
1219</tr>
10e4f239
MT
1220<tr>
1221 <td colspan='2' width='50%'><textarea name='CUSTOM_BLACK_DOMAINS' cols='32' rows='6' wrap='off'>
1222END
1223;
1224
1225print $filtersettings{'CUSTOM_BLACK_DOMAINS'};
1226
1227print <<END
1228</textarea></td>
1229 <td colspan='2' width='50%'><textarea name='CUSTOM_BLACK_URLS' cols='32' rows='6' wrap='off'>
1230END
1231;
1232
1233print $filtersettings{'CUSTOM_BLACK_URLS'};
1234
1235print <<END
1236</textarea></td>
1237</tr>
1238</table>
1239<table width='100%'>
1240<tr>
1241 <td class='base' width='25%'>$Lang::tr{'urlfilter enable custom blacklist'}:</td>
1242 <td><input type='checkbox' name='ENABLE_CUSTOM_BLACKLIST' $checked{'ENABLE_CUSTOM_BLACKLIST'}{'on'} /></td>
1243 <td>&nbsp;</td>
1244 <td>&nbsp;</td>
1245</tr>
1246</table>
1247<hr size='1'>
1248<table width='100%'>
1249<tr>
1250 <td><b>$Lang::tr{'urlfilter custom whitelist'}</b></td>
1251 <td>&nbsp;</td>
1252 <td>&nbsp;</td>
1253 <td>&nbsp;</td>
1254</tr>
1255<tr>
1256 <td colspan='2'>$Lang::tr{'urlfilter allowed domains'}&nbsp;<img src='/blob.gif' alt='*' /></td>
1257 <td colspan='2'>$Lang::tr{'urlfilter allowed urls'}&nbsp;<img src='/blob.gif' alt='*' /></td>
1258</tr>
1259<tr>
1260 <td colspan='2' width='50%'><textarea name='CUSTOM_WHITE_DOMAINS' cols='32' rows='6' wrap='off'>
1261END
1262;
1263
1264print $filtersettings{'CUSTOM_WHITE_DOMAINS'};
1265
1266print <<END
1267</textarea></td>
1268 <td colspan='2' width='50%'><textarea name='CUSTOM_WHITE_URLS' cols='32' rows='6' wrap='off'>
1269END
1270;
1271
1272print $filtersettings{'CUSTOM_WHITE_URLS'};
1273
1274print <<END
1275</textarea></td>
1276</tr>
1277</table>
1278<table width='100%'>
1279<tr>
1280 <td class='base' width='25%'>$Lang::tr{'urlfilter enable custom whitelist'}:</td>
1281 <td><input type='checkbox' name='ENABLE_CUSTOM_WHITELIST' $checked{'ENABLE_CUSTOM_WHITELIST'}{'on'} /></td>
1282 <td>&nbsp;</td>
1283 <td>&nbsp;</td>
1284</tr>
1285</table>
1286<hr size='1'>
1287<table width='100%'>
1288<tr>
1289 <td colspan='4'><b>$Lang::tr{'urlfilter custom expression list'}</b></td>
1290</tr>
1291<tr>
1292 <td colspan='4'>$Lang::tr{'urlfilter blocked expressions'}&nbsp;<img src='/blob.gif' alt='*' /></td>
1293</tr>
1294<tr>
1295 <td colspan='4'><textarea name='CUSTOM_EXPRESSIONS' cols='70' rows='3' wrap='off'>
1296END
1297;
1298
1299print $filtersettings{'CUSTOM_EXPRESSIONS'};
1300
1301print <<END
1302</textarea></td>
1303</tr>
1304<tr>
1305 <td class='base' width='25%'>$Lang::tr{'urlfilter enable custom expression list'}:</td>
1306 <td><input type='checkbox' name='ENABLE_CUSTOM_EXPRESSIONS' $checked{'ENABLE_CUSTOM_EXPRESSIONS'}{'on'} /></td>
1307 <td>&nbsp;</td>
1308 <td>&nbsp;</td>
1309</tr>
1310</table>
1311<hr size='1'>
1312<table width='100%'>
1313<tr>
1314 <td colspan='4'><b>$Lang::tr{'urlfilter file ext block'}</b></td>
1315</tr>
1316<tr>
1317 <td width='25%' class='base'>$Lang::tr{'urlfilter block executables'}:</td>
1318 <td width='12%'><input type='checkbox' name='BLOCK_EXECUTABLES' $checked{'BLOCK_EXECUTABLES'}{'on'} /></td>
1319 <td width='25%' class='base'>$Lang::tr{'urlfilter block audio-video'}:</td>
1320 <td><input type='checkbox' name='BLOCK_AUDIO-VIDEO' $checked{'BLOCK_AUDIO-VIDEO'}{'on'} /></td>
1321</tr>
1322<tr>
1323 <td class='base'>$Lang::tr{'urlfilter block archives'}:</td>
1324 <td><input type='checkbox' name='BLOCK_ARCHIVES' $checked{'BLOCK_ARCHIVES'}{'on'} /></td>
1325 <td>&nbsp;</td>
1326 <td>&nbsp;</td>
1327</tr>
1328</table>
1329<hr size='1'>
1330<table width='100%'>
1331<tr>
1332 <td colspan='4'><b>$Lang::tr{'urlfilter local file redirection'}</b></td>
1333</tr>
1334<tr>
1335 <td width='25%' class='base'>$Lang::tr{'urlfilter enable rewrite rules'}:</td>
1336 <td width='12%'><input type='checkbox' name='ENABLE_REWRITE' $checked{'ENABLE_REWRITE'}{'on'} /></td>
1337 <td>&nbsp;</td>
1338 <td>&nbsp;</td>
1339</tr>
1340<tr>
1341 <td><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter manage repository'}'></td>
1342 <td>&nbsp;</td>
1343 <td>&nbsp;</td>
1344 <td>&nbsp;</td>
1345</tr>
1346</table>
1347<hr size='1'>
1348<table width='100%'>
1349<tr>
1350 <td colspan='2'><b>$Lang::tr{'urlfilter network access control'}</b></td>
1351 <td>&nbsp;</td>
1352 <td>&nbsp;</td>
1353</tr>
1354<tr>
1465b127
MT
1355 <td colspan='2'>$Lang::tr{'urlfilter unfiltered clients'}&nbsp;<img src='/blob.gif' alt='*' /></td>
1356 <td colspan='2'>$Lang::tr{'urlfilter banned clients'}&nbsp;<img src='/blob.gif' alt='*' /></td>
1357</tr>
1358<tr>
1359 <td colspan='2' width='50%'><textarea name='UNFILTERED_CLIENTS' cols='32' rows='6' wrap='off'>
1360END
1361;
1362
1363# transform from pre1.8 client definitions
1364$filtersettings{'UNFILTERED_CLIENTS'} =~ s/^\s+//g;
1365$filtersettings{'UNFILTERED_CLIENTS'} =~ s/\s+$//g;
1366$filtersettings{'UNFILTERED_CLIENTS'} =~ s/\s+-\s+/-/g;
1367$filtersettings{'UNFILTERED_CLIENTS'} =~ s/\s+/ /g;
1368
1369@clients = split(/ /,$filtersettings{'UNFILTERED_CLIENTS'});
1370undef $filtersettings{'UNFILTERED_CLIENTS'};
1371foreach (@clients) { $filtersettings{'UNFILTERED_CLIENTS'} .= "$_\n"; }
1372
1373print $filtersettings{'UNFILTERED_CLIENTS'};
1374
1375print <<END
1376</textarea></td>
1377 <td colspan='2' width='50%'><textarea name='BANNED_CLIENTS' cols='32' rows='6' wrap='off'>
1378END
1379;
1380
1381# transform from pre1.8 client definitions
1382$filtersettings{'BANNED_CLIENTS'} =~ s/^\s+//g;
1383$filtersettings{'BANNED_CLIENTS'} =~ s/\s+$//g;
1384$filtersettings{'BANNED_CLIENTS'} =~ s/\s+-\s+/-/g;
1385$filtersettings{'BANNED_CLIENTS'} =~ s/\s+/ /g;
1386
1387@clients = split(/ /,$filtersettings{'BANNED_CLIENTS'});
1388undef $filtersettings{'BANNED_CLIENTS'};
1389foreach (@clients) { $filtersettings{'BANNED_CLIENTS'} .= "$_\n"; }
1390
1391print $filtersettings{'BANNED_CLIENTS'};
1392
1393print <<END
1394</textarea></td>
10e4f239
MT
1395</tr>
1396</table>
1397<hr size='1'>
1398<table width='100%'>
1399<tr>
1400 <td colspan='4'><b>$Lang::tr{'urlfilter timebased access control'}</b></td>
1401</tr>
1402<tr>
1403 <td width='25%'><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter set time constraints'}'></td>
1404 <td width='25%'><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter set user quota'}'></td>
1405 <td>&nbsp;</td>
1406 <td>&nbsp;</td>
1407</tr>
1408</table>
1409<hr size='1'>
1410<table width='100%'>
1411<tr>
1412 <td colspan='4'><b>$Lang::tr{'urlfilter block settings'}</b></td>
1413</tr>
1414<tr>
1415 <td width='25%' class='base'>$Lang::tr{'urlfilter show category'}:</td>
1416 <td width='12%'><input type='checkbox' name='SHOW_CATEGORY' $checked{'SHOW_CATEGORY'}{'on'} /></td>
1417 <td width='25%' class='base'>$Lang::tr{'urlfilter redirectpage'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
1418 <td><input type='text' name='REDIRECT_PAGE' value='$filtersettings{'REDIRECT_PAGE'}' size='40' /></td>
1419</tr>
1420<tr>
1421 <td class='base'>$Lang::tr{'urlfilter show url'}:</td>
1422 <td><input type='checkbox' name='SHOW_URL' $checked{'SHOW_URL'}{'on'} /></td>
1423 <td class='base'>$Lang::tr{'urlfilter msg text 1'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
1424 <td><input type='text' name='MSG_TEXT_1' value='$filtersettings{'MSG_TEXT_1'}' size='40' /></td>
1425</tr>
1426<tr>
1427 <td class='base'>$Lang::tr{'urlfilter show ip'}:</td>
1428 <td><input type='checkbox' name='SHOW_IP' $checked{'SHOW_IP'}{'on'} /></td>
1429 <td class='base'>$Lang::tr{'urlfilter msg text 2'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
1430 <td><input type='text' name='MSG_TEXT_2' value='$filtersettings{'MSG_TEXT_2'}' size='40' /></td>
1431</tr>
1432<tr>
1433 <td class='base'>$Lang::tr{'urlfilter show dnserror'}:</td>
1434 <td><input type='checkbox' name='ENABLE_DNSERROR' $checked{'ENABLE_DNSERROR'}{'on'} /></td>
1435 <td class='base'>$Lang::tr{'urlfilter msg text 3'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
1436 <td><input type='text' name='MSG_TEXT_3' value='$filtersettings{'MSG_TEXT_3'}' size='40' /></td>
1437</tr>
10e4f239 1438</table>
10e4f239
MT
1439<hr size='1'>
1440<table width='100%'>
1441<tr>
1442 <td colspan='4'><b>$Lang::tr{'urlfilter advanced settings'}</b></td>
1443</tr>
1444<tr>
1445 <td width='25%' class='base'>$Lang::tr{'urlfilter enable expression lists'}:</td>
1446 <td width='12%'><input type='checkbox' name='ENABLE_EXPR_LISTS' $checked{'ENABLE_EXPR_LISTS'}{'on'} /></td>
1447 <td width='25%' class='base'>$Lang::tr{'urlfilter enable log'}:</td>
1448 <td><input type='checkbox' name='ENABLE_LOG' $checked{'ENABLE_LOG'}{'on'} /></td>
1449</tr>
1450<tr>
1451 <td class='base'>$Lang::tr{'urlfilter safesearch'}:</td>
1452 <td><input type='checkbox' name='ENABLE_SAFESEARCH' $checked{'ENABLE_SAFESEARCH'}{'on'} /></td>
1453 <td class='base'>$Lang::tr{'urlfilter username log'}:</td>
1454 <td><input type='checkbox' name='ENABLE_USERNAME_LOG' $checked{'ENABLE_USERNAME_LOG'}{'on'} /></td>
1455</tr>
1456<tr>
1457 <td class='base'>$Lang::tr{'urlfilter empty ads'}:</td>
1458 <td><input type='checkbox' name='ENABLE_EMPTY_ADS' $checked{'ENABLE_EMPTY_ADS'}{'on'} /></td>
1459 <td class='base'>$Lang::tr{'urlfilter category log'}:</td>
1460 <td><input type='checkbox' name='ENABLE_CATEGORY_LOG' $checked{'ENABLE_CATEGORY_LOG'}{'on'} /></td>
1461</tr>
1462<tr>
1463 <td class='base'>$Lang::tr{'urlfilter block ip'}:</td>
1464 <td><input type='checkbox' name='BLOCK_IP_ADDR' $checked{'BLOCK_IP_ADDR'}{'on'} /></td>
10e4f239
MT
1465</tr>
1466<tr>
1467 <td class='base'>$Lang::tr{'urlfilter block all'}:</td>
1468 <td><input type='checkbox' name='BLOCK_ALL' $checked{'BLOCK_ALL'}{'on'} /></td>
1469 <td class='base'>$Lang::tr{'urlfilter whitelist always allowed'}:</td>
1470 <td><input type='checkbox' name='ENABLE_GLOBAL_WHITELIST' $checked{'ENABLE_GLOBAL_WHITELIST'}{'on'} /></td>
1471</tr>
1472</table>
1473<hr size='1'>
1474<table width='100%'>
1475<tr>
1476 <td>
1477 <img src='/blob.gif' align='top' alt='*' />&nbsp;
1478 <font class='base'>$Lang::tr{'this field may be blank'}</font>
1479 </td>
8deebac8 1480 <td align='right'>&nbsp;
1465b127 1481 </td>
10e4f239
MT
1482</tr>
1483</table>
1484<table width='100%'>
1485<tr>
1486<td>&nbsp;</td>
1487<td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
1488<td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter save and restart'}' /></td>
1489<td>&nbsp;</td>
1490</tr>
1491</table>
1492END
1493;
1494
1495&Header::closebox();
1496
1497print "</form>\n";
1498
1499print "<form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'>\n";
1500
1501&Header::openbox('100%', 'left', "$Lang::tr{'urlfilter maintenance'}:");
1502
1503print <<END
1504<table width='100%'>
1505<tr>
1506<td class='base'><b>$Lang::tr{'urlfilter blacklist update'}</b></td>
1507</tr>
1508<tr>
1509<td>$Lang::tr{'urlfilter upload information'}<p>$Lang::tr{'urlfilter upload text'}:</td>
1510</tr>
1511<tr>
1512<td><input type='file' name='UPDATEFILE' size='40' /> &nbsp; <input type='submit' name='ACTION' value='$Lang::tr{'urlfilter upload blacklist'}' /></td>
1513</tr>
1514</table>
1515
1516<hr size='1'>
1517
1518<table width='100%'>
1519<tr>
1520 <td colspan='2' class='base'><b>$Lang::tr{'urlfilter automatic blacklist update'}</b>
1521END
1522;
1523if (-e "$updflagfile")
1524{
1525$blacklistage = int(-M "$updflagfile");
1526print "&nbsp; <b>[</b> <small><i>$Lang::tr{'urlfilter blacklist age 1'} <b>$blacklistage</b> $Lang::tr{'urlfilter blacklist age 2'}</i></small> <b>]</b>";
1527}
1528
1529$updatesettings{'UPDATE_SCHEDULE'} = 'monthly';
1530$updatesettings{'CUSTOM_UPDATE_URL'} = '';
1531
1532if (-e "$updconffile") { &General::readhash("$updconffile", \%updatesettings); }
1533
1534$checked{'ENABLE_AUTOUPDATE'}{'off'} = '';
1535$checked{'ENABLE_AUTOUPDATE'}{'on'} = '';
1536$checked{'ENABLE_AUTOUPDATE'}{$updatesettings{'ENABLE_AUTOUPDATE'}} = "checked='checked'";
1537
1538$selected{'UPDATE_SCHEDULE'}{$updatesettings{'UPDATE_SCHEDULE'}} = "selected='selected'";
1539
1540$selected{'UPDATE_SOURCE'}{$updatesettings{'UPDATE_SOURCE'}} = "selected='selected'";
1541
1542print <<END
1543 </td>
1544</tr>
1545<tr>
1546 <td width='25%' class='base'>$Lang::tr{'urlfilter enable automatic blacklist update'}:</td>
1547 <td width='75%' class='base'><input type='checkbox' name='ENABLE_AUTOUPDATE' $checked{'ENABLE_AUTOUPDATE'}{'on'} /></td>
1548</tr>
1549<tr>
1550 <td class='base'>$Lang::tr{'urlfilter automatic update schedule'}:</td>
1551 <td class='base'>
1552 <select name='UPDATE_SCHEDULE'>
1553 <option value='daily' $selected{'UPDATE_SCHEDULE'}{'daily'}>$Lang::tr{'urlfilter daily'}</option>
1554 <option value='weekly' $selected{'UPDATE_SCHEDULE'}{'weekly'}>$Lang::tr{'urlfilter weekly'}</option>
1555 <option value='monthly' $selected{'UPDATE_SCHEDULE'}{'monthly'}>$Lang::tr{'urlfilter monthly'}</option>
1556 </select>
1557 </td>
1558</tr>
1559<tr>
1560 <td class='base'>$Lang::tr{'urlfilter select source'}:</td>
1561 <td class='base' colspan='2'>
1562 <select name='UPDATE_SOURCE'>
1563END
1564;
1565
1566foreach (@source_urllist) {
1567 chomp;
1568 $source_name = substr($_,0,rindex($_,","));
1569 $source_url = substr($_,index($_,",")+1);
1570 print "\t<option value='$source_url' $selected{'UPDATE_SOURCE'}{$source_url}>$source_name</option>\n";
1571}
1572
1573print <<END
1574 <option value='custom' $selected{'UPDATE_SOURCE'}{'custom'}>$Lang::tr{'urlfilter custom url'}</option>
1575 </select>
1576 </td>
1577</tr>
1578<tr>
1579 <td>$Lang::tr{'urlfilter custom url'}:</td>
1580 <td><input type='text' name='CUSTOM_UPDATE_URL' value='$updatesettings{'CUSTOM_UPDATE_URL'}' size='72' /></td>
1581</tr>
1582</table>
1583<table width='100%'>
1584<tr>
1585 <td width='25%'><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter save schedule'}'>&nbsp;&nbsp;&nbsp;<input type='submit' name='ACTION' value='$Lang::tr{'urlfilter update now'}'></td>
1586</tr>
1587</table>
1588
1589<hr size='1'>
1590
1591<table width='100%'>
1592<tr>
1593 <td class='base'><b>$Lang::tr{'urlfilter blacklist editor'}</b></td>
1594</tr>
1595<tr>
1596 <td>$Lang::tr{'urlfilter blacklist editor info'}</td>
1597</tr>
1598<tr>
1599 <td><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter blacklist editor'}' /></td>
1600</tr>
1601</table>
1602
1603<hr size='1'>
1604
1605<table width='100%'>
1606<tr>
1607 <td colspan='4' class='base'><b>$Lang::tr{'urlfilter backup settings'}</b></td>
1608</tr>
1609<tr>
1610 <td width='25%' class='base'>$Lang::tr{'urlfilter enable full backup'}:</td>
1611 <td width='12%' class='base'><input type='checkbox' name='ENABLE_FULLBACKUP' $checked{'ENABLE_FULLBACKUP'}{'on'} /></td>
1612 <td>&nbsp;</td>
1613 <td>&nbsp;</td>
1614</tr>
1615<tr>
1616 <td colspan='4' class='base'><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter backup'}' /></td>
1617</tr>
1618</table>
1619
1620<hr size='1'>
1621
1622<table width='100%'>
1623<tr>
1624 <td class='base'><b>$Lang::tr{'urlfilter restore settings'}</b></td>
1625</tr>
1626<tr>
1627 <td>$Lang::tr{'urlfilter restore text'}:</td>
1628</tr>
1629<tr>
1630 <td><input type='file' name='UPDATEFILE' size='40' /> &nbsp; <input type='submit' name='ACTION' value='$Lang::tr{'urlfilter restore'}' /></td>
1631</tr>
1632</table>
1633</form>
1634END
1635;
1636
1637&Header::closebox();
1638
1639} else {
1640
1641#==========================================================
1642#
1643# Section: Manage Repository
1644#
1645#==========================================================
1646
1647print "<form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'>\n";
1648
1649&Header::openbox('100%', 'left', "$Lang::tr{'urlfilter manage local file repository'}:");
1650print <<END
1651<table width='100%'>
1652<tr>
1653 <td>$Lang::tr{'urlfilter repository information'}<br><br></td>
1654</tr>
1655<tr>
1656 <td>$Lang::tr{'urlfilter upload file text'}:</td>
1657</tr>
1658<tr>
1659 <td><input type='file' name='UPLOADFILE' size='50' /> &nbsp; <input type='submit' name='ACTION' value='$Lang::tr{'urlfilter upload file'}' /></td>
1660</tr>
1661<tr>
1662 <td><br><b>$Lang::tr{'urlfilter upload file information 1'}:</b> $Lang::tr{'urlfilter upload file information 2'}</td>
1663</tr>
1664</table>
1665<hr size='1'>
1666<table width='100%'>
1667<tr>
1668 <td><input type='button' name='return2main' value='$Lang::tr{'urlfilter back to main page'}' onClick='self.location.href="$ENV{'SCRIPT_NAME'}"'></td>
1669</tr>
1670</table>
1671</form>
1672END
1673;
1674
1675&Header::closebox();
1676
1677&Header::openbox('100%', 'left', "$Lang::tr{'urlfilter current files'}: </b>[$repository]");
1678
1679@repositorylist = <$repository/*>;
1680
1681undef @repositoryfiles;
1682foreach (@repositorylist)
1683{
1684 if (!-d) { push(@repositoryfiles,substr($_,rindex($_,"/")+1)); }
1685}
1686
1687if (@repositoryfiles)
1688{
1689 print <<END
1690<table width='100%'>
1691<tr>
1692 <td align='center'><b>$Lang::tr{'urlfilter filename'}</b></td>
1693 <td width='15%' align='center'><b>$Lang::tr{'urlfilter filesize'}</b></td>
1694 <td width='10%'></td>
1695</tr>
1696END
1697;
1698 $id = 0;
1699 foreach $line (@repositoryfiles)
1700 {
1701 $id++;
1702 if ($id % 2) {
1703 print "<tr bgcolor='$Header::table1colour'>\n"; }
1704 else {
1705 print "<tr bgcolor='$Header::table2colour'>\n"; }
1706 $filesize = (-s "$repository/$line");
1707 1 while $filesize =~ s/^(-?\d+)(\d{3})/$1.$2/;
1708
1709print <<END
1710 <td>&nbsp; &nbsp;$line</td>
1711 <td align='right'>$filesize&nbsp; &nbsp;</td>
1712
1713 <td align='center'>
1714 <form method='post' name='frma$id' action='$ENV{'SCRIPT_NAME'}'>
1715 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' title='$Lang::tr{'remove'}' alt='$Lang::tr{'remove'}' />
1716 <input type='hidden' name='ID' value='$line' />
1717 <input type='hidden' name='ACTION' value='$Lang::tr{'urlfilter remove file'}' />
1718 </form>
1719 </td>
1720
1721 </tr>
1722END
1723;
1724 }
1725
1726print <<END
1727</table>
1728<table>
1729 <tr>
1730 </tr>
1731</table>
1732<table>
1733 <tr>
1734 <td class='boldbase'>&nbsp; <b>$Lang::tr{'legend'}:</b></td>
1735 <td>&nbsp; &nbsp; <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
1736 <td class='base'>$Lang::tr{'remove'}</td>
1737 </tr>
1738</table>
1739END
1740;
1741} else {
1742
1743 print "<i>$Lang::tr{'urlfilter empty repository'}</i>\n";
1744}
1745
1746&Header::closebox();
1747
1748}
1749
1750} elsif ($tcsettings{'TCMODE'}) {
1751
1752#==========================================================
1753#
1754# Section: Set Time Constraints
1755#
1756#==========================================================
1757
1758print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
1759
1760$buttontext = $Lang::tr{'urlfilter add rule'};
1761if ($tcsettings{'ACTION'} eq $Lang::tr{'edit'}) {
1762&Header::openbox('100%', 'left', $Lang::tr{'urlfilter edit time constraint rule'}.':');
1763$buttontext = $Lang::tr{'urlfilter update rule'};
1764} else {
1765&Header::openbox('100%', 'left', $Lang::tr{'urlfilter add new time constraint rule'}.':');
1766}
1767print <<END
1768
1769<table width='100%'>
1770<tr>
1771 <td width='2%'>$Lang::tr{'urlfilter constraint definition'}</td>
1772 <td width='1%'>&nbsp;&nbsp;</td>
1773 <td width='2%' align='center'>$Lang::tr{'urlfilter monday'}</td>
1774 <td width='2%' align='center'>$Lang::tr{'urlfilter tuesday'}</td>
1775 <td width='2%' align='center'>$Lang::tr{'urlfilter wednesday'}</td>
1776 <td width='2%' align='center'>$Lang::tr{'urlfilter thursday'}</td>
1777 <td width='2%' align='center'>$Lang::tr{'urlfilter friday'}</td>
1778 <td width='2%' align='center'>$Lang::tr{'urlfilter saturday'}</td>
1779 <td width='2%' align='center'>$Lang::tr{'urlfilter sunday'}</td>
1780 <td width='1%'>&nbsp;&nbsp;</td>
1781 <td width='7%' colspan=3>$Lang::tr{'urlfilter from'}</td>
1782 <td width='1%'>&nbsp;</td>
1783 <td width='7%' colspan=3>$Lang::tr{'urlfilter to'}</td>
1784 <td>&nbsp;</td>
1785</tr>
1786<tr>
1787 <td class='base'>
1788 <select name='DEFINITION'>
1789 <option value='within' $selected{'DEFINITION'}{'within'}>$Lang::tr{'urlfilter constraint within'}</option>
1790 <option value='outside' $selected{'DEFINITION'}{'outside'}>$Lang::tr{'urlfilter constraint outside'}</option>
1791 </select>
1792 </td>
1793 <td>&nbsp;</td>
1794 <td class='base'><input type='checkbox' name='MON' $checked{'MON'}{'on'} /></td>
1795 <td class='base'><input type='checkbox' name='TUE' $checked{'TUE'}{'on'} /></td>
1796 <td class='base'><input type='checkbox' name='WED' $checked{'WED'}{'on'} /></td>
1797 <td class='base'><input type='checkbox' name='THU' $checked{'THU'}{'on'} /></td>
1798 <td class='base'><input type='checkbox' name='FRI' $checked{'FRI'}{'on'} /></td>
1799 <td class='base'><input type='checkbox' name='SAT' $checked{'SAT'}{'on'} /></td>
1800 <td class='base'><input type='checkbox' name='SUN' $checked{'SUN'}{'on'} /></td>
1801 <td>&nbsp;</td>
1802 <td class='base'>
1803 <select name='FROM_HOUR'>
1804END
1805;
1806for ($i=0;$i<=24;$i++) {
1807$_ = sprintf("%02s",$i);
1808print "<option $selected{'FROM_HOUR'}{$_}>$_</option>\n";
1809}
1810print <<END
1811 </select>
1812 </td>
1813 <td>:</td>
1814 <td class='base'>
1815 <select name='FROM_MINUTE'>
1816END
1817;
1818for ($i=0;$i<=45;$i+=15) {
1819$_ = sprintf("%02s",$i);
1820print "<option $selected{'FROM_MINUTE'}{$_}>$_</option>\n";
1821}
1822print <<END
1823 </select>
1824 <td> - </td>
1825 </td>
1826 <td class='base'>
1827 <select name='TO_HOUR'>
1828END
1829;
1830for ($i=0;$i<=24;$i++) {
1831$_ = sprintf("%02s",$i);
1832print "<option $selected{'TO_HOUR'}{$_}>$_</option>\n";
1833}
1834print <<END
1835 </select>
1836 </td>
1837 <td>:</td>
1838 <td class='base'>
1839 <select name='TO_MINUTE'>
1840END
1841;
1842for ($i=0;$i<=45;$i+=15) {
1843$_ = sprintf("%02s",$i);
1844print "<option $selected{'TO_MINUTE'}{$_}>$_</option>\n";
1845}
1846print <<END
1847 </select>
1848 </td>
1849 <td>&nbsp;</td>
1850</tr>
1851</table>
1852
1853<br>
1854
1855<table width='100%'>
1856 <tr>
1857 <td width='5%'>$Lang::tr{'urlfilter source'}</td>
1858 <td width='1%'>&nbsp;&nbsp;</td>
1859 <td width='5%'>$Lang::tr{'urlfilter dst'}&nbsp;<img src='/blob.gif' alt='*'><img src='/blob.gif' alt='*'></td>
1860 <td width='1%'>&nbsp;&nbsp;</td>
1861 <td width='5%'>$Lang::tr{'urlfilter access'}</td>
1862 <td>&nbsp;</td>
1863 </tr>
1864 <tr>
1465b127
MT
1865 <td rowspan='2'><textarea name='SRC' cols='28' rows='5' wrap='off'>
1866END
1867;
1868
1869# transform from pre1.8 client definitions
1870$tcsettings{'SRC'} =~ s/^\s+//g;
1871$tcsettings{'SRC'} =~ s/\s+$//g;
1872$tcsettings{'SRC'} =~ s/\s+-\s+/-/g;
1873$tcsettings{'SRC'} =~ s/\s+/ /g;
1874
1875@clients = split(/ /,$tcsettings{'SRC'});
1876undef $tcsettings{'SRC'};
1877foreach (@clients) { $tcsettings{'SRC'} .= "$_\n"; }
1878
1879print $tcsettings{'SRC'};
1880
1881print <<END
1882</textarea></td>
1883
10e4f239 1884 <td>&nbsp;</td>
1465b127
MT
1885 <td class='base' rowspan='2' valign='top'>
1886 <select name='DST' size='6' multiple>
10e4f239
MT
1887 <option value='any' $selected{'DST'}{'any'} = "selected='selected'">$Lang::tr{'urlfilter category all'}</option>
1888 <option value='in-addr' $selected{'DST'}{'in-addr'} = "selected='selected'">in-addr</option>
1889END
1890;
1891
1892&readblockcategories;
1893foreach (@categories)
1894{
1895 print "<option value='$_' $selected{'DST'}{$_}>$_</option>\n";
1896}
1897
1898print <<END
1899 <option value='files' $selected{'DST'}{'files'} = "selected='selected'">files</option>
1900 <option value='custom-blocked' $selected{'DST'}{'custom-blocked'} = "selected='selected'">custom-blocked</option>
1901 <option value='custom-expressions' $selected{'DST'}{'custom-expressions'} = "selected='selected'">custom-expressions</option>
1902 </select>
1903 </td>
1904 <td>&nbsp;</td>
1905 <td class='base' valign='top'>
1906 <select name='ACCESS'>
1907 <option value='block' $selected{'ACCESS'}{'block'}>$Lang::tr{'urlfilter mode block'}</option>
1908 <option value='allow' $selected{'ACCESS'}{'allow'}>$Lang::tr{'urlfilter mode allow'}</option>
1909 </select>
1910 </td>
1911 <td>&nbsp;</td>
1912 </tr>
1465b127
MT
1913 <tr>
1914 <td>&nbsp;</td>
1915 <td>&nbsp;</td>
1916 <td>&nbsp;</td>
1917 <td>&nbsp;</td>
1918 </tr>
10e4f239
MT
1919 <tr>
1920 <td>$Lang::tr{'remark'}&nbsp;<img src='/blob.gif' alt='*'></td>
1921 <td>&nbsp;</td>
1922 <td>&nbsp;</td>
1923 <td>&nbsp;</td>
1924 <td>&nbsp;</td>
1465b127 1925 <td>&nbsp;</td>
10e4f239
MT
1926 </tr>
1927 <tr>
1928 <td><input type='text' name='COMMENT' value='$tcsettings{'COMMENT'}' size='32' /></td>
1929 <td>&nbsp;</td>
1930 <td>&nbsp;</td>
1931 <td>&nbsp;</td>
1932 <td>&nbsp;</td>
1465b127 1933 <td>&nbsp;</td>
10e4f239
MT
1934 </tr>
1935</table>
1936
1937<table width='100%'>
1938 <tr>
1939 <td class='base'>$Lang::tr{'urlfilter enabled'}<input type='checkbox' name='ENABLERULE' $checked{'ENABLERULE'}{'on'} /></td>
1940 </tr>
1941</table>
1942
1943<p>
1944
1945<table width='50%'>
1946 <tr>
1947 <td><input type='hidden' name='ACTION' value='$Lang::tr{'add'}' /></td>
1948 <td><input type='hidden' name='MODE' value='TIMECONSTRAINT' /></td>
1949 <td><input type='submit' name='SUBMIT' value='$buttontext' /></td>
1950 <td><input type='reset' name='ACTION' value='$Lang::tr{'urlfilter reset'}' /></td>
1951 <td>&nbsp;</td>
1952 <td><input type='button' name='return2main' value='$Lang::tr{'urlfilter back to main page'}' onClick='self.location.href="$ENV{'SCRIPT_NAME'}"'></td>
1953 </tr>
1954</table>
1955<p>
1956<table width='100%'>
1957 <tr>
1958 <td width='1%' align='right'> <img src='/blob.gif' align='top' alt='*' />&nbsp;</td>
1959 <td><font class='base'>$Lang::tr{'this field may be blank'}</font></td>
1960 </tr>
1961 <tr>
1962 <td width='1%' align='right'><img src='/blob.gif' align='top' alt='*' /><img src='/blob.gif' align='top' alt='*' />&nbsp;</td>
1963 <td><font class='base'>$Lang::tr{'urlfilter select multi'}</font></td>
1964 </tr>
1965</table>
1966END
1967;
1968
1969if ($tcsettings{'ACTION'} eq $Lang::tr{'edit'}) {
1970 print "<input type='hidden' name='EDITING' value='$tcsettings{'ID'}' />\n";
1971} else {
1972 print "<input type='hidden' name='EDITING' value='no' />\n";
1973}
1974
1975&Header::closebox();
1976print "</form>\n";
1977
1978&Header::openbox('100%', 'left', $Lang::tr{'current rules'});
1979print <<END
1980<table width='100%'>
1981 <tr>
1982 <td width='5%' class='boldbase' align='center'><b>$Lang::tr{'urlfilter constraint definition'}</b></td>
1983 <td width='10%' class='boldbase' align='center'><b>$Lang::tr{'urlfilter time space'}</b></td>
1984 <td width='15%' class='boldbase' align='center'><b>$Lang::tr{'urlfilter src'}</b></td>
1985 <td width='5%' class='boldbase' align='center'><b>$Lang::tr{'urlfilter dst'}</b></td>
1465b127 1986 <td width='10%' class='boldbase' colspan='5' align='center'>&nbsp;</td>
10e4f239
MT
1987 </tr>
1988END
1989;
1990
1991if ($tcsettings{'ACTION'} ne '' or $changed ne 'no')
1992{
1993 open(FILE, $tcfile);
1994 @tclist = <FILE>;
1995 close(FILE);
1996}
1997
1998$id = 0;
1999foreach $line (@tclist)
2000{
2001 $id++;
2002 chomp($line);
2003 @temp = split(/\,/,$line);
2004 if($tcsettings{'ACTION'} eq $Lang::tr{'edit'} && $tcsettings{'ID'} eq $id) {
2005 print "<tr bgcolor='$Header::colouryellow'>\n"; }
2006 elsif ($id % 2) {
2007 print "<tr bgcolor='$Header::table1colour'>\n"; }
2008 else {
2009 print "<tr bgcolor='$Header::table2colour'>\n"; }
2010 if ($temp[0] eq 'within') { $temp[0]=$Lang::tr{'urlfilter constraint within'}; } else { $temp[0]=$Lang::tr{'urlfilter constraint outside'}; }
2011 if ($temp[13] eq 'any') { $temp[13]=$Lang::tr{'urlfilter category all'}; }
2012 if ($temp[15] eq 'on') { $gif='on.gif'; $toggle='off'; $gdesc=$Lang::tr{'click to disable'};}
2013 else { $gif='off.gif'; $toggle='on'; $gdesc=$Lang::tr{'click to enable'}; }
2014 if ($temp[14] eq 'block') { $led='led-red.gif'; $ldesc=$Lang::tr{'urlfilter block access'};}
2015 else { $led='led-green.gif'; $ldesc=$Lang::tr{'urlfilter allow access'}; }
2016
2017 undef $time;
2018 if ($temp[1] eq 'on') { $time.=$Lang::tr{'urlfilter mon'}; } else { $time.='='; }
2019 if ($temp[2] eq 'on') { $time.=$Lang::tr{'urlfilter tue'}; } else { $time.='='; }
2020 if ($temp[3] eq 'on') { $time.=$Lang::tr{'urlfilter wed'}; } else { $time.='='; }
2021 if ($temp[4] eq 'on') { $time.=$Lang::tr{'urlfilter thu'}; } else { $time.='='; }
2022 if ($temp[5] eq 'on') { $time.=$Lang::tr{'urlfilter fri'}; } else { $time.='='; }
2023 if ($temp[6] eq 'on') { $time.=$Lang::tr{'urlfilter sat'}; } else { $time.='='; }
2024 if ($temp[7] eq 'on') { $time.=$Lang::tr{'urlfilter sun'}; } else { $time.='='; }
2025 $time=$time.' &nbsp; '.$temp[8].':'.$temp[9].' to '.$temp[10].':'.$temp[11];
2026
2027print <<END
2028 <td align='center'>$temp[0]</td>
2029 <td align='center' nowrap>$time</td>
2030 <td align='center'>$temp[12]</td>
2031 <td align='center'>$temp[13]</td>
2032 <td align='center'><image src='/images/urlfilter/$led' alt='$ldesc'></td>
2033
2034 <td align='center'>
2035 <form method='post' name='frma$id' action='$ENV{'SCRIPT_NAME'}'>
2036 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' title='$gdesc' alt='$gdesc' />
2037 <input type='hidden' name='MODE' value='TIMECONSTRAINT' />
2038 <input type='hidden' name='ID' value='$id' />
2039 <input type='hidden' name='ACTIVE' value='$toggle' />
2040 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
2041 </form>
2042 </td>
2043
2044 <td align='center'>
2045 <form method='post' name='frmb$id' action='$ENV{'SCRIPT_NAME'}'>
2046 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' title='$Lang::tr{'edit'}' alt='$Lang::tr{'edit'}' />
2047 <input type='hidden' name='MODE' value='TIMECONSTRAINT' />
2048 <input type='hidden' name='ID' value='$id' />
2049 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' />
2050 </form>
2051 </td>
2052
2053 <td align='center'>
2054 <form method='post' name='frmc$id' action='$ENV{'SCRIPT_NAME'}'>
1465b127
MT
2055 <input type='image' name='$Lang::tr{'urlfilter copy rule'}' src='/images/urlfilter/copy.gif' title='$Lang::tr{'urlfilter copy rule'}' alt='$Lang::tr{'urlfilter copy rule'}' />
2056 <input type='hidden' name='MODE' value='TIMECONSTRAINT' />
2057 <input type='hidden' name='ID' value='$id' />
2058 <input type='hidden' name='ACTION' value='$Lang::tr{'urlfilter copy rule'}' />
2059 </form>
2060 </td>
2061
2062 <td align='center'>
2063 <form method='post' name='frmd$id' action='$ENV{'SCRIPT_NAME'}'>
10e4f239
MT
2064 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' title='$Lang::tr{'remove'}' alt='$Lang::tr{'remove'}' />
2065 <input type='hidden' name='MODE' value='TIMECONSTRAINT' />
2066 <input type='hidden' name='ID' value='$id' />
2067 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' />
2068 </form>
2069 </td>
2070
2071 </tr>
2072END
2073;
2074 if($tcsettings{'ACTION'} eq $Lang::tr{'edit'} && $tcsettings{'ID'} eq $id) {
2075 print "<tr bgcolor='$Header::colouryellow'>\n"; }
2076 elsif ($id % 2) {
2077 print "<tr bgcolor='$Header::table1colour'>\n"; }
2078 else {
2079 print "<tr bgcolor='$Header::table2colour'>\n"; }
2080print <<END
2081 <td align='center' colspan='4'>$temp[16]
2082 </td>
1465b127 2083 <td align='center' colspan='5'>
10e4f239
MT
2084 </td>
2085 </tr>
2086END
2087;
2088}
2089
2090print "</table>\n";
2091
2092# If the time constraint file contains entries, print entries and action icons
2093if (! -z "$tcfile") {
2094print <<END
2095
2096<table>
2097 <tr>
2098 <td class='boldbase'>&nbsp; <b>$Lang::tr{'legend'}:</b></td>
2099 <td>&nbsp; &nbsp; <img src='/images/urlfilter/led-green.gif' alt='$Lang::tr{'urlfilter allow access'}' /></td>
2100 <td class='base'>$Lang::tr{'urlfilter allow'}</td>
2101 <td>&nbsp; &nbsp; <img src='/images/urlfilter/led-red.gif' alt='$Lang::tr{'urlfilter block access'}' /></td>
2102 <td class='base'>$Lang::tr{'urlfilter block'}</td>
2103 <td>&nbsp; <img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
2104 <td class='base'>$Lang::tr{'click to disable'}</td>
2105 <td>&nbsp; &nbsp; <img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td>
2106 <td class='base'>$Lang::tr{'click to enable'}</td>
2107 <td>&nbsp; &nbsp; <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
2108 <td class='base'>$Lang::tr{'edit'}</td>
1465b127
MT
2109 <td>&nbsp; &nbsp; <img src='/images/urlfilter/copy.gif' alt='$Lang::tr{'urlfilter copy rule'}' /></td>
2110 <td class='base'>$Lang::tr{'urlfilter copy rule'}</td>
10e4f239
MT
2111 <td>&nbsp; &nbsp; <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
2112 <td class='base'>$Lang::tr{'remove'}</td>
2113 </tr>
2114</table>
2115END
2116;
2117}
2118
2119&Header::closebox();
2120
2121} elsif ($uqsettings{'UQMODE'}) {
2122
2123#==========================================================
2124#
2125# Section: Set User Quota
2126#
2127#==========================================================
2128
2129print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
2130
2131$buttontext = $Lang::tr{'urlfilter add rule'};
2132if ($uqsettings{'ACTION'} eq $Lang::tr{'edit'}) {
2133&Header::openbox('100%', 'left', $Lang::tr{'urlfilter edit user quota rule'}.':');
2134$buttontext = $Lang::tr{'urlfilter update rule'};
2135} else {
2136&Header::openbox('100%', 'left', $Lang::tr{'urlfilter add new user quota rule'}.':');
2137}
2138print <<END
2139
2140<table width='100%'>
2141<tr>
2142 <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td>
2143</tr>
2144<tr>
2145 <td class='base'>$Lang::tr{'urlfilter user time quota'}:</td>
2146 <td><input type='text' name='TIME_QUOTA' value='$uqsettings{'TIME_QUOTA'}' size='5' /></td>
2147 <td colspan='2' rowspan= '5' valign='top' class='base'>
2148 <table cellpadding='0' cellspacing='0'>
2149 <tr>
2150 <!-- intentionally left empty -->
2151 </tr>
2152 <tr>
2153 <td>$Lang::tr{'urlfilter assigned quota users'}:</td>
2154 </tr>
2155 <tr>
2156 <!-- intentionally left empty -->
2157 </tr>
2158 <tr>
2159 <!-- intentionally left empty -->
2160 </tr>
2161 <tr>
2162 <td><textarea name='QUOTA_USERS' cols='32' rows='6' wrap='off'>
2163END
2164;
2165
2166$uqsettings{'QUOTA_USERS'} =~ s/\|/\n/g;
2167print $uqsettings{'QUOTA_USERS'};
2168
2169print <<END
2170</textarea></td>
2171 </tr>
2172 </table>
2173 </td>
2174</tr>
2175<tr>
2176 <td class='base'>$Lang::tr{'urlfilter activity detection'}:</td>
2177 <td class='base'><select name='SPORADIC'>
2178 <option value='0' $selected{'SPORADIC'}{'0'}>$Lang::tr{'urlfilter disabled'}</option>
2179 <option value='300' $selected{'SPORADIC'}{'300'}>5 $Lang::tr{'urlfilter minutes'}</option>
2180 <option value='900' $selected{'SPORADIC'}{'900'}>15 $Lang::tr{'urlfilter minutes'}</option>
2181 </select></td>
2182</tr>
2183<tr>
2184 <td class='base'>$Lang::tr{'urlfilter renewal period'}:</td>
2185 <td class='base'><select name='RENEWAL'>
2186 <option value='hourly' $selected{'RENEWAL'}{'hourly'}>$Lang::tr{'urlfilter hourly'}</option>
2187 <option value='daily' $selected{'RENEWAL'}{'daily'}>$Lang::tr{'urlfilter daily'}</option>
2188 <option value='weekly' $selected{'RENEWAL'}{'weekly'}>$Lang::tr{'urlfilter weekly'}</option>
2189 </select></td>
2190</tr>
2191<tr>
2192 <td colspan='2'>&nbsp;</td>
2193</tr>
2194<tr>
2195 <td class='base'>$Lang::tr{'urlfilter enabled'}</td>
2196 <td class='base'><input type='checkbox' name='ENABLEQUOTA' $checked{'ENABLEQUOTA'}{'on'} /></td>
2197</tr>
2198
2199</table>
2200<p>
2201
2202<table width='50%'>
2203 <tr>
2204 <td><input type='hidden' name='ACTION' value='$Lang::tr{'add'}' /></td>
2205 <td><input type='hidden' name='MODE' value='USERQUOTA' /></td>
2206 <td><input type='submit' name='SUBMIT' value='$buttontext' /></td>
2207 <td><input type='reset' name='ACTION' value='$Lang::tr{'urlfilter reset'}' /></td>
2208 <td>&nbsp;</td>
2209 <td><input type='button' name='return2main' value='$Lang::tr{'urlfilter back to main page'}' onClick='self.location.href="$ENV{'SCRIPT_NAME'}"'></td>
2210 </tr>
2211</table>
2212
2213<p>
2214END
2215;
2216
2217if ($uqsettings{'ACTION'} eq $Lang::tr{'edit'}) {
2218 print "<input type='hidden' name='EDITING' value='$uqsettings{'ID'}' />\n";
2219} else {
2220 print "<input type='hidden' name='EDITING' value='no' />\n";
2221}
2222
2223&Header::closebox();
2224print "</form>\n";
2225
2226&Header::openbox('100%', 'left', $Lang::tr{'current rules'});
2227print <<END
2228<table width='100%'>
2229 <tr>
2230 <td width='15%' class='boldbase' align='center'><b><nobr>$Lang::tr{'urlfilter time quota'}</nobr></b></td>
2231 <td width='15%' class='boldbase' align='center'><b><nobr>$Lang::tr{'urlfilter activity detection'}</nobr></b></td>
2232 <td width='10%' class='boldbase' align='center'><b>$Lang::tr{'urlfilter renewal'}</b></td>
2233 <td class='boldbase' align='center'><b>$Lang::tr{'urlfilter assigned users'}</b></td>
2234 <td width='20%' class='boldbase' colspan='4' align='center'>&nbsp;</td>
2235 </tr>
2236END
2237;
2238
2239if ($uqsettings{'ACTION'} ne '' or $changed ne 'no')
2240{
2241 open(FILE, $uqfile);
2242 @uqlist = <FILE>;
2243 close(FILE);
2244}
2245
2246$id = 0;
2247foreach $line (@uqlist)
2248{
2249 $id++;
2250 chomp($line);
2251 @temp = split(/\,/,$line);
2252 if($uqsettings{'ACTION'} eq $Lang::tr{'edit'} && $uqsettings{'ID'} eq $id) {
2253 print "<tr bgcolor='$Header::colouryellow'>\n"; }
2254 elsif ($id % 2) {
2255 print "<tr bgcolor='$Header::table1colour'>\n"; }
2256 else {
2257 print "<tr bgcolor='$Header::table2colour'>\n"; }
2258 if ($temp[4] eq 'on') { $gif='on.gif'; $toggle='off'; $gdesc=$Lang::tr{'click to disable'};}
2259 else { $gif='off.gif'; $toggle='on'; $gdesc=$Lang::tr{'click to enable'}; }
2260
2261 $temp[5] = $temp[1];
2262 if ($temp[1] eq '0') { $temp[5] = $Lang::tr{'urlfilter disabled'} } else { $temp[5] = ($temp[5]/60).' '.$Lang::tr{'urlfilter minutes'} }
2263 $_ = $temp[3]; s/\|/, /g; $temp[6] = $_;
2264
2265print <<END
2266 <td align='center'>$temp[0] $Lang::tr{'urlfilter minutes'}</td>
2267 <td align='center'>$temp[5]</td>
2268 <td align='center'>$Lang::tr{'urlfilter '.$temp[2]}</td>
2269 <td align='center'>$temp[6]</td>
2270
2271 <td align='center'>
2272 <form method='post' name='frma$id' action='$ENV{'SCRIPT_NAME'}'>
2273 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' title='$gdesc' alt='$gdesc' />
2274 <input type='hidden' name='MODE' value='USERQUOTA' />
2275 <input type='hidden' name='ID' value='$id' />
2276 <input type='hidden' name='ACTIVE' value='$toggle' />
2277 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
2278 </form>
2279 </td>
2280
2281 <td align='center'>
2282 <form method='post' name='frmb$id' action='$ENV{'SCRIPT_NAME'}'>
2283 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' title='$Lang::tr{'edit'}' alt='$Lang::tr{'edit'}' />
2284 <input type='hidden' name='MODE' value='USERQUOTA' />
2285 <input type='hidden' name='ID' value='$id' />
2286 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' />
2287 </form>
2288 </td>
2289
2290 <td align='center'>
2291 <form method='post' name='frmc$id' action='$ENV{'SCRIPT_NAME'}'>
2292 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' title='$Lang::tr{'remove'}' alt='$Lang::tr{'remove'}' />
2293 <input type='hidden' name='MODE' value='USERQUOTA' />
2294 <input type='hidden' name='ID' value='$id' />
2295 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' />
2296 </form>
2297 </td>
2298
2299 </tr>
2300END
2301;
2302}
2303
2304print "</table>\n";
2305
2306# If the user quota file contains entries, print entries and action icons
2307if (! -z "$uqfile") {
2308print <<END
2309
2310<table>
2311 <tr>
2312 <td class='boldbase'>&nbsp; <b>$Lang::tr{'legend'}:</b></td>
2313 <td>&nbsp; <img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
2314 <td class='base'>$Lang::tr{'click to disable'}</td>
2315 <td>&nbsp; &nbsp; <img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td>
2316 <td class='base'>$Lang::tr{'click to enable'}</td>
2317 <td>&nbsp; &nbsp; <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
2318 <td class='base'>$Lang::tr{'edit'}</td>
2319 <td>&nbsp; &nbsp; <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
2320 <td class='base'>$Lang::tr{'remove'}</td>
2321 </tr>
2322</table>
2323END
2324;
2325}
2326
2327&Header::closebox();
2328
2329} else {
2330
2331#==========================================================
2332#
2333# Section: Blacklist editor
2334#
2335#==========================================================
2336
2337print "<form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'>\n";
2338
2339&Header::openbox('100%', 'left', $Lang::tr{'urlfilter urlfilter blacklist editor'}.':');
2340
2341print <<END
2342
2343<table width='100%'>
2344<tr>
2345 <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td>
2346</tr>
2347<tr>
2348 <td class='base'><b>$Lang::tr{'urlfilter blacklist name'}</b></td>
2349</tr>
2350<tr>
2351 <td class='base'>$Lang::tr{'urlfilter blacklist category name'}:</td>
2352 <td><input type='text' name='BE_NAME' value='$besettings{'BE_NAME'}' size='12' /></td>
2353</tr>
2354</table>
2355<hr size='1'>
2356<table width='100%'>
2357<tr>
2358 <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='20%'></td>
2359</tr>
2360<tr>
2361 <td class='base' colspan='4'><b>$Lang::tr{'urlfilter edit domains urls expressions'}</b></td>
2362</tr>
2363<tr>
2364 <td colspan='2'>$Lang::tr{'urlfilter domains'}</td>
2365 <td colspan='2'>$Lang::tr{'urlfilter urls'}</td>
2366</tr>
2367<tr>
2368 <td colspan='2'><textarea name='BE_DOMAINS' cols='38' rows='10' wrap='off'>
2369END
2370;
2371
2372print $besettings{'BE_DOMAINS'};
2373
2374print <<END
2375</textarea></td>
2376 <td colspan='2'><textarea name='BE_URLS' cols='38' rows='10' wrap='off'>
2377END
2378;
2379
2380print $besettings{'BE_URLS'};
2381
2382print <<END
2383</textarea></td>
2384</tr>
2385<tr>
2386 <td colspan='4'>$Lang::tr{'urlfilter expressions'}</td>
2387</tr>
2388<tr>
2389 <td colspan='4'><textarea name='BE_EXPRESSIONS' cols='80' rows='3' wrap='off'>
2390END
2391;
2392
2393print $besettings{'BE_EXPRESSIONS'};
2394
2395print <<END
2396</textarea></td>
2397</tr>
2398</table>
2399<hr size='1'>
2400<table width='100%'>
2401<tr>
2402 <td class='base' colspan='4'><b>$Lang::tr{'urlfilter load blacklist'}</b></td>
2403</tr>
2404<tr>
2405 <td width='25%' class='base'>$Lang::tr{'urlfilter select blacklist'}:</td>
2406 <td width='20%' class='base'>
2407 <select name='BE_BLACKLIST'>
2408END
2409;
2410
2411&readblockcategories;
2412foreach (@categories)
2413{
2414 print "<option value='$_' $selected{'BE_BLACKLIST'}{$_}>$_</option>\n";
2415}
2416
2417print <<END
2418 </select>
2419 </td>
2420 <td>&nbsp;</td>
2421 <td>&nbsp;</td>
2422<tr>
2423 <td colpsan='4'><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter load blacklist'}' /></td>
2424</tr>
2425</tr>
2426</table>
2427<hr size='1'>
2428<table width='100%'>
2429<tr>
2430 <td class='base' colspan='4'><b>$Lang::tr{'urlfilter import blacklist'}</b></td>
2431</tr>
2432<tr>
2433 <td colspan='4'>$Lang::tr{'urlfilter import text'}:</td>
2434</tr>
2435<tr>
2436 <td nowrap><input type='file' name='IMPORTFILE' size='40' /> &nbsp; <input type='submit' name='ACTION' value='$Lang::tr{'urlfilter import blacklist'}' /></td>
2437 <td><input type='hidden' name='MODE' value='BLACKLIST_EDITOR' /></td>
2438</tr>
2439</table>
2440<hr size='1'>
2441<table width='100%'>
2442<tr>
2443 <td class='base' colspan='4'><b>$Lang::tr{'urlfilter export blacklist'}</b></td>
2444</tr>
2445<tr>
2446 <td><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter export blacklist'}' /></td>
2447</tr>
2448</table>
2449<hr size='1'>
2450<table width='100%'>
2451<tr>
2452 <td class='base' colspan='4'><b>$Lang::tr{'urlfilter install blacklist'}</b></td>
2453</tr>
2454<tr>
2455 <td width='25%' class='base'>$Lang::tr{'urlfilter dont restart urlfilter'}:</td>
2456 <td width='20%' class='base'><input type='checkbox' name='NORESTART' $checked{'NORESTART'}{'on'} /></td>
2457 <td>&nbsp;</td>
2458 <td>&nbsp;</td>
2459</tr>
2460<tr>
2461 <td><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter install blacklist'}' /></td>
2462</tr>
2463<tr>
2464 <td class='base' colspan='4'><br>$Lang::tr{'urlfilter install information'}</td>
2465</tr>
2466</table>
2467<hr size='1'>
2468<table width='20%'>
2469<tr>
2470 <td><input type='reset' name='ACTION' value='$Lang::tr{'urlfilter reset'}' /></td>
2471 <td>&nbsp;</td>
2472 <td><input type='button' name='return2main' value='$Lang::tr{'urlfilter back to main page'}' onClick='self.location.href="$ENV{'SCRIPT_NAME'}"'></td>
2473</tr>
2474</table>
2475
2476END
2477;
2478
2479&Header::closebox();
2480print "</form>\n";
2481
2482}
2483
2484&Header::closebigbox();
2485
2486&Header::closepage();
2487
2488# -------------------------------------------------------------------
2489
2490sub savesettings
2491{
1465b127
MT
2492 # transform to pre1.8 client definitions
2493 @clients = split(/\n/,$filtersettings{'UNFILTERED_CLIENTS'});
2494 undef $filtersettings{'UNFILTERED_CLIENTS'};
2495 foreach(@clients)
2496 {
2497 s/^\s+//g; s/\s+$//g; s/\s+-\s+/-/g; s/\s+/ /g; s/\n//g;
2498 $filtersettings{'UNFILTERED_CLIENTS'} .= "$_ ";
2499 }
2500 $filtersettings{'UNFILTERED_CLIENTS'} =~ s/\s+$//;
2501
2502 # transform to pre1.8 client definitions
2503 @clients = split(/\n/,$filtersettings{'BANNED_CLIENTS'});
2504 undef $filtersettings{'BANNED_CLIENTS'};
2505 foreach(@clients)
2506 {
2507 s/^\s+//g; s/\s+$//g; s/\s+-\s+/-/g; s/\s+/ /g; s/\n//g;
2508 $filtersettings{'BANNED_CLIENTS'} .= "$_ ";
2509 }
2510 $filtersettings{'BANNED_CLIENTS'} =~ s/\s+$//;
2511
10e4f239
MT
2512 &writeconfigfile;
2513
2514 delete $filtersettings{'CUSTOM_BLACK_DOMAINS'};
2515 delete $filtersettings{'CUSTOM_BLACK_URLS'};
2516 delete $filtersettings{'CUSTOM_WHITE_DOMAINS'};
2517 delete $filtersettings{'CUSTOM_WHITE_URLS'};
2518 delete $filtersettings{'CUSTOM_EXPRESSIONS'};
2519 delete $filtersettings{'BACKGROUND'};
2520 delete $filtersettings{'UPDATEFILE'};
2521
3fbe7122
AF
2522 system("chown -R nobody.nobody $dbdir");
2523 system('/usr/bin/squidGuard -C custom/allowed/domains >/dev/null 2>&1');
2524 system('/usr/bin/squidGuard -C custom/allowed/urls >/dev/null 2>&1');
2525 system('/usr/bin/squidGuard -C custom/blocked/domains >/dev/null 2>&1');
2526 system('/usr/bin/squidGuard -C custom/blocked/urls >/dev/null 2>&1 ');
2527 &setpermissions ($dbdir);
2528
10e4f239
MT
2529 &General::writehash("${General::swroot}/urlfilter/settings", \%filtersettings);
2530}
2531
2532# -------------------------------------------------------------------
2533
2534sub readblockcategories
2535{
2536 undef(@categories);
1465b127
MT
2537
2538 &getblockcategory ($dbdir);
2539
2540 foreach (@categories) { $_ = substr($_,length($dbdir)+1); }
10e4f239
MT
2541
2542 @filtergroups = @categories;
1465b127 2543
10e4f239 2544 foreach (@filtergroups) {
7438d80a 2545 s/\//_/g;
10e4f239
MT
2546 tr/a-z/A-Z/;
2547 $_ = "FILTER_".$_;
2548 }
2549}
2550
2551# -------------------------------------------------------------------
2552
1465b127
MT
2553sub getblockcategory
2554{
2555 foreach $category (<$_[0]/*>)
2556 {
2557 if (-d $category)
2558 {
2559 if ((-e "$category/domains") || (-e "$category/urls"))
2560 {
2561 unless ($category =~ /\bcustom\b/) { push(@categories,$category); }
2562 }
2563 &getblockcategory ($category);
2564 }
2565 }
2566}
2567
2568# -------------------------------------------------------------------
2569
10e4f239
MT
2570sub readcustomlists
2571{
2572 if (-e "$dbdir/custom/blocked/domains") {
2573 open(FILE,"$dbdir/custom/blocked/domains");
2574 delete $filtersettings{'CUSTOM_BLACK_DOMAINS'};
2575 while (<FILE>) { $filtersettings{'CUSTOM_BLACK_DOMAINS'} .= $_ };
2576 close(FILE);
2577 }
2578
2579 if (-e "$dbdir/custom/blocked/urls") {
2580 open(FILE,"$dbdir/custom/blocked/urls");
2581 delete $filtersettings{'CUSTOM_BLACK_URLS'};
2582 while (<FILE>) { $filtersettings{'CUSTOM_BLACK_URLS'} .= $_ };
2583 close(FILE);
2584 }
2585
2586 if (-e "$dbdir/custom/blocked/expressions") {
2587 open(FILE,"$dbdir/custom/blocked/expressions");
2588 delete $filtersettings{'CUSTOM_EXPRESSIONS'};
2589 while (<FILE>) { $filtersettings{'CUSTOM_EXPRESSIONS'} .= $_ };
2590 close(FILE);
2591 }
2592
2593 if (-e "$dbdir/custom/allowed/domains") {
2594 open(FILE,"$dbdir/custom/allowed/domains");
2595 delete $filtersettings{'CUSTOM_WHITE_DOMAINS'};
2596 while (<FILE>) { $filtersettings{'CUSTOM_WHITE_DOMAINS'} .= $_ };
2597 close(FILE);
2598 }
2599 if (-e "$dbdir/custom/allowed/urls") {
2600 open(FILE,"$dbdir/custom/allowed/urls");
2601 delete $filtersettings{'CUSTOM_WHITE_URLS'};
2602 while (<FILE>) { $filtersettings{'CUSTOM_WHITE_URLS'} .= $_ };
2603 close(FILE);
2604 }
2605}
2606
2607# -------------------------------------------------------------------
2608
2609sub aggregatedconstraints
2610{
2611 my $aggregated;
2612 my @old;
2613 my @new;
2614 my @tmp1;
2615 my @tmp2;
2616 my $x;
2617
2618 if (-e $tcfile)
2619 {
2620 open(TC, $tcfile);
2621 @old = <TC>;
2622 close(TC);
2623
2624 while (@old > 0)
2625 {
2626 $aggregated = 0;
2627 $x = shift(@old);
2628 chomp($x);
2629 @tmp1 = split(/\,/,$x);
2630 $tmp1[16] = '';
2631 foreach (@new)
2632 {
2633 @tmp2 = split(/\,/);
1465b127 2634 if (($tmp1[15] eq 'on') && ($tmp2[15] eq 'on'))
10e4f239
MT
2635 {
2636 if (($tmp1[0] eq $tmp2[0]) && ($tmp1[12] eq $tmp2[12]) && ($tmp1[13] eq $tmp2[13]) && ($tmp1[14] eq $tmp2[14]))
2637 {
2638 $aggregated = 1;
2639 $tmp2[16] .= " weekly ";
2640 if ($tmp1[1] eq 'on') { $tmp2[16] .= "m"; }
2641 if ($tmp1[2] eq 'on') { $tmp2[16] .= "t"; }
2642 if ($tmp1[3] eq 'on') { $tmp2[16] .= "w"; }
2643 if ($tmp1[4] eq 'on') { $tmp2[16] .= "h"; }
2644 if ($tmp1[5] eq 'on') { $tmp2[16] .= "f"; }
2645 if ($tmp1[6] eq 'on') { $tmp2[16] .= "a"; }
2646 if ($tmp1[7] eq 'on') { $tmp2[16] .= "s"; }
2647 $tmp2[16] .= " $tmp1[8]:$tmp1[9]-$tmp1[10]:$tmp1[11]\n";
2648 $_ = join(",",@tmp2);
2649 }
2650
2651 }
2652 }
2653 if (!$aggregated)
2654 {
2655 $tmp1[16] .= " weekly ";
2656 if ($tmp1[1] eq 'on') { $tmp1[16] .= "m"; }
2657 if ($tmp1[2] eq 'on') { $tmp1[16] .= "t"; }
2658 if ($tmp1[3] eq 'on') { $tmp1[16] .= "w"; }
2659 if ($tmp1[4] eq 'on') { $tmp1[16] .= "h"; }
2660 if ($tmp1[5] eq 'on') { $tmp1[16] .= "f"; }
2661 if ($tmp1[6] eq 'on') { $tmp1[16] .= "a"; }
2662 if ($tmp1[7] eq 'on') { $tmp1[16] .= "s"; }
2663 $tmp1[16] .= " $tmp1[8]:$tmp1[9]-$tmp1[10]:$tmp1[11]\n";
2664 $x = join(",",@tmp1);
2665 push(@new,$x);
2666 }
2667 }
2668 }
2669
2670 return @new;
2671
2672}
2673
2674# -------------------------------------------------------------------
2675
1465b127
MT
2676sub setpermissions
2677{
2678 my $bldir = $_[0];
2679
2680 foreach $category (<$bldir/*>)
2681 {
2682 if (-d $category){
2683 system("chmod 755 $category &> /dev/null");
2684 foreach $blacklist (<$category/*>)
2685 {
2686 if (-f $blacklist) { system("chmod 644 $blacklist &> /dev/null"); }
2687 if (-d $blacklist) { system("chmod 755 $blacklist &> /dev/null"); }
2688 }
2689 system("chmod 666 $category/*.db &> /dev/null");
2690 &setpermissions ($category);
2691 }
2692 }
2693}
2694
2695# -------------------------------------------------------------------
2696
10e4f239
MT
2697sub writeconfigfile
2698{
2699 my $executables = "\\.\(ade|adp|asx|bas|bat|chm|com|cmd|cpl|crt|dll|eml|exe|hiv|hlp|hta|inc|inf|ins|isp|jse|jtd|lnk|msc|msh|msi|msp|mst|nws|ocx|oft|ops|pcd|pif|plx|reg|scr|sct|sha|shb|shm|shs|sys|tlb|tsp|url|vbe|vbs|vxd|wsc|wsf|wsh\)\$";
1465b127 2700 my $audiovideo = "\\.\(aiff|asf|avi|dif|divx|mov|movie|mp3|mpe?g?|mpv2|ogg|ra?m|snd|qt|wav|wma|wmf|wmv\)\$";
10e4f239
MT
2701 my $archives = "\\.\(bin|bz2|cab|cdr|dmg|gz|hqx|rar|smi|sit|sea|tar|tgz|zip\)\$";
2702
2703 my $ident = " anonymous";
2704
2705 my $defaultrule='';
2706 my $tcrule='';
2707 my $redirect='';
2708 my $qredirect='';
2709
2710 my $idx;
2711
2712 my @ec=();
2713 my @tc=();
2714 my @uq=();
2715
2716 if (!(-d "$dbdir/custom")) { mkdir("$dbdir/custom") }
2717 if (!(-d "$dbdir/custom/blocked")) { mkdir("$dbdir/custom/blocked") }
2718 if (!(-d "$dbdir/custom/allowed")) { mkdir("$dbdir/custom/allowed") }
2719
2720 open(FILE, ">/$dbdir/custom/blocked/domains");
2721 print FILE $filtersettings{'CUSTOM_BLACK_DOMAINS'};
2722 close(FILE);
2723 open(FILE, ">/$dbdir/custom/blocked/urls");
2724 print FILE $filtersettings{'CUSTOM_BLACK_URLS'};
2725 close(FILE);
2726 open(FILE, ">/$dbdir/custom/blocked/expressions");
2727 print FILE $filtersettings{'CUSTOM_EXPRESSIONS'};
2728 close(FILE);
2729 open(FILE, ">/$dbdir/custom/blocked/files");
2730 if ($filtersettings{'BLOCK_EXECUTABLES'} eq 'on') { print FILE "$executables\n"; }
2731 if ($filtersettings{'BLOCK_AUDIO-VIDEO'} eq 'on') { print FILE "$audiovideo\n"; }
2732 if ($filtersettings{'BLOCK_ARCHIVES'} eq 'on') { print FILE "$archives\n"; }
2733 close(FILE);
2734 open(FILE, ">/$dbdir/custom/allowed/domains");
2735 print FILE $filtersettings{'CUSTOM_WHITE_DOMAINS'};
2736 close(FILE);
2737 open(FILE, ">/$dbdir/custom/allowed/urls");
2738 print FILE $filtersettings{'CUSTOM_WHITE_URLS'};
2739 close(FILE);
2740
2741 if ($filtersettings{'ENABLE_USERNAME_LOG'} eq 'on') { $ident = ""; }
2742
2743 if ($filtersettings{'REDIRECT_PAGE'} eq '')
2744 {
2745 if (($filtersettings{'SHOW_CATEGORY'} eq 'on') || ($filtersettings{'SHOW_URL'} eq 'on') || ($filtersettings{'SHOW_IP'} eq 'on')) {
2746 if ($filtersettings{'SHOW_CATEGORY'} eq 'on') { $redirect .= "&category=%t"; }
2747 if ($filtersettings{'SHOW_URL'} eq 'on') { $redirect .= "&url=%u"; }
2748 if ($filtersettings{'SHOW_IP'} eq 'on') { $redirect .= "&ip=%a"; }
2749 $redirect =~ s/^&/?/;
d47ad587 2750 $redirect = "http:\/\/$netsettings{'GREEN_ADDRESS'}:$http_port\/redirect.cgi".$redirect;
10e4f239 2751 } else {
1465b127 2752 $redirect="http:\/\/$netsettings{'GREEN_ADDRESS'}:$http_port\/redirect.cgi";
10e4f239
MT
2753 }
2754 } else { $redirect=$filtersettings{'REDIRECT_PAGE'}; }
2755
2756 if ($filtersettings{'ENABLE_DNSERROR'} eq 'on') { $redirect = "302:http://0.0.0.0"; }
2757
2758 undef $defaultrule;
2759
2760 if ($filtersettings{'ENABLE_CUSTOM_WHITELIST'} eq 'on')
2761 {
2762 $defaultrule .= "custom-allowed ";
2763 }
2764 if ($filtersettings{'BLOCK_ALL'} eq 'on')
2765 {
2766 $defaultrule .= "none";
2767 }
2768 else
2769 {
2770 if ($filtersettings{'BLOCK_IP_ADDR'} eq 'on')
2771 {
2772 $defaultrule .= "!in-addr ";
2773 }
2774 for ($i=0; $i<=@filtergroups; $i++) {
2775 if ($filtersettings{@filtergroups[$i]} eq 'on')
2776 {
2777 $defaultrule .= "!@categories[$i] ";
2778 }
2779 }
2780 if ($filtersettings{'ENABLE_CUSTOM_BLACKLIST'} eq 'on')
2781 {
2782 $defaultrule .= "!custom-blocked ";
2783 }
2784 if ($filtersettings{'ENABLE_CUSTOM_EXPRESSIONS'} eq 'on')
2785 {
2786 $defaultrule .= "!custom-expressions ";
2787 }
2788 if (($filtersettings{'BLOCK_EXECUTABLES'} eq 'on') ||
2789 ($filtersettings{'BLOCK_AUDIO-VIDEO'} eq 'on') ||
2790 ($filtersettings{'BLOCK_ARCHIVES'} eq 'on'))
2791 {
2792 $defaultrule .= "!files ";
2793 }
2794 $defaultrule .= "any";
2795 }
2796
1465b127
MT
2797 $defaultrule =~ s/\//_/g;
2798
10e4f239
MT
2799 open(FILE, ">${General::swroot}/urlfilter/squidGuard.conf") or die "Unable to write squidGuard.conf file";
2800 flock(FILE, 2);
2801
2802 print FILE "logdir /var/log/squidGuard\n";
2803 print FILE "dbhome $dbdir\n\n";
2804
2805 undef @repositoryfiles;
2806 if ($filtersettings{'ENABLE_REWRITE'} eq 'on')
2807 {
2808 @repositorylist = <$repository/*>;
2809 foreach (@repositorylist)
2810 {
2811 if (!-d) { push(@repositoryfiles,substr($_,rindex($_,"/")+1)); }
2812 }
2813 }
2814
2815 if ((($filtersettings{'ENABLE_REWRITE'} eq 'on') && (@repositoryfiles)) || ($filtersettings{'ENABLE_SAFESEARCH'} eq 'on'))
2816 {
1465b127 2817 print FILE "rewrite rew-rule-1 {\n";
10e4f239
MT
2818
2819 if (($filtersettings{'ENABLE_REWRITE'} eq 'on') && (@repositoryfiles))
2820 {
2821 print FILE " # rewrite localfiles\n";
2822 foreach (@repositoryfiles)
2823 {
1465b127 2824 print FILE " s@.*/$_\$\@http://$netsettings{'GREEN_ADDRESS'}:$http_port/repository/$_\@i\n";
10e4f239
MT
2825 }
2826 }
2827
2828 if ($filtersettings{'ENABLE_SAFESEARCH'} eq 'on')
2829 {
2830 print FILE " # rewrite safesearch\n";
2831 print FILE " s@(.*\\Wgoogle\\.\\w+/(webhp|search|imghp|images|grphp|groups|frghp|froogle)\\?)(.*)(\\bsafe=\\w+)(.*)\@\\1\\3safe=strict\\5\@i\n";
2832 print FILE " s@(.*\\Wgoogle\\.\\w+/(webhp|search|imghp|images|grphp|groups|frghp|froogle)\\?)(.*)\@\\1safe=strict\\\&\\3\@i\n";
2833 print FILE " s@(.*\\Wsearch\\.yahoo\\.\\w+/search\\W)(.*)(\\bvm=\\w+)(.*)\@\\1\\2vm=r\\4\@i\n";
2834 print FILE " s@(.*\\Wsearch\\.yahoo\\.\\w+/search\\W.*)\@\\1\\\&vm=r\@i\n";
2835 print FILE " s@(.*\\Walltheweb\\.com/customize\\?)(.*)(\\bcopt_offensive=\\w+)(.*)\@\\1\\2copt_offensive=on\\4\@i\n";
2836 }
2837
2838 print FILE "}\n\n";
2839
2840 if ((!($filtersettings{'UNFILTERED_CLIENTS'} eq '')) && ($filtersettings{'ENABLE_SAFESEARCH'} eq 'on')) {
1465b127 2841 print FILE "rewrite rew-rule-2 {\n";
10e4f239
MT
2842 if (($filtersettings{'ENABLE_REWRITE'} eq 'on') && (@repositoryfiles))
2843 {
2844 print FILE " # rewrite localfiles\n";
2845 foreach (@repositoryfiles)
2846 {
1465b127 2847 print FILE " s@.*/$_\$\@http://$netsettings{'GREEN_ADDRESS'}:$http_port/repository/$_\@i\n";
10e4f239
MT
2848 }
2849 } else {
2850 print FILE " # rewrite nothing\n";
2851 }
2852 print FILE "}\n\n";
2853 }
2854 }
2855
1465b127
MT
2856 if (!($filtersettings{'UNFILTERED_CLIENTS'} eq '')) {
2857 print FILE "src unfiltered {\n";
2858 print FILE " ip $filtersettings{'UNFILTERED_CLIENTS'}\n";
2859 print FILE "}\n\n";
2860 }
2861 if (!($filtersettings{'BANNED_CLIENTS'} eq '')) {
2862 print FILE "src banned {\n";
2863 print FILE " ip $filtersettings{'BANNED_CLIENTS'}\n";
2864 if ($filtersettings{'ENABLE_LOG'} eq 'on')
2865 {
2866 if ($filtersettings{'ENABLE_CATEGORY_LOG'} eq 'on')
2867 {
2868 print FILE " logfile ".$ident." banned.log\n";
2869 } else {
2870 print FILE " logfile ".$ident." urlfilter.log\n";
2871 }
2872 }
2873 print FILE "}\n\n";
2874 }
2875
10e4f239
MT
2876 if (-e $uqfile)
2877 {
2878 open(UQ, $uqfile);
2879 @uqlist = <UQ>;
2880 close(UQ);
2881
2882 if (@uqlist > 0)
2883 {
2884 $idx=0;
2885 foreach (@uqlist)
2886 {
2887 chomp;
2888 @uq = split(/\,/);
2889 if ($uq[4] eq 'on')
2890 {
2891 $idx++;
2892 $uq[0] = $uq[0] * 60;
2893 if ($uq[1] eq '0') {
2894 if ($uq[2] eq 'hourly') { $uq[1] = 3600 }
2895 if ($uq[2] eq 'daily') { $uq[1] = 86400 }
2896 if ($uq[2] eq 'weekly') { $uq[1] = 604800 }
2897 }
2898 $uq[3] =~ s/\|/ /g;
2899 print FILE "src quota-$idx {\n";
2900 print FILE " user $uq[3]\n";
2901 print FILE " userquota $uq[0] $uq[1] $uq[2]\n";
2902 print FILE "}\n\n";
2903 }
2904 }
2905
2906 }
2907 }
2908
2909 @tclist = &aggregatedconstraints;
2910
2911 if (@tclist > 0)
2912 {
2913 $idx=0;
2914 foreach (@tclist)
2915 {
2916 chomp;
2917 @tc = split(/\,/);
2918 if ($tc[15] eq 'on')
2919 {
2920 $idx++;
2921 print FILE "src network-$idx {\n";
1465b127
MT
2922 @clients = split(/ /,$tc[12]);
2923 @temp = split(/-/,$clients[0]);
2924 if ( (&General::validipormask($temp[0])) || (&General::validipandmask($temp[0])))
2925 {
2926 print FILE " ip $tc[12]\n";
2927 } else {
2928 print FILE " user";
2929 @clients = split(/ /,$tc[12]);
2930 foreach $line (@clients)
2931 {
2932 $line =~ s/(^\w+)\\(\w+$)/$1%5c$2/;
2933 print FILE " $line";
2934 }
2935 print FILE "\n";
2936 }
2937 if (($filtersettings{'ENABLE_LOG'} eq 'on') && ($tc[14] eq 'block') && ($tc[13] eq 'any'))
2938 {
2939 if ($filtersettings{'ENABLE_CATEGORY_LOG'} eq 'on')
2940 {
2941 print FILE " logfile ".$ident." timeconst.log\n";
2942 } else {
2943 print FILE " logfile ".$ident." urlfilter.log\n";
2944 }
2945 }
10e4f239
MT
2946 print FILE "}\n\n";
2947 }
2948 }
2949
2950 $idx=0;
2951 foreach (@tclist)
2952 {
2953 chomp;
2954 @tc = split(/\,/);
2955 if ($tc[15] eq 'on')
2956 {
2957 $idx++;
2958 print FILE "time constraint-$idx {\n";
2959 print FILE "$tc[16]\n";
2960 print FILE "}\n\n";
2961 }
2962 }
2963 }
2964
10e4f239 2965 foreach $category (@categories) {
1465b127
MT
2966 $blacklist = $category;
2967 $category =~ s/\//_/g;
8f451574
CS
2968
2969 if ( $filtersettings{"FILTER_".uc($category)} ne "on" ){
2970 my $constraintrule = "false";
2971
2972 foreach (@tclist){
2973 chomp;
2974 @tc = split(/\,/);
2975 $tc[13] =~ s/\//_/g;
2976 if ($tc[15] eq 'on' && $tc[13] =~ $category){
2977 $constraintrule = "true";
2978 }
2979 }
2980
2981 if ( $constraintrule eq "false"){
2982 next;
2983 }
2984 }
2985
10e4f239 2986 print FILE "dest $category {\n";
1465b127
MT
2987 if (-e "$dbdir/$blacklist/domains") {
2988 print FILE " domainlist $blacklist\/domains\n";
10e4f239 2989 }
1465b127
MT
2990 if (-e "$dbdir/$blacklist/urls") {
2991 print FILE " urllist $blacklist\/urls\n";
10e4f239 2992 }
1465b127
MT
2993 if ((-e "$dbdir/$blacklist/expressions") && ($filtersettings{'ENABLE_EXPR_LISTS'} eq 'on')) {
2994 print FILE " expressionlist $blacklist\/expressions\n";
10e4f239 2995 }
1465b127 2996 if ((($category eq 'ads') || ($category eq 'adv')) && ($filtersettings{'ENABLE_EMPTY_ADS'} eq 'on'))
10e4f239 2997 {
1465b127 2998 print FILE " redirect http:\/\/$netsettings{'GREEN_ADDRESS'}:$http_port\/images/urlfilter/1x1.gif\n";
10e4f239
MT
2999 }
3000 if ($filtersettings{'ENABLE_LOG'} eq 'on')
3001 {
3002 if ($filtersettings{'ENABLE_CATEGORY_LOG'} eq 'on')
3003 {
3004 print FILE " logfile $ident $category.log\n";
3005 } else {
3006 print FILE " logfile $ident urlfilter.log\n";
3007 }
3008 }
3009 print FILE "}\n\n";
1465b127 3010 $category = $blacklist;
10e4f239 3011 }
d47ad587 3012
10e4f239
MT
3013 print FILE "dest files {\n";
3014 print FILE " expressionlist custom\/blocked\/files\n";
3015 if ($filtersettings{'ENABLE_LOG'} eq 'on')
3016 {
3017 if ($filtersettings{'ENABLE_CATEGORY_LOG'} eq 'on')
3018 {
3019 print FILE " logfile $ident files.log\n";
3020 } else {
3021 print FILE " logfile $ident urlfilter.log\n";
3022 }
3023 }
3024 print FILE "}\n\n";
3025
3026 print FILE "dest custom-allowed {\n";
3027 print FILE " domainlist custom\/allowed\/domains\n";
3028 print FILE " urllist custom\/allowed\/urls\n";
3029 print FILE "}\n\n";
3030
3031 print FILE "dest custom-blocked {\n";
3032 print FILE " domainlist custom\/blocked\/domains\n";
3033 print FILE " urllist custom\/blocked\/urls\n";
3034 if ($filtersettings{'ENABLE_LOG'} eq 'on')
3035 {
3036 if ($filtersettings{'ENABLE_CATEGORY_LOG'} eq 'on')
3037 {
3038 print FILE " logfile $ident custom.log\n";
3039 } else {
3040 print FILE " logfile $ident urlfilter.log\n";
3041 }
3042 }
3043 print FILE "}\n\n";
3044
3045 print FILE "dest custom-expressions {\n";
3046 print FILE " expressionlist custom\/blocked\/expressions\n";
3047 if ($filtersettings{'ENABLE_LOG'} eq 'on')
3048 {
3049 if ($filtersettings{'ENABLE_CATEGORY_LOG'} eq 'on')
3050 {
3051 print FILE " logfile $ident custom.log\n";
3052 } else {
3053 print FILE " logfile $ident urlfilter.log\n";
3054 }
3055 }
3056 print FILE "}\n\n";
3057
3058 print FILE "acl {\n";
3059 if (!($filtersettings{'UNFILTERED_CLIENTS'} eq '')) {
3060 print FILE " unfiltered {\n";
3061 print FILE " pass all\n";
3062 if ($filtersettings{'ENABLE_SAFESEARCH'} eq 'on')
3063 {
1465b127 3064 print FILE " rewrite rew-rule-2\n";
10e4f239
MT
3065 }
3066 print FILE " }\n\n";
3067 }
3068 if (!($filtersettings{'BANNED_CLIENTS'} eq '')) {
3069 print FILE " banned {\n";
3070 print FILE " pass ";
3071 if (($filtersettings{'ENABLE_CUSTOM_WHITELIST'} eq 'on') && ($filtersettings{'ENABLE_GLOBAL_WHITELIST'} eq 'on'))
3072 {
3073 print FILE "custom-allowed ";
3074 }
3075 print FILE "none\n";
3076 print FILE " }\n\n";
3077 }
3078
3079 if (-s $uqfile)
3080 {
3081 open(UQ, $uqfile);
3082 @uqlist = <UQ>;
3083 close(UQ);
3084
3085 $idx=0;
3086 foreach (@uqlist)
3087 {
3088 chomp;
3089 @uq = split(/\,/);
3090 if ($uq[4] eq 'on')
3091 {
3092 $idx++;
3093 $qredirect = $redirect;
3094 $qredirect =~ s/\%t/\%q\%20-\%20\%i/;
3095 print FILE " quota-$idx {\n";
3096 print FILE " pass ";
3097 if (($filtersettings{'ENABLE_CUSTOM_WHITELIST'} eq 'on') && ($filtersettings{'ENABLE_GLOBAL_WHITELIST'} eq 'on'))
3098 {
3099 print FILE "custom-allowed ";
3100 }
3101 print FILE "none\n";
3102 unless ($redirect eq $qredirect) { print FILE " redirect $qredirect\n"; }
3103 print FILE " }\n\n";
3104 }
3105 }
3106 }
3107
3108 if (@tclist > 0)
3109 {
3110 $idx=0;
3111 foreach (@tclist)
3112 {
3113 chomp;
3114 @tc = split(/\,/);
3115 @ec = split(/\|/,$tc[13]);
1465b127 3116 foreach (@ec) { s/\//_/g; }
10e4f239
MT
3117 if ($tc[15] eq 'on')
3118 {
3119 $idx++;
3120 print FILE " network-$idx $tc[0] constraint-$idx {\n";
3121 print FILE " pass ";
3122
3123 if ($filtersettings{'BLOCK_ALL'} eq 'on')
3124 {
3125 if ($tc[14] eq 'block')
3126 {
3127 if ((@ec == 1) && ($ec[0] eq 'any')) {
3128 if (($filtersettings{'ENABLE_CUSTOM_WHITELIST'} eq 'on') && ($filtersettings{'ENABLE_GLOBAL_WHITELIST'} eq 'on'))
3129 {
3130 print FILE "custom-allowed ";
3131 }
3132 print FILE "none";
3133 } else {
3134 print FILE $defaultrule;
3135 }
3136 } else {
3137 foreach (@ec)
3138 {
3139 print FILE "$_ ";
3140 }
3141 print FILE $defaultrule unless ((@ec == 1) && ($ec[0] eq 'any'));
3142 }
3143 } else {
3144 if ($tc[14] eq 'block')
3145 {
3146 $tcrule = $defaultrule;
3147 if ($filtersettings{'ENABLE_CUSTOM_WHITELIST'} eq 'on') {
3148 $tcrule =~ s/custom-allowed //;
3149 print FILE "custom-allowed " unless ((@ec == 1) && ($ec[0] eq 'any') && ($filtersettings{'ENABLE_GLOBAL_WHITELIST'} eq 'off'));
3150 }
3151 if ((@ec == 1) && ($ec[0] eq 'any')) {
3152 print FILE "none";
3153 } else {
3154 foreach (@ec)
3155 {
3156 print FILE "!$_ " unless (index($defaultrule,"!".$_." ") ge 0);
3157 }
3158 }
3159 print FILE $tcrule unless ((@ec == 1) && ($ec[0] eq 'any'));
3160 } else {
3161 $tcrule = $defaultrule;
1465b127 3162 if ((@ec == 1) && ($ec[0] eq 'any'))
10e4f239 3163 {
1465b127
MT
3164 print FILE "any";
3165 } else {
3166 foreach (@ec)
3167 {
3168 $tcrule = "$_ ".$tcrule unless (index($defaultrule,"!".$_." ") ge 0);
3169 $tcrule =~ s/!$_ //;
3170 }
3171 print FILE $tcrule;
10e4f239 3172 }
10e4f239
MT
3173 }
3174 }
3175
3176 print FILE "\n";
3177
3178 print FILE " }\n\n";
3179 }
3180 }
3181 }
3182
3183 print FILE " default {\n";
3184 print FILE " pass $defaultrule\n";
3185 if (($filtersettings{'ENABLE_LOG'} eq 'on') && ($filtersettings{'BLOCK_ALL'} eq 'on'))
3186 {
3187 if ($filtersettings{'ENABLE_CATEGORY_LOG'} eq 'on')
3188 {
3189 print FILE " logfile".$ident." default.log\n";
3190 } else {
3191 print FILE " logfile".$ident." urlfilter.log\n";
3192 }
3193 }
3194 if ((($filtersettings{'ENABLE_REWRITE'} eq 'on') && (@repositoryfiles)) || ($filtersettings{'ENABLE_SAFESEARCH'} eq 'on'))
3195 {
1465b127 3196 print FILE " rewrite rew-rule-1\n";
10e4f239
MT
3197 }
3198 print FILE " redirect $redirect\n";
3199 print FILE " }\n";
3200 print FILE "}\n";
3201
3202 close FILE;
3203}
3204
3205# -------------------------------------------------------------------