#!/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 <http://www.gnu.org/licenses/>. #
+# #
+###############################################################################
use strict;
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='';
$filtersettings{'ENABLE_LOG'} = 'off';
$filtersettings{'ENABLE_USERNAME_LOG'} = 'off';
$filtersettings{'ENABLE_CATEGORY_LOG'} = 'off';
-$filtersettings{'CHILDREN'} = '5';
$filtersettings{'ENABLE_AUTOUPDATE'} = 'off';
$filtersettings{'ACTION'} = '';
($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'}))
}
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'};
}
}
-
- 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'});
$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'};
{
$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)
{
$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');
}
}
{
$errormessage = $!;
} else {
-
+
my $exitcode = system("/bin/tar --no-same-owner --preserve-permissions -xzf $editdir/blacklist.tar.gz -C $editdir");
if ($exitcode > 0)
{
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');
}
}
}
<td colspan='2'>$Lang::tr{'urlfilter blocked domains'} <img src='/blob.gif' alt='*' /></td>
<td colspan='2'>$Lang::tr{'urlfilter blocked urls'} <img src='/blob.gif' alt='*' /></td>
</tr>
+<tr>
+ <td colspan='2'>$Lang::tr{'urlfilter example'}</td>
+ <td colspan='2'>$Lang::tr{'urlfilter example ads'}</td>
+</tr>
<tr>
<td colspan='2' width='50%'><textarea name='CUSTOM_BLACK_DOMAINS' cols='32' rows='6' wrap='off'>
END
<td colspan='2'>$Lang::tr{'urlfilter allowed domains'} <img src='/blob.gif' alt='*' /></td>
<td colspan='2'>$Lang::tr{'urlfilter allowed urls'} <img src='/blob.gif' alt='*' /></td>
</tr>
+<tr>
+ <td colspan='2'>$Lang::tr{'urlfilter example'}</td>
+ <td colspan='2'>$Lang::tr{'urlfilter example ads'}</td>
+</tr>
<tr>
<td colspan='2' width='50%'><textarea name='CUSTOM_WHITE_DOMAINS' cols='32' rows='6' wrap='off'>
END
<td class='base'>$Lang::tr{'urlfilter msg text 3'}: <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> </td>
- <td> </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' /> <input type='submit' name='ACTION' value='$Lang::tr{'urlfilter upload background'}' /></td>
-</tr>
</table>
<hr size='1'>
<table width='100%'>
<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>
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);
}
@filtergroups = @categories;
foreach (@filtergroups) {
- s/\//_SLASH_/g;
+ s/\//_/g;
tr/a-z/A-Z/;
$_ = "FILTER_".$_;
}
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";
}
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";
print FILE "}\n\n";
$category = $blacklist;
}
-
+
print FILE "dest files {\n";
print FILE " expressionlist custom\/blocked\/files\n";
if ($filtersettings{'ENABLE_LOG'} eq 'on')