Merge branch 'next' of ssh://arne_f@git.ipfire.org/pub/git/ipfire-2.x into next
[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'>$Lang::tr{'urlfilter example'}</td>
1218 <td colspan='2'>$Lang::tr{'urlfilter example ads'}</td>
1219 </tr>
1220 <tr>
1221 <td colspan='2' width='50%'><textarea name='CUSTOM_BLACK_DOMAINS' cols='32' rows='6' wrap='off'>
1222 END
1223 ;
1224
1225 print $filtersettings{'CUSTOM_BLACK_DOMAINS'};
1226
1227 print <<END
1228 </textarea></td>
1229 <td colspan='2' width='50%'><textarea name='CUSTOM_BLACK_URLS' cols='32' rows='6' wrap='off'>
1230 END
1231 ;
1232
1233 print $filtersettings{'CUSTOM_BLACK_URLS'};
1234
1235 print <<END
1236 </textarea></td>
1237 </tr>
1238 </table>
1239 <table width='100%'>
1240 <tr>
1241 <td class='base' width='25%'>$Lang::tr{'urlfilter enable custom blacklist'}:</td>
1242 <td><input type='checkbox' name='ENABLE_CUSTOM_BLACKLIST' $checked{'ENABLE_CUSTOM_BLACKLIST'}{'on'} /></td>
1243 <td>&nbsp;</td>
1244 <td>&nbsp;</td>
1245 </tr>
1246 </table>
1247 <hr size='1'>
1248 <table width='100%'>
1249 <tr>
1250 <td><b>$Lang::tr{'urlfilter custom whitelist'}</b></td>
1251 <td>&nbsp;</td>
1252 <td>&nbsp;</td>
1253 <td>&nbsp;</td>
1254 </tr>
1255 <tr>
1256 <td colspan='2'>$Lang::tr{'urlfilter allowed domains'}&nbsp;<img src='/blob.gif' alt='*' /></td>
1257 <td colspan='2'>$Lang::tr{'urlfilter allowed urls'}&nbsp;<img src='/blob.gif' alt='*' /></td>
1258 </tr>
1259 <tr>
1260 <td colspan='2'>$Lang::tr{'urlfilter example'}</td>
1261 <td colspan='2'>$Lang::tr{'urlfilter example ads'}</td>
1262 </tr>
1263 <tr>
1264 <td colspan='2' width='50%'><textarea name='CUSTOM_WHITE_DOMAINS' cols='32' rows='6' wrap='off'>
1265 END
1266 ;
1267
1268 print $filtersettings{'CUSTOM_WHITE_DOMAINS'};
1269
1270 print <<END
1271 </textarea></td>
1272 <td colspan='2' width='50%'><textarea name='CUSTOM_WHITE_URLS' cols='32' rows='6' wrap='off'>
1273 END
1274 ;
1275
1276 print $filtersettings{'CUSTOM_WHITE_URLS'};
1277
1278 print <<END
1279 </textarea></td>
1280 </tr>
1281 </table>
1282 <table width='100%'>
1283 <tr>
1284 <td class='base' width='25%'>$Lang::tr{'urlfilter enable custom whitelist'}:</td>
1285 <td><input type='checkbox' name='ENABLE_CUSTOM_WHITELIST' $checked{'ENABLE_CUSTOM_WHITELIST'}{'on'} /></td>
1286 <td>&nbsp;</td>
1287 <td>&nbsp;</td>
1288 </tr>
1289 </table>
1290 <hr size='1'>
1291 <table width='100%'>
1292 <tr>
1293 <td colspan='4'><b>$Lang::tr{'urlfilter custom expression list'}</b></td>
1294 </tr>
1295 <tr>
1296 <td colspan='4'>$Lang::tr{'urlfilter blocked expressions'}&nbsp;<img src='/blob.gif' alt='*' /></td>
1297 </tr>
1298 <tr>
1299 <td colspan='4'><textarea name='CUSTOM_EXPRESSIONS' cols='70' rows='3' wrap='off'>
1300 END
1301 ;
1302
1303 print $filtersettings{'CUSTOM_EXPRESSIONS'};
1304
1305 print <<END
1306 </textarea></td>
1307 </tr>
1308 <tr>
1309 <td class='base' width='25%'>$Lang::tr{'urlfilter enable custom expression list'}:</td>
1310 <td><input type='checkbox' name='ENABLE_CUSTOM_EXPRESSIONS' $checked{'ENABLE_CUSTOM_EXPRESSIONS'}{'on'} /></td>
1311 <td>&nbsp;</td>
1312 <td>&nbsp;</td>
1313 </tr>
1314 </table>
1315 <hr size='1'>
1316 <table width='100%'>
1317 <tr>
1318 <td colspan='4'><b>$Lang::tr{'urlfilter file ext block'}</b></td>
1319 </tr>
1320 <tr>
1321 <td width='25%' class='base'>$Lang::tr{'urlfilter block executables'}:</td>
1322 <td width='12%'><input type='checkbox' name='BLOCK_EXECUTABLES' $checked{'BLOCK_EXECUTABLES'}{'on'} /></td>
1323 <td width='25%' class='base'>$Lang::tr{'urlfilter block audio-video'}:</td>
1324 <td><input type='checkbox' name='BLOCK_AUDIO-VIDEO' $checked{'BLOCK_AUDIO-VIDEO'}{'on'} /></td>
1325 </tr>
1326 <tr>
1327 <td class='base'>$Lang::tr{'urlfilter block archives'}:</td>
1328 <td><input type='checkbox' name='BLOCK_ARCHIVES' $checked{'BLOCK_ARCHIVES'}{'on'} /></td>
1329 <td>&nbsp;</td>
1330 <td>&nbsp;</td>
1331 </tr>
1332 </table>
1333 <hr size='1'>
1334 <table width='100%'>
1335 <tr>
1336 <td colspan='4'><b>$Lang::tr{'urlfilter local file redirection'}</b></td>
1337 </tr>
1338 <tr>
1339 <td width='25%' class='base'>$Lang::tr{'urlfilter enable rewrite rules'}:</td>
1340 <td width='12%'><input type='checkbox' name='ENABLE_REWRITE' $checked{'ENABLE_REWRITE'}{'on'} /></td>
1341 <td>&nbsp;</td>
1342 <td>&nbsp;</td>
1343 </tr>
1344 <tr>
1345 <td><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter manage repository'}'></td>
1346 <td>&nbsp;</td>
1347 <td>&nbsp;</td>
1348 <td>&nbsp;</td>
1349 </tr>
1350 </table>
1351 <hr size='1'>
1352 <table width='100%'>
1353 <tr>
1354 <td colspan='2'><b>$Lang::tr{'urlfilter network access control'}</b></td>
1355 <td>&nbsp;</td>
1356 <td>&nbsp;</td>
1357 </tr>
1358 <tr>
1359 <td colspan='2'>$Lang::tr{'urlfilter unfiltered clients'}&nbsp;<img src='/blob.gif' alt='*' /></td>
1360 <td colspan='2'>$Lang::tr{'urlfilter banned clients'}&nbsp;<img src='/blob.gif' alt='*' /></td>
1361 </tr>
1362 <tr>
1363 <td colspan='2' width='50%'><textarea name='UNFILTERED_CLIENTS' cols='32' rows='6' wrap='off'>
1364 END
1365 ;
1366
1367 # transform from pre1.8 client definitions
1368 $filtersettings{'UNFILTERED_CLIENTS'} =~ s/^\s+//g;
1369 $filtersettings{'UNFILTERED_CLIENTS'} =~ s/\s+$//g;
1370 $filtersettings{'UNFILTERED_CLIENTS'} =~ s/\s+-\s+/-/g;
1371 $filtersettings{'UNFILTERED_CLIENTS'} =~ s/\s+/ /g;
1372
1373 @clients = split(/ /,$filtersettings{'UNFILTERED_CLIENTS'});
1374 undef $filtersettings{'UNFILTERED_CLIENTS'};
1375 foreach (@clients) { $filtersettings{'UNFILTERED_CLIENTS'} .= "$_\n"; }
1376
1377 print $filtersettings{'UNFILTERED_CLIENTS'};
1378
1379 print <<END
1380 </textarea></td>
1381 <td colspan='2' width='50%'><textarea name='BANNED_CLIENTS' cols='32' rows='6' wrap='off'>
1382 END
1383 ;
1384
1385 # transform from pre1.8 client definitions
1386 $filtersettings{'BANNED_CLIENTS'} =~ s/^\s+//g;
1387 $filtersettings{'BANNED_CLIENTS'} =~ s/\s+$//g;
1388 $filtersettings{'BANNED_CLIENTS'} =~ s/\s+-\s+/-/g;
1389 $filtersettings{'BANNED_CLIENTS'} =~ s/\s+/ /g;
1390
1391 @clients = split(/ /,$filtersettings{'BANNED_CLIENTS'});
1392 undef $filtersettings{'BANNED_CLIENTS'};
1393 foreach (@clients) { $filtersettings{'BANNED_CLIENTS'} .= "$_\n"; }
1394
1395 print $filtersettings{'BANNED_CLIENTS'};
1396
1397 print <<END
1398 </textarea></td>
1399 </tr>
1400 </table>
1401 <hr size='1'>
1402 <table width='100%'>
1403 <tr>
1404 <td colspan='4'><b>$Lang::tr{'urlfilter timebased access control'}</b></td>
1405 </tr>
1406 <tr>
1407 <td width='25%'><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter set time constraints'}'></td>
1408 <td width='25%'><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter set user quota'}'></td>
1409 <td>&nbsp;</td>
1410 <td>&nbsp;</td>
1411 </tr>
1412 </table>
1413 <hr size='1'>
1414 <table width='100%'>
1415 <tr>
1416 <td colspan='4'><b>$Lang::tr{'urlfilter block settings'}</b></td>
1417 </tr>
1418 <tr>
1419 <td width='25%' class='base'>$Lang::tr{'urlfilter show category'}:</td>
1420 <td width='12%'><input type='checkbox' name='SHOW_CATEGORY' $checked{'SHOW_CATEGORY'}{'on'} /></td>
1421 <td width='25%' class='base'>$Lang::tr{'urlfilter redirectpage'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
1422 <td><input type='text' name='REDIRECT_PAGE' value='$filtersettings{'REDIRECT_PAGE'}' size='40' /></td>
1423 </tr>
1424 <tr>
1425 <td class='base'>$Lang::tr{'urlfilter show url'}:</td>
1426 <td><input type='checkbox' name='SHOW_URL' $checked{'SHOW_URL'}{'on'} /></td>
1427 <td class='base'>$Lang::tr{'urlfilter msg text 1'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
1428 <td><input type='text' name='MSG_TEXT_1' value='$filtersettings{'MSG_TEXT_1'}' size='40' /></td>
1429 </tr>
1430 <tr>
1431 <td class='base'>$Lang::tr{'urlfilter show ip'}:</td>
1432 <td><input type='checkbox' name='SHOW_IP' $checked{'SHOW_IP'}{'on'} /></td>
1433 <td class='base'>$Lang::tr{'urlfilter msg text 2'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
1434 <td><input type='text' name='MSG_TEXT_2' value='$filtersettings{'MSG_TEXT_2'}' size='40' /></td>
1435 </tr>
1436 <tr>
1437 <td class='base'>$Lang::tr{'urlfilter show dnserror'}:</td>
1438 <td><input type='checkbox' name='ENABLE_DNSERROR' $checked{'ENABLE_DNSERROR'}{'on'} /></td>
1439 <td class='base'>$Lang::tr{'urlfilter msg text 3'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
1440 <td><input type='text' name='MSG_TEXT_3' value='$filtersettings{'MSG_TEXT_3'}' size='40' /></td>
1441 </tr>
1442 </table>
1443 <hr size='1'>
1444 <table width='100%'>
1445 <tr>
1446 <td colspan='4'><b>$Lang::tr{'urlfilter advanced settings'}</b></td>
1447 </tr>
1448 <tr>
1449 <td width='25%' class='base'>$Lang::tr{'urlfilter enable expression lists'}:</td>
1450 <td width='12%'><input type='checkbox' name='ENABLE_EXPR_LISTS' $checked{'ENABLE_EXPR_LISTS'}{'on'} /></td>
1451 <td width='25%' class='base'>$Lang::tr{'urlfilter enable log'}:</td>
1452 <td><input type='checkbox' name='ENABLE_LOG' $checked{'ENABLE_LOG'}{'on'} /></td>
1453 </tr>
1454 <tr>
1455 <td class='base'>$Lang::tr{'urlfilter safesearch'}:</td>
1456 <td><input type='checkbox' name='ENABLE_SAFESEARCH' $checked{'ENABLE_SAFESEARCH'}{'on'} /></td>
1457 <td class='base'>$Lang::tr{'urlfilter username log'}:</td>
1458 <td><input type='checkbox' name='ENABLE_USERNAME_LOG' $checked{'ENABLE_USERNAME_LOG'}{'on'} /></td>
1459 </tr>
1460 <tr>
1461 <td class='base'>$Lang::tr{'urlfilter empty ads'}:</td>
1462 <td><input type='checkbox' name='ENABLE_EMPTY_ADS' $checked{'ENABLE_EMPTY_ADS'}{'on'} /></td>
1463 <td class='base'>$Lang::tr{'urlfilter category log'}:</td>
1464 <td><input type='checkbox' name='ENABLE_CATEGORY_LOG' $checked{'ENABLE_CATEGORY_LOG'}{'on'} /></td>
1465 </tr>
1466 <tr>
1467 <td class='base'>$Lang::tr{'urlfilter block ip'}:</td>
1468 <td><input type='checkbox' name='BLOCK_IP_ADDR' $checked{'BLOCK_IP_ADDR'}{'on'} /></td>
1469 </tr>
1470 <tr>
1471 <td class='base'>$Lang::tr{'urlfilter block all'}:</td>
1472 <td><input type='checkbox' name='BLOCK_ALL' $checked{'BLOCK_ALL'}{'on'} /></td>
1473 <td class='base'>$Lang::tr{'urlfilter whitelist always allowed'}:</td>
1474 <td><input type='checkbox' name='ENABLE_GLOBAL_WHITELIST' $checked{'ENABLE_GLOBAL_WHITELIST'}{'on'} /></td>
1475 </tr>
1476 </table>
1477 <hr size='1'>
1478 <table width='100%'>
1479 <tr>
1480 <td>
1481 <img src='/blob.gif' align='top' alt='*' />&nbsp;
1482 <font class='base'>$Lang::tr{'this field may be blank'}</font>
1483 </td>
1484 <td align='right'>&nbsp;
1485 </td>
1486 </tr>
1487 </table>
1488 <table width='100%'>
1489 <tr>
1490 <td>&nbsp;</td>
1491 <td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
1492 <td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter save and restart'}' /></td>
1493 <td>&nbsp;</td>
1494 </tr>
1495 </table>
1496 END
1497 ;
1498
1499 &Header::closebox();
1500
1501 print "</form>\n";
1502
1503 print "<form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'>\n";
1504
1505 &Header::openbox('100%', 'left', "$Lang::tr{'urlfilter maintenance'}:");
1506
1507 print <<END
1508 <table width='100%'>
1509 <tr>
1510 <td class='base'><b>$Lang::tr{'urlfilter blacklist update'}</b></td>
1511 </tr>
1512 <tr>
1513 <td>$Lang::tr{'urlfilter upload information'}<p>$Lang::tr{'urlfilter upload text'}:</td>
1514 </tr>
1515 <tr>
1516 <td><input type='file' name='UPDATEFILE' size='40' /> &nbsp; <input type='submit' name='ACTION' value='$Lang::tr{'urlfilter upload blacklist'}' /></td>
1517 </tr>
1518 </table>
1519
1520 <hr size='1'>
1521
1522 <table width='100%'>
1523 <tr>
1524 <td colspan='2' class='base'><b>$Lang::tr{'urlfilter automatic blacklist update'}</b>
1525 END
1526 ;
1527 if (-e "$updflagfile")
1528 {
1529 $blacklistage = int(-M "$updflagfile");
1530 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>";
1531 }
1532
1533 $updatesettings{'UPDATE_SCHEDULE'} = 'monthly';
1534 $updatesettings{'CUSTOM_UPDATE_URL'} = '';
1535
1536 if (-e "$updconffile") { &General::readhash("$updconffile", \%updatesettings); }
1537
1538 $checked{'ENABLE_AUTOUPDATE'}{'off'} = '';
1539 $checked{'ENABLE_AUTOUPDATE'}{'on'} = '';
1540 $checked{'ENABLE_AUTOUPDATE'}{$updatesettings{'ENABLE_AUTOUPDATE'}} = "checked='checked'";
1541
1542 $selected{'UPDATE_SCHEDULE'}{$updatesettings{'UPDATE_SCHEDULE'}} = "selected='selected'";
1543
1544 $selected{'UPDATE_SOURCE'}{$updatesettings{'UPDATE_SOURCE'}} = "selected='selected'";
1545
1546 print <<END
1547 </td>
1548 </tr>
1549 <tr>
1550 <td width='25%' class='base'>$Lang::tr{'urlfilter enable automatic blacklist update'}:</td>
1551 <td width='75%' class='base'><input type='checkbox' name='ENABLE_AUTOUPDATE' $checked{'ENABLE_AUTOUPDATE'}{'on'} /></td>
1552 </tr>
1553 <tr>
1554 <td class='base'>$Lang::tr{'urlfilter automatic update schedule'}:</td>
1555 <td class='base'>
1556 <select name='UPDATE_SCHEDULE'>
1557 <option value='daily' $selected{'UPDATE_SCHEDULE'}{'daily'}>$Lang::tr{'urlfilter daily'}</option>
1558 <option value='weekly' $selected{'UPDATE_SCHEDULE'}{'weekly'}>$Lang::tr{'urlfilter weekly'}</option>
1559 <option value='monthly' $selected{'UPDATE_SCHEDULE'}{'monthly'}>$Lang::tr{'urlfilter monthly'}</option>
1560 </select>
1561 </td>
1562 </tr>
1563 <tr>
1564 <td class='base'>$Lang::tr{'urlfilter select source'}:</td>
1565 <td class='base' colspan='2'>
1566 <select name='UPDATE_SOURCE'>
1567 END
1568 ;
1569
1570 foreach (@source_urllist) {
1571 chomp;
1572 $source_name = substr($_,0,rindex($_,","));
1573 $source_url = substr($_,index($_,",")+1);
1574 print "\t<option value='$source_url' $selected{'UPDATE_SOURCE'}{$source_url}>$source_name</option>\n";
1575 }
1576
1577 print <<END
1578 <option value='custom' $selected{'UPDATE_SOURCE'}{'custom'}>$Lang::tr{'urlfilter custom url'}</option>
1579 </select>
1580 </td>
1581 </tr>
1582 <tr>
1583 <td>$Lang::tr{'urlfilter custom url'}:</td>
1584 <td><input type='text' name='CUSTOM_UPDATE_URL' value='$updatesettings{'CUSTOM_UPDATE_URL'}' size='72' /></td>
1585 </tr>
1586 </table>
1587 <table width='100%'>
1588 <tr>
1589 <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>
1590 </tr>
1591 </table>
1592
1593 <hr size='1'>
1594
1595 <table width='100%'>
1596 <tr>
1597 <td class='base'><b>$Lang::tr{'urlfilter blacklist editor'}</b></td>
1598 </tr>
1599 <tr>
1600 <td>$Lang::tr{'urlfilter blacklist editor info'}</td>
1601 </tr>
1602 <tr>
1603 <td><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter blacklist editor'}' /></td>
1604 </tr>
1605 </table>
1606
1607 <hr size='1'>
1608
1609 <table width='100%'>
1610 <tr>
1611 <td colspan='4' class='base'><b>$Lang::tr{'urlfilter backup settings'}</b></td>
1612 </tr>
1613 <tr>
1614 <td width='25%' class='base'>$Lang::tr{'urlfilter enable full backup'}:</td>
1615 <td width='12%' class='base'><input type='checkbox' name='ENABLE_FULLBACKUP' $checked{'ENABLE_FULLBACKUP'}{'on'} /></td>
1616 <td>&nbsp;</td>
1617 <td>&nbsp;</td>
1618 </tr>
1619 <tr>
1620 <td colspan='4' class='base'><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter backup'}' /></td>
1621 </tr>
1622 </table>
1623
1624 <hr size='1'>
1625
1626 <table width='100%'>
1627 <tr>
1628 <td class='base'><b>$Lang::tr{'urlfilter restore settings'}</b></td>
1629 </tr>
1630 <tr>
1631 <td>$Lang::tr{'urlfilter restore text'}:</td>
1632 </tr>
1633 <tr>
1634 <td><input type='file' name='UPDATEFILE' size='40' /> &nbsp; <input type='submit' name='ACTION' value='$Lang::tr{'urlfilter restore'}' /></td>
1635 </tr>
1636 </table>
1637 </form>
1638 END
1639 ;
1640
1641 &Header::closebox();
1642
1643 } else {
1644
1645 #==========================================================
1646 #
1647 # Section: Manage Repository
1648 #
1649 #==========================================================
1650
1651 print "<form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'>\n";
1652
1653 &Header::openbox('100%', 'left', "$Lang::tr{'urlfilter manage local file repository'}:");
1654 print <<END
1655 <table width='100%'>
1656 <tr>
1657 <td>$Lang::tr{'urlfilter repository information'}<br><br></td>
1658 </tr>
1659 <tr>
1660 <td>$Lang::tr{'urlfilter upload file text'}:</td>
1661 </tr>
1662 <tr>
1663 <td><input type='file' name='UPLOADFILE' size='50' /> &nbsp; <input type='submit' name='ACTION' value='$Lang::tr{'urlfilter upload file'}' /></td>
1664 </tr>
1665 <tr>
1666 <td><br><b>$Lang::tr{'urlfilter upload file information 1'}:</b> $Lang::tr{'urlfilter upload file information 2'}</td>
1667 </tr>
1668 </table>
1669 <hr size='1'>
1670 <table width='100%'>
1671 <tr>
1672 <td><input type='button' name='return2main' value='$Lang::tr{'urlfilter back to main page'}' onClick='self.location.href="$ENV{'SCRIPT_NAME'}"'></td>
1673 </tr>
1674 </table>
1675 </form>
1676 END
1677 ;
1678
1679 &Header::closebox();
1680
1681 &Header::openbox('100%', 'left', "$Lang::tr{'urlfilter current files'}: </b>[$repository]");
1682
1683 @repositorylist = <$repository/*>;
1684
1685 undef @repositoryfiles;
1686 foreach (@repositorylist)
1687 {
1688 if (!-d) { push(@repositoryfiles,substr($_,rindex($_,"/")+1)); }
1689 }
1690
1691 if (@repositoryfiles)
1692 {
1693 print <<END
1694 <table width='100%'>
1695 <tr>
1696 <td align='center'><b>$Lang::tr{'urlfilter filename'}</b></td>
1697 <td width='15%' align='center'><b>$Lang::tr{'urlfilter filesize'}</b></td>
1698 <td width='10%'></td>
1699 </tr>
1700 END
1701 ;
1702 $id = 0;
1703 foreach $line (@repositoryfiles)
1704 {
1705 $id++;
1706 if ($id % 2) {
1707 print "<tr bgcolor='$Header::table1colour'>\n"; }
1708 else {
1709 print "<tr bgcolor='$Header::table2colour'>\n"; }
1710 $filesize = (-s "$repository/$line");
1711 1 while $filesize =~ s/^(-?\d+)(\d{3})/$1.$2/;
1712
1713 print <<END
1714 <td>&nbsp; &nbsp;$line</td>
1715 <td align='right'>$filesize&nbsp; &nbsp;</td>
1716
1717 <td align='center'>
1718 <form method='post' name='frma$id' action='$ENV{'SCRIPT_NAME'}'>
1719 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' title='$Lang::tr{'remove'}' alt='$Lang::tr{'remove'}' />
1720 <input type='hidden' name='ID' value='$line' />
1721 <input type='hidden' name='ACTION' value='$Lang::tr{'urlfilter remove file'}' />
1722 </form>
1723 </td>
1724
1725 </tr>
1726 END
1727 ;
1728 }
1729
1730 print <<END
1731 </table>
1732 <table>
1733 <tr>
1734 </tr>
1735 </table>
1736 <table>
1737 <tr>
1738 <td class='boldbase'>&nbsp; <b>$Lang::tr{'legend'}:</b></td>
1739 <td>&nbsp; &nbsp; <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
1740 <td class='base'>$Lang::tr{'remove'}</td>
1741 </tr>
1742 </table>
1743 END
1744 ;
1745 } else {
1746
1747 print "<i>$Lang::tr{'urlfilter empty repository'}</i>\n";
1748 }
1749
1750 &Header::closebox();
1751
1752 }
1753
1754 } elsif ($tcsettings{'TCMODE'}) {
1755
1756 #==========================================================
1757 #
1758 # Section: Set Time Constraints
1759 #
1760 #==========================================================
1761
1762 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
1763
1764 $buttontext = $Lang::tr{'urlfilter add rule'};
1765 if ($tcsettings{'ACTION'} eq $Lang::tr{'edit'}) {
1766 &Header::openbox('100%', 'left', $Lang::tr{'urlfilter edit time constraint rule'}.':');
1767 $buttontext = $Lang::tr{'urlfilter update rule'};
1768 } else {
1769 &Header::openbox('100%', 'left', $Lang::tr{'urlfilter add new time constraint rule'}.':');
1770 }
1771 print <<END
1772
1773 <table width='100%'>
1774 <tr>
1775 <td width='2%'>$Lang::tr{'urlfilter constraint definition'}</td>
1776 <td width='1%'>&nbsp;&nbsp;</td>
1777 <td width='2%' align='center'>$Lang::tr{'urlfilter monday'}</td>
1778 <td width='2%' align='center'>$Lang::tr{'urlfilter tuesday'}</td>
1779 <td width='2%' align='center'>$Lang::tr{'urlfilter wednesday'}</td>
1780 <td width='2%' align='center'>$Lang::tr{'urlfilter thursday'}</td>
1781 <td width='2%' align='center'>$Lang::tr{'urlfilter friday'}</td>
1782 <td width='2%' align='center'>$Lang::tr{'urlfilter saturday'}</td>
1783 <td width='2%' align='center'>$Lang::tr{'urlfilter sunday'}</td>
1784 <td width='1%'>&nbsp;&nbsp;</td>
1785 <td width='7%' colspan=3>$Lang::tr{'urlfilter from'}</td>
1786 <td width='1%'>&nbsp;</td>
1787 <td width='7%' colspan=3>$Lang::tr{'urlfilter to'}</td>
1788 <td>&nbsp;</td>
1789 </tr>
1790 <tr>
1791 <td class='base'>
1792 <select name='DEFINITION'>
1793 <option value='within' $selected{'DEFINITION'}{'within'}>$Lang::tr{'urlfilter constraint within'}</option>
1794 <option value='outside' $selected{'DEFINITION'}{'outside'}>$Lang::tr{'urlfilter constraint outside'}</option>
1795 </select>
1796 </td>
1797 <td>&nbsp;</td>
1798 <td class='base'><input type='checkbox' name='MON' $checked{'MON'}{'on'} /></td>
1799 <td class='base'><input type='checkbox' name='TUE' $checked{'TUE'}{'on'} /></td>
1800 <td class='base'><input type='checkbox' name='WED' $checked{'WED'}{'on'} /></td>
1801 <td class='base'><input type='checkbox' name='THU' $checked{'THU'}{'on'} /></td>
1802 <td class='base'><input type='checkbox' name='FRI' $checked{'FRI'}{'on'} /></td>
1803 <td class='base'><input type='checkbox' name='SAT' $checked{'SAT'}{'on'} /></td>
1804 <td class='base'><input type='checkbox' name='SUN' $checked{'SUN'}{'on'} /></td>
1805 <td>&nbsp;</td>
1806 <td class='base'>
1807 <select name='FROM_HOUR'>
1808 END
1809 ;
1810 for ($i=0;$i<=24;$i++) {
1811 $_ = sprintf("%02s",$i);
1812 print "<option $selected{'FROM_HOUR'}{$_}>$_</option>\n";
1813 }
1814 print <<END
1815 </select>
1816 </td>
1817 <td>:</td>
1818 <td class='base'>
1819 <select name='FROM_MINUTE'>
1820 END
1821 ;
1822 for ($i=0;$i<=45;$i+=15) {
1823 $_ = sprintf("%02s",$i);
1824 print "<option $selected{'FROM_MINUTE'}{$_}>$_</option>\n";
1825 }
1826 print <<END
1827 </select>
1828 <td> - </td>
1829 </td>
1830 <td class='base'>
1831 <select name='TO_HOUR'>
1832 END
1833 ;
1834 for ($i=0;$i<=24;$i++) {
1835 $_ = sprintf("%02s",$i);
1836 print "<option $selected{'TO_HOUR'}{$_}>$_</option>\n";
1837 }
1838 print <<END
1839 </select>
1840 </td>
1841 <td>:</td>
1842 <td class='base'>
1843 <select name='TO_MINUTE'>
1844 END
1845 ;
1846 for ($i=0;$i<=45;$i+=15) {
1847 $_ = sprintf("%02s",$i);
1848 print "<option $selected{'TO_MINUTE'}{$_}>$_</option>\n";
1849 }
1850 print <<END
1851 </select>
1852 </td>
1853 <td>&nbsp;</td>
1854 </tr>
1855 </table>
1856
1857 <br>
1858
1859 <table width='100%'>
1860 <tr>
1861 <td width='5%'>$Lang::tr{'urlfilter source'}</td>
1862 <td width='1%'>&nbsp;&nbsp;</td>
1863 <td width='5%'>$Lang::tr{'urlfilter dst'}&nbsp;<img src='/blob.gif' alt='*'><img src='/blob.gif' alt='*'></td>
1864 <td width='1%'>&nbsp;&nbsp;</td>
1865 <td width='5%'>$Lang::tr{'urlfilter access'}</td>
1866 <td>&nbsp;</td>
1867 </tr>
1868 <tr>
1869 <td rowspan='2'><textarea name='SRC' cols='28' rows='5' wrap='off'>
1870 END
1871 ;
1872
1873 # transform from pre1.8 client definitions
1874 $tcsettings{'SRC'} =~ s/^\s+//g;
1875 $tcsettings{'SRC'} =~ s/\s+$//g;
1876 $tcsettings{'SRC'} =~ s/\s+-\s+/-/g;
1877 $tcsettings{'SRC'} =~ s/\s+/ /g;
1878
1879 @clients = split(/ /,$tcsettings{'SRC'});
1880 undef $tcsettings{'SRC'};
1881 foreach (@clients) { $tcsettings{'SRC'} .= "$_\n"; }
1882
1883 print $tcsettings{'SRC'};
1884
1885 print <<END
1886 </textarea></td>
1887
1888 <td>&nbsp;</td>
1889 <td class='base' rowspan='2' valign='top'>
1890 <select name='DST' size='6' multiple>
1891 <option value='any' $selected{'DST'}{'any'} = "selected='selected'">$Lang::tr{'urlfilter category all'}</option>
1892 <option value='in-addr' $selected{'DST'}{'in-addr'} = "selected='selected'">in-addr</option>
1893 END
1894 ;
1895
1896 &readblockcategories;
1897 foreach (@categories)
1898 {
1899 print "<option value='$_' $selected{'DST'}{$_}>$_</option>\n";
1900 }
1901
1902 print <<END
1903 <option value='files' $selected{'DST'}{'files'} = "selected='selected'">files</option>
1904 <option value='custom-blocked' $selected{'DST'}{'custom-blocked'} = "selected='selected'">custom-blocked</option>
1905 <option value='custom-expressions' $selected{'DST'}{'custom-expressions'} = "selected='selected'">custom-expressions</option>
1906 </select>
1907 </td>
1908 <td>&nbsp;</td>
1909 <td class='base' valign='top'>
1910 <select name='ACCESS'>
1911 <option value='block' $selected{'ACCESS'}{'block'}>$Lang::tr{'urlfilter mode block'}</option>
1912 <option value='allow' $selected{'ACCESS'}{'allow'}>$Lang::tr{'urlfilter mode allow'}</option>
1913 </select>
1914 </td>
1915 <td>&nbsp;</td>
1916 </tr>
1917 <tr>
1918 <td>&nbsp;</td>
1919 <td>&nbsp;</td>
1920 <td>&nbsp;</td>
1921 <td>&nbsp;</td>
1922 </tr>
1923 <tr>
1924 <td>$Lang::tr{'remark'}&nbsp;<img src='/blob.gif' alt='*'></td>
1925 <td>&nbsp;</td>
1926 <td>&nbsp;</td>
1927 <td>&nbsp;</td>
1928 <td>&nbsp;</td>
1929 <td>&nbsp;</td>
1930 </tr>
1931 <tr>
1932 <td><input type='text' name='COMMENT' value='$tcsettings{'COMMENT'}' size='32' /></td>
1933 <td>&nbsp;</td>
1934 <td>&nbsp;</td>
1935 <td>&nbsp;</td>
1936 <td>&nbsp;</td>
1937 <td>&nbsp;</td>
1938 </tr>
1939 </table>
1940
1941 <table width='100%'>
1942 <tr>
1943 <td class='base'>$Lang::tr{'urlfilter enabled'}<input type='checkbox' name='ENABLERULE' $checked{'ENABLERULE'}{'on'} /></td>
1944 </tr>
1945 </table>
1946
1947 <p>
1948
1949 <table width='50%'>
1950 <tr>
1951 <td><input type='hidden' name='ACTION' value='$Lang::tr{'add'}' /></td>
1952 <td><input type='hidden' name='MODE' value='TIMECONSTRAINT' /></td>
1953 <td><input type='submit' name='SUBMIT' value='$buttontext' /></td>
1954 <td><input type='reset' name='ACTION' value='$Lang::tr{'urlfilter reset'}' /></td>
1955 <td>&nbsp;</td>
1956 <td><input type='button' name='return2main' value='$Lang::tr{'urlfilter back to main page'}' onClick='self.location.href="$ENV{'SCRIPT_NAME'}"'></td>
1957 </tr>
1958 </table>
1959 <p>
1960 <table width='100%'>
1961 <tr>
1962 <td width='1%' align='right'> <img src='/blob.gif' align='top' alt='*' />&nbsp;</td>
1963 <td><font class='base'>$Lang::tr{'this field may be blank'}</font></td>
1964 </tr>
1965 <tr>
1966 <td width='1%' align='right'><img src='/blob.gif' align='top' alt='*' /><img src='/blob.gif' align='top' alt='*' />&nbsp;</td>
1967 <td><font class='base'>$Lang::tr{'urlfilter select multi'}</font></td>
1968 </tr>
1969 </table>
1970 END
1971 ;
1972
1973 if ($tcsettings{'ACTION'} eq $Lang::tr{'edit'}) {
1974 print "<input type='hidden' name='EDITING' value='$tcsettings{'ID'}' />\n";
1975 } else {
1976 print "<input type='hidden' name='EDITING' value='no' />\n";
1977 }
1978
1979 &Header::closebox();
1980 print "</form>\n";
1981
1982 &Header::openbox('100%', 'left', $Lang::tr{'current rules'});
1983 print <<END
1984 <table width='100%'>
1985 <tr>
1986 <td width='5%' class='boldbase' align='center'><b>$Lang::tr{'urlfilter constraint definition'}</b></td>
1987 <td width='10%' class='boldbase' align='center'><b>$Lang::tr{'urlfilter time space'}</b></td>
1988 <td width='15%' class='boldbase' align='center'><b>$Lang::tr{'urlfilter src'}</b></td>
1989 <td width='5%' class='boldbase' align='center'><b>$Lang::tr{'urlfilter dst'}</b></td>
1990 <td width='10%' class='boldbase' colspan='5' align='center'>&nbsp;</td>
1991 </tr>
1992 END
1993 ;
1994
1995 if ($tcsettings{'ACTION'} ne '' or $changed ne 'no')
1996 {
1997 open(FILE, $tcfile);
1998 @tclist = <FILE>;
1999 close(FILE);
2000 }
2001
2002 $id = 0;
2003 foreach $line (@tclist)
2004 {
2005 $id++;
2006 chomp($line);
2007 @temp = split(/\,/,$line);
2008 if($tcsettings{'ACTION'} eq $Lang::tr{'edit'} && $tcsettings{'ID'} eq $id) {
2009 print "<tr bgcolor='$Header::colouryellow'>\n"; }
2010 elsif ($id % 2) {
2011 print "<tr bgcolor='$Header::table1colour'>\n"; }
2012 else {
2013 print "<tr bgcolor='$Header::table2colour'>\n"; }
2014 if ($temp[0] eq 'within') { $temp[0]=$Lang::tr{'urlfilter constraint within'}; } else { $temp[0]=$Lang::tr{'urlfilter constraint outside'}; }
2015 if ($temp[13] eq 'any') { $temp[13]=$Lang::tr{'urlfilter category all'}; }
2016 if ($temp[15] eq 'on') { $gif='on.gif'; $toggle='off'; $gdesc=$Lang::tr{'click to disable'};}
2017 else { $gif='off.gif'; $toggle='on'; $gdesc=$Lang::tr{'click to enable'}; }
2018 if ($temp[14] eq 'block') { $led='led-red.gif'; $ldesc=$Lang::tr{'urlfilter block access'};}
2019 else { $led='led-green.gif'; $ldesc=$Lang::tr{'urlfilter allow access'}; }
2020
2021 undef $time;
2022 if ($temp[1] eq 'on') { $time.=$Lang::tr{'urlfilter mon'}; } else { $time.='='; }
2023 if ($temp[2] eq 'on') { $time.=$Lang::tr{'urlfilter tue'}; } else { $time.='='; }
2024 if ($temp[3] eq 'on') { $time.=$Lang::tr{'urlfilter wed'}; } else { $time.='='; }
2025 if ($temp[4] eq 'on') { $time.=$Lang::tr{'urlfilter thu'}; } else { $time.='='; }
2026 if ($temp[5] eq 'on') { $time.=$Lang::tr{'urlfilter fri'}; } else { $time.='='; }
2027 if ($temp[6] eq 'on') { $time.=$Lang::tr{'urlfilter sat'}; } else { $time.='='; }
2028 if ($temp[7] eq 'on') { $time.=$Lang::tr{'urlfilter sun'}; } else { $time.='='; }
2029 $time=$time.' &nbsp; '.$temp[8].':'.$temp[9].' to '.$temp[10].':'.$temp[11];
2030
2031 print <<END
2032 <td align='center'>$temp[0]</td>
2033 <td align='center' nowrap>$time</td>
2034 <td align='center'>$temp[12]</td>
2035 <td align='center'>$temp[13]</td>
2036 <td align='center'><image src='/images/urlfilter/$led' alt='$ldesc'></td>
2037
2038 <td align='center'>
2039 <form method='post' name='frma$id' action='$ENV{'SCRIPT_NAME'}'>
2040 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' title='$gdesc' alt='$gdesc' />
2041 <input type='hidden' name='MODE' value='TIMECONSTRAINT' />
2042 <input type='hidden' name='ID' value='$id' />
2043 <input type='hidden' name='ACTIVE' value='$toggle' />
2044 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
2045 </form>
2046 </td>
2047
2048 <td align='center'>
2049 <form method='post' name='frmb$id' action='$ENV{'SCRIPT_NAME'}'>
2050 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' title='$Lang::tr{'edit'}' alt='$Lang::tr{'edit'}' />
2051 <input type='hidden' name='MODE' value='TIMECONSTRAINT' />
2052 <input type='hidden' name='ID' value='$id' />
2053 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' />
2054 </form>
2055 </td>
2056
2057 <td align='center'>
2058 <form method='post' name='frmc$id' action='$ENV{'SCRIPT_NAME'}'>
2059 <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'}' />
2060 <input type='hidden' name='MODE' value='TIMECONSTRAINT' />
2061 <input type='hidden' name='ID' value='$id' />
2062 <input type='hidden' name='ACTION' value='$Lang::tr{'urlfilter copy rule'}' />
2063 </form>
2064 </td>
2065
2066 <td align='center'>
2067 <form method='post' name='frmd$id' action='$ENV{'SCRIPT_NAME'}'>
2068 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' title='$Lang::tr{'remove'}' alt='$Lang::tr{'remove'}' />
2069 <input type='hidden' name='MODE' value='TIMECONSTRAINT' />
2070 <input type='hidden' name='ID' value='$id' />
2071 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' />
2072 </form>
2073 </td>
2074
2075 </tr>
2076 END
2077 ;
2078 if($tcsettings{'ACTION'} eq $Lang::tr{'edit'} && $tcsettings{'ID'} eq $id) {
2079 print "<tr bgcolor='$Header::colouryellow'>\n"; }
2080 elsif ($id % 2) {
2081 print "<tr bgcolor='$Header::table1colour'>\n"; }
2082 else {
2083 print "<tr bgcolor='$Header::table2colour'>\n"; }
2084 print <<END
2085 <td align='center' colspan='4'>$temp[16]
2086 </td>
2087 <td align='center' colspan='5'>
2088 </td>
2089 </tr>
2090 END
2091 ;
2092 }
2093
2094 print "</table>\n";
2095
2096 # If the time constraint file contains entries, print entries and action icons
2097 if (! -z "$tcfile") {
2098 print <<END
2099
2100 <table>
2101 <tr>
2102 <td class='boldbase'>&nbsp; <b>$Lang::tr{'legend'}:</b></td>
2103 <td>&nbsp; &nbsp; <img src='/images/urlfilter/led-green.gif' alt='$Lang::tr{'urlfilter allow access'}' /></td>
2104 <td class='base'>$Lang::tr{'urlfilter allow'}</td>
2105 <td>&nbsp; &nbsp; <img src='/images/urlfilter/led-red.gif' alt='$Lang::tr{'urlfilter block access'}' /></td>
2106 <td class='base'>$Lang::tr{'urlfilter block'}</td>
2107 <td>&nbsp; <img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
2108 <td class='base'>$Lang::tr{'click to disable'}</td>
2109 <td>&nbsp; &nbsp; <img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td>
2110 <td class='base'>$Lang::tr{'click to enable'}</td>
2111 <td>&nbsp; &nbsp; <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
2112 <td class='base'>$Lang::tr{'edit'}</td>
2113 <td>&nbsp; &nbsp; <img src='/images/urlfilter/copy.gif' alt='$Lang::tr{'urlfilter copy rule'}' /></td>
2114 <td class='base'>$Lang::tr{'urlfilter copy rule'}</td>
2115 <td>&nbsp; &nbsp; <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
2116 <td class='base'>$Lang::tr{'remove'}</td>
2117 </tr>
2118 </table>
2119 END
2120 ;
2121 }
2122
2123 &Header::closebox();
2124
2125 } elsif ($uqsettings{'UQMODE'}) {
2126
2127 #==========================================================
2128 #
2129 # Section: Set User Quota
2130 #
2131 #==========================================================
2132
2133 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
2134
2135 $buttontext = $Lang::tr{'urlfilter add rule'};
2136 if ($uqsettings{'ACTION'} eq $Lang::tr{'edit'}) {
2137 &Header::openbox('100%', 'left', $Lang::tr{'urlfilter edit user quota rule'}.':');
2138 $buttontext = $Lang::tr{'urlfilter update rule'};
2139 } else {
2140 &Header::openbox('100%', 'left', $Lang::tr{'urlfilter add new user quota rule'}.':');
2141 }
2142 print <<END
2143
2144 <table width='100%'>
2145 <tr>
2146 <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td>
2147 </tr>
2148 <tr>
2149 <td class='base'>$Lang::tr{'urlfilter user time quota'}:</td>
2150 <td><input type='text' name='TIME_QUOTA' value='$uqsettings{'TIME_QUOTA'}' size='5' /></td>
2151 <td colspan='2' rowspan= '5' valign='top' class='base'>
2152 <table cellpadding='0' cellspacing='0'>
2153 <tr>
2154 <!-- intentionally left empty -->
2155 </tr>
2156 <tr>
2157 <td>$Lang::tr{'urlfilter assigned quota users'}:</td>
2158 </tr>
2159 <tr>
2160 <!-- intentionally left empty -->
2161 </tr>
2162 <tr>
2163 <!-- intentionally left empty -->
2164 </tr>
2165 <tr>
2166 <td><textarea name='QUOTA_USERS' cols='32' rows='6' wrap='off'>
2167 END
2168 ;
2169
2170 $uqsettings{'QUOTA_USERS'} =~ s/\|/\n/g;
2171 print $uqsettings{'QUOTA_USERS'};
2172
2173 print <<END
2174 </textarea></td>
2175 </tr>
2176 </table>
2177 </td>
2178 </tr>
2179 <tr>
2180 <td class='base'>$Lang::tr{'urlfilter activity detection'}:</td>
2181 <td class='base'><select name='SPORADIC'>
2182 <option value='0' $selected{'SPORADIC'}{'0'}>$Lang::tr{'urlfilter disabled'}</option>
2183 <option value='300' $selected{'SPORADIC'}{'300'}>5 $Lang::tr{'urlfilter minutes'}</option>
2184 <option value='900' $selected{'SPORADIC'}{'900'}>15 $Lang::tr{'urlfilter minutes'}</option>
2185 </select></td>
2186 </tr>
2187 <tr>
2188 <td class='base'>$Lang::tr{'urlfilter renewal period'}:</td>
2189 <td class='base'><select name='RENEWAL'>
2190 <option value='hourly' $selected{'RENEWAL'}{'hourly'}>$Lang::tr{'urlfilter hourly'}</option>
2191 <option value='daily' $selected{'RENEWAL'}{'daily'}>$Lang::tr{'urlfilter daily'}</option>
2192 <option value='weekly' $selected{'RENEWAL'}{'weekly'}>$Lang::tr{'urlfilter weekly'}</option>
2193 </select></td>
2194 </tr>
2195 <tr>
2196 <td colspan='2'>&nbsp;</td>
2197 </tr>
2198 <tr>
2199 <td class='base'>$Lang::tr{'urlfilter enabled'}</td>
2200 <td class='base'><input type='checkbox' name='ENABLEQUOTA' $checked{'ENABLEQUOTA'}{'on'} /></td>
2201 </tr>
2202
2203 </table>
2204 <p>
2205
2206 <table width='50%'>
2207 <tr>
2208 <td><input type='hidden' name='ACTION' value='$Lang::tr{'add'}' /></td>
2209 <td><input type='hidden' name='MODE' value='USERQUOTA' /></td>
2210 <td><input type='submit' name='SUBMIT' value='$buttontext' /></td>
2211 <td><input type='reset' name='ACTION' value='$Lang::tr{'urlfilter reset'}' /></td>
2212 <td>&nbsp;</td>
2213 <td><input type='button' name='return2main' value='$Lang::tr{'urlfilter back to main page'}' onClick='self.location.href="$ENV{'SCRIPT_NAME'}"'></td>
2214 </tr>
2215 </table>
2216
2217 <p>
2218 END
2219 ;
2220
2221 if ($uqsettings{'ACTION'} eq $Lang::tr{'edit'}) {
2222 print "<input type='hidden' name='EDITING' value='$uqsettings{'ID'}' />\n";
2223 } else {
2224 print "<input type='hidden' name='EDITING' value='no' />\n";
2225 }
2226
2227 &Header::closebox();
2228 print "</form>\n";
2229
2230 &Header::openbox('100%', 'left', $Lang::tr{'current rules'});
2231 print <<END
2232 <table width='100%'>
2233 <tr>
2234 <td width='15%' class='boldbase' align='center'><b><nobr>$Lang::tr{'urlfilter time quota'}</nobr></b></td>
2235 <td width='15%' class='boldbase' align='center'><b><nobr>$Lang::tr{'urlfilter activity detection'}</nobr></b></td>
2236 <td width='10%' class='boldbase' align='center'><b>$Lang::tr{'urlfilter renewal'}</b></td>
2237 <td class='boldbase' align='center'><b>$Lang::tr{'urlfilter assigned users'}</b></td>
2238 <td width='20%' class='boldbase' colspan='4' align='center'>&nbsp;</td>
2239 </tr>
2240 END
2241 ;
2242
2243 if ($uqsettings{'ACTION'} ne '' or $changed ne 'no')
2244 {
2245 open(FILE, $uqfile);
2246 @uqlist = <FILE>;
2247 close(FILE);
2248 }
2249
2250 $id = 0;
2251 foreach $line (@uqlist)
2252 {
2253 $id++;
2254 chomp($line);
2255 @temp = split(/\,/,$line);
2256 if($uqsettings{'ACTION'} eq $Lang::tr{'edit'} && $uqsettings{'ID'} eq $id) {
2257 print "<tr bgcolor='$Header::colouryellow'>\n"; }
2258 elsif ($id % 2) {
2259 print "<tr bgcolor='$Header::table1colour'>\n"; }
2260 else {
2261 print "<tr bgcolor='$Header::table2colour'>\n"; }
2262 if ($temp[4] eq 'on') { $gif='on.gif'; $toggle='off'; $gdesc=$Lang::tr{'click to disable'};}
2263 else { $gif='off.gif'; $toggle='on'; $gdesc=$Lang::tr{'click to enable'}; }
2264
2265 $temp[5] = $temp[1];
2266 if ($temp[1] eq '0') { $temp[5] = $Lang::tr{'urlfilter disabled'} } else { $temp[5] = ($temp[5]/60).' '.$Lang::tr{'urlfilter minutes'} }
2267 $_ = $temp[3]; s/\|/, /g; $temp[6] = $_;
2268
2269 print <<END
2270 <td align='center'>$temp[0] $Lang::tr{'urlfilter minutes'}</td>
2271 <td align='center'>$temp[5]</td>
2272 <td align='center'>$Lang::tr{'urlfilter '.$temp[2]}</td>
2273 <td align='center'>$temp[6]</td>
2274
2275 <td align='center'>
2276 <form method='post' name='frma$id' action='$ENV{'SCRIPT_NAME'}'>
2277 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' title='$gdesc' alt='$gdesc' />
2278 <input type='hidden' name='MODE' value='USERQUOTA' />
2279 <input type='hidden' name='ID' value='$id' />
2280 <input type='hidden' name='ACTIVE' value='$toggle' />
2281 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
2282 </form>
2283 </td>
2284
2285 <td align='center'>
2286 <form method='post' name='frmb$id' action='$ENV{'SCRIPT_NAME'}'>
2287 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' title='$Lang::tr{'edit'}' alt='$Lang::tr{'edit'}' />
2288 <input type='hidden' name='MODE' value='USERQUOTA' />
2289 <input type='hidden' name='ID' value='$id' />
2290 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' />
2291 </form>
2292 </td>
2293
2294 <td align='center'>
2295 <form method='post' name='frmc$id' action='$ENV{'SCRIPT_NAME'}'>
2296 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' title='$Lang::tr{'remove'}' alt='$Lang::tr{'remove'}' />
2297 <input type='hidden' name='MODE' value='USERQUOTA' />
2298 <input type='hidden' name='ID' value='$id' />
2299 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' />
2300 </form>
2301 </td>
2302
2303 </tr>
2304 END
2305 ;
2306 }
2307
2308 print "</table>\n";
2309
2310 # If the user quota file contains entries, print entries and action icons
2311 if (! -z "$uqfile") {
2312 print <<END
2313
2314 <table>
2315 <tr>
2316 <td class='boldbase'>&nbsp; <b>$Lang::tr{'legend'}:</b></td>
2317 <td>&nbsp; <img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
2318 <td class='base'>$Lang::tr{'click to disable'}</td>
2319 <td>&nbsp; &nbsp; <img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td>
2320 <td class='base'>$Lang::tr{'click to enable'}</td>
2321 <td>&nbsp; &nbsp; <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
2322 <td class='base'>$Lang::tr{'edit'}</td>
2323 <td>&nbsp; &nbsp; <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
2324 <td class='base'>$Lang::tr{'remove'}</td>
2325 </tr>
2326 </table>
2327 END
2328 ;
2329 }
2330
2331 &Header::closebox();
2332
2333 } else {
2334
2335 #==========================================================
2336 #
2337 # Section: Blacklist editor
2338 #
2339 #==========================================================
2340
2341 print "<form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'>\n";
2342
2343 &Header::openbox('100%', 'left', $Lang::tr{'urlfilter urlfilter blacklist editor'}.':');
2344
2345 print <<END
2346
2347 <table width='100%'>
2348 <tr>
2349 <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td>
2350 </tr>
2351 <tr>
2352 <td class='base'><b>$Lang::tr{'urlfilter blacklist name'}</b></td>
2353 </tr>
2354 <tr>
2355 <td class='base'>$Lang::tr{'urlfilter blacklist category name'}:</td>
2356 <td><input type='text' name='BE_NAME' value='$besettings{'BE_NAME'}' size='12' /></td>
2357 </tr>
2358 </table>
2359 <hr size='1'>
2360 <table width='100%'>
2361 <tr>
2362 <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='20%'></td>
2363 </tr>
2364 <tr>
2365 <td class='base' colspan='4'><b>$Lang::tr{'urlfilter edit domains urls expressions'}</b></td>
2366 </tr>
2367 <tr>
2368 <td colspan='2'>$Lang::tr{'urlfilter domains'}</td>
2369 <td colspan='2'>$Lang::tr{'urlfilter urls'}</td>
2370 </tr>
2371 <tr>
2372 <td colspan='2'><textarea name='BE_DOMAINS' cols='38' rows='10' wrap='off'>
2373 END
2374 ;
2375
2376 print $besettings{'BE_DOMAINS'};
2377
2378 print <<END
2379 </textarea></td>
2380 <td colspan='2'><textarea name='BE_URLS' cols='38' rows='10' wrap='off'>
2381 END
2382 ;
2383
2384 print $besettings{'BE_URLS'};
2385
2386 print <<END
2387 </textarea></td>
2388 </tr>
2389 <tr>
2390 <td colspan='4'>$Lang::tr{'urlfilter expressions'}</td>
2391 </tr>
2392 <tr>
2393 <td colspan='4'><textarea name='BE_EXPRESSIONS' cols='80' rows='3' wrap='off'>
2394 END
2395 ;
2396
2397 print $besettings{'BE_EXPRESSIONS'};
2398
2399 print <<END
2400 </textarea></td>
2401 </tr>
2402 </table>
2403 <hr size='1'>
2404 <table width='100%'>
2405 <tr>
2406 <td class='base' colspan='4'><b>$Lang::tr{'urlfilter load blacklist'}</b></td>
2407 </tr>
2408 <tr>
2409 <td width='25%' class='base'>$Lang::tr{'urlfilter select blacklist'}:</td>
2410 <td width='20%' class='base'>
2411 <select name='BE_BLACKLIST'>
2412 END
2413 ;
2414
2415 &readblockcategories;
2416 foreach (@categories)
2417 {
2418 print "<option value='$_' $selected{'BE_BLACKLIST'}{$_}>$_</option>\n";
2419 }
2420
2421 print <<END
2422 </select>
2423 </td>
2424 <td>&nbsp;</td>
2425 <td>&nbsp;</td>
2426 <tr>
2427 <td colpsan='4'><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter load blacklist'}' /></td>
2428 </tr>
2429 </tr>
2430 </table>
2431 <hr size='1'>
2432 <table width='100%'>
2433 <tr>
2434 <td class='base' colspan='4'><b>$Lang::tr{'urlfilter import blacklist'}</b></td>
2435 </tr>
2436 <tr>
2437 <td colspan='4'>$Lang::tr{'urlfilter import text'}:</td>
2438 </tr>
2439 <tr>
2440 <td nowrap><input type='file' name='IMPORTFILE' size='40' /> &nbsp; <input type='submit' name='ACTION' value='$Lang::tr{'urlfilter import blacklist'}' /></td>
2441 <td><input type='hidden' name='MODE' value='BLACKLIST_EDITOR' /></td>
2442 </tr>
2443 </table>
2444 <hr size='1'>
2445 <table width='100%'>
2446 <tr>
2447 <td class='base' colspan='4'><b>$Lang::tr{'urlfilter export blacklist'}</b></td>
2448 </tr>
2449 <tr>
2450 <td><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter export blacklist'}' /></td>
2451 </tr>
2452 </table>
2453 <hr size='1'>
2454 <table width='100%'>
2455 <tr>
2456 <td class='base' colspan='4'><b>$Lang::tr{'urlfilter install blacklist'}</b></td>
2457 </tr>
2458 <tr>
2459 <td width='25%' class='base'>$Lang::tr{'urlfilter dont restart urlfilter'}:</td>
2460 <td width='20%' class='base'><input type='checkbox' name='NORESTART' $checked{'NORESTART'}{'on'} /></td>
2461 <td>&nbsp;</td>
2462 <td>&nbsp;</td>
2463 </tr>
2464 <tr>
2465 <td><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter install blacklist'}' /></td>
2466 </tr>
2467 <tr>
2468 <td class='base' colspan='4'><br>$Lang::tr{'urlfilter install information'}</td>
2469 </tr>
2470 </table>
2471 <hr size='1'>
2472 <table width='20%'>
2473 <tr>
2474 <td><input type='reset' name='ACTION' value='$Lang::tr{'urlfilter reset'}' /></td>
2475 <td>&nbsp;</td>
2476 <td><input type='button' name='return2main' value='$Lang::tr{'urlfilter back to main page'}' onClick='self.location.href="$ENV{'SCRIPT_NAME'}"'></td>
2477 </tr>
2478 </table>
2479
2480 END
2481 ;
2482
2483 &Header::closebox();
2484 print "</form>\n";
2485
2486 }
2487
2488 &Header::closebigbox();
2489
2490 &Header::closepage();
2491
2492 # -------------------------------------------------------------------
2493
2494 sub savesettings
2495 {
2496 # transform to pre1.8 client definitions
2497 @clients = split(/\n/,$filtersettings{'UNFILTERED_CLIENTS'});
2498 undef $filtersettings{'UNFILTERED_CLIENTS'};
2499 foreach(@clients)
2500 {
2501 s/^\s+//g; s/\s+$//g; s/\s+-\s+/-/g; s/\s+/ /g; s/\n//g;
2502 $filtersettings{'UNFILTERED_CLIENTS'} .= "$_ ";
2503 }
2504 $filtersettings{'UNFILTERED_CLIENTS'} =~ s/\s+$//;
2505
2506 # transform to pre1.8 client definitions
2507 @clients = split(/\n/,$filtersettings{'BANNED_CLIENTS'});
2508 undef $filtersettings{'BANNED_CLIENTS'};
2509 foreach(@clients)
2510 {
2511 s/^\s+//g; s/\s+$//g; s/\s+-\s+/-/g; s/\s+/ /g; s/\n//g;
2512 $filtersettings{'BANNED_CLIENTS'} .= "$_ ";
2513 }
2514 $filtersettings{'BANNED_CLIENTS'} =~ s/\s+$//;
2515
2516 &writeconfigfile;
2517
2518 delete $filtersettings{'CUSTOM_BLACK_DOMAINS'};
2519 delete $filtersettings{'CUSTOM_BLACK_URLS'};
2520 delete $filtersettings{'CUSTOM_WHITE_DOMAINS'};
2521 delete $filtersettings{'CUSTOM_WHITE_URLS'};
2522 delete $filtersettings{'CUSTOM_EXPRESSIONS'};
2523 delete $filtersettings{'BACKGROUND'};
2524 delete $filtersettings{'UPDATEFILE'};
2525
2526 system("chown -R nobody.nobody $dbdir");
2527 system('/usr/bin/squidGuard -C custom/allowed/domains >/dev/null 2>&1');
2528 system('/usr/bin/squidGuard -C custom/allowed/urls >/dev/null 2>&1');
2529 system('/usr/bin/squidGuard -C custom/blocked/domains >/dev/null 2>&1');
2530 system('/usr/bin/squidGuard -C custom/blocked/urls >/dev/null 2>&1 ');
2531 &setpermissions ($dbdir);
2532
2533 &General::writehash("${General::swroot}/urlfilter/settings", \%filtersettings);
2534 }
2535
2536 # -------------------------------------------------------------------
2537
2538 sub readblockcategories
2539 {
2540 undef(@categories);
2541
2542 &getblockcategory ($dbdir);
2543
2544 foreach (@categories) { $_ = substr($_,length($dbdir)+1); }
2545
2546 @filtergroups = @categories;
2547
2548 foreach (@filtergroups) {
2549 s/\//_/g;
2550 tr/a-z/A-Z/;
2551 $_ = "FILTER_".$_;
2552 }
2553 }
2554
2555 # -------------------------------------------------------------------
2556
2557 sub getblockcategory
2558 {
2559 foreach $category (<$_[0]/*>)
2560 {
2561 if (-d $category)
2562 {
2563 if ((-e "$category/domains") || (-e "$category/urls"))
2564 {
2565 unless ($category =~ /\bcustom\b/) { push(@categories,$category); }
2566 }
2567 &getblockcategory ($category);
2568 }
2569 }
2570 }
2571
2572 # -------------------------------------------------------------------
2573
2574 sub readcustomlists
2575 {
2576 if (-e "$dbdir/custom/blocked/domains") {
2577 open(FILE,"$dbdir/custom/blocked/domains");
2578 delete $filtersettings{'CUSTOM_BLACK_DOMAINS'};
2579 while (<FILE>) { $filtersettings{'CUSTOM_BLACK_DOMAINS'} .= $_ };
2580 close(FILE);
2581 }
2582
2583 if (-e "$dbdir/custom/blocked/urls") {
2584 open(FILE,"$dbdir/custom/blocked/urls");
2585 delete $filtersettings{'CUSTOM_BLACK_URLS'};
2586 while (<FILE>) { $filtersettings{'CUSTOM_BLACK_URLS'} .= $_ };
2587 close(FILE);
2588 }
2589
2590 if (-e "$dbdir/custom/blocked/expressions") {
2591 open(FILE,"$dbdir/custom/blocked/expressions");
2592 delete $filtersettings{'CUSTOM_EXPRESSIONS'};
2593 while (<FILE>) { $filtersettings{'CUSTOM_EXPRESSIONS'} .= $_ };
2594 close(FILE);
2595 }
2596
2597 if (-e "$dbdir/custom/allowed/domains") {
2598 open(FILE,"$dbdir/custom/allowed/domains");
2599 delete $filtersettings{'CUSTOM_WHITE_DOMAINS'};
2600 while (<FILE>) { $filtersettings{'CUSTOM_WHITE_DOMAINS'} .= $_ };
2601 close(FILE);
2602 }
2603 if (-e "$dbdir/custom/allowed/urls") {
2604 open(FILE,"$dbdir/custom/allowed/urls");
2605 delete $filtersettings{'CUSTOM_WHITE_URLS'};
2606 while (<FILE>) { $filtersettings{'CUSTOM_WHITE_URLS'} .= $_ };
2607 close(FILE);
2608 }
2609 }
2610
2611 # -------------------------------------------------------------------
2612
2613 sub aggregatedconstraints
2614 {
2615 my $aggregated;
2616 my @old;
2617 my @new;
2618 my @tmp1;
2619 my @tmp2;
2620 my $x;
2621
2622 if (-e $tcfile)
2623 {
2624 open(TC, $tcfile);
2625 @old = <TC>;
2626 close(TC);
2627
2628 while (@old > 0)
2629 {
2630 $aggregated = 0;
2631 $x = shift(@old);
2632 chomp($x);
2633 @tmp1 = split(/\,/,$x);
2634 $tmp1[16] = '';
2635 foreach (@new)
2636 {
2637 @tmp2 = split(/\,/);
2638 if (($tmp1[15] eq 'on') && ($tmp2[15] eq 'on'))
2639 {
2640 if (($tmp1[0] eq $tmp2[0]) && ($tmp1[12] eq $tmp2[12]) && ($tmp1[13] eq $tmp2[13]) && ($tmp1[14] eq $tmp2[14]))
2641 {
2642 $aggregated = 1;
2643 $tmp2[16] .= " weekly ";
2644 if ($tmp1[1] eq 'on') { $tmp2[16] .= "m"; }
2645 if ($tmp1[2] eq 'on') { $tmp2[16] .= "t"; }
2646 if ($tmp1[3] eq 'on') { $tmp2[16] .= "w"; }
2647 if ($tmp1[4] eq 'on') { $tmp2[16] .= "h"; }
2648 if ($tmp1[5] eq 'on') { $tmp2[16] .= "f"; }
2649 if ($tmp1[6] eq 'on') { $tmp2[16] .= "a"; }
2650 if ($tmp1[7] eq 'on') { $tmp2[16] .= "s"; }
2651 $tmp2[16] .= " $tmp1[8]:$tmp1[9]-$tmp1[10]:$tmp1[11]\n";
2652 $_ = join(",",@tmp2);
2653 }
2654
2655 }
2656 }
2657 if (!$aggregated)
2658 {
2659 $tmp1[16] .= " weekly ";
2660 if ($tmp1[1] eq 'on') { $tmp1[