]>
Commit | Line | Data |
---|---|---|
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 |
24 | use strict; |
25 | use IPC::Open2; | |
26 | use IO::Handle; | |
ff5ec02a CS |
27 | |
28 | # define here your redirectors (use a comma sperated list) | |
e775d06c | 29 | my $redirectors; |
ff5ec02a | 30 | |
d12aede7 CS |
31 | require '/var/ipfire/general-functions.pl'; |
32 | ||
33 | my %proxysettings=(); | |
e5a63a6f CS |
34 | $proxysettings{'ENABLE_FILTER'} = 'off'; |
35 | $proxysettings{'ENABLE_CLAMAV'} = 'off'; | |
36 | $proxysettings{'ENABLE_UPDXLRATOR'} = 'off'; | |
d12aede7 | 37 | &General::readhash("${General::swroot}/proxy/settings", \%proxysettings); |
a393e0ba MT |
38 | |
39 | # define here your redirectors (use a comma sperated list) | |
e775d06c CS |
40 | if ( $proxysettings{'ENABLE_FILTER'} eq 'on' && $proxysettings{'ENABLE_CLAMAV'} eq 'on' && $proxysettings{'ENABLE_UPDXLRATOR'} eq 'on' ){$redirectors = [ '/usr/bin/squidGuard', '/usr/bin/squidclamav', '/usr/sbin/updxlrator' ];} |
41 | elsif ( $proxysettings{'ENABLE_FILTER'} eq 'on' && $proxysettings{'ENABLE_CLAMAV'} eq 'on' && $proxysettings{'ENABLE_UPDXLRATOR'} eq 'off' ){$redirectors = [ '/usr/bin/squidGuard', '/usr/bin/squidclamav' ];} | |
42 | elsif ( $proxysettings{'ENABLE_FILTER'} eq 'on' && $proxysettings{'ENABLE_CLAMAV'} eq 'off' && $proxysettings{'ENABLE_UPDXLRATOR'} eq 'on' ){$redirectors = [ '/usr/bin/squidGuard', '/usr/sbin/updxlrator' ];} | |
43 | elsif ( $proxysettings{'ENABLE_FILTER'} eq 'on' && $proxysettings{'ENABLE_CLAMAV'} eq 'off' && $proxysettings{'ENABLE_UPDXLRATOR'} eq 'off' ){$redirectors = [ '/usr/bin/squidGuard' ];} | |
44 | elsif ( $proxysettings{'ENABLE_FILTER'} eq 'off' && $proxysettings{'ENABLE_CLAMAV'} eq 'on' && $proxysettings{'ENABLE_UPDXLRATOR'} eq 'on' ){$redirectors = [ '/usr/bin/squidclamav', '/usr/sbin/updxlrator' ];} | |
45 | elsif ( $proxysettings{'ENABLE_FILTER'} eq 'off' && $proxysettings{'ENABLE_CLAMAV'} eq 'on' && $proxysettings{'ENABLE_UPDXLRATOR'} eq 'off' ){$redirectors = [ '/usr/bin/squidclamav' ];} | |
46 | elsif ( $proxysettings{'ENABLE_FILTER'} eq 'off' && $proxysettings{'ENABLE_CLAMAV'} eq 'off' && $proxysettings{'ENABLE_UPDXLRATOR'} eq 'on' ){$redirectors = [ '/usr/sbin/updxlrator' ];} | |
47 | else { $redirectors = [ '/usr/bin/squidGuard', '/usr/sbin/updxlrator' ];} | |
a393e0ba MT |
48 | |
49 | # Attention: keep in mind that the order of your redirectors is important. | |
50 | # It doesn't make sense to scan for viruses on pages you restrict access to... | |
51 | # So place first your tools which restrict access, then the tools which do the | |
52 | # content filtering! | |
53 | ||
a393e0ba MT |
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; | |
ff5ec02a | 62 | my $debug=0; # enable only for debugging |
a393e0ba | 63 | |
e775d06c | 64 | if ($debug){ |
0ba563aa CS |
65 | writetolog("Urlfilter = ".$proxysettings{'ENABLE_FILTER'}); |
66 | writetolog("Clamav = ".$proxysettings{'ENABLE_CLAMAV'}); | |
67 | writetolog("Updxlrator = ".$proxysettings{'ENABLE_UPDXLRATOR'}); | |
e775d06c CS |
68 | } |
69 | ||
a393e0ba MT |
70 | # open progamms |
71 | my $pidlist = []; | |
72 | my $rlist = []; | |
73 | my $wlist = []; | |
ff5ec02a | 74 | for($i = 0; $i < @$redirectors; $i++) { |
0ba563aa | 75 | if ($debug){writetolog("Current redirector is ".$redirectors->[$i]);} |
e775d06c | 76 | $pidlist->[$i] = open2($rlist->[$i], $wlist->[$i], $redirectors->[$i]); |
a393e0ba MT |
77 | } |
78 | ||
79 | # wait for data... | |
80 | while($line = <>) { | |
ff5ec02a | 81 | for($i = 0; $i < @$redirectors; $i++) { |
a393e0ba MT |
82 | $wlist->[$i]->print($line); |
83 | $return = $rlist->[$i]->getline; | |
84 | last if($return ne "\n" and $return ne $line); | |
0ba563aa CS |
85 | # break if redirector changes data |
86 | if ( $return eq "Processing file and database" ){ | |
87 | writetolog("Emergency - squidGuard not initialised please run squidGuard -C all"); | |
88 | last; | |
89 | } | |
a393e0ba MT |
90 | } |
91 | print $return; | |
ff5ec02a | 92 | |
0ba563aa CS |
93 | if ($debug){ |
94 | chomp $line; | |
95 | chomp $return; | |
96 | if ( $line ne $return ){ | |
97 | writetolog("Requested ".$line."\nAnswer ".$return); | |
98 | } | |
99 | } | |
a393e0ba MT |
100 | } |
101 | exit 0; | |
0ba563aa CS |
102 | |
103 | sub writetolog { | |
104 | my $log = shift; | |
105 | open(DATEI, ">>/var/log/squid/redirector_debug") || die "Unable to acces file /var/log/redirector_debug"; | |
106 | print DATEI $log."\n"; | |
107 | close(DATEI); | |
108 | } |