#!/usr/bin/perl # # SmoothWall CGIs # # This code is distributed under the terms of the GPL # # (c) The SmoothWall Team # # $Id: proxy.cgi,v 1.13.2.23 2006/01/29 09:29:47 eoberlander Exp $ # use strict; # enable only the following on debugging purpose #use warnings; #use CGI::Carp 'fatalsToBrowser'; require 'CONFIG_ROOT/general-functions.pl'; require "${General::swroot}/lang.pl"; require "${General::swroot}/header.pl"; my %proxysettings=(); my %netsettings=(); my %mainsettings=(); my $errormessage = ''; my $NeedDoHTML = 1; &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); &General::readhash("${General::swroot}/main/settings", \%mainsettings); &Header::showhttpheaders(); $proxysettings{'ACTION'} = ''; $proxysettings{'VALID'} = ''; $proxysettings{'UPSTREAM_PROXY'} = ''; $proxysettings{'UPSTREAM_USER'} = ''; $proxysettings{'UPSTREAM_PASSWORD'} = ''; $proxysettings{'ENABLE'} = 'off'; $proxysettings{'ENABLE_BLUE'} = 'off'; $proxysettings{'CACHE_SIZE'} = '50'; $proxysettings{'TRANSPARENT'} = 'off'; $proxysettings{'TRANSPARENT_BLUE'} = 'off'; $proxysettings{'MAX_SIZE'} = '4096'; $proxysettings{'MIN_SIZE'} = '0'; $proxysettings{'MAX_OUTGOING_SIZE'} = '0'; $proxysettings{'MAX_INCOMING_SIZE'} = '0'; $proxysettings{'LOGGING'} = 'off'; $proxysettings{'PROXY_PORT'} = '800'; $proxysettings{'EXTENSION_METHODS'} = ''; &Header::getcgihash(\%proxysettings); my $needhup = 0; my $cachemem = ''; if ($proxysettings{'ACTION'} eq $Lang::tr{'save'}) { #assume error my $configerror = 1; if ($proxysettings{'ENABLE'} !~ /^(on|off)$/ || $proxysettings{'TRANSPARENT'} !~ /^(on|off)$/ || $proxysettings{'ENABLE_BLUE'} !~ /^(on|off)$/ || $proxysettings{'TRANSPARENT_BLUE'} !~ /^(on|off)$/ ) { $errormessage = $Lang::tr{'invalid input'}; goto ERROR; } if (!($proxysettings{'CACHE_SIZE'} =~ /^\d+/) || ($proxysettings{'CACHE_SIZE'} < 10)) { $errormessage = $Lang::tr{'invalid cache size'}; goto ERROR; } if (!($proxysettings{'MAX_SIZE'} =~ /^\d+/)) { $errormessage = $Lang::tr{'invalid maximum object size'}; goto ERROR; } if (!($proxysettings{'MIN_SIZE'} =~ /^\d+/)) { $errormessage = $Lang::tr{'invalid minimum object size'}; goto ERROR; } if (!($proxysettings{'MAX_OUTGOING_SIZE'} =~ /^\d+/)) { $errormessage = $Lang::tr{'invalid maximum outgoing size'}; goto ERROR; } if (!($proxysettings{'MAX_INCOMING_SIZE'} =~ /^\d+/)) { $errormessage = $Lang::tr{'invalid maximum incoming size'}; goto ERROR; } if (!($proxysettings{'EXTENSION_METHODS'} =~ /^(|[A-Z0-9 _-]+)$/)) { $errormessage = $Lang::tr{'squid extension methods invalid'}; goto ERROR; } # Quick parent proxy error checking of username and password info. If username password don't both exist give an error. my $proxy1 = 'YES'; my $proxy2 = 'YES'; if (($proxysettings{'UPSTREAM_USER'} eq '')) {$proxy1 = '';} if (($proxysettings{'UPSTREAM_PASSWORD'} eq '')) {$proxy2 = '';} if (($proxy1 ne $proxy2)) { $errormessage = $Lang::tr{'invalid upstream proxy username or password setting'}; goto ERROR; } $_ = $proxysettings{'UPSTREAM_PROXY'}; my ($remotehost, $remoteport) = (/^(?:[a-zA-Z ]+\:\/\/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?)?$/); $remoteport = 80 if ($remoteport eq ''); $proxysettings{'VALID'} = 'yes'; &General::writehash("${General::swroot}/proxy/settings", \%proxysettings); # # NAH, 03-Jan-2004 # my @free = `/usr/bin/free`; $free[1] =~ m/(\d+)/; $cachemem = int $1 / 10; if ($cachemem < 4096) { $cachemem = 4096; } if ($cachemem > $proxysettings{'CACHE_SIZE'} * 40) { $cachemem = ( $proxysettings{'CACHE_SIZE'} * 40 ); } open(FILE, ">/${General::swroot}/proxy/squid.conf") or die "Unable to write squid.conf file"; flock(FILE, 2); print FILE <) { $_ =~ s/__GREEN_IP__/$netsettings{'GREEN_ADDRESS'}/; $_ =~ s/__GREEN_NET__/$netsettings{'GREEN_NETADDRESS'}\/$netsettings{'GREEN_NETMASK'}/; $_ =~ s/__BLUE_IP__/$blue_ip/; $_ =~ s/__BLUE_NET__/$blue_net/; $_ =~ s/__PROXY_PORT__/$proxysettings{'PROXY_PORT'}/; print FILE $_; } close (ACL); # This value is in bytes, so we must turn it from KB into bytes my $max_incoming_size = $proxysettings{'MAX_INCOMING_SIZE'} * 1024; print FILE <$errormessage \n"; &Header::closebox(); } print "
\n"; &Header::openbox('100%', 'left', "$Lang::tr{'web proxy'}:"); print < $Lang::tr{'enabled on'} Green: $Lang::tr{'upstream proxy host:port'}: * $Lang::tr{'transparent on'} Green: $Lang::tr{'upstream username'} * END ; if ($netsettings{'BLUE_DEV'}) { print "$Lang::tr{'enabled on'} Blue:"; print ""; } else { print " "; } print <$Lang::tr{'upstream password'} * END ; if ($netsettings{'BLUE_DEV'}) { print "$Lang::tr{'transparent on'} Blue:"; print ""; } else { print " "; } print <$Lang::tr{'proxy port'}: $Lang::tr{'log enabled'}: $Lang::tr{'squid extension methods'}: *
$Lang::tr{'cache management'} $Lang::tr{'cache size'} $Lang::tr{'min size'} $Lang::tr{'max size'}
$Lang::tr{'transfer limits'} $Lang::tr{'max incoming size'} $Lang::tr{'max outgoing size'}
*  $Lang::tr{'this field may be blank'}
END ; &Header::closebox(); print "\n"; &Header::closebigbox(); &Header::closepage(); } # end sub DoHTML 1