]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - config/urlfilter/redirect_wrapper
Forgotten half of the files :D
[people/teissler/ipfire-2.x.git] / config / urlfilter / redirect_wrapper
1 #!/usr/bin/perl
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 ###############################################################################
23
24 use strict;
25 use IPC::Open2;
26 use IO::Handle;
27
28 # define here your redirectors (use a comma sperated list)
29 my $redirectors = [ '/usr/bin/squidGuard', '/usr/sbin/updxlrator' ];
30
31 require '/var/ipfire/general-functions.pl';
32
33 my %proxysettings=();
34 $proxysettings{'ENABLE_FILTER'} = 'off';
35 $proxysettings{'ENABLE_CLAMAV'} = 'off';
36 $proxysettings{'ENABLE_UPDXLRATOR'} = 'off';
37 &General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
38
39 # define here your redirectors (use a comma sperated list)
40 if ( $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' ];}
41 if ( $proxysettings{'ENABLE_FILTER'} eq 'on' && $proxysettings{'ENABLE_CLAMAV'} eq 'on' && $proxysettings{'ENABLE_UPDXLRATOR'} eq 'off' ){my $redirectors = [ '/usr/bin/squidGuard', '/usr/bin/squidclamav' ];}
42 if ( $proxysettings{'ENABLE_FILTER'} eq 'on' && $proxysettings{'ENABLE_CLAMAV'} eq 'off' && $proxysettings{'ENABLE_UPDXLRATOR'} eq 'on' ){my $redirectors = [ '/usr/bin/squidGuard', '/usr/sbin/updxlrator' ];}
43 if ( $proxysettings{'ENABLE_FILTER'} eq 'on' && $proxysettings{'ENABLE_CLAMAV'} eq 'off' && $proxysettings{'ENABLE_UPDXLRATOR'} eq 'off' ){my $redirectors = [ '/usr/bin/squidGuard' ];}
44 if ( $proxysettings{'ENABLE_FILTER'} eq 'off' && $proxysettings{'ENABLE_CLAMAV'} eq 'on' && $proxysettings{'ENABLE_UPDXLRATOR'} eq 'on' ){my $redirectors = [ '/usr/bin/squidclamav', '/usr/sbin/updxlrator' ];}
45 if ( $proxysettings{'ENABLE_FILTER'} eq 'off' && $proxysettings{'ENABLE_CLAMAV'} eq 'on' && $proxysettings{'ENABLE_UPDXLRATOR'} eq 'off' ){my $redirectors = [ '/usr/bin/squidclamav' ];}
46 if ( $proxysettings{'ENABLE_FILTER'} eq 'off' && $proxysettings{'ENABLE_CLAMAV'} eq 'off' && $proxysettings{'ENABLE_UPDXLRATOR'} eq 'on' ){my $redirectors = [ '/usr/sbin/updxlrator' ];}
47
48 # Attention: keep in mind that the order of your redirectors is important.
49 # It doesn't make sense to scan for viruses on pages you restrict access to...
50 # So place first your tools which restrict access, then the tools which do the
51 # content filtering!
52
53
54 ##### no need to change anything below this line #####
55
56 # init
57 $| = 1;
58 STDOUT->autoflush(1);
59 my $line;
60 my $return;
61 my $i;
62 my $debug=0; # enable only for debugging
63
64 # open progamms
65 my $pidlist = [];
66 my $rlist = [];
67 my $wlist = [];
68 for($i = 0; $i < @$redirectors; $i++) {
69 $pidlist->[$i] = open2($rlist->[$i], $wlist->[$i], $redirectors->[$i]);
70 }
71
72 # wait for data...
73 while($line = <>) {
74 for($i = 0; $i < @$redirectors; $i++) {
75 $wlist->[$i]->print($line);
76 $return = $rlist->[$i]->getline;
77 last if($return ne "\n" and $return ne $line);
78 # break if redirector changes data
79 }
80 print $return;
81
82 if ($debug){
83 chomp $line;
84 chomp $return;
85 if ( $line ne $return ){
86 open(DATEI, ">>/var/log/squid/redirector_debug") || die "Unable to acces file /var/log/redirector_debug";
87 print DATEI "Requested ".$line."\nAnswer ".$return."\n";
88 close(DATEI);
89 }
90 }
91 }
92 exit 0;