Location: PHPKode > scripts > CrawlProtect > crawlprotect/include/functionsdata.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: functiondata.php
//----------------------------------------------------------------------
//  Last update: 03/07/2010
//----------------------------------------------------------------------
//function to escape query string
function sql_quote( $value )
	{
	if( get_magic_quotes_gpc() )
		{
		$value = stripslashes( $value );
		}
	//check if this function exists
	if( function_exists( "mysql_real_escape_string"))
		{
		$value = mysql_real_escape_string($value);
		}
	//for PHP version < 4.3.0 use addslashes
		else
		{
		$value = addslashes( $value );
		}
	return $value;
	}
//functions to change login
function changelogin($type)
	{
	global $validuser, $connexion, $errorchangelogin, $logindb;
	if($type=='mysql')
		{
		$sql ="UPDATE crawlp_login SET crawlp_user = '0', crawlp_password = '0'";
		$requete = mysql_query($sql, $connexion);
		session_destroy();
		$validuser=0;
		$logindb=0;
		if($requete)
			{
			$errorchangelogin=0;
			}
		else
			{
			$errorchangelogin=1;
			}
			if(!isset($_SESSION['flag']))
				{
				session_name('crawlp');
				session_start();
				$_SESSION['flag'] = true;
				}
		}
	else
		{
		if(function_exists('chmod'))
			{
			$path=$_SESSION['path']."/include";
			chmod($path,0755);
			chmod('include/config.php',0644);
			}
		unlink("include/config.php");
		session_destroy();
		$validuser=0;
		if(file_exists('include/config.php'))
			{
			$errorchangelogin=1;
			}
		else
			{
			$errorchangelogin=0;
			}
			if(!isset($_SESSION['flag']))
				{
				session_name('crawlp');
				session_start();
				$_SESSION['flag'] = true;
				}
		}
	}
//functions to get language file info
function getlanguage($type)
	{
	global $languageuse,$connexion, $langdb;
	if($type=='mysql')
		{
		$sqlsetting = "SELECT * FROM crawlp_setting";
		$requetesetting = mysql_query($sqlsetting, $connexion);
		$nbrresult=mysql_num_rows($requetesetting);
		if($nbrresult>=1)
			{
			$ligne = mysql_fetch_assoc($requetesetting);
			$languageuse = $ligne['language'];
			$langdb=$languageuse;
			}
		else
			{
			$languageuse='language/english.php';
			$langdb='';
			}
		}
	elseif($type=='file')
		{
		if(file_exists('data/language.php'))
			{
			include "data/language.php";
			}
		else
			{
			$languageuse='language/english.php';
			}
		}
	else
		{
		$languageuse='language/english.php';
		}
	}
//function to login
function login($type)
	{
	global $validuser, $userlogin, $userpass, $connexion;
	if($type=='mysql')
		{
		$sqlconfig = "SELECT * FROM crawlp_login";
		$requeteconfig = mysql_query($sqlconfig, $connexion);
		$nbrresult=mysql_num_rows($requeteconfig);
		if($nbrresult>=1  && (!isset($validuser) OR $validuser==0))
			{
			$ligne = mysql_fetch_assoc($requeteconfig);
			$logindb = $ligne['crawlp_user'];
			$passworddb = $ligne['crawlp_password'];
			if(isset($_POST['userlogin']))
				{
				$userlogin = $_POST['userlogin'];
				}
			else
				{
				$userlogin = '';
				}
			if(isset($_POST['userpass']))
				{
				$userpass = md5($_POST['userpass']);
				}
			else
				{
				$userpass = '';
				}
			if($userlogin==$logindb && $userpass==$passworddb && $logindb!='0' && $passworddb!='0')
				{
				$validuser=1;
				$_SESSION['login2']='ok';
				}
			else
			 	{
				$validuser=0;
				$_SESSION['login2']='nook';
				}
			}
		}
	elseif($type=='file')
		{
		if(file_exists('include/config.php') && (!isset($validuser) OR $validuser==0))
			{
			if(isset($_POST['userlogin']))
				{
				$userlogin = $_POST['userlogin'];
				}
			else
				{
				$userlogin = '';
				}
			if(isset($_POST['userpass']))
				{
				$userpass = md5($_POST['userpass']);
				}
			else
				{
				$userpass = '';
				}
			include("include/config.php");

			if($userlogin==$adminlogin && $userpass==$adminpass)
				{
				$validuser=1;
				$_SESSION['login2']='ok';
				}
			else
			 	{
				$validuser=0;
				}
			//clear the cache folder
			$dir = dir('./cache/');
			if(function_exists('chmod'))
				{
				chmod('./cache/', 0755);
				}
			while (false !== $entry = $dir->read())
				{
				// Skip pointers
			 	if ($entry == '.' || $entry == '..')
					{
					continue;
					}
				unlink("./cache/$entry");
				}
			}
		}
	}
//function to refresh data
function refresh($type)
	{
	global $refresh;
	if($type=='mysql' OR $type=='mysql-no-configconnect')
		{
		if($refresh=='ok')
			{
			if(isset($_SESSION['nofile']))
				{
				unset($_SESSION['nofile']);
				}
			if(isset($_SESSION['yourrelease']))
				{
				unset($_SESSION['yourrelease']);
				}
			if(isset($_SESSION['verif']))
				{
				unset($_SESSION['verif']);
				}
			}
		}
	else
		{
		if($refresh=='ok')
			{
			if(isset($_SESSION['nofile']))
				{
				unset($_SESSION['nofile']);
				}
			if(isset($_SESSION['yourrelease']))
				{
				unset($_SESSION['yourrelease']);
				}
			if(isset($_SESSION['verif']))
				{
				unset($_SESSION['verif']);
				}
			//clear the cache folder
			$dir = dir('./cache/');
			if(function_exists('chmod'))
				{
				chmod('./cache/', 0755);
				}
			while (false !== $entry = $dir->read())
				{
				// Skip pointers
				if ($entry == '.' || $entry == '..')
					{
					continue;
					}
				unlink("./cache/$entry");
				}
			}
		}
	}
//function to get the datas
function getdatas($type)
	{
	global $injection, $badbot, $shell, $spam, $listipserialize, $countryserialize, $logrecording, $graph, $connexion, $log;
	if($type=='mysql')
		{
		$injection=0;
		$badbot=0;
		$shell=0;
		$spam=0;
		$log='';
		$country=array();
		$listip=array();
		$sql = "SELECT * FROM crawlp_stats";
		$requete = mysql_query($sql, $connexion);
		$nbrresult=mysql_num_rows($requete);
		if($nbrresult>=1)
			{
			if(file_exists("./geoipdatabase/geoip.inc"))
				{
				$case=1;
				}
			else
				{
				$case=2;
				}
			// Test to see if the server is running a standalone version of GeoIP
			if(!function_exists('geoip_country_name_by_addr'))
				{
				if($case==1)
					{
					include("./geoipdatabase/geoip.inc");
					}
				else
					{
					include("../geoipdatabase/geoip.inc");
					}
				}
			while($ligne = mysql_fetch_assoc($requete))
				{
				$ip=$ligne['ip'];
				if($case==1)
					{
					$gi = geoip_open("./geoipdatabase/GeoIP.dat",GEOIP_STANDARD);
					}
				else
					{
					$gi = geoip_open("../geoipdatabase/GeoIP.dat",GEOIP_STANDARD);
					}
				$code = str_replace("'"," ",geoip_country_name_by_addr($gi, $ip));
				geoip_close($gi);
				// to cut and wrap the url to avoid oversize display
				$length=90;
				$url=$ligne['url'];
				$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;
				}
				if(isset($country[$code]))
					{
					$country[$code]++;
					}
				else
					{
					$country[$code]=1;
					}
				if(isset($listip[$ligne['ip']]))
					{
					$listip[$ligne['ip']]++;
					}
				else
					{
					$listip[$ligne['ip']]=1;
					}
				if($ligne['attack']==1)
					{
					$injection++;
					$loginfo="<tr><td>".$ligne['date']."</td><td><b>Url:</b>&nbsp;".$urldisplay."</td><td>".$ligne['ip']."</td><td>".$code."</td></tr>\n";
					}
				elseif($ligne['attack']==2)
					{
					$badbot++;
					$loginfo="<tr><td>".$ligne['date']."</td><td><b>User-Agent:</b>&nbsp;".$urldisplay."</td><td>".$ligne['ip']."</td><td>".$code."</td></tr>\n";
					}
				elseif($ligne['attack']==3)
					{
					$shell++;
					$loginfo="<tr><td>".$ligne['date']."</td><td><b>Url:</b>&nbsp;".$urldisplay."</td><td>".$ligne['ip']."</td><td>".$code."</td></tr>\n";
					}
				elseif($ligne['attack']==4)
					{
					$spam++;
					$loginfo="<tr><td>".$ligne['date']."</td><td><b>Referer:</b>&nbsp;".$urldisplay."</td><td>".$ligne['ip']."</td><td>".$code."</td></tr>\n";
					}
				$log=$log.$loginfo;
				}
			$countryserialize=serialize($country);
			$listipserialize=serialize($listip);
			}
		else
			{
			$injection = 0;
			$badbot = 0;
			$shell = 0;
			$spam = 0;
			$listipserialize='a:0:{}';
			$countryserialize='a:0:{}';
			}
		$sql = "SELECT * FROM crawlp_setting";
		$requete = mysql_query($sql, $connexion);
		$nbrresult=mysql_num_rows($requete);
		if($nbrresult>=1)
			{
			$ligne = mysql_fetch_assoc($requete);
			$logrecording = $ligne['logrecording'];
			$graph = $ligne['graph'];
			}
		else
			{
			$logrecording = 'ok';
			$graph = 1;
			}
		}
	else
		{
		if(file_exists('data/injection.php') )
			{
			include "data/injection.php";
			}
		else
			{
			$injection=0;
			}
		if(file_exists('data/badbot.php') )
			{
			include "data/badbot.php";
			}
		else
			{
			$badbot=0;
			}
		if(file_exists('data/shell.php') )
			{
			include "data/shell.php";
			}
		else
			{
			$shell=0;
			}
		if(file_exists('data/spam.php') )
			{
			include "data/spam.php";
			}
		else
			{
			$spam=0;
			}
		if(file_exists('data/country.php') )
			{
			include "data/country.php";
			//case upgrade from release before 1.8.0
			if(!isset($listipserialize))
				{
				$listipserialize='a:0:{}';
				}
			}
		else
			{
			$countryserialize='a:0:{}';
			$listipserialize='a:0:{}';
			} 
		if(!isset($logrecording))
			{
			$logrecording='ok';
			}
		if(file_exists('data/graph.php') )
			{
			include "data/graph.php";
			}
		else
			{
			$graph=1;
			}
		}
	}
//function to get bad IP list
function badip($type)
	{
	global $listbadip, $connexion, $badip;
	if($type=='mysql')
		{
		$sql = "SELECT * FROM crawlp_bad";
		$requete = mysql_query($sql, $connexion);
		$nbrresult=mysql_num_rows($requete);
		if($nbrresult>=1)
			{
			$ligne = mysql_fetch_assoc($requete);
			$badip = $ligne['listip'];
			if($badip !='')
				{
				$listbadip=explode(',',$badip);	
				}
			else
				{
				$listbadip=array();
				}
			}
		else
			{
			$listbadip=array();
			}
		}
	else
		{
		if(file_exists('data/badip.php') )
			{
			include("data/badip.php");
			if($badip !='')
				{
				$listbadip=explode(',',$badip);
				}
			else
				{
				$listbadip=array();
				}
			}
		elseif(file_exists('badip.php') ) //to keep settings from previous release
			{
			include "badip.php";
			if($badip !='')
				{
				$listbadip=explode(',',$badip);
				}
			else
				{
				$listbadip=array();
				}
			}
		else
			{
			$listbadip=array();
			}
		}
	}
//functions to enter login info in file or database
function createlogin($type)
	{
	global $password2, $login, $connexion, $language;
	if($type=='mysql' OR $type=='mysql-no-configconnect')
		{
		//password treatment
		$pass=md5($password2);
		$sql ="INSERT INTO crawlp_login (crawlp_user,crawlp_password) VALUES ( '".sql_quote($login)."','".sql_quote($pass)."')";
		$requete = mysql_query($sql, $connexion);
		if($requete)
			{
			$_SESSION['login2']='ok';
			echo"<br><br>\n";
			echo"<h2>".$language['Installation_OK']."</h2>\n";
			echo"<form action=\"index.php\" method=\"POST\">\n";
			echo "<input type=\"hidden\" name ='navig' value='0'>\n";
			$text=$language['Continue'];
			echo"<input name='ok' type='submit'  value='$text' size='20' >\n";
			echo"</p></form>&nbsp;\n";
			}
		}
	else
		{
		//create the config file
		//password treatment
		$pass=md5($password2);
		@$content.="<?php\n";
		@$content.="\$adminlogin='$login';\n";
		@$content.="\$adminpass='$pass';\n";
		@$content.="?>\n";
		if(function_exists('chmod'))
			{
			$path=$_SESSION['path']."/include";
			chmod($path,0755);
			}
		if ( $file = fopen('include/config.php', "w"))
			{
			fwrite($file, $content);
			fclose($file);
			}
		//check is file creation is successfull
		if(file_exists('include/config.php'))
			{
			$_SESSION['login2']='ok';
			if(function_exists('chmod'))
				{
				chmod($path,0505);
				chmod('include/config.php',0404);
				}
			echo"<br><br>\n";
			echo"<h2>".$language['Installation_OK']."</h2>\n";
			echo"<form action=\"index.php\" method=\"POST\">\n";
			echo "<input type=\"hidden\" name ='navig' value='0'>\n";
			$text=$language['Continue'];
			echo"<input name='ok' type='submit'  value='$text' size='20' >\n";
			echo"</p></form>&nbsp;\n";
			}
		else
			{
			echo"<h2>".$language['chmod_no_ok']."</h2>\n";
			echo"<p>".$language['chmod_no_ok2']."</p>\n";
			}
		}
	}
//functions to enter language info in file or database	
function createlang($type)
	{
	global $languageuse, $langdb, $connexion, $language;
	if($type=='mysql' OR $type=='mysql-no-configconnect')
		{
		if($langdb == '')
			{
			$lang= $_POST['langinstall'];
			if($lang==1)
				{
				$languageuse='language/french.php';
				}
			elseif($lang==2)
				{
				$languageuse='language/english.php';
				}
			$sqlsetting = "SELECT * FROM crawlp_setting";
			$requetesetting = mysql_query($sqlsetting, $connexion);
			$nbrresult=mysql_num_rows($requetesetting);
			if($nbrresult>=1)
				{
				$sql ="UPDATE crawlp_setting SET language='".sql_quote($languageuse)."'";
				$requete = mysql_query($sql, $connexion);
				}
			else
				{
				$sql ="INSERT INTO crawlp_setting (language) VALUES ( '".sql_quote($languageuse)."')";
				$requete = mysql_query($sql, $connexion);
				}
			include ("".$languageuse."");
			}
		else
			{
			include ("".$langdb."");
			}
		}
	else
		{
		if(!file_exists('data/language.php'))
			{
			$lang= $_POST['langinstall'];
			if(function_exists('chmod'))
				{
				$path=$_SESSION['path']."/data";
				chmod($path,0755);
				}
			if($lang==1)
				{
				@$content.="<?php\n";
				@$content.="\$languageuse='language/french.php';\n";
				@$content.="?>\n";
				$fp = fopen("data/language.php", "w");
				if (flock($fp, LOCK_EX))
					{
					ftruncate($fp, 0); 
					fwrite($fp, $content);
					flock($fp, LOCK_UN);
					}
				fclose($fp);
				require "language/french.php";
				}
			elseif($lang==2)
				{
				@$content.="<?php\n";
				@$content.="\$languageuse='language/english.php';\n";
				@$content.="?>\n";
				$fp = fopen("data/language.php", "w");	
				if (flock($fp, LOCK_EX))
					{
					ftruncate($fp, 0); 
					fwrite($fp, $content);
					flock($fp, LOCK_UN);
					}
				fclose($fp);
				require "language/english.php";
				}
			if(function_exists('chmod'))
				{
				chmod($path, 0505);
				}
			}
		else
			{
			include "data/language.php";
			include ("".$languageuse."");
			}
		}
	}
//function to get log
function displaylog($type)
	{
	global $log;
	if($type=='mysql')
		{
		echo $log;
		}
	else
		{
		include("data/log.txt");
		}
	}
//function to get logrecording value
function getlogrecording($type)
	{
	global $connexion,$logrecording, $logrecording2;
	if($type=='mysql')
		{
		$sql = "SELECT * FROM crawlp_setting";
		$requete = mysql_query($sql, $connexion);
		$nbrresult=mysql_num_rows($requete);
		if($nbrresult>=1)
			{
			$ligne = mysql_fetch_assoc($requete);
			$logrecording = $ligne['logrecording'];
			}
		else
			{
			$logrecording='yes';
			}
		}
	else
		{
		if(file_exists('data/country.php') )
			{
			include "data/country.php";
			if(!isset($logrecording))
				{
				$logrecording='yes';
				}
			}
		else
			{
			$logrecording=$logrecording2;
			}
		}
	}
//function to change logrecording value
function changelogrecording($type)
	{
	global $connexion,$logrecording, $logrecording2;
	if($type=='mysql')
		{
		$sqlsetting = "SELECT * FROM crawlp_setting";
		$requetesetting = mysql_query($sqlsetting, $connexion);
		$nbrresult=mysql_num_rows($requetesetting);
		if($nbrresult>=1)
			{
			$sql ="UPDATE crawlp_setting SET logrecording='".sql_quote($logrecording2)."'";
			$requete = mysql_query($sql, $connexion);
			}
		else
			{
			$sql ="INSERT INTO crawlp_setting (logrecording) VALUES ( '".sql_quote($logrecording2)."')";
			$requete = mysql_query($sql, $connexion);
			}
		}
	else
		{
		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:{}';
			}
		@$content2.="<?php\n";
		@$content2.="\$countryserialize='$countryserialize';\n";
		@$content2.="\$listipserialize='$listipserialize';\n";
		@$content2.="\$logrecording='$logrecording2';\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);
		if(function_exists('chmod'))
			{
			chmod('data/country.php', 0404);
			}
		$logrecording=$logrecording2;
		//clear the cache folder
		$dir = dir('./cache/');
		if(function_exists('chmod'))
			{
			chmod('./cache/', 0755);
			}
		while (false !== $entry = $dir->read())
			{
			// Skip pointers
			if ($entry == '.' || $entry == '..')
				{
				continue;
				}
			unlink("./cache/$entry");
			}
		}
	}
//function to change files setting value
function changefilesetting($type)
	{
	global $connexion,$whichfile, $folderlevel, $justbad, $nocache, $nostats, $nologs;
	if($type=='mysql')
		{
		$sqlsetting = "SELECT * FROM crawlp_setting";
		$requetesetting = mysql_query($sqlsetting, $connexion);
		$nbrresult=mysql_num_rows($requetesetting);
		if($nbrresult>=1)
			{
			$sql ="UPDATE crawlp_setting SET whichfile='".sql_quote($whichfile)."', folderlevel='".sql_quote($folderlevel)."', justbad='".sql_quote($justbad)."', nocache='".sql_quote($nocache)."',nostats='".sql_quote($nostats)."', nologs='".sql_quote($nologs)."'";
			$requete = mysql_query($sql, $connexion) or die(mysql_error());
			}
		else
			{
			$sql ="INSERT INTO crawlp_setting (whichfile, folderlevel, justbad,nocache, nostats, nologs) VALUES ( '".sql_quote($whichfile)."','".sql_quote($folderlevel)."','".sql_quote($justbad)."','".sql_quote($nocache)."','".sql_quote($nostats)."','".sql_quote($nologs)."')";
			$requete = mysql_query($sql, $connexion) or die(mysql_error());
			}
		}
	else
		{
		if(function_exists('chmod'))
			{
			$path=$_SESSION['path']."/data";
			chmod($path,0755);
			if(file_exists('data/file.php'))
				{
				chmod('data/file.php',0644);
				}
			}
			@$content.="<?php\n";
			@$content.="\$whichfile='$whichfile';\n";
			@$content.="\$folderlevel='$folderlevel';\n";
			@$content.="\$justbad='$justbad';\n";
			@$content.="\$nocache='$nocache';\n";
			@$content.="\$nostats='$nostats';\n";
			@$content.="\$nologs='$nologs';\n";
			@$content.="?>\n";
			$fp = fopen("data/file.php", "w");
			if (flock($fp, LOCK_EX))
				{
				ftruncate($fp, 0);
				fwrite($fp, $content);
				flock($fp, LOCK_UN);
				}
			fclose($fp);
		if(function_exists('chmod'))
			{
			chmod($path, 0505);
			if(file_exists('data/file.php'))
				{
				chmod('data/file.php',0404);
				}
			}
		//clear the cache folder
		$dir = dir('./cache/');
		if(function_exists('chmod'))
			{
			chmod('./cache/',0755);
			}
		while (false !== $entry = $dir->read())
			{
			// Skip pointers
			if ($entry == '.' || $entry == '..')
				{
				continue;
				}
			unlink("./cache/$entry");
			}
		}
	}
//function to change language
function changelang($type)
	{
	global $connexion,$lang;
	if($type=='mysql')
		{
		if($lang==1)
			{
			$languageuse='language/french.php';
			}
		elseif($lang==2)
			{
			$languageuse='language/english.php';
			}
		$sqlsetting = "SELECT * FROM crawlp_setting";
		$requetesetting = mysql_query($sqlsetting, $connexion);
		$nbrresult=mysql_num_rows($requetesetting);
		if($nbrresult>=1)
			{
			$sql ="UPDATE crawlp_setting SET  language='".sql_quote($languageuse)."'";
			$requete = mysql_query($sql, $connexion);
			}
		else
			{
			$sql ="INSERT INTO crawlp_setting (language) VALUES ( '".sql_quote($languageuse)."')";
			$requete = mysql_query($sql, $connexion);
			}
		}
	else
		{
		if(function_exists('chmod'))
			{
			$path=$_SESSION['path']."/data";
			chmod($path,0755);
			if(file_exists('data/language.php'))
				{
				chmod('data/language.php',0644);
				}
			}
		if($lang==1)
			{
			@$content.="<?php\n";
			@$content.="\$languageuse='language/french.php';\n";
			@$content.="?>\n";
			$fp = fopen("data/language.php", "w");
			if (flock($fp, LOCK_EX))
				{
				ftruncate($fp, 0);
				fwrite($fp, $content);
				flock($fp, LOCK_UN);
				}
			fclose($fp);
			}
		elseif($lang==2)
			{
			@$content.="<?php\n";
			@$content.="\$languageuse='language/english.php';\n";
			@$content.="?>\n";
			$fp = fopen("data/language.php", "w");
			if (flock($fp, LOCK_EX))
				{
				ftruncate($fp, 0);
				fwrite($fp, $content);
				flock($fp, LOCK_UN);
				}
			fclose($fp);
			}
		if(function_exists('chmod'))
			{
			chmod($path,0505);
			if(file_exists('data/language.php'))
				{
				chmod('data/language.php',0404);
				}
			}
		}
	}
//function to change graph display
function changegraph($type)
	{
	global $connexion,$graph;
	if($type=='mysql')
		{
		$sqlsetting = "SELECT * FROM crawlp_setting";
		$requetesetting = mysql_query($sqlsetting, $connexion);
		$nbrresult=mysql_num_rows($requetesetting);
		if($nbrresult>=1)
			{
			$sql ="UPDATE crawlp_setting SET  graph='".sql_quote($graph)."'";
			$requete = mysql_query($sql, $connexion);
			}
		else
			{
			$sql ="INSERT INTO crawlp_setting (graph) VALUES ( '".sql_quote($graph)."')";
			$requete = mysql_query($sql, $connexion);
			}
		}
	else
		{
		if(function_exists('chmod'))
			{
			$path=$_SESSION['path']."/data";
			chmod($path,0755);
			if(file_exists('data/graph.php'))
				{
				chmod('data/graph.php',0644);
				}
			}
		if($graph==1)
			{
			@$content.="<?php\n";
			@$content.="\$graph=1;\n";
			@$content.="?>\n";
			$fp = fopen("data/graph.php", "w");
			if (flock($fp, LOCK_EX))
				{
				ftruncate($fp, 0);
				fwrite($fp, $content);
				flock($fp, LOCK_UN);
				}
			fclose($fp);
			}
		elseif($graph==0)
			{
			@$content.="<?php\n";
			@$content.="\$graph=0;\n";
			@$content.="?>\n";
			$fp = fopen("data/graph.php", "w");
			if (flock($fp, LOCK_EX))
				{
				ftruncate($fp, 0);
				fwrite($fp, $content);
				flock($fp, LOCK_UN);
				}
			fclose($fp);
			}
		if(function_exists('chmod'))
			{
			chmod($path,0505);
			if(file_exists('data/graph.php'))
				{
				chmod('data/graph.php',0404);
				}
			}
		}
	}
//function to get setting value
function getsetting($type)
	{
	global $connexion,$whichfile, $folderlevel, $justbad, $nocache, $nostats, $nologs;
	if($type=='mysql')
		{
		$sql = "SELECT * FROM crawlp_setting";
		$requete = mysql_query($sql, $connexion);
		$nbrresult=mysql_num_rows($requete);
		if($nbrresult>=1)
			{
			$ligne = mysql_fetch_assoc($requete);
			$whichfile = $ligne['whichfile'];
			$folderlevel = $ligne['folderlevel'];
			$justbad = $ligne['justbad'];
			$nocache = $ligne['nocache'];
			$nostats = $ligne['nostats'];
			$nologs = $ligne['nologs'];
			}
		else
			{
			$whichfile='all';
			$folderlevel='all';
			$justbad='no';
			$nocache='no';
			$nostats='no';
			$nologs='no';
			}
		}
	else
		{
		if(file_exists('data/file.php'))
			{
			include "data/file.php";
			}
		else
			{
			$whichfile='all';
			$folderlevel='all';
			$justbad='no';
			$nocache='no';
			$nostats='no';
			$nologs='no';
			}
		}
	}
//function to reset the datas
function resetdatas($type)
	{
	global $injection, $badbot, $shell, $spam, $listipserialize, $countryserialize,$logrecording, $connexion;
	if($type=='mysql')
		{
		$sql = "TRUNCATE crawlp_stats";
		$requete = mysql_query($sql, $connexion);
		}
	else
		{
		if(function_exists('chmod'))
			{
			if(file_exists('data/injection.php'))
				{
				chmod('data/injection.php',0644);
				}
			if(file_exists('data/badbot.php'))
				{
				chmod('data/badbot.php',0644);
				}
			if(file_exists('data/shell.php'))
				{
				chmod('data/shell.php',0644);
				}
			if(file_exists('data/spam.php'))
				{
				chmod('data/spam.php',0644);
				}
			if(file_exists('data/country.php'))
				{
				chmod('data/country.php',0644);
				}
			if(file_exists('data/log.txt'))
				{
				chmod('data/log.txt',0644);
				}
			}
		@$content.="<?php\n";
		@$content.="\$injection=\"0\";\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);
		@$content2.="<?php\n";
		@$content2.="\$badbot=\"0\";\n";
		@$content2.="?>\n";
		$fp = fopen("data/badbot.php","w");
		if (flock($fp, LOCK_EX))
			{
			ftruncate($fp, 0);
			fwrite($fp, $content2);
			flock($fp, LOCK_UN);
			}
		fclose($fp);
		@$content3.="<?php\n";
		@$content3.="\$shell=\"0\";\n";
		@$content3.="?>\n";
		$fp = fopen("data/shell.php","w");
		if (flock($fp, LOCK_EX))
			{
			ftruncate($fp, 0);
			fwrite($fp, $content3);
			flock($fp, LOCK_UN);
			}
		fclose($fp);
		@$content5.="<?php\n";
		@$content5.="\$spam=\"0\";\n";
		@$content5.="?>\n";
		$fp = fopen("data/spam.php","w");
		if (flock($fp, LOCK_EX))
			{
			ftruncate($fp, 0);
			fwrite($fp, $content5);
			flock($fp, LOCK_UN);
			}
		fclose($fp);
		@$content4.="<?php\n";
		@$content4.="\$countryserialize='a:0:{}';\n";
		@$content4.="\$listipserialize='a:0:{}';\n";
		@$content4.="\$logrecording='$logrecording';\n";
		@$content4.="?>\n";
		$fp = fopen("data/country.php", "w");
		if (flock($fp, LOCK_EX))
			{
			ftruncate($fp, 0);
			fwrite($fp, $content4);
			flock($fp, LOCK_UN);
			}
		fclose($fp);
		$fp = fopen("data/log.txt","w");
		$content6="";
		if (flock($fp, LOCK_EX))
			{
			ftruncate($fp, 0);
			fwrite($fp, $content6);
			flock($fp, LOCK_UN);
			}
		fclose($fp);
		if(function_exists('chmod'))
			{
			if(file_exists('data/injection.php'))
				{
				chmod('data/injection.php',0404);
				}
			if(file_exists('data/badbot.php'))
				{
				chmod('data/badbot.php',0404);
				}
			if(file_exists('data/shell.php'))
				{
				chmod('data/shell.php',0404);
				}
			if(file_exists('data/spam.php'))
				{
				chmod('data/spam.php',0404);
				}
			if(file_exists('data/country.php'))
				{
				chmod('data/country.php',0404);
				}
			if(file_exists('data/log.txt'))
				{
				chmod('data/log.txt',0404);
				}
			}
		if(isset($_SESSION['filelist']))
			{
			unset($_SESSION['filelist']);
			}
		if(isset($_SESSION['dirlist']))
			{
			unset($_SESSION['dirlist']);
			}
		//clear the cache folder
		$dir = dir('./cache/');
		if(function_exists('chmod'))
			{
			chmod('./cache/',0755);
			}
		while (false !== $entry = $dir->read())
			{
			// Skip pointers
			if ($entry == '.' || $entry == '..')
				{
				continue;
				}
			unlink("./cache/$entry");
			}
		}
	}
//function to get bad referer list
function badreferer($type)
	{
	global $listbadreferer, $connexion, $badreferer;
	if($type=='mysql')
		{
		$sql = "SELECT * FROM crawlp_bad";
		$requete = mysql_query($sql, $connexion);
		$nbrresult=mysql_num_rows($requete);
		if($nbrresult>=1)
			{
			$ligne = mysql_fetch_assoc($requete);
			$badreferer = $ligne['listreferer'];
			if($badreferer !='')
				{
				$listbadreferer=explode(',',$badreferer);
				}
			else
				{
				$listbadreferer=array();
				}
			}
		else
			{
			$listbadreferer=array();
			}
		}
	else
		{
		if(file_exists('data/badreferer.php') )
			{
			include("data/badreferer.php");
			if($badreferer !='')
				{
				$listbadreferer=explode(',',$badreferer);
				}
			else
				{
				$listbadreferer=array();
				}
			}
		elseif(file_exists('badreferer.php') ) //to keep settings from previous release
			{
			include "badreferer.php";
			if($badreferer !='')
				{
				$listbadreferer=explode(',',$badreferer);
				}
			else
				{
				$listbadreferer=array();
				}
			}
		else
			{
			$listbadreferer=array();
			}
		}
	}
//function to change files setting value
function updateselectionscript($type)
	{
	global $connexion,$crawltrack, $phpmyvisites, $piwik, $socialengine, $vbulletin, $wordpress,$pageear,$JosDewplayer,$imperial,$cornerpubli,$vbseo,$drupal,$punbb,$openx;
	if($type=='mysql')
		{
		$sqlsetting = "SELECT * FROM crawlp_script";
		$requetesetting = mysql_query($sqlsetting, $connexion);
		$nbrresult=mysql_num_rows($requetesetting);
		if($nbrresult>=1)
			{
			$sql ="UPDATE crawlp_script SET crawltrack='".sql_quote($crawltrack)."', phpmyvisites='".sql_quote($phpmyvisites)."', piwik='".sql_quote($piwik)."', socialengine='".sql_quote($socialengine)."', vbulletin='".sql_quote($vbulletin)."', wordpress='".sql_quote($wordpress)."', pageear='".sql_quote($pageear)."', josdewplayer='".sql_quote($JosDewplayer)."',imperial='".sql_quote($imperial)."',cornerpubli='".sql_quote($cornerpubli)."',vbseo='".sql_quote($vbseo)."',drupal='".sql_quote($drupal)."',punbb='".sql_quote($punbb)."',openx='".sql_quote($openx)."'";
			$requete = mysql_query($sql, $connexion);
			}
		else
			{
			$sql ="INSERT INTO crawlp_script (crawltrack, phpmyvisites, piwik, socialengine, vbulletin, wordpress, pageear, josdewplayer, imperial, cornerpubli, vbseo, drupal, punbb, openx) VALUES ( '".sql_quote($crawltrack)."','".sql_quote($phpmyvisites)."','".sql_quote($piwik)."','".sql_quote($socialengine)."','".sql_quote($vbulletin)."','".sql_quote($wordpress)."','".sql_quote($pageear)."','".sql_quote($JosDewplayer)."','".sql_quote($imperial)."','".sql_quote($cornerpubli)."','".sql_quote($vbseo)."','".sql_quote($drupal)."','".sql_quote($punbb)."','".sql_quote($openx)."')";
			$requete = mysql_query($sql, $connexion) ;
			}
		}
	else
		{
		//chmod the directory
		if(function_exists('chmod'))
			{
			chmod('./data',0755);
			}
		if(file_exists('data/selectionscript.php') )
			{
			if(function_exists('chmod'))
				{
				chmod('data/selectionscript.php',0644);
				}
			}
		@$content3.="<?php\n";
		@$content3.="\$crawltrack=\"$crawltrack\";\n";
		@$content3.="\$phpmyvisites=\"$phpmyvisites\";\n";
		@$content3.="\$piwik=\"$piwik\";\n";
		@$content3.="\$socialengine=\"$socialengine\";\n";
		@$content3.="\$vbulletin=\"$vbulletin\";\n";
		@$content3.="\$wordpress=\"$wordpress\";\n";
		@$content3.="\$pageear=\"$pageear\";\n";
		@$content3.="\$JosDewplayer=\"$JosDewplayer\";\n";
		@$content3.="\$imperial=\"$imperial\";\n";
		@$content3.="\$cornerpubli=\"$cornerpubli\";\n";
		@$content3.="\$vbseo=\"$vbseo\";\n";
		@$content3.="\$drupal=\"$drupal\";\n";
		@$content3.="\$punbb=\"$punbb\";\n";
		@$content3.="\$openx=\"$openx\";\n";
		@$content3.="?>\n";
		$fp = fopen("data/selectionscript.php","w");
		if (flock($fp, LOCK_EX))
			{
			ftruncate($fp, 0);
			fwrite($fp, $content3);
			flock($fp, LOCK_UN);
			}
		fclose($fp);
		//chmod the directory & the file
		if(function_exists('chmod'))
			{
			chmod('./data',0505);
			chmod('data/selectionscript.php',0404);
			}
		}
	}
//function to update badip list
function updatebadip($type)
	{
	global $connexion,$badip;
	if($type=='mysql')
		{
		$sql = "SELECT * FROM crawlp_bad";
		$requete = mysql_query($sql, $connexion);
		$nbrresult=mysql_num_rows($requete);
		if($nbrresult>=1)
			{
			$sql ="UPDATE crawlp_bad SET  listip='".sql_quote($badip)."'";
			$requete = mysql_query($sql, $connexion);
			}
		else
			{
			$sql ="INSERT INTO crawlp_bad (listip) VALUES ( '".sql_quote($badip)."')";
			$requete = mysql_query($sql, $connexion);
			}
		}
	else
		{
		//chmod the directory
		if(function_exists('chmod'))
			{
			chmod('./data',0755);
			}
		if(file_exists('data/badip.php') )
			{
			if(function_exists('chmod'))
				{
				chmod('data/badip.php',0644);
				}
			}
		@$content.="<?php\n";
		@$content.="\$badip=\"$badip\";\n";
		@$content.="?>\n";
		$fp = fopen("data/badip.php","w");
		if (flock($fp, LOCK_EX))
			{
			ftruncate($fp, 0);
			fwrite($fp, $content);
			flock($fp, LOCK_UN);
			}
		fclose($fp);
		//chmod the directory & the file
		if(function_exists('chmod'))
			{
			chmod('./data',0505);
			chmod('data/badip.php', 0404);
			}
		}
	}
//function to update badreferer list
function updatebadreferer($type)
	{
	global $connexion,$badreferer;
	if($type=='mysql')
		{
		$sql = "SELECT * FROM crawlp_bad";
		$requete = mysql_query($sql, $connexion);
		$nbrresult=mysql_num_rows($requete);
		if($nbrresult>=1)
			{
			$sql ="UPDATE crawlp_bad SET  listreferer='".sql_quote($badreferer)."'";
			$requete = mysql_query($sql, $connexion);
			}
		else
			{
			$sql ="INSERT INTO crawlp_bad (listreferer) VALUES ( '".sql_quote($badreferer)."')";
			$requete = mysql_query($sql, $connexion);
			}
		}
	else
		{
		//chmod the directory
		if(function_exists('chmod'))
			{
			chmod('./data',0755);
			}
		if(file_exists('data/badreferer.php') )
			{
			if(function_exists('chmod'))
				{
				chmod('data/badreferer.php',0644);
				}
			}
		@$content2.="<?php\n";
		@$content2.="\$badreferer=\"$badreferer\";\n";
		@$content2.="?>\n";
		$fp = fopen("data/badreferer.php","w");
		if (flock($fp, LOCK_EX))
			{
			ftruncate($fp, 0);
			fwrite($fp, $content2);
			flock($fp, LOCK_UN);
			}
		fclose($fp);
		//chmod the directory & the file
		if(function_exists('chmod'))
			{
			chmod('./data',0505);
			chmod('data/badreferer.php',0404);
			}
		}
	}
//function to get lock folders and files list
function getlock($type)
	{
	global $connexion,$listfolderdontchange, $listfiledontchange, $listfolderdontchangeserialize, $listfiledontchangeserialize;
	if($type=='mysql')
		{
		$sql = "SELECT * FROM crawlp_setting";
		$requete = mysql_query($sql, $connexion);
		$nbrresult=mysql_num_rows($requete);
		if($nbrresult>=1)
			{
			$ligne = mysql_fetch_assoc($requete);
			$listfolderdontchangeserialize = $ligne['listfolderdontchangeserialize'];
			$listfiledontchangeserialize = $ligne['listfiledontchangeserialize'];
			$listfolderdontchange=unserialize($listfolderdontchangeserialize);
			if(!is_array($listfolderdontchange))
				{
				$listfolderdontchange=array();
				}
			$listfiledontchange=unserialize($listfiledontchangeserialize);
			if(!is_array($listfiledontchange))
				{
				$listfiledontchange=array();
				}
			}
		else
			{
			$listfolderdontchangeserialize='a:0:{}';
			$listfiledontchangeserialize='a:0:{}';
			$listfolderdontchange=array();
			$listfiledontchange=array();
			}
		}
	else
		{
		if(file_exists('data/lock.php') )
			{
			include "data/lock.php";
			$listfolderdontchange=unserialize($listfolderdontchangeserialize);
			$listfiledontchange=unserialize($listfiledontchangeserialize);
			}
		else
			{
			$listfolderdontchangeserialize='a:0:{}';
			$listfiledontchangeserialize='a:0:{}';
			$listfolderdontchange=array();
			$listfiledontchange=array();
			}
		}
	}
//function to update lock folders and files list
function updatelock($type)
	{
	global $connexion, $listfolderdontchangeserialize, $listfiledontchangeserialize;
	if($type=='mysql')
		{
		$sql = "SELECT * FROM crawlp_setting";
		$requete = mysql_query($sql, $connexion);
		$nbrresult=mysql_num_rows($requete);
		if($nbrresult>=1)
			{
			$sql ="UPDATE crawlp_setting SET  listfiledontchangeserialize='".sql_quote($listfiledontchangeserialize)."',listfolderdontchangeserialize='".sql_quote($listfolderdontchangeserialize)."'";
			$requete = mysql_query($sql, $connexion);
			}
		else
			{
			$sql ="INSERT INTO crawlp_bad (listfiledontchangeserialize,listfolderdontchangeserialize) VALUES ( '".sql_quote($listfiledontchangeserialize)."','".sql_quote($listfolderdontchangeserialize)."')";
			$requete = mysql_query($sql, $connexion);
			}
		}
	else
		{
		if(function_exists('chmod'))
			{
			$path=$_SESSION['path']."/data";
			chmod($path, 0755);
			if(file_exists('data/lock.php'))
				{
				chmod('data/lock.php',0644);
				}
			}
		@$content2.="<?php\n";
		@$content2.="\$listfiledontchangeserialize='$listfiledontchangeserialize';\n";
		@$content2.="\$listfolderdontchangeserialize='$listfolderdontchangeserialize';\n";
		@$content2.="?>\n";
		$fp = fopen("data/lock.php", "w");
		if (flock($fp, LOCK_EX))
			{
			ftruncate($fp, 0);
			fwrite($fp, $content2);
			flock($fp, LOCK_UN);
			}
		fclose($fp);
		if(function_exists('chmod'))
			{
			chmod($path,0505);
			if(file_exists('data/lock.php'))
				{
				chmod('data/lock.php',0404);
				}
			}
		}
	}
//function to get htaccess setting value
function getselectionscript($type)
	{
	global $connexion,$crawltrack, $phpmyvisites, $piwik, $socialengine, $vbulletin, $wordpress,$pageear,$JosDewplayer,$imperial,$cornerpubli,$vbseo,$drupal,$punbb,$openx;
	if($type=='mysql')
		{
		$sql = "SELECT * FROM crawlp_script";
		$requete = mysql_query($sql, $connexion);
		$nbrresult=mysql_num_rows($requete);
		if($nbrresult>=1)
			{
			$ligne = mysql_fetch_assoc($requete);
			$crawltrack = $ligne['crawltrack'];
			$phpmyvisites = $ligne['phpmyvisites'];
			$piwik = $ligne['piwik'];
			$socialengine = $ligne['socialengine'];
			$vbulletin = $ligne['vbulletin'];
			$wordpress = $ligne['wordpress'];
			$pageear = $ligne['pageear'];
			$JosDewplayer = $ligne['josdewplayer'];
			$imperial = $ligne['imperial'];
			$cornerpubli = $ligne['cornerpubli'];
			$vbseo = $ligne['vbseo'];
			$drupal = $ligne['drupal'];
			$punbb = $ligne['punbb'];
			$openx = $ligne['openx'];
			}
		else
			{
			$crawltrack = 0;
			$phpmyvisites = 0;
			$piwik = 0;
			$socialengine = 0;
			$vbulletin = 0;
			$wordpress = 0;
			$pageear = 0;
			$JosDewplayer = 0;
			$imperial = 0;
			$cornerpubli = 0;
			$vbseo = 0;
			$drupal = 0;
			$punbb = 0;
			$openx = 0;
			}
		}
	else
		{
		if(file_exists('data/selectionscript.php') )
			{
			include "data/selectionscript.php";
			}
		elseif(file_exists('selectionscript.php') ) //to keep settings from previous release
			{
			include "selectionscript.php";
			}
		else
			{
			$crawltrack = 0;
			$phpmyvisites = 0;
			$piwik = 0;
			$socialengine = 0;
			$vbulletin = 0;
			$wordpress = 0;
			$pageear = 0;
			$JosDewplayer = 0;
			$imperial = 0;
			$cornerpubli = 0;
			$vbseo = 0;
			$drupal = 0;
			$punbb = 0;
			$openx = 0;
			}
		}
	}
?>
Return current item: CrawlProtect