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