Просмотр файла sad/system/antidos.php

Размер файла: 2.45Kb
<?php
/**********************************
*	@year: 2018				      *
*	@author: Klubv	              *
*   @icq: 611940693			      *
*	@link: http://baz23.ru        *
**********************************/
$doslimit = 60;
$trans = preg_replace('|[^0-9\.]|', '', $_SERVER['REMOTE_ADDR']);
/* Удаляем просроченые записи */
$time_off=mysql_query("SELECT * FROM `ddos`");  
while($set_or=mysql_fetch_array($time_off)){ 
if($set_or['time'] <= time()){
mysql_query('DELETE FROM `ddos` WHERE `id` = "'.$set_or['id'].'"');
}
}
/* Удаляем просроченые записи у данного ip */
$time_off_ip=mysql_query('SELECT * FROM `ddos` WHERE ip = "'.$trans.'"');  
while($set_or_ip=mysql_fetch_array($time_off_ip)){ 
if($set_or_ip['time'] <= time()){
mysql_query('DELETE FROM `ddos` WHERE `id` = "'.$set_or_ip['id'].'"');
}
}
/* Удаляем просроченые записи у данного ip */
$time_off_ip=mysql_query('SELECT * FROM `banip` WHERE ip = "'.$trans.'"');  
while($set_or_ip=mysql_fetch_array($time_off_ip)){ 
if($set_or_ip['time'] <= time()){
mysql_query('DELETE FROM `banip` WHERE `id` = "'.$set_or_ip['id'].'"');
}
}
/* Автоматическая блокировка */
$count_ddos=mysql_result(mysql_query("SELECT COUNT(*) FROM `ddos` WHERE `ip`='".$trans."'"),0);
$times = time() + 60; 
if($count_ddos > $doslimit){
$ban = mysql_query('SELECT * FROM banip WHERE ip = "'.$trans.'"');
$ban = mysql_fetch_assoc($ban);
if(empty($ban['ip'])){
mysql_query('INSERT INTO `banip` (`ip`, `time`) VALUES ("'.$trans.'","'.$times.'");');
mysql_query('DELETE FROM `ddos` WHERE `ip` = "'.$trans.'"');
}
}

/* Антидос */
$time = time() + 60;
if (isset($_SERVER['REQUEST_URI'])) {
$request_uri = urldecode(substr(strtok($_SERVER['REQUEST_URI'], 'S'), 1));
}
if (isset($_SERVER['HTTP_REFERER'])) {
$http_referer = urldecode(strtok($_SERVER['HTTP_REFERER'], 'S'));
} else {
$http_referer = 'Не определено';
}
$arbuz = explode("/",$_SERVER['HTTP_USER_AGENT']);
$arbuz = htmlspecialchars($arbuz[0]);

$trans = $_SERVER['REMOTE_ADDR'];
mysql_query("INSERT INTO `ddos`(`time`, `ip`, `url`, `refer`, `brow`) VALUES ('".$time."','".$trans."','".$request_uri."','".$http_referer."','".$arbuz."');");
if(mysql_num_rows(mysql_query("SELECT ip FROM `banip` WHERE `ip`='".$trans."'"))!=0){
die("<center>Антидос! Превышен допустимый лимит запросов!<br/>Зайдите на сайт через 1 минуту!</center>"); }

?>