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