1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
20 // include the common header files
28 const int APPLY_GLINES = 1;
29 const int APPLY_KLINES = 2;
30 const int APPLY_QLINES = 4;
31 const int APPLY_ZLINES = 8;
32 const int APPLY_ALL = APPLY_GLINES | APPLY_KLINES | APPLY_QLINES | APPLY_ZLINES;
34 /** XLine is the base class for ban lines such as G lines and K lines.
36 class XLine : public classbase
40 XLine(time_t s_time, long d, const char* src, const char* re)
41 : set_time(s_time), duration(d)
45 expiry = set_time + duration;
53 /** The time the line was added.
57 /** The duration of the ban, or 0 if permenant
61 /** Source of the ban. This can be a servername or an oper nickname
65 /** Reason for the ban
76 class KLine : public XLine
79 /** Hostmask (ident@host) to match against
80 * May contain wildcards.
82 KLine(time_t s_time, long d, const char* src, const char* re, const char* ident, const char* host) : XLine(s_time, d, src, re)
84 identmask = strdup(ident);
85 hostmask = strdup(host);
100 class GLine : public XLine
103 /** Hostmask (ident@host) to match against
104 * May contain wildcards.
106 GLine(time_t s_time, long d, const char* src, const char* re, const char* ident, const char* host) : XLine(s_time, d, src, re)
108 identmask = strdup(ident);
109 hostmask = strdup(host);
124 class ELine : public XLine
127 /** Hostmask (ident@host) to match against
128 * May contain wildcards.
130 ELine(time_t s_time, long d, const char* src, const char* re, const char* ident, const char* host) : XLine(s_time, d, src, re)
132 identmask = strdup(ident);
133 hostmask = strdup(host);
148 class ZLine : public XLine
151 /** IP Address (xx.yy.zz.aa) to match against
152 * May contain wildcards.
154 ZLine(time_t s_time, long d, const char* src, const char* re, const char* ip) : XLine(s_time, d, src, re)
169 class QLine : public XLine
172 /** Nickname to match against.
173 * May contain wildcards.
175 QLine(time_t s_time, long d, const char* src, const char* re, const char* nickname) : XLine(s_time, d, src, re)
177 nick = strdup(nickname);
191 bool InitXLine(ServerConfig* conf, const char* tag);
192 bool DoneXLine(ServerConfig* conf, const char* tag);
194 bool DoZLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
195 bool DoQLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
196 bool DoKLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
197 bool DoELine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
199 typedef std::pair<std::string, std::string> IdentHostPair;
201 /** XLineManager is a class used to manage glines, klines, elines, zlines and qlines.
206 /** The owner/creator of this class
208 InspIRCd* ServerInstance;
210 /** This functor is used by the std::sort() function to keep glines in order
212 static bool GSortComparison ( const GLine* one, const GLine* two );
214 /** This functor is used by the std::sort() function to keep elines in order
216 static bool ESortComparison ( const ELine* one, const ELine* two );
218 /** This functor is used by the std::sort() function to keep zlines in order
220 static bool ZSortComparison ( const ZLine* one, const ZLine* two );
222 /** This functor is used by the std::sort() function to keep klines in order
224 static bool KSortComparison ( const KLine* one, const KLine* two );
226 /** This functor is used by the std::sort() function to keep qlines in order
228 static bool QSortComparison ( const QLine* one, const QLine* two );
230 /* Lists for temporary lines with an expiry time */
232 /** Temporary KLines */
233 std::vector<KLine*> klines;
235 /** Temporary Glines */
236 std::vector<GLine*> glines;
238 /** Temporary Zlines */
239 std::vector<ZLine*> zlines;
241 /** Temporary QLines */
242 std::vector<QLine*> qlines;
244 /** Temporary ELines */
245 std::vector<ELine*> elines;
247 /* Seperate lists for perm XLines that isnt checked by expiry functions */
249 /** Permenant KLines */
250 std::vector<KLine*> pklines;
252 /** Permenant GLines */
253 std::vector<GLine*> pglines;
255 /** Permenant ZLines */
256 std::vector<ZLine*> pzlines;
258 /** Permenant QLines */
259 std::vector<QLine*> pqlines;
261 /** Permenant ELines */
262 std::vector<ELine*> pelines;
265 * @param Instance A pointer to the creator object
267 XLineManager(InspIRCd* Instance);
269 IdentHostPair IdentSplit(const std::string &ident_and_host);
272 * @param duration The duration of the line
273 * @param source The source of the line
274 * @param reason The reason for the line
275 * @param hostmask The hostmask
276 * @return True if the line was added successfully
278 bool add_gline(long duration, const char* source, const char* reason, const char* hostmask);
281 * @param duration The duration of the line
282 * @param source The source of the line
283 * @param reason The reason for the line
284 * @param nickname The nickmask
285 * @return True if the line was added successfully
287 bool add_qline(long duration, const char* source, const char* reason, const char* nickname);
290 * @param duration The duration of the line
291 * @param source The source of the line
292 * @param reason The reason for the line
293 * @param ipaddr The IP mask
294 * @return True if the line was added successfully
296 bool add_zline(long duration, const char* source, const char* reason, const char* ipaddr);
299 * @param duration The duration of the line
300 * @param source The source of the line
301 * @param reason The reason for the line
302 * @param hostmask The hostmask
303 * @return True if the line was added successfully
305 bool add_kline(long duration, const char* source, const char* reason, const char* hostmask);
308 * @param duration The duration of the line
309 * @param source The source of the line
310 * @param reason The reason for the line
311 * @param hostmask The hostmask
312 * @return True if the line was added successfully
314 bool add_eline(long duration, const char* source, const char* reason, const char* hostmask);
317 * @return hostmask The host to remove
318 * @return True if the line was deleted successfully
320 bool del_gline(const char* hostmask);
323 * @return nickname The nick to remove
324 * @return True if the line was deleted successfully
326 bool del_qline(const char* nickname);
329 * @return ipaddr The IP to remove
330 * @return True if the line was deleted successfully
332 bool del_zline(const char* ipaddr);
335 * @return hostmask The host to remove
336 * @return True if the line was deleted successfully
338 bool del_kline(const char* hostmask);
341 * @return hostmask The host to remove
342 * @return True if the line was deleted successfully
344 bool del_eline(const char* hostmask);
346 /** Check if a nickname matches a QLine
347 * @return nick The nick to check against
348 * @return The reason for the line if there is a match, or NULL if there is no match
350 QLine* matches_qline(const char* nick);
352 /** Check if a hostname matches a GLine
353 * @param user The user to check against
354 * @return The reason for the line if there is a match, or NULL if there is no match
356 GLine* matches_gline(userrec* user);
358 /** Check if a IP matches a ZLine
359 * @param ipaddr The IP to check against
360 * @return The reason for the line if there is a match, or NULL if there is no match
362 ZLine* matches_zline(const char* ipaddr);
364 /** Check if a hostname matches a KLine
365 * @param user The user to check against
366 * @return The reason for the line if there is a match, or NULL if there is no match
368 KLine* matches_kline(userrec* user);
370 /** Check if a hostname matches a ELine
371 * @param user The user to check against
372 * @return The reason for the line if there is a match, or NULL if there is no match
374 ELine* matches_exception(userrec* user);
376 /** Expire any pending non-permenant lines
380 /** Apply any new lines
381 * @param What The types of lines to apply, from the set
382 * APPLY_GLINES | APPLY_KLINES | APPLY_QLINES | APPLY_ZLINES | APPLY_ALL
384 void apply_lines(const int What);
387 * @param user The username making the query
388 * @param results The string_list to receive the results
390 void stats_k(userrec* user, string_list &results);
393 * @param user The username making the query
394 * @param results The string_list to receive the results
396 void stats_g(userrec* user, string_list &results);
399 * @param user The username making the query
400 * @param results The string_list to receive the results
402 void stats_q(userrec* user, string_list &results);
405 * @param user The username making the query
406 * @param results The string_list to receive the results
408 void stats_z(userrec* user, string_list &results);
411 * @param user The username making the query
412 * @param results The string_list to receive the results
414 void stats_e(userrec* user, string_list &results);
416 /** Change creation time of a GLine
417 * @param host The hostname to change
418 * @param create_Time The new creation time
420 void gline_set_creation_time(const char* host, time_t create_time);
422 /** Change creation time of a QLine
423 * @param nick The nickmask to change
424 * @param create_Time The new creation time
426 void qline_set_creation_time(const char* nick, time_t create_time);
428 /** Change creation time of a ZLine
429 * @param ip The ipmask to change
430 * @param create_Time The new creation time
432 void zline_set_creation_time(const char* ip, time_t create_time);
434 /** Change creation time of a ELine
435 * @param host The hostname to change
436 * @param create_Time The new creation time
438 void eline_set_creation_time(const char* host, time_t create_time);