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