]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - html/cgi-bin/urlfilter.cgi
Fixed the urlfilter bug #0000552
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / urlfilter.cgi
index 3316ff27122e41f184dd0cc1a437b102239b5fbf..2d180e29292a5eedcd1a99e921351f4c506cc704 100644 (file)
@@ -1,11 +1,23 @@
 #!/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) 2010  Michael Tremer & Christian Schmidt                      #
+#                                                                             #
+# 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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
 
 use strict;
 
@@ -132,7 +144,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 +158,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 +181,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 +209,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 +225,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 +307,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 +353,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 +773,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)
                        {
@@ -1459,23 +1443,6 @@ print <<END
        <td class='base'>$Lang::tr{'urlfilter msg text 3'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
        <td><input type='text' name='MSG_TEXT_3' value='$filtersettings{'MSG_TEXT_3'}' size='40' /></td>
 </tr>
-<tr>
-       <td class='base'>$Lang::tr{'urlfilter enable jpeg'}:</td>
-       <td><input type='checkbox' name='ENABLE_JPEG' $checked{'ENABLE_JPEG'}{'on'} /></td>
-       <td>&nbsp;</td>
-       <td>&nbsp;</td>
-</tr>
-</table>
-<table width='100%'>
-<tr>
-       <td class='base'><b>$Lang::tr{'urlfilter background image'}</b></td>
-</tr>
-<tr>
-       <td><br>$Lang::tr{'urlfilter background text'}:</td>
-</tr>
-<tr>
-       <td><input type='file' name='BACKGROUND' size='40' /> &nbsp; <input type='submit' name='ACTION' value='$Lang::tr{'urlfilter upload background'}' /></td>
-</tr>
 </table>
 <hr size='1'>
 <table width='100%'>
@@ -1503,8 +1470,6 @@ print <<END
 <tr>
        <td class='base'>$Lang::tr{'urlfilter block ip'}:</td>
        <td><input type='checkbox' name='BLOCK_IP_ADDR' $checked{'BLOCK_IP_ADDR'}{'on'} /></td>
-       <td class='base'>$Lang::tr{'urlfilter children'}:</td>
-       <td><input type='text' name='CHILDREN' value='$filtersettings{'CHILDREN'}' size='5' /></td>
 </tr>
 <tr>
        <td class='base'>$Lang::tr{'urlfilter block all'}:</td>
@@ -2562,6 +2527,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 +2550,7 @@ sub readblockcategories
        @filtergroups = @categories;
 
        foreach (@filtergroups) {
-               s/\//_SLASH_/g;
+               s/\//_/g;
                tr/a-z/A-Z/;
                $_ = "FILTER_".$_;
        }
@@ -2783,7 +2755,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 +2973,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 +3017,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')