-#!/usr/bin/perl\r
-#\r
-# SmoothWall CGIs\r
-#\r
-# This code is distributed under the terms of the GPL\r
-#\r
-# (c) The SmoothWall Team\r
-#\r
-# $Id: proxy.cgi,v 1.13.2.23 2006/01/29 09:29:47 eoberlander Exp $\r
-#\r
-\r
-use strict;\r
-\r
-# enable only the following on debugging purpose\r
-#use warnings;\r
-#use CGI::Carp 'fatalsToBrowser';\r
-\r
-require 'CONFIG_ROOT/general-functions.pl';\r
-require "${General::swroot}/lang.pl";\r
-require "${General::swroot}/header.pl";\r
-\r
-my %proxysettings=();\r
-my %netsettings=();\r
-my %mainsettings=();\r
-my $errormessage = '';\r
-my $NeedDoHTML = 1;\r
-\r
-&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);\r
-&General::readhash("${General::swroot}/main/settings", \%mainsettings);\r
-\r
-&Header::showhttpheaders();\r
-\r
-$proxysettings{'ACTION'} = '';\r
-$proxysettings{'VALID'} = '';\r
-\r
-$proxysettings{'UPSTREAM_PROXY'} = '';\r
-$proxysettings{'UPSTREAM_USER'} = '';\r
-$proxysettings{'UPSTREAM_PASSWORD'} = '';\r
-$proxysettings{'ENABLE'} = 'off';\r
-$proxysettings{'ENABLE_BLUE'} = 'off';\r
-$proxysettings{'CACHE_SIZE'} = '50';\r
-$proxysettings{'TRANSPARENT'} = 'off';\r
-$proxysettings{'TRANSPARENT_BLUE'} = 'off';\r
-$proxysettings{'MAX_SIZE'} = '4096';\r
-$proxysettings{'MIN_SIZE'} = '0';\r
-$proxysettings{'MAX_OUTGOING_SIZE'} = '0';\r
-$proxysettings{'MAX_INCOMING_SIZE'} = '0';\r
-$proxysettings{'LOGGING'} = 'off';\r
-$proxysettings{'PROXY_PORT'} = '800';\r
-$proxysettings{'EXTENSION_METHODS'} = '';\r
-\r
-&Header::getcgihash(\%proxysettings);\r
-\r
-my $needhup = 0;\r
-my $cachemem = '';\r
-\r
-if ($proxysettings{'ACTION'} eq $Lang::tr{'save'})\r
-{\r
- \r
- #assume error\r
- my $configerror = 1;\r
-\r
- if ($proxysettings{'ENABLE'} !~ /^(on|off)$/ || \r
- $proxysettings{'TRANSPARENT'} !~ /^(on|off)$/ || \r
- $proxysettings{'ENABLE_BLUE'} !~ /^(on|off)$/ || \r
- $proxysettings{'TRANSPARENT_BLUE'} !~ /^(on|off)$/ ) {\r
- $errormessage = $Lang::tr{'invalid input'};\r
- goto ERROR;\r
- } \r
- if (!($proxysettings{'CACHE_SIZE'} =~ /^\d+/) ||\r
- ($proxysettings{'CACHE_SIZE'} < 10))\r
- {\r
- $errormessage = $Lang::tr{'invalid cache size'};\r
- goto ERROR;\r
- } \r
- if (!($proxysettings{'MAX_SIZE'} =~ /^\d+/))\r
- {\r
- $errormessage = $Lang::tr{'invalid maximum object size'};\r
- goto ERROR;\r
- }\r
- if (!($proxysettings{'MIN_SIZE'} =~ /^\d+/))\r
- {\r
- $errormessage = $Lang::tr{'invalid minimum object size'};\r
- goto ERROR;\r
- }\r
- if (!($proxysettings{'MAX_OUTGOING_SIZE'} =~ /^\d+/))\r
- {\r
- $errormessage = $Lang::tr{'invalid maximum outgoing size'};\r
- goto ERROR;\r
- }\r
- if (!($proxysettings{'MAX_INCOMING_SIZE'} =~ /^\d+/))\r
- {\r
- $errormessage = $Lang::tr{'invalid maximum incoming size'};\r
- goto ERROR;\r
- }\r
-\r
- if (!($proxysettings{'EXTENSION_METHODS'} =~ /^(|[A-Z0-9 _-]+)$/))\r
- {\r
- $errormessage = $Lang::tr{'squid extension methods invalid'};\r
- goto ERROR;\r
- }\r
-\r
- # Quick parent proxy error checking of username and password info. If username password don't both exist give an error.\r
- my $proxy1 = 'YES';\r
- my $proxy2 = 'YES';\r
- if (($proxysettings{'UPSTREAM_USER'} eq '')) {$proxy1 = '';}\r
- if (($proxysettings{'UPSTREAM_PASSWORD'} eq '')) {$proxy2 = '';}\r
- if (($proxy1 ne $proxy2))\r
- {\r
- $errormessage = $Lang::tr{'invalid upstream proxy username or password setting'};\r
- goto ERROR;\r
- }\r
-\r
- $_ = $proxysettings{'UPSTREAM_PROXY'};\r
- my ($remotehost, $remoteport) = (/^(?:[a-zA-Z ]+\:\/\/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?)?$/);\r
- $remoteport = 80 if ($remoteport eq '');\r
-\r
- $proxysettings{'VALID'} = 'yes';\r
- &General::writehash("${General::swroot}/proxy/settings", \%proxysettings);\r
-\r
- #\r
- # NAH, 03-Jan-2004\r
- #\r
- my @free = `/usr/bin/free`;\r
- $free[1] =~ m/(\d+)/;\r
- $cachemem = int $1 / 10;\r
- if ($cachemem < 4096) {\r
- $cachemem = 4096;\r
- }\r
- if ($cachemem > $proxysettings{'CACHE_SIZE'} * 40) {\r
- $cachemem = ( $proxysettings{'CACHE_SIZE'} * 40 );\r
- }\r
-\r
- open(FILE, ">/${General::swroot}/proxy/squid.conf") or die "Unable to write squid.conf file";\r
- flock(FILE, 2);\r
- print FILE <<END\r
-shutdown_lifetime 5 seconds\r
-icp_port 0\r
-\r
-http_port $netsettings{'GREEN_ADDRESS'}:$proxysettings{'PROXY_PORT'}\r
-END\r
- ;\r
- print FILE "\nextension_methods $proxysettings{'EXTENSION_METHODS'}\n" if ($proxysettings{'EXTENSION_METHODS'} ne '');\r
-\r
- if ($netsettings{'BLUE_DEV'} && $proxysettings{'ENABLE_BLUE'} eq 'on') {\r
- print FILE "http_port $netsettings{'BLUE_ADDRESS'}:$proxysettings{'PROXY_PORT'}\n";\r
- }\r
- print FILE <<END\r
-\r
-acl QUERY urlpath_regex cgi-bin \\?\r
-no_cache deny QUERY\r
-\r
-cache_effective_user squid\r
-cache_effective_group squid\r
-\r
-pid_filename /var/run/squid.pid\r
-\r
-END\r
- ;\r
-\r
- if ($proxysettings{'LOGGING'} eq 'on')\r
- {\r
- print FILE <<END\r
-cache_access_log /var/log/squid/access.log\r
-cache_log /var/log/squid/cache.log\r
-cache_store_log none\r
-\r
-END\r
- ;} else {\r
- print FILE <<END\r
-cache_access_log /dev/null\r
-cache_log /dev/null\r
-cache_store_log none\r
-\r
-END\r
- ;}\r
- print FILE <<END\r
-log_mime_hdrs off\r
-forwarded_for off\r
-\r
-END\r
- ;\r
-\r
- #Insert acl file and replace __VAR__ with correct values\r
- my $blue_net = ''; #BLUE empty by default\r
- my $blue_ip = '';\r
- if ($netsettings{'BLUE_DEV'} && $proxysettings{'ENABLE_BLUE'} eq 'on') {\r
- $blue_net = "$netsettings{'BLUE_NETADDRESS'}/$netsettings{'BLUE_NETMASK'}";\r
- $blue_ip = "$netsettings{'BLUE_ADDRESS'}";\r
- }\r
- open (ACL, "${General::swroot}/proxy/acl") or die "Unable to open ACL list file";\r
- while (<ACL>) {\r
- $_ =~ s/__GREEN_IP__/$netsettings{'GREEN_ADDRESS'}/;\r
- $_ =~ s/__GREEN_NET__/$netsettings{'GREEN_NETADDRESS'}\/$netsettings{'GREEN_NETMASK'}/;\r
- $_ =~ s/__BLUE_IP__/$blue_ip/;\r
- $_ =~ s/__BLUE_NET__/$blue_net/;\r
- $_ =~ s/__PROXY_PORT__/$proxysettings{'PROXY_PORT'}/;\r
- print FILE $_;\r
- }\r
- close (ACL);\r
-\r
- # This value is in bytes, so we must turn it from KB into bytes\r
- my $max_incoming_size = $proxysettings{'MAX_INCOMING_SIZE'} * 1024;\r
-\r
- print FILE <<END\r
-\r
-maximum_object_size $proxysettings{'MAX_SIZE'} KB\r
-minimum_object_size $proxysettings{'MIN_SIZE'} KB\r
-\r
-cache_mem $cachemem KB\r
-cache_dir aufs /var/log/cache $proxysettings{'CACHE_SIZE'} 16 256\r
-\r
-request_body_max_size $proxysettings{'MAX_OUTGOING_SIZE'} KB\r
-reply_body_max_size $max_incoming_size allow all\r
-\r
-visible_hostname $mainsettings{'HOSTNAME'}.$mainsettings{'DOMAINNAME'}\r
-\r
-END\r
- ;\r
-\r
- # Write the parent proxy info, if needed.\r
- if ($remotehost ne '')\r
- {\r
- # Enter authentication for the parent cache (format is login=user:password)\r
- if ($proxy1 eq 'YES') {\r
- print FILE <<END\r
-cache_peer $remotehost parent $remoteport 3130 login=$proxysettings{'UPSTREAM_USER'}:$proxysettings{'UPSTREAM_PASSWORD'} default no-query\r
-\r
-END\r
- ; \r
- } else {\r
- # Not using authentication with the parent cache\r
- print FILE <<END\r
-cache_peer $remotehost parent $remoteport 3130 default no-query\r
-\r
-END\r
- ;\r
- }\r
- print FILE "never_direct allow all\n";\r
- }\r
- if (($proxysettings{'TRANSPARENT'} eq 'on') ||\r
- ($proxysettings{'TRANSPARENT_BLUE'} eq 'on'))\r
- {\r
- print FILE <<END\r
-httpd_accel_host virtual \r
-httpd_accel_port 80 \r
-httpd_accel_with_proxy on\r
-httpd_accel_uses_host_header on \r
-END\r
- ;\r
- }\r
- close FILE;\r
- $configerror = 0; ## a good config!\r
-\r
-ERROR:\r
- unlink "${General::swroot}/proxy/enable";\r
- unlink "${General::swroot}/proxy/transparent";\r
- unlink "${General::swroot}/proxy/enable_blue";\r
- unlink "${General::swroot}/proxy/transparent_blue";\r
- &DoHTML;\r
-\r
- if (!$configerror)\r
- {\r
- if ($proxysettings{'ENABLE'} eq 'on') {\r
- system ('/bin/touch', "${General::swroot}/proxy/enable"); }\r
- if ($proxysettings{'TRANSPARENT'} eq 'on') {\r
- system ('/bin/touch', "${General::swroot}/proxy/transparent"); }\r
- if ($proxysettings{'ENABLE_BLUE'} eq 'on') {\r
- system ('/bin/touch', "${General::swroot}/proxy/enable_blue"); }\r
- if ($proxysettings{'TRANSPARENT_BLUE'} eq 'on') {\r
- system ('/bin/touch', "${General::swroot}/proxy/transparent_blue"); }\r
- system('/usr/local/bin/restartsquid');\r
- }\r
-}\r
-\r
-if ($proxysettings{'ACTION'} eq $Lang::tr{'clear cache'})\r
-{\r
- &DoHTML;\r
- system('/usr/local/bin/restartsquid','-f');\r
-}\r
-\r
-&DoHTML if $NeedDoHTML;\r
-\r
-\r
-sub DoHTML {\r
-\r
-$NeedDoHTML = 0;\r
-&General::readhash("${General::swroot}/proxy/settings", \%proxysettings);\r
-\r
-my %checked=();\r
-\r
-$checked{'ENABLE'}{'off'} = '';\r
-$checked{'ENABLE'}{'on'} = '';\r
-$checked{'ENABLE'}{$proxysettings{'ENABLE'}} = "checked='checked'";\r
-\r
-$checked{'TRANSPARENT'}{'off'} = '';\r
-$checked{'TRANSPARENT'}{'on'} = '';\r
-$checked{'TRANSPARENT'}{$proxysettings{'TRANSPARENT'}} = "checked='checked'";\r
-\r
-$checked{'ENABLE_BLUE'}{'off'} = '';\r
-$checked{'ENABLE_BLUE'}{'on'} = '';\r
-$checked{'ENABLE_BLUE'}{$proxysettings{'ENABLE_BLUE'}} = "checked='checked'";\r
-\r
-$checked{'TRANSPARENT_BLUE'}{'off'} = '';\r
-$checked{'TRANSPARENT_BLUE'}{'on'} = '';\r
-$checked{'TRANSPARENT_BLUE'}{$proxysettings{'TRANSPARENT_BLUE'}} = "checked='checked'";\r
-\r
-$checked{'LOGGING'}{'off'} = '';\r
-$checked{'LOGGING'}{'on'} = '';\r
-$checked{'LOGGING'}{$proxysettings{'LOGGING'}} = "checked='checked'";\r
-\r
-&Header::openpage($Lang::tr{'web proxy configuration'}, 1, '');\r
-\r
-&Header::openbigbox('100%', 'left', '', $errormessage);\r
-\r
-if ($errormessage) {\r
- &Header::openbox('100%', 'left', $Lang::tr{'error messages'});\r
- print "<font class='base'>$errormessage </font>\n";\r
- &Header::closebox();\r
-}\r
-\r
-print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";\r
-\r
-&Header::openbox('100%', 'left', "$Lang::tr{'web proxy'}:");\r
-print <<END\r
-<table width='100%'>\r
-<tr>\r
- <td width='25%' class='base'>$Lang::tr{'enabled on'} <font color="${Header::colourgreen}">Green</font>:</td>\r
- <td width='15%'><input type='checkbox' name='ENABLE' $checked{'ENABLE'}{'on'} /></td>\r
- <td width='30%' class='base'>$Lang::tr{'upstream proxy host:port'}: <img src='/blob.gif' alt='*' /></td>\r
- <td width='30%'><input type='text' name='UPSTREAM_PROXY' value='$proxysettings{'UPSTREAM_PROXY'}' /></td>\r
-</tr>\r
-<tr>\r
- <td class='base'>$Lang::tr{'transparent on'} <font color="${Header::colourgreen}">Green</font>:</td>\r
- <td><input type='checkbox' name='TRANSPARENT' $checked{'TRANSPARENT'}{'on'} /></td>\r
- <td class='base'>$Lang::tr{'upstream username'} <img src='/blob.gif' alt='*' /></td>\r
- <td><input type='text' name='UPSTREAM_USER' value='$proxysettings{'UPSTREAM_USER'}' /></td>\r
-</tr>\r
-<tr>\r
-END\r
-;\r
-if ($netsettings{'BLUE_DEV'}) {\r
- print "<td class='base'>$Lang::tr{'enabled on'} <font color='${Header::colourblue}'>Blue</font>:</td>";\r
- print "<td><input type='checkbox' name='ENABLE_BLUE' $checked{'ENABLE_BLUE'}{'on'} /></td>";\r
-} else {\r
- print "<td colspan='2'> </td>";\r
-}\r
-print <<END\r
- <td class='base'>$Lang::tr{'upstream password'} <img src='/blob.gif' alt='*' /></td>\r
- <td><input type='password' name='UPSTREAM_PASSWORD' value='$proxysettings{'UPSTREAM_PASSWORD'}' /></td>\r
-</tr>\r
-<tr>\r
-END\r
-;\r
-if ($netsettings{'BLUE_DEV'}) {\r
- print "<td class='base'>$Lang::tr{'transparent on'} <font color='${Header::colourblue}'>Blue</font>:</td>";\r
- print "<td><input type='checkbox' name='TRANSPARENT_BLUE' $checked{'TRANSPARENT_BLUE'}{'on'} /></td>";\r
-} else {\r
- print "<td colspan='2'> </td>";\r
-}\r
-print <<END\r
- <td class='base'>$Lang::tr{'proxy port'}:</td>\r
- <td><input type='text' name='PROXY_PORT' value='$proxysettings{'PROXY_PORT'}' size='5' /></td>\r
-</tr>\r
-<tr>\r
- <td class='base'>$Lang::tr{'log enabled'}:</td>\r
- <td><input type='checkbox' name='LOGGING' $checked{'LOGGING'}{'on'} /></td>\r
- <td>$Lang::tr{'squid extension methods'}: <img src='/blob.gif' alt='*' /></td>\r
- <td><input type='text' name='EXTENSION_METHODS' value='$proxysettings{'EXTENSION_METHODS'}' /></td>\r
-</tr>\r
-<!--TAG FOR ADDONS-->\r
-<tr>\r
- <td colspan='4'><hr /><b>$Lang::tr{'cache management'}</b></td>\r
-</tr>\r
-<tr>\r
- <td width='25%' class='base'>$Lang::tr{'cache size'}</td>\r
- <td><input type='text' name='CACHE_SIZE' value='$proxysettings{'CACHE_SIZE'}' size='5' /></td>\r
-</tr>\r
-<tr>\r
- <td class='base'>$Lang::tr{'min size'}</td>\r
- <td><input type='text' name='MIN_SIZE' value='$proxysettings{'MIN_SIZE'}' size='5' /></td>\r
- <td class='base'>$Lang::tr{'max size'}</td>\r
- <td><input type='text' name='MAX_SIZE' value='$proxysettings{'MAX_SIZE'}' size='5' /></td>\r
-</tr>\r
-<tr>\r
- <td colspan='4'><hr /><b>$Lang::tr{'transfer limits'}</b></td>\r
-</tr>\r
-<tr>\r
- <td class='base'>$Lang::tr{'max incoming size'}</td>\r
- <td><input type='text' name='MAX_INCOMING_SIZE' value='$proxysettings{'MAX_INCOMING_SIZE'}' size='5' /></td>\r
- <td class='base'>$Lang::tr{'max outgoing size'}</td>\r
- <td><input type='text' name='MAX_OUTGOING_SIZE' value='$proxysettings{'MAX_OUTGOING_SIZE'}' size='5' /></td>\r
-</tr>\r
-</table>\r
-<table width='100%'>\r
-<hr />\r
-<tr>\r
- <td width='28%'>\r
- <img src='/blob.gif' align='top' alt='*' /> \r
- <font class='base'>$Lang::tr{'this field may be blank'}</font>\r
- </td>\r
- <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'clear cache'}' /></td>\r
- <td width=33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>\r
- <td width='5%' align='right'>\r
- <a href='${General::adminmanualurl}/services.html#services_webproxy' target='_blank'>\r
- <img src='/images/web-support.png' title='$Lang::tr{'online help en'}' /></a></td>\r
-</tr>\r
-\r
-</table>\r
-END\r
-;\r
-&Header::closebox();\r
-\r
-print "</form>\n";\r
-\r
-&Header::closebigbox();\r
-\r
-&Header::closepage();\r
-\r
-} # end sub DoHTML\r
-1\r
+#!/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 <<END
+shutdown_lifetime 5 seconds
+icp_port 0
+
+http_port $netsettings{'GREEN_ADDRESS'}:$proxysettings{'PROXY_PORT'}
+END
+ ;
+ print FILE "\nextension_methods $proxysettings{'EXTENSION_METHODS'}\n" if ($proxysettings{'EXTENSION_METHODS'} ne '');
+
+ if ($netsettings{'BLUE_DEV'} && $proxysettings{'ENABLE_BLUE'} eq 'on') {
+ print FILE "http_port $netsettings{'BLUE_ADDRESS'}:$proxysettings{'PROXY_PORT'}\n";
+ }
+ print FILE <<END
+
+acl QUERY urlpath_regex cgi-bin \\?
+no_cache deny QUERY
+
+cache_effective_user squid
+cache_effective_group squid
+
+pid_filename /var/run/squid.pid
+
+END
+ ;
+
+ if ($proxysettings{'LOGGING'} eq 'on')
+ {
+ print FILE <<END
+cache_access_log /var/log/squid/access.log
+cache_log /var/log/squid/cache.log
+cache_store_log none
+
+END
+ ;} else {
+ print FILE <<END
+cache_access_log /dev/null
+cache_log /dev/null
+cache_store_log none
+
+END
+ ;}
+ print FILE <<END
+log_mime_hdrs off
+forwarded_for off
+
+END
+ ;
+
+ #Insert acl file and replace __VAR__ with correct values
+ my $blue_net = ''; #BLUE empty by default
+ my $blue_ip = '';
+ if ($netsettings{'BLUE_DEV'} && $proxysettings{'ENABLE_BLUE'} eq 'on') {
+ $blue_net = "$netsettings{'BLUE_NETADDRESS'}/$netsettings{'BLUE_NETMASK'}";
+ $blue_ip = "$netsettings{'BLUE_ADDRESS'}";
+ }
+ open (ACL, "${General::swroot}/proxy/acl") or die "Unable to open ACL list file";
+ while (<ACL>) {
+ $_ =~ 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 <<END
+
+maximum_object_size $proxysettings{'MAX_SIZE'} KB
+minimum_object_size $proxysettings{'MIN_SIZE'} KB
+
+cache_mem $cachemem KB
+cache_dir aufs /var/log/cache $proxysettings{'CACHE_SIZE'} 16 256
+
+request_body_max_size $proxysettings{'MAX_OUTGOING_SIZE'} KB
+reply_body_max_size $max_incoming_size allow all
+
+visible_hostname $mainsettings{'HOSTNAME'}.$mainsettings{'DOMAINNAME'}
+
+END
+ ;
+
+ # Write the parent proxy info, if needed.
+ if ($remotehost ne '')
+ {
+ # Enter authentication for the parent cache (format is login=user:password)
+ if ($proxy1 eq 'YES') {
+ print FILE <<END
+cache_peer $remotehost parent $remoteport 3130 login=$proxysettings{'UPSTREAM_USER'}:$proxysettings{'UPSTREAM_PASSWORD'} default no-query
+
+END
+ ;
+ } else {
+ # Not using authentication with the parent cache
+ print FILE <<END
+cache_peer $remotehost parent $remoteport 3130 default no-query
+
+END
+ ;
+ }
+ print FILE "never_direct allow all\n";
+ }
+ if (($proxysettings{'TRANSPARENT'} eq 'on') ||
+ ($proxysettings{'TRANSPARENT_BLUE'} eq 'on'))
+ {
+ print FILE <<END
+httpd_accel_host virtual
+httpd_accel_port 80
+httpd_accel_with_proxy on
+httpd_accel_uses_host_header on
+END
+ ;
+ }
+ close FILE;
+ $configerror = 0; ## a good config!
+
+ERROR:
+ unlink "${General::swroot}/proxy/enable";
+ unlink "${General::swroot}/proxy/transparent";
+ unlink "${General::swroot}/proxy/enable_blue";
+ unlink "${General::swroot}/proxy/transparent_blue";
+ &DoHTML;
+
+ if (!$configerror)
+ {
+ if ($proxysettings{'ENABLE'} eq 'on') {
+ system ('/bin/touch', "${General::swroot}/proxy/enable"); }
+ if ($proxysettings{'TRANSPARENT'} eq 'on') {
+ system ('/bin/touch', "${General::swroot}/proxy/transparent"); }
+ if ($proxysettings{'ENABLE_BLUE'} eq 'on') {
+ system ('/bin/touch', "${General::swroot}/proxy/enable_blue"); }
+ if ($proxysettings{'TRANSPARENT_BLUE'} eq 'on') {
+ system ('/bin/touch', "${General::swroot}/proxy/transparent_blue"); }
+ system('/usr/local/bin/restartsquid');
+ }
+}
+
+if ($proxysettings{'ACTION'} eq $Lang::tr{'clear cache'})
+{
+ &DoHTML;
+ system('/usr/local/bin/restartsquid','-f');
+}
+
+&DoHTML if $NeedDoHTML;
+
+
+sub DoHTML {
+
+$NeedDoHTML = 0;
+&General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
+
+my %checked=();
+
+$checked{'ENABLE'}{'off'} = '';
+$checked{'ENABLE'}{'on'} = '';
+$checked{'ENABLE'}{$proxysettings{'ENABLE'}} = "checked='checked'";
+
+$checked{'TRANSPARENT'}{'off'} = '';
+$checked{'TRANSPARENT'}{'on'} = '';
+$checked{'TRANSPARENT'}{$proxysettings{'TRANSPARENT'}} = "checked='checked'";
+
+$checked{'ENABLE_BLUE'}{'off'} = '';
+$checked{'ENABLE_BLUE'}{'on'} = '';
+$checked{'ENABLE_BLUE'}{$proxysettings{'ENABLE_BLUE'}} = "checked='checked'";
+
+$checked{'TRANSPARENT_BLUE'}{'off'} = '';
+$checked{'TRANSPARENT_BLUE'}{'on'} = '';
+$checked{'TRANSPARENT_BLUE'}{$proxysettings{'TRANSPARENT_BLUE'}} = "checked='checked'";
+
+$checked{'LOGGING'}{'off'} = '';
+$checked{'LOGGING'}{'on'} = '';
+$checked{'LOGGING'}{$proxysettings{'LOGGING'}} = "checked='checked'";
+
+&Header::openpage($Lang::tr{'web proxy configuration'}, 1, '');
+
+&Header::openbigbox('100%', 'left', '', $errormessage);
+
+if ($errormessage) {
+ &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
+ print "<font class='base'>$errormessage </font>\n";
+ &Header::closebox();
+}
+
+print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
+
+&Header::openbox('100%', 'left', "$Lang::tr{'web proxy'}:");
+print <<END
+<table width='100%'>
+<tr>
+ <td width='25%' class='base'>$Lang::tr{'enabled on'} <font color="${Header::colourgreen}">Green</font>:</td>
+ <td width='15%'><input type='checkbox' name='ENABLE' $checked{'ENABLE'}{'on'} /></td>
+ <td width='30%' class='base'>$Lang::tr{'upstream proxy host:port'}: <img src='/blob.gif' alt='*' /></td>
+ <td width='30%'><input type='text' name='UPSTREAM_PROXY' value='$proxysettings{'UPSTREAM_PROXY'}' /></td>
+</tr>
+<tr>
+ <td class='base'>$Lang::tr{'transparent on'} <font color="${Header::colourgreen}">Green</font>:</td>
+ <td><input type='checkbox' name='TRANSPARENT' $checked{'TRANSPARENT'}{'on'} /></td>
+ <td class='base'>$Lang::tr{'upstream username'} <img src='/blob.gif' alt='*' /></td>
+ <td><input type='text' name='UPSTREAM_USER' value='$proxysettings{'UPSTREAM_USER'}' /></td>
+</tr>
+<tr>
+END
+;
+if ($netsettings{'BLUE_DEV'}) {
+ print "<td class='base'>$Lang::tr{'enabled on'} <font color='${Header::colourblue}'>Blue</font>:</td>";
+ print "<td><input type='checkbox' name='ENABLE_BLUE' $checked{'ENABLE_BLUE'}{'on'} /></td>";
+} else {
+ print "<td colspan='2'> </td>";
+}
+print <<END
+ <td class='base'>$Lang::tr{'upstream password'} <img src='/blob.gif' alt='*' /></td>
+ <td><input type='password' name='UPSTREAM_PASSWORD' value='$proxysettings{'UPSTREAM_PASSWORD'}' /></td>
+</tr>
+<tr>
+END
+;
+if ($netsettings{'BLUE_DEV'}) {
+ print "<td class='base'>$Lang::tr{'transparent on'} <font color='${Header::colourblue}'>Blue</font>:</td>";
+ print "<td><input type='checkbox' name='TRANSPARENT_BLUE' $checked{'TRANSPARENT_BLUE'}{'on'} /></td>";
+} else {
+ print "<td colspan='2'> </td>";
+}
+print <<END
+ <td class='base'>$Lang::tr{'proxy port'}:</td>
+ <td><input type='text' name='PROXY_PORT' value='$proxysettings{'PROXY_PORT'}' size='5' /></td>
+</tr>
+<tr>
+ <td class='base'>$Lang::tr{'log enabled'}:</td>
+ <td><input type='checkbox' name='LOGGING' $checked{'LOGGING'}{'on'} /></td>
+ <td>$Lang::tr{'squid extension methods'}: <img src='/blob.gif' alt='*' /></td>
+ <td><input type='text' name='EXTENSION_METHODS' value='$proxysettings{'EXTENSION_METHODS'}' /></td>
+</tr>
+<!--TAG FOR ADDONS-->
+<tr>
+ <td colspan='4'><hr /><b>$Lang::tr{'cache management'}</b></td>
+</tr>
+<tr>
+ <td width='25%' class='base'>$Lang::tr{'cache size'}</td>
+ <td><input type='text' name='CACHE_SIZE' value='$proxysettings{'CACHE_SIZE'}' size='5' /></td>
+</tr>
+<tr>
+ <td class='base'>$Lang::tr{'min size'}</td>
+ <td><input type='text' name='MIN_SIZE' value='$proxysettings{'MIN_SIZE'}' size='5' /></td>
+ <td class='base'>$Lang::tr{'max size'}</td>
+ <td><input type='text' name='MAX_SIZE' value='$proxysettings{'MAX_SIZE'}' size='5' /></td>
+</tr>
+<tr>
+ <td colspan='4'><hr /><b>$Lang::tr{'transfer limits'}</b></td>
+</tr>
+<tr>
+ <td class='base'>$Lang::tr{'max incoming size'}</td>
+ <td><input type='text' name='MAX_INCOMING_SIZE' value='$proxysettings{'MAX_INCOMING_SIZE'}' size='5' /></td>
+ <td class='base'>$Lang::tr{'max outgoing size'}</td>
+ <td><input type='text' name='MAX_OUTGOING_SIZE' value='$proxysettings{'MAX_OUTGOING_SIZE'}' size='5' /></td>
+</tr>
+</table>
+<table width='100%'>
+<hr />
+<tr>
+ <td width='28%'>
+ <img src='/blob.gif' align='top' alt='*' />
+ <font class='base'>$Lang::tr{'this field may be blank'}</font>
+ </td>
+ <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'clear cache'}' /></td>
+ <td width=33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
+ <td width='5%' align='right'>
+ <a href='${General::adminmanualurl}/services.html#services_webproxy' target='_blank'>
+ <img src='/images/web-support.png' title='$Lang::tr{'online help en'}' /></a></td>
+</tr>
+
+</table>
+END
+;
+&Header::closebox();
+
+print "</form>\n";
+
+&Header::closebigbox();
+
+&Header::closepage();
+
+} # end sub DoHTML
+1