Location: PHPKode > scripts > CrawlProtect > crawlprotect/noaccess/noaccess1.php
<?php
//----------------------------------------------------------------------
//  CrawlProtect 2.0.0
//----------------------------------------------------------------------
// Protect your website from hackers
//----------------------------------------------------------------------
// Author: Jean-Denis Brun
//----------------------------------------------------------------------
// Website: www.crawlprotect.com
//----------------------------------------------------------------------
// That script is distributed under GNU GPL license
//----------------------------------------------------------------------
// file: noaccess1.php
//----------------------------------------------------------------------
//  Last update: 20/06/2010
//----------------------------------------------------------------------
error_reporting(E_ALL);
header( "Status: 403 request forbidden", false, 403); 
//chmod the directory
if(function_exists('chmod'))
	{
	chmod('../data', 0755);
	}
if(file_exists('../data/injection.php') )
	{
	include "../data/injection.php";
	if(function_exists('chmod'))
		{
		chmod('../data/injection.php', 0644);
		}
	}
else
	{
	$injection=0;
	}
//count the hacking attempt
if(isset($injection))
	{
	$injection++;
	@$content.="<?php\n";
	@$content.="\$injection=\"$injection\";\n";
	@$content.="?>\n";
	$fp = fopen("../data/injection.php", "w");
	if (flock($fp, LOCK_EX))
		{
		ftruncate($fp, 0); 
		fwrite($fp, $content);
		flock($fp, LOCK_UN);
		}
	fclose($fp);
	}
//detect country of origin
//requete to get the country code
$ip = $_SERVER['REMOTE_ADDR'];
// Test to see if the server is running a standalone version of GeoIP
if(!function_exists('geoip_country_name_by_addr'))
	{
	include("../geoipdatabase/geoip.inc");
	}
$gi = geoip_open("../geoipdatabase/GeoIP.dat",GEOIP_STANDARD);
$code = str_replace("'"," ",geoip_country_name_by_addr($gi, $ip));
geoip_close($gi);

if(file_exists('../data/country.php'))
	{
	include "../data/country.php";
	if(function_exists('chmod'))
		{
		chmod('../data/country.php', 0644);
		}
	}
else
	{
	$countryserialize='a:0:{}';
	$listipserialize='a:0:{}';
	}
if(!isset($logrecording))
	{
	$logrecording='ok';
	}
 

if(isset($countryserialize))
	{
	$country=unserialize($countryserialize);
	if(isset($country[$code]))
		{
		$country[$code]++;
		}
	else
		{
		$country[$code]=1;
		}
	$countryserialize=serialize($country);

	$listip=unserialize($listipserialize);
	if(isset($listip[$ip]))
		{
		$listip[$ip]++;
		}
	else
		{
		$listip[$ip]=1;
		}
	$listipserialize=serialize($listip);

	@$content2.="<?php\n";
	@$content2.="\$countryserialize='$countryserialize';\n";
	@$content2.="\$listipserialize='$listipserialize';\n";
	@$content2.="\$logrecording='$logrecording';\n";
	@$content2.="?>\n";
	$fp = fopen("../data/country.php", "w");
	if (flock($fp, LOCK_EX))
		{
		ftruncate($fp, 0);
		fwrite($fp, $content2);
		flock($fp, LOCK_UN);
		}
	fclose($fp);
	}

//log attack info
if($logrecording=='ok')
	{
	// to cut and wrap the url to avoid oversize display
	$length=90;
	$url=$_SERVER['REQUEST_URI'];
	$urldisplaylength = strlen($url);

	$cutvalue = 0;
	$urldisplay='';
	while ($cutvalue <= $urldisplaylength)
	{
	$cutvalue2 = $cutvalue + $length;
	$urldisplay= $urldisplay.htmlspecialchars(substr($url,$cutvalue,$length));
	if ($cutvalue2 <= $urldisplaylength)
		{
		$urldisplay = $urldisplay.'<br>&nbsp;&nbsp;';
		$urlcut=1;
		}
	$cutvalue = $cutvalue2;
	}

	$file = '../data/log.txt';

	if(file_exists($file) )
		{
		chmod($file, 0644);
		}

	$loginfo="<tr><td>".date("M j . Y , H:i")."</td><td><b>Url:</b>&nbsp;".$urldisplay."</td><td>".$ip."</td><td>".$code."</td></tr>\n";

	$fp = fopen($file, "a");
	if (flock($fp, LOCK_EX))
		{
		fwrite($fp, $loginfo);
		flock($fp, LOCK_UN);
		}
	fclose($fp);
	if(function_exists('chmod'))
		{
		chmod('../data/log.txt', 0404);
		}
	}


//chmod the directory & the file
if(function_exists('chmod'))
	{
	chmod('../data', 0505);
	chmod('../data/injection.php', 0404);
	chmod('../data/country.php', 0404);
	}

echo"<!-Noaccess1 Bad url= ".$_SERVER['REQUEST_URI']."  -->\n";
?>
<html>
<head>
<title>CrawlProtect 2-0-0</title>
<meta http-equiv="Content-Language" content="en">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<br><br><br><br><br><br>
<div align="center">
<h1>This site is protected by CrawlProtect !!!</h1>
<h1>Your visit has been blocked.</h1>
<p>If you think that this shouldn't have been the case, please contact the webmaster.</p>
</div>
<br><br><br>
</body>
</html>
Return current item: CrawlProtect