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