View file antidos.php

File size: 2.2Kb
<?php
Error_Reporting(E_ALL & ~E_NOTICE);
Error_Reporting (ERROR | WARNING);
if(preg_match("/adminka/si",getcwd())){$adm=true;chdir("..");}else $adm=false;
if(preg_match("/profile/si",getcwd())){$prof=true;chdir("..");}else $prof=false;
$ip=@$_SERVER['REMOTE_ADDR'];
$config_doslimit=150;
$brow=@$_SERVER['HTTP_USER_AGENT'];
$http_referer = @$_SERVER['HTTP_REFERER'];
$request_uri = urldecode(@$_SERVER['REQUEST_URI']);
$logfiles = "datados/".$ip.".dat";
$logdat = "logfiles.dat";
$hostname = gethostbyaddr($ip);
$datetime = date("Y-m-d H:i:s");
$time = time();
$timenow = time()-60;
if(empty($http_referer)){$http_referer='Отсутствует';}

if ($opendir = opendir("datados")) {
while (false !== ($doslog = readdir($opendir))) {
if ($doslog != "." and $doslog != "..") {

$file_array_time =@file("datados/$doslog");
$file_array_str= explode("|",$file_array_time[0]);
if ($file_array_str[1] < $timenow) {
@unlink("datados/$doslog");
}}}}

$write = '|'.$time.'|Время: '.$datetime.'|Хост: '.$hostname.'|Browser: '.$brow.'|Referer: '.$http_referer.'|URL: '.$request_uri.'|';
$fp=@fopen($logfiles,"a+");
@flock ($fp,LOCK_EX);
@fputs($fp,"$write\r\n");
@flock ($fp,LOCK_UN);
@fclose($fp);
@chmod ($logfiles, 0666);

if (count(@file($logfiles)) > $config_doslimit) {
	
	
	
$banlines=file("ban.dat");
$bancount=count($banlines);
for ($bban=0; $bban<$bancount; $bban++) { 
list(,$banbase)=explode("|",$banlines[$bban]); if ($ip == $banbase) {
$result="ok"; }}


	
if($result!="ok"){
$fp=fopen("ban.dat","a+");
flock ($fp,LOCK_EX);
fputs($fp,"|$ip|\r\n"); 
fflush ($fp); 
flock ($fp,LOCK_UN);                                           
fclose($fp);  

$write = '|1|Заблокирован доступ для IP: '.$ip.'|Время: '.$datetime.'|Хост: '.$hostname.'|Browser: '.$brow.'|Referer: '.$http_referer.'|URL: '.$request_uri.'|';

$fp=fopen($logdat,"a+");
flock ($fp,LOCK_EX);
fputs($fp,"$write\r\n");
flock ($fp,LOCK_UN);
fclose($fp);

$file=file($logdat); 
$i = count($file);
if ($i>=$config_maxlogdat) {
$fp=fopen($logdat,"w");
flock ($fp,LOCK_EX);
unset($file[0]);
unset($file[1]);
fputs($fp, implode("",$file));
flock ($fp,LOCK_UN);
fclose($fp);
}}}
?>