PDA

View Full Version : adapt PHP Code Sample into a Perl Script


Ohnsorg
12-31-2008, 11:01 PM
a very happy New Year to all!

I am looking for Help to adapt the following PHP Code to make it work in a Perl Script.
It does deny access to a site by using Proxy Server Connection. In PHP Environment, this part of code works quite well.



if(isset($_SERVER['HTTP_X_FORWARDED_FOR']) || ($_SERVER['HTTP_USER_AGENT']=='') || ($_SERVER['HTTP_VIA']!='')){
die("Don't use Proxy server please");
}

$proxy_headers = array(
'HTTP_VIA',
'HTTP_X_FORWARDED_FOR',
'HTTP_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_FORWARDED',
'HTTP_CLIENT_IP',
'HTTP_FORWARDED_FOR_IP',
'VIA',
'X_FORWARDED_FOR',
'FORWARDED_FOR',
'X_FORWARDED',
'FORWARDED',
'CLIENT_IP',
'FORWARDED_FOR_IP',
'HTTP_PROXY_CONNECTION'
);
foreach($proxy_headers as $x){
if (isset($_SERVER[$x])) die("You are using a proxy!");
}


Thank you for assistance

Ohnsorg

KevinADC
12-31-2008, 11:12 PM
CGI scripts written with perl have to print an http header before trying to print anything else to the browser. A simple header is:

print "Content-type: text/html\n\n";

You can modify that per your own requirements or remove it if your script has already printed a header.


if ($ENV{'HTTP_X_FORWARDED_FOR'} || ! $ENV{'HTTP_USER_AGENT'} || $ENV{'HTTP_VIA'}){
print "Content-type: text/html\n\n";
print "Don't use Proxy server please";
exit;
}

my @proxy_headers = (
'HTTP_VIA',
'HTTP_X_FORWARDED_FOR',
'HTTP_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_FORWARDED',
'HTTP_CLIENT_IP',
'HTTP_FORWARDED_FOR_IP',
'VIA',
'X_FORWARDED_FOR',
'FORWARDED_FOR',
'X_FORWARDED',
'FORWARDED',
'CLIENT_IP',
'FORWARDED_FOR_IP',
'HTTP_PROXY_CONNECTION'
);

foreach my $x (@proxy_headers){
if ($ENV{$x}) {
print "Content-type: text/html\n\n";
print "You are using a proxy!";
exit;
}
}