#!/usr/bin/perl -w
#-d:DProf
#
# Copyright (C) 2000, 2001 Bob McElrath.
# See the file COPYING for redistribution and modification terms.
#
# 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 2 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, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package FilterProxy;
use vars qw($HOME $VERSION $CONFIG @MODULES $HOSTNAME $LISTEN_PORT $agent $client);
# Do some things to make Taint happy:
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; # Make %ENV safer
$ENV{PATH} = '/bin:/usr/bin:/usr/local/bin';# Set a reasonable path
# Place configuration here
my($NAME, $CONFIG_FILE);
BEGIN {
chomp($HOSTNAME = `hostname`); # change this for multi-homed hosts.
$LISTEN_PORT = 8888; # Is also a command-line option
$VERSION = "0.30";
$NAME = "FilterProxy \$Revision: 0.35 $VERSION \$";
chomp($HOME = `pwd`); # change if necessary (needs absolute paths)
if($HOME =~ m{([-_A-Za-z0-9./]+)}) { # untaint $HOME
$HOME = $1;
}
$CONFIG_FILE = $ENV{FILTERPROXYCONF} || $HOME . "/FilterProxy.conf"; # should be an option
push(@INC, $HOME . "/FilterProxy"); # add my home to perl's include path list
use lib "."; # Only this works with taint on...
}
# End configuration. You shouldn't have to change anything below this line.
#=============================================================================#
# FIXME Uploaded data (forms) broken for large/streaming uploads (who cares?)
# FIXME Large compressable content will be downloaded in its entireity first -- possible
# client timeout. Should compress as a stream while feeding to client.
use strict;
no strict 'subs';
no strict 'refs';
use POSIX qw(:sys_wait_h :signal_h setsid setpgid setuid setgid); # part of perl
use sigtrap qw(stack-trace error-signals);
use Carp qw(cluck croak confess); # part of perl
use Config; # part of perl
use File::stat; # part of perl
use CGI; # part of perl
use Getopt::Std; # part of perl
use Data::Dumper; # part of perl
$Data::Dumper::Indent = 1;
use HTTP::Daemon; # in Bundle::LWP (libwww)
use HTTP::Status; # in Bundle::LWP (perl-libwww-perl rpm)
use URI::Escape; # URI module (perl-URI)
use LWP::UserAgent; # in Bundle::LWP
use LWP::MediaTypes; # in Bundle::LWP
#use LWP::Debug qw(+debug +trace +conns);
use Time::HiRes; # grab this from CPAN
use HTML::Mason; # grab this from CPAN
# subclass UserAgent to disallow redirects.
@UserAgent::ISA = qw /LWP::UserAgent/;
sub UserAgent::redirect_ok {0;}
sub UserAgent::get_basic_credentials {
return ($CONFIG->{http_proxy_username}, $CONFIG->{http_proxy_password});
}
# Configuration saved to config file (This is only in case this info isn't
# already in the config file!) Don't change this! The config file overrides it!
$CONFIG = {};
$CONFIG->{filtering} = 1; # on/off switch for the filter
$CONFIG->{info} = 1; # log informational messages
$CONFIG->{timing} = 0; # log timing information (how long it takes to run filters)
$CONFIG->{debug} = 0; # log debugging messages
$CONFIG->{authenable} = 0; # enable authentication of users by password
$CONFIG->{localhostonly} = 0;# accept connections from localhost only
$CONFIG->{logfile} = $HOME . "/FilterProxy.log"; # set to "" to disable logfile
$CONFIG->{timeout} = 300; # wait 5 minutes before giving up on outgoing connections.
$CONFIG->{filters} = {};
$CONFIG->{http_proxy} = "";
$CONFIG->{http_proxy_username} = "";
$CONFIG->{http_proxy_password} = "";
# File scoped variables
my(%children) = (); # keys are pids of my children
# $client; # connection to the client
my($inreq); # incoming request -- needs to be accessable to data_handler
my($clientprotocol); # protocol client is using (0.9, 1.0, 1.01, 1.1)
my($send_response); # We're going to grab the whole file, as opposed to passing it through in pieces.
=1= |