-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplug_Flood.php
executable file
·255 lines (217 loc) · 7.54 KB
/
plug_Flood.php
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<?php
////////////////////////////////////////
// Encodage du fichier : UTF-8
// Utilisation des tabulations : Oui
// 1 tabulation = 4 caractères
// Fins de lignes = LF (Unix)
////////////////////////////////////////
///////////////////////////////
// LICENCE
///////////////////////////////
//
// QOpServ is a PHP program with which you can publish any project
// or sources files of any type supported you want.
//
// International Copyright © 2000 - 2012 CRDF All Rights Reserved.
//
// Contact @ http://www.crdf.fr - clients@crdf.fr
//
// QOpServ is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// QOpServ is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with QOpServ; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
///////////////////////////////
/**
* QOpServ - Application PHP Bots PHP
*
* @author G. Jocelyn
* @copyright CRDF France
* @license GNU GPL (http://www.gnu.org/copyleft/gpl.html)
* @link http://www.crdf.fr
* @name QOpServ
* @since 17/08/2008
* @version 4.0.1
*/
class plug_Flood implements plugin {
private $main;
public function __construct($main) {
$this->main = $main;
}
/**
* Déclaration des fonctions
*
* @param unknown_type $IRCtext
*/
public function start($IRCtext)
{
$this->AntiFlood__CTCP__PRIVMSG($IRCtext);
$this->AntiFlood__NOTICE($IRCtext);
$this->AutoTimeOutIgnore($IRCtext);
$this->AntiFlood__URL($IRCtext);
$this->AntiSpam__URL($IRCtext);
}
/**
* Function Antiflood for CTCP/PRIVMSG
*
* @param unknown_type $IRCtxt
*/
private function AntiFlood__CTCP__PRIVMSG ($IRCtxt)
{
if(preg_match('`^:(.*?)!(.*?) PRIVMSG '.preg_quote(IRCConn::$myBotName, '`').' :(.*?)`', $IRCtxt, $T) && !file_exists(dirname(__FILE__) . '/data/ignore/' . $T[2]))
{
if($this->main->MyConn->GlobalAntiFlood(3, 5, "privmsg.ctcp." . $T[2]) === true && !eregi("services@services.quitenet.org", $T[2]))
{
$fp = fopen(dirname(__FILE__) . '/data/ignore/' . $T[2], "w");
fputs($fp, "AUTOIGNORE");
fclose($fp);
$this->main->MyConn->put("PRIVMSG #IRCOPS FLOOD PRIVMSG/CTCP -> ".trim($T[2])." added in ignore list on ". IRCConn::$myBotName .".");
}
}
}
/**
* Function AntiFlood for Notice
*
* @param unknown_type $IRCtxt
*/
private function AntiFlood__NOTICE ($IRCtxt)
{
if(preg_match('`^:(.*?)!(.*?) NOTICE '.preg_quote(IRCConn::$myBotName, '`').' :(.*?)`', $IRCtxt, $T) && !file_exists(dirname(__FILE__) . '/data/ignore/' . $T[2]))
{
if($this->main->MyConn->GlobalAntiFlood(8, 20, "notice." . $T[2]) === true && !eregi("services@services.quitenet.org", $T[2]))
{
$fp = fopen(dirname(__FILE__) . '/data/ignore/' . $T[2], "w");
fputs($fp, "AUTOIGNORE");
fclose($fp);
$this->main->MyConn->put("PRIVMSG #IRCOPS FLOOD NOTICE -> ".trim($T[2])." added in ignore list on ". IRCConn::$myBotName .".");
}
}
}
/**
* Remove ignore timeout
*
* @param unknown_type $IRCtext
*/
private function AutoTimeOutIgnore ($IRCtext)
{
/**
* TIME OUT
*/
if(file_exists(dirname(__FILE__) . '/data/.ignore'))
{
if(time() - filemtime(dirname(__FILE__) . '/data/.ignore') > ( 60 * 5 ))
{
unlink(dirname(__FILE__) . '/data/.ignore');
}
} else
{
$fp = fopen(dirname(__FILE__) . '/data/.ignore', "w");
fputs($fp, time());
fclose($fp);
$Ignore['TimeOut'] = TRUE;
}
/**
* Executing command
*/
if($Ignore['TimeOut'] === TRUE)
{
$dir = opendir(dirname(__FILE__) . '/data/ignore/');
while ($fread = readdir($dir))
{
if($fread != "." && $fread != "..")
{
$__OPEN__FILE__ = file(dirname(__FILE__) . '/data/ignore/' . $fread);
$__INFO__IGNORE__ = trim($__OPEN__FILE__[0]);
if($__INFO__IGNORE__ == "AUTOIGNORE")
{
if(filemtime(dirname(__FILE__) . '/data/ignore/' . $fread) + ( 60 * 10 ) < time())
{
unlink(dirname(__FILE__) . '/data/ignore/' . $fread);
}
}
}
}
}
}
/**
* Detect an flood advert in all channel
*
* @param unknown_type $IRCtext
*/
private function AntiFlood__URL ($IRCtxt)
{
if(preg_match('`^:(.*?)!(.*?) PRIVMSG (.*?) :(.*?)([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])`', $IRCtxt, $T))
{
if($this->main->MyConn->AntiFloodSpecial(5, 1, "advert.flood." . $T[2]) === TRUE)
{
$CreateAbuseReport = $this->main->MyConn->CreateAbuseRepport('Multiflood advertising channels detected', $T[1], $T[3], $T[2], "KILL");
$this->main->MyConn->put("KILL ".$T[1]." You are violating network rules, ID: " . $CreateAbuseReport . " (please read /RULES for more information).");
$this->main->MyConn->put("PRIVMSG #IRCOPS Flood -> Multiflood advertising channels detected -> ".trim($T[2])." (channel: ".$T[3].", abuse ID: " . $CreateAbuseReport . ").");
}
}
}
/**
* Anti-Spam Detector (for botnet)
*
* @param unknown_type $IRCtext
*/
private function AntiSpam__URL ($IRCtxt)
{
/**
* Detect spam
*/
if(preg_match('`^:(.*?)!(.*?) PRIVMSG (.*?) :(.*?)([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])`', $IRCtxt, $T))
{
if(time() - filemtime(dirname(__FILE__) . '/data/antiflood.join/' . $T[2] . $T[3]) < ( 15 ))
{
$CreateAbuseReport = $this->main->MyConn->CreateAbuseRepport('To send web addresses, you must wait a few seconds. Otherwise you will be identified as a spammer.', $T[1], $T[3], $T[2], "KILL");
$this->main->MyConn->put("KILL ".$T[1]." You are violating network rules, ID: " . $CreateAbuseReport . " (please read /RULES for more information).");
$this->main->MyConn->put("PRIVMSG #IRCOPS Spam -> Spam detected -> ".trim($T[2])." (channel: ".$T[3].", abuse ID: " . $CreateAbuseReport . ").");
}
}
/**
* Join
*/
if(preg_match('`^:(.*?)!(.*?) JOIN :(.*)`', $IRCtxt, $T))
{
$T[3] = trim($T[3]);
if(!file_exists(dirname(__FILE__) . '/data/antiflood.join/') || !is_readable(dirname(__FILE__) . '/data/antiflood.join/'))
{
$this->main->MyConn->put("PRIVMSG #IRCOPS Une erreur s'est produite : le dossier '".dirname(__FILE__) . '/data/antiflood.join/'."' n'existe pas ou n'est pas accessible en lecture/écriture.");
} else
{
if(file_exists(dirname(__FILE__) . '/data/antiflood.join/' . $T[2] . $T[3]) && time() - filemtime(dirname(__FILE__) . '/data/antiflood.join/' . $T[2] . $T[3]) > ( 30 ))
{
unlink(dirname(__FILE__) . '/data/antiflood.join/' . $T[2] . $T[3]);
}
$fp = fopen(dirname(__FILE__) . '/data/antiflood.join/' . $T[2] . $T[3], "w");
fputs($fp, time());
fclose($fp);
}
}
/**
* Timeout
*/
$dir = opendir(dirname(__FILE__) . '/data/antiflood.join/');
while ($fread = readdir($dir))
{
if($fread != "." && $fread != "..")
{
if(filemtime(dirname(__FILE__) . '/data/antiflood.join/' . $fread) + ( 30 ) < time())
{
unlink(dirname(__FILE__) . '/data/antiflood.join/' . $fread);
}
}
}
}
}
?>