]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - config/urlfilter/redirect_wrapper
Finalized core13 and redirector fixes
[people/teissler/ipfire-2.x.git] / config / urlfilter / redirect_wrapper
CommitLineData
a393e0ba 1#!/usr/bin/perl
70df8302
MT
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2007 Michael Tremer & Christian Schmidt #
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20# Based on Steffen Schoch (sschoch@users.sourceforge.net) #
21# #
22###############################################################################
a393e0ba 23
a393e0ba
MT
24use strict;
25use IPC::Open2;
26use IO::Handle;
ff5ec02a
CS
27
28# define here your redirectors (use a comma sperated list)
29my $redirectors = [ '/usr/bin/squidGuard', '/usr/sbin/updxlrator' ];
30
d12aede7
CS
31require '/var/ipfire/general-functions.pl';
32
33my %proxysettings=();
34&General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
a393e0ba
MT
35
36# define here your redirectors (use a comma sperated list)
ff5ec02a
CS
37if ( $proxysettings{'ENABLE_FILTER'} eq 'on' && $proxysettings{'ENABLE_CLAMAV'} eq 'on' && $proxysettings{'ENABLE_UPDXLRATOR'} eq 'on' ){my $redirectors = [ '/usr/bin/squidGuard', '/usr/bin/squidclamav', '/usr/sbin/updxlrator' ];}
38if ( $proxysettings{'ENABLE_FILTER'} eq 'on' && $proxysettings{'ENABLE_CLAMAV'} eq 'on' && $proxysettings{'ENABLE_UPDXLRATOR'} eq 'off' ){my $redirectors = [ '/usr/bin/squidGuard', '/usr/bin/squidclamav' ];}
39if ( $proxysettings{'ENABLE_FILTER'} eq 'on' && $proxysettings{'ENABLE_CLAMAV'} eq 'off' && $proxysettings{'ENABLE_UPDXLRATOR'} eq 'on' ){my $redirectors = [ '/usr/bin/squidGuard', '/usr/sbin/updxlrator' ];}
40if ( $proxysettings{'ENABLE_FILTER'} eq 'on' && $proxysettings{'ENABLE_CLAMAV'} eq 'off' && $proxysettings{'ENABLE_UPDXLRATOR'} eq 'off' ){my $redirectors = [ '/usr/bin/squidGuard' ];}
41if ( $proxysettings{'ENABLE_FILTER'} eq 'off' && $proxysettings{'ENABLE_CLAMAV'} eq 'on' && $proxysettings{'ENABLE_UPDXLRATOR'} eq 'on' ){my $redirectors = [ '/usr/bin/squidclamav', '/usr/sbin/updxlrator' ];}
42if ( $proxysettings{'ENABLE_FILTER'} eq 'off' && $proxysettings{'ENABLE_CLAMAV'} eq 'on' && $proxysettings{'ENABLE_UPDXLRATOR'} eq 'off' ){my $redirectors = [ '/usr/bin/squidclamav' ];}
43if ( $proxysettings{'ENABLE_FILTER'} eq 'off' && $proxysettings{'ENABLE_CLAMAV'} eq 'off' && $proxysettings{'ENABLE_UPDXLRATOR'} eq 'on' ){my $redirectors = [ '/usr/sbin/updxlrator' ];}
a393e0ba
MT
44
45# Attention: keep in mind that the order of your redirectors is important.
46# It doesn't make sense to scan for viruses on pages you restrict access to...
47# So place first your tools which restrict access, then the tools which do the
48# content filtering!
49
50
51##### no need to change anything below this line #####
52
53# init
54$| = 1;
55STDOUT->autoflush(1);
56my $line;
57my $return;
58my $i;
ff5ec02a 59my $debug=0; # enable only for debugging
a393e0ba
MT
60
61# open progamms
62my $pidlist = [];
63my $rlist = [];
64my $wlist = [];
ff5ec02a
CS
65for($i = 0; $i < @$redirectors; $i++) {
66 $pidlist->[$i] = open2($rlist->[$i], $wlist->[$i], $redirectors->[$i]);
a393e0ba
MT
67}
68
69# wait for data...
70while($line = <>) {
ff5ec02a 71 for($i = 0; $i < @$redirectors; $i++) {
a393e0ba
MT
72 $wlist->[$i]->print($line);
73 $return = $rlist->[$i]->getline;
74 last if($return ne "\n" and $return ne $line);
75 # break if redirector changes data
76 }
77 print $return;
ff5ec02a
CS
78
79 if ($debug){
80 chomp $line;
81 chomp $return;
82 if ( $line ne $return ){
83 open(DATEI, ">>/var/log/squid/redirector_debug") || die "Unable to acces file /var/log/redirector_debug";
84 print DATEI "Requested ".$line."\nAnswer ".$return."\n";
85 close(DATEI);
86 }
87 }
a393e0ba
MT
88}
89exit 0;