// Ensure that the timeouts from fsockopen don't get reported as errors (possible, depends on the php server config)
error_reporting(0);
// Limit the amount of proxies that can be tested at any one time
$maximum_proxies_to_test = 50;
// Enter a password (if required) to protect the page
$password = '';
// Actual proxyjudge part of the page
function return_env_variables()
{
echo '<pre>'."\n";
foreach ($_SERVER as $header => $value )
{
if ((strpos($header , 'REMOTE')!== false || strpos($header , 'HTTP')!== false || strpos($header , 'REQUEST')!== false) && ( strpos($header , 'HTTP_HOST') !== 0))
{
echo $header.' = '.$value."\n";
}
}
echo '</pre>';
}
// Function to go away and get the page (calls through the proxy back to itself)
function get_judge_page($proxy)
{
// Depending on the server environment, this timeout setting may not be available.
$timeout = 15;
$proxy_cont = '';
list($proxy_host, $proxy_port) = explode(":", $proxy);
$proxy_fp = fsockopen($proxy_host, $proxy_port, $errornumber, $errorstring, $timeout);
if ($proxy_fp)
{
stream_set_timeout($proxy_fp, $timeout);
fputs($proxy_fp, "GET " . $_SERVER['SCRIPT_NAME'] . "?test HTTP/1.0\r\nHost: " . $_SERVER['SERVER_NAME'] . "\r\n\r\n");
while(!feof($proxy_fp))
{
$proxy_cont .= fread($proxy_fp,4096);
}
fclose($proxy_fp);
$proxy_cont = substr($proxy_cont, strpos($proxy_cont,"\r\n\r\n")+4);
}
return $proxy_cont;
}
// Check for the control string to see if it's a valid fetch of the judge
function check_valid_judge_response($page)
{
if(strlen($page) < 5)
return false;
return strpos($page, 'REMOTE_ADDR') !== false;
}
// Check for the IP addresses
function check_anonymity($page)
{
if(strpos($page, $_SERVER['LOCAL_ADDR']) !== false)
return false;
return true;
}
// Takes and tests a proxy
// 0 - Bad proxy
// 1 - Good (non anon) proxy
// 2 - Good (anonymous) proxy
function test_proxy($proxy)
{
$page = get_judge_page($proxy);
if(!check_valid_judge_response($page))
return 0;
if(!check_anonymity($page))
return 1;
return 2;
}
////////// Main Page ////////////
// If this is a judge request, just return the environmental variables
if(getenv('QUERY_STRING') == "test")
{
return_env_variables();
}
// Else check whether we have been passed a list of proxies to test or not
// Should really use $_POST but it's been left as $HTTP_POST_VARS for older versions of php (3.x)
elseif( (isset($HTTP_POST_VARS['action']) && $HTTP_POST_VARS['action'] === 'fred') &&
(isset($HTTP_POST_VARS['proxies']) && $HTTP_POST_VARS['proxies'] != '') &&
( (strlen($password) == 0) || (isset($HTTP_POST_VARS['password']) && $HTTP_POST_VARS['password'] === $password) ))
{
$proxies = explode("\n", str_replace("\r", "", $HTTP_POST_VARS['proxies']), $maximum_proxies_to_test + 1);
// Set the overall time limit for the page execution to 10 mins
set_time_limit(600);
// Set up some arrays to hold the results
$anon_proxies = array();
$nonanon_proxies = array();
$bad_proxies = array();