X-Git-Url: http://git.ipfire.org/?p=people%2Fpmueller%2Fipfire-2.x.git;a=blobdiff_plain;f=html%2Fcgi-bin%2Furlfilter.cgi;h=eea32bff2226d4df1863b76c03937fb5318ef156;hp=697965546cbd6d60e8993cdc3a2cf66ca85662ff;hb=a4883c68c14fbf73474cbcf050d3d99acf5b2cfb;hpb=7d3af7f772cc9ef6b5a83a3c0856567b935f051e diff --git a/html/cgi-bin/urlfilter.cgi b/html/cgi-bin/urlfilter.cgi index 697965546c..eea32bff22 100644 --- a/html/cgi-bin/urlfilter.cgi +++ b/html/cgi-bin/urlfilter.cgi @@ -1,17 +1,29 @@ #!/usr/bin/perl -# -# This code is distributed under the terms of the GPL -# -# (c) 2004-2007 marco.s - http://www.urlfilter.net -# -# $Id: urlfilter.cgi,v 1.9.1 2007/03/22 00:00:00 marco.s Exp $ -# +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2005-2010 IPFire Team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### use strict; # enable only the following on debugging purpose -use warnings; -use CGI::Carp 'fatalsToBrowser'; +#use warnings; +#use CGI::Carp 'fatalsToBrowser'; use File::Copy; use IO::Socket; @@ -47,15 +59,12 @@ my $tcfile = "${General::swroot}/urlfilter/timeconst"; my $uqfile = "${General::swroot}/urlfilter/userquota"; my $dbdir = "${General::swroot}/urlfilter/blacklists"; my $editdir = "${General::swroot}/urlfilter/editor"; -my $repository = "/home/httpd/html/repository"; +my $repository = "/var/urlrepo"; my $hintcolour = '#FFFFCC'; my $sourceurlfile = "${General::swroot}/urlfilter/autoupdate/autoupdate.urls"; my $updconffile = "${General::swroot}/urlfilter/autoupdate/autoupdate.conf"; my $updflagfile = "${General::swroot}/urlfilter/blacklists/.autoupdate.last"; -my $upd_cron_dly = "${General::swroot}/urlfilter/autoupdate/cron.daily"; -my $upd_cron_wly = "${General::swroot}/urlfilter/autoupdate/cron.weekly"; -my $upd_cron_mly = "${General::swroot}/urlfilter/autoupdate/cron.monthly"; my $errormessage=''; my $updatemessage=''; @@ -132,7 +141,6 @@ $filtersettings{'ENABLE_SAFESEARCH'} = 'off'; $filtersettings{'ENABLE_LOG'} = 'off'; $filtersettings{'ENABLE_USERNAME_LOG'} = 'off'; $filtersettings{'ENABLE_CATEGORY_LOG'} = 'off'; -$filtersettings{'CHILDREN'} = '5'; $filtersettings{'ENABLE_AUTOUPDATE'} = 'off'; $filtersettings{'ACTION'} = ''; @@ -147,7 +155,6 @@ if (($filtersettings{'ACTION'} eq $Lang::tr{'save'}) || ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter save and restart'}) || ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter upload file'}) || ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter remove file'}) || - ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter upload background'}) || ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter upload blacklist'}) || ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter backup'}) || ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter restore'})) @@ -171,12 +178,6 @@ if (($filtersettings{'ACTION'} eq $Lang::tr{'save'}) || } if ($errormessage) { goto ERROR; } - if (!($filtersettings{'CHILDREN'} =~ /^\d+$/) || ($filtersettings{'CHILDREN'} < 1)) - { - $errormessage = $Lang::tr{'urlfilter invalid num of children'}; - goto ERROR; - } - if ((!($filtersettings{'REDIRECT_PAGE'} eq '')) && (!($filtersettings{'REDIRECT_PAGE'} =~ /^https?:\/\//))) { $filtersettings{'REDIRECT_PAGE'} = "http://".$filtersettings{'REDIRECT_PAGE'}; @@ -205,18 +206,7 @@ if (($filtersettings{'ACTION'} eq $Lang::tr{'save'}) || } } - - if ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter upload background'}) - { - &Header::getcgihash(\%filtersettings, {'wantfile' => 1, 'filevar' => 'BACKGROUND'}); - if (copy($filtersettings{'BACKGROUND'}, "/home/httpd/html/images/urlfilter/background.jpg") != 1) - { - $errormessage = $!; - goto ERROR; - } - } - if ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter upload blacklist'}) { &Header::getcgihash(\%filtersettings, {'wantfile' => 1, 'filevar' => 'UPDATEFILE'}); @@ -232,11 +222,11 @@ if (($filtersettings{'ACTION'} eq $Lang::tr{'save'}) || $errormessage = $!; goto ERROR; } - + if (!(-d "${General::swroot}/urlfilter/update")) { mkdir("${General::swroot}/urlfilter/update"); } my $exitcode = system("/bin/tar --no-same-owner -xzf ${General::swroot}/urlfilter/blacklists.tar.gz -C ${General::swroot}/urlfilter/update"); - + if ($exitcode > 0) { $errormessage = $Lang::tr{'urlfilter tar error'}; @@ -314,7 +304,7 @@ if (($filtersettings{'ACTION'} eq $Lang::tr{'save'}) || { $errormessage = $!; } - + my $exitcode = system("/bin/tar --no-same-owner --preserve-permissions -xzf ${General::swroot}/urlfilter/backup.tar.gz -C ${General::swroot}/urlfilter/restore"); if ($exitcode > 0) { @@ -360,15 +350,6 @@ if (($filtersettings{'ACTION'} eq $Lang::tr{'save'}) || $filtersettings{'VALID'} = 'yes'; &savesettings; - system("chown -R nobody.nobody $dbdir"); - - if (-e "$dbdir/custom/allowed/domains.db") { unlink("$dbdir/custom/allowed/domains.db"); } - if (-e "$dbdir/custom/allowed/urls.db") { unlink("$dbdir/custom/allowed/urls.db"); } - if (-e "$dbdir/custom/blocked/domains.db") { unlink("$dbdir/custom/blocked/domains.db"); } - if (-e "$dbdir/custom/blocked/urls.db") { unlink("$dbdir/custom/blocked/urls.db"); } - - &setpermissions ($dbdir); - system('/usr/local/bin/squidctrl restart >/dev/null 2>&1'); } } @@ -789,7 +770,7 @@ if (($besettings{'ACTION'} eq $Lang::tr{'urlfilter import blacklist'}) && ($bese { $errormessage = $!; } else { - + my $exitcode = system("/bin/tar --no-same-owner --preserve-permissions -xzf $editdir/blacklist.tar.gz -C $editdir"); if ($exitcode > 0) { @@ -981,29 +962,20 @@ if ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter save schedule'}) print FILE "CUSTOM_UPDATE_URL=$filtersettings{'CUSTOM_UPDATE_URL'}\n"; close FILE; - if (-e $upd_cron_dly) { unlink($upd_cron_dly); } - if (-e $upd_cron_wly) { unlink($upd_cron_wly); } - if (-e $upd_cron_mly) { unlink($upd_cron_mly); } if (($filtersettings{'ENABLE_AUTOUPDATE'} eq 'on') && ($filtersettings{'UPDATE_SCHEDULE'} eq 'daily')) { - symlink("../bin/autoupdate.pl",$upd_cron_dly) - } else { - symlink("/bin/false",$upd_cron_dly) + system('/usr/local/bin/urlfilterctrl cron daily >/dev/null 2>&1'); } if (($filtersettings{'ENABLE_AUTOUPDATE'} eq 'on') && ($filtersettings{'UPDATE_SCHEDULE'} eq 'weekly')) { - symlink("../bin/autoupdate.pl",$upd_cron_wly) - } else { - symlink("/bin/false",$upd_cron_wly) + system('/usr/local/bin/urlfilterctrl cron weekly >/dev/null 2>&1'); } if (($filtersettings{'ENABLE_AUTOUPDATE'} eq 'on') && ($filtersettings{'UPDATE_SCHEDULE'} eq 'monthly')) { - symlink("../bin/autoupdate.pl",$upd_cron_mly) - } else { - symlink("/bin/false",$upd_cron_mly) + system('/usr/local/bin/urlfilterctrl cron monthly >/dev/null 2>&1'); } } } @@ -1459,23 +1431,6 @@ print <$Lang::tr{'urlfilter msg text 3'}: * - - $Lang::tr{'urlfilter enable jpeg'}: - -   -   - - - - - - - - - - - -
$Lang::tr{'urlfilter background image'}

$Lang::tr{'urlfilter background text'}:
 

@@ -1503,8 +1458,6 @@ print < - - @@ -2562,6 +2515,13 @@ sub savesettings delete $filtersettings{'BACKGROUND'}; delete $filtersettings{'UPDATEFILE'}; + system("chown -R nobody.nobody $dbdir"); + system('/usr/bin/squidGuard -C custom/allowed/domains >/dev/null 2>&1'); + system('/usr/bin/squidGuard -C custom/allowed/urls >/dev/null 2>&1'); + system('/usr/bin/squidGuard -C custom/blocked/domains >/dev/null 2>&1'); + system('/usr/bin/squidGuard -C custom/blocked/urls >/dev/null 2>&1 '); + &setpermissions ($dbdir); + &General::writehash("${General::swroot}/urlfilter/settings", \%filtersettings); } @@ -2578,7 +2538,7 @@ sub readblockcategories @filtergroups = @categories; foreach (@filtergroups) { - s/\//_SLASH_/g; + s/\//_/g; tr/a-z/A-Z/; $_ = "FILTER_".$_; } @@ -2783,7 +2743,7 @@ sub writeconfigfile if ($filtersettings{'SHOW_URL'} eq 'on') { $redirect .= "&url=%u"; } if ($filtersettings{'SHOW_IP'} eq 'on') { $redirect .= "&ip=%a"; } $redirect =~ s/^&/?/; - $redirect = "http:\/\/$netsettings{'GREEN_ADDRESS'}:$http_port\/redirect.cgi".$redirect; + $redirect = "http:\/\/$netsettings{'GREEN_ADDRESS'}:$http_port\/redirect.cgi".$redirect; } else { $redirect="http:\/\/$netsettings{'GREEN_ADDRESS'}:$http_port\/redirect.cgi"; } @@ -3001,6 +2961,24 @@ sub writeconfigfile foreach $category (@categories) { $blacklist = $category; $category =~ s/\//_/g; + + if ( $filtersettings{"FILTER_".uc($category)} ne "on" ){ + my $constraintrule = "false"; + + foreach (@tclist){ + chomp; + @tc = split(/\,/); + $tc[13] =~ s/\//_/g; + if ($tc[15] eq 'on' && $tc[13] =~ $category){ + $constraintrule = "true"; + } + } + + if ( $constraintrule eq "false"){ + next; + } + } + print FILE "dest $category {\n"; if (-e "$dbdir/$blacklist/domains") { print FILE " domainlist $blacklist\/domains\n"; @@ -3027,7 +3005,7 @@ sub writeconfigfile print FILE "}\n\n"; $category = $blacklist; } - + print FILE "dest files {\n"; print FILE " expressionlist custom\/blocked\/files\n"; if ($filtersettings{'ENABLE_LOG'} eq 'on')
$Lang::tr{'urlfilter block ip'}: $Lang::tr{'urlfilter children'}:
$Lang::tr{'urlfilter block all'}: