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