Файл: sys/ban.php
Строк: 47
<?
# BAN SYSTEM V2.0
$settings = DB::run() -> queryFetch("SELECT * FROM `setting` WHERE `id`=? LIMIT 1",array(1));
# NO IP
$ip = preg_replace('|[^0-9.]|', '', $_SERVER['REMOTE_ADDR']);
if ($ip == NULL){
header("Location: /pages/banned.php?mode=no_ip"); exit;
}
# BAN USER / IP
if(is_user()){
$user = DB::run() -> queryFetch("SELECT * FROM `ban` WHERE `login`=? LIMIT 1",array(check($_COOKIE['login'])));
if($user['login'] == !NULL){
$get_urls = $_SERVER['REQUEST_URI'];
if($get_urls != '/pages/banned.php?mode=user'){
header("Location: /pages/banned.php?mode=user");
}
}
} else {
$user = DB::run() -> queryFetch("SELECT * FROM `ban` WHERE `ip`=? LIMIT 1",array($ip));
if($user['ip'] == !NULL){
header("Location: /pages/banned.php?mode=ip");
}
}
# ANTIDDOS US v1.9
if($settings['ddos'] == 'on'){
$doslimit = $settings['ddos_limit'];
#1
$time_off = DB::run()->query("SELECT * FROM `ddos`");
$time_off = $time_off -> fetchAll();
foreach($time_off AS $set_or){
if($set_or['time'] <= time()){
mysql_query('DELETE FROM `ddos` WHERE `id` = "'.$set_or['id'].'"');
DB::run() -> query("DELETE FROM `ddos` WHERE `id` =?",array($set_or['id']));
}
}
#2
$time_off_ip = DB::run()->query("SELECT * FROM `ddos`");
$time_off_ip = $time_off_ip -> fetchAll();
foreach($time_off_ip AS $set_or_ip){
if($set_or_ip['time'] <= time()){
DB::run() -> query("DELETE FROM `ddos` WHERE `id` =?",array($set_or_ip['id']));
}
}
#3
$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]);
if(is_user()){$ddoser = check($_COOKIE['login']); } else {$ddoser = 'Гость'; }
DB::run() -> query("INSERT INTO `ddos`(`time`, `ip`, `url`, `refer`, `brow`, `user`) VALUES (?,?,?,?,?,?)",array($time,ip,$request_uri,$http_referer,$arbuz,$ddoser));
#4
$count_ddos = DB::run() -> query("SELECT * FROM `ddos` WHERE `ip`=?",array($ip)) -> rowCount();
if($count_ddos > $doslimit){
$ban = DB::run() -> queryFetch("SELECT * FROM `ban` WHERE ip = ?",array($ip));
if(empty($ban['ip'])){
$msg_baned = 'Ваш IP:<strong>'.$ip.'</strong> был забанен за ддос сайта!';
DB::run() -> query("INSERT INTO `ban` (`ip`, `pri`) VALUES (?,?)",array($ip,$msg_baned));
DB::run() -> query("DELETE FROM `ddos` WHERE `ip`=?",array($ip));
}
}
}
?>