1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
| <?
// файл на Майк
// в него се дефинират действията и променливите
class ProtectContent {
var $filename; var $timeout;
var $log;
var $AGENTS;
function ProtectContent($filename="flooders.txt",$timeout=600) {
$this->filename=$filename;
$this->timeout=$timeout;
$this->AGENTS=Array();
$this->log="";
}
function SetLogFileName($filename) {
$this->log=$filename;
}
function Check($http_error=0) {
GLOBAL $HTTP_SERVER_VARS;
$ip1=$HTTP_SERVER_VARS["REMOTE_ADDR"];
$ip2=$HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"];
$ip1=str_replace(":","_",$ip1);
$ip2=str_replace(":","_",$ip2);
$curtime=time();
$d=@file($this->filename);
if (!is_array($d)) {print "Error reading file"".$this->filename."".";return(false);}
$found=false;
for ($i=0;$i<count($d);$i++) {
$e=explode(" : ",$d[$i]);
if ($e[1]==$ip1 && trim($e[2])==$ip2 && $e[0]+$this->timeout>$curtime) {$found=true;break;}
}
if ($http_error==404 && $found==true) {
header("HTTP/1.0 404 Not Found");
die("<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">n<HTML><HEAD>n<TITLE>404 Not Found</TITLE>n</HEAD><BODY>n<H1>Not Found</H1>nThe requested URL ".$HTTP_SERVER_VARS["REQUEST_URI"]." was not found on this server.<P>n<HR>n".$HTTP_SERVER_VARS["SERVER_SIGNATURE"]."n</BODY></HTML>");
}
if ($http_error==403 && $found==true) {
header("HTTP/1.0 403 Forbidden");
die("<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">n<HTML><HEAD>n<TITLE>403 Forbidden</TITLE>n</HEAD><BODY>n<H1>Forbidden</H1>nYou don't have permission to access ".$HTTP_SERVER_VARS["REQUEST_URI"]."non this server.<P>n<HR>n".$HTTP_SERVER_VARS["SERVER_SIGNATURE"]."n</BODY></HTML>");
}
return($found);
}
function Ban() {
GLOBAL $HTTP_SERVER_VARS;
$agent=" ".$HTTP_SERVER_VARS["HTTP_USER_AGENT"];
for ($i=0;$i<count($this->AGENTS);$i++) {
if (strpos($agent,$this->AGENTS[$i])) return;
}
$ip1=$HTTP_SERVER_VARS["REMOTE_ADDR"];
$ip2=$HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"];
$ip1=str_replace(":","_",$ip1);
$ip2=str_replace(":","_",$ip2);
$curtime=time();
$d=@file($this->filename);
if (!is_array($d)) {print "Eroor reading file "".$this->filename."".";}
for ($i=0;$i<count($d);$i++) {
$e=explode(" : ",$d[$i]);
if ($e[1]==$ip1 && trim($e[2])==$ip2) unset($d[$i]);
}
if (need_add) {
if (!empty($this->log)) {
$fw=fopen($this->log,"at");
if ($fw) {
fputs($fw, date("Y-m-d H:i:s")." [".$ip1."|".$ip2."]".$agent."n");
fclose($fw);
}
}
$d[]=$curtime." : ".$ip1." : ".$ip2."n";
}
$fw=@fopen($this->filename,"wt");
if (!$fw) {print "Error in file "".$this->filename."".";return;}
foreach ($d as $e) fputs($fw,$e);
fclose($fw);
}
function AddAlowAgent($agent) {
$this->AGENTS[]=$agent;
}
}
?> |