#!/usr/bin/perl -w use strict; my $username = 'PUT-YOUR-USERNAME-HERE'; my $password = 'PUT-YOUR-PASSWORD-HERE'; my $proxyhost = 'wwwproxy.ru.ac.za'; my $proxyport = '3128'; # process name for PS $0 = 'simpleproxy'; use HTTP::Proxy qw/:log/; use HTTP::Proxy::HeaderFilter::simple; use LWP::UserAgent; use POSIX; my $proxy = new HTTP::Proxy port=>3128, host=>'localhost'; # set the useragent to use a proxy for non rhodes requests my $agent = LWP::UserAgent->new(); $agent->agent("$0/1.0"); $agent->proxy(['http', 'https', 'ftp'], "http://$username:$password\@$proxyhost:$proxyport/"); $agent->no_proxy('.ru.ac.za', '.rhodes.ac.za', 'localhost', '146.231.', '127.0.0.1'); # set up some logging open LOG, '>>' . ($< == 0 ? "/var/log/$0" : "$0.log"); $proxy->logfh(\*LOG); $proxy->logmask(STATUS | PROCESS); $proxy->agent($agent); # if we wanted to do some content filtering #$proxy->push_filter ( request => HTTP::Proxy::HeaderFilter::simple->new( # sub { # my ($self, $headers, $message) = @_; # } ) #); # fork off and daemonise my $pid = fork(); if ($pid) { open PID, '>' . ($< == 0 ? "/var/run/$0.pid" : "$0.pid"); print PID "$pid\n"; close PID; exit; } # detach from the TTY POSIX::setsid(); # be a bit safer if ($< == 0 or $> == 0) { my ($uid, $gid) = (scalar getpwnam('www'), scalar getgrnam('www')); # chroot('/var/empty'); $< = $> = $uid; $( = $) = $gid; } # start the daemon $proxy->start();