1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
17 // include the common header files
25 const int APPLY_GLINES = 1;
26 const int APPLY_KLINES = 2;
27 const int APPLY_QLINES = 4;
28 const int APPLY_ZLINES = 8;
29 const int APPLY_PERM_ONLY = 16;
30 const int APPLY_ALL = APPLY_GLINES | APPLY_KLINES | APPLY_QLINES | APPLY_ZLINES;
32 /** XLine is the base class for ban lines such as G lines and K lines.
34 class XLine : public classbase
38 XLine(time_t s_time, long d, const char* src, const char* re)
39 : set_time(s_time), duration(d)
43 expiry = set_time + duration;
51 /** The time the line was added.
55 /** The duration of the ban, or 0 if permenant
59 /** Source of the ban. This can be a servername or an oper nickname
63 /** Reason for the ban
74 class KLine : public XLine
77 /** Hostmask (ident@host) to match against
78 * May contain wildcards.
80 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)
82 identmask = strdup(ident);
83 hostmask = strdup(host);
98 class GLine : public XLine
101 /** Hostmask (ident@host) to match against
102 * May contain wildcards.
104 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)
106 identmask = strdup(ident);
107 hostmask = strdup(host);
122 class ELine : public XLine
125 /** Hostmask (ident@host) to match against
126 * May contain wildcards.
128 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)
130 identmask = strdup(ident);
131 hostmask = strdup(host);
146 class ZLine : public XLine
149 /** IP Address (xx.yy.zz.aa) to match against
150 * May contain wildcards.
152 ZLine(time_t s_time, long d, const char* src, const char* re, const char* ip) : XLine(s_time, d, src, re)
167 class QLine : public XLine
170 /** Nickname to match against.
171 * May contain wildcards.
173 QLine(time_t s_time, long d, const char* src, const char* re, const char* nickname) : XLine(s_time, d, src, re)
175 nick = strdup(nickname);
189 bool InitXLine(ServerConfig* conf, const char* tag);
191 bool DoneZLine(ServerConfig* conf, const char* tag);
192 bool DoneQLine(ServerConfig* conf, const char* tag);
193 bool DoneKLine(ServerConfig* conf, const char* tag);
194 bool DoneELine(ServerConfig* conf, const char* tag);
196 bool DoZLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
197 bool DoQLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
198 bool DoKLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
199 bool DoELine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
201 typedef std::pair<std::string, std::string> IdentHostPair;
203 /** XLineManager is a class used to manage glines, klines, elines, zlines and qlines.
208 /** The owner/creator of this class
210 InspIRCd* ServerInstance;
212 /** This functor is used by the std::sort() function to keep glines in order
214 static bool GSortComparison ( const GLine* one, const GLine* two );
216 /** This functor is used by the std::sort() function to keep elines in order
218 static bool ESortComparison ( const ELine* one, const ELine* two );
220 /** This functor is used by the std::sort() function to keep zlines in order
222 static bool ZSortComparison ( const ZLine* one, const ZLine* two );
224 /** This functor is used by the std::sort() function to keep klines in order
226 static bool KSortComparison ( const KLine* one, const KLine* two );
228 /** This functor is used by the std::sort() function to keep qlines in order
230 static bool QSortComparison ( const QLine* one, const QLine* two );
232 /* Lists for temporary lines with an expiry time */
234 /** Temporary KLines */
235 std::vector<KLine*> klines;
237 /** Temporary Glines */
238 std::vector<GLine*> glines;
240 /** Temporary Zlines */
241 std::vector<ZLine*> zlines;
243 /** Temporary QLines */
244 std::vector<QLine*> qlines;
246 /** Temporary ELines */
247 std::vector<ELine*> elines;
249 /* Seperate lists for perm XLines that isnt checked by expiry functions */
251 /** Permenant KLines */
252 std::vector<KLine*> pklines;
254 /** Permenant GLines */
255 std::vector<GLine*> pglines;
257 /** Permenant ZLines */
258 std::vector<ZLine*> pzlines;
260 /** Permenant QLines */
261 std::vector<QLine*> pqlines;
263 /** Permenant ELines */
264 std::vector<ELine*> pelines;
267 * @param Instance A pointer to the creator object
269 XLineManager(InspIRCd* Instance);
271 IdentHostPair IdentSplit(const std::string &ident_and_host);
274 * @param duration The duration of the line
275 * @param source The source of the line
276 * @param reason The reason for the line
277 * @param hostmask The hostmask
278 * @return True if the line was added successfully
280 bool add_gline(long duration, const char* source, const char* reason, const char* hostmask);
283 * @param duration The duration of the line
284 * @param source The source of the line
285 * @param reason The reason for the line
286 * @param nickname The nickmask
287 * @return True if the line was added successfully
289 bool add_qline(long duration, const char* source, const char* reason, const char* nickname);
292 * @param duration The duration of the line
293 * @param source The source of the line
294 * @param reason The reason for the line
295 * @param ipaddr The IP mask
296 * @return True if the line was added successfully
298 bool add_zline(long duration, const char* source, const char* reason, const char* ipaddr);
301 * @param duration The duration of the line
302 * @param source The source of the line
303 * @param reason The reason for the line
304 * @param hostmask The hostmask
305 * @return True if the line was added successfully
307 bool add_kline(long duration, const char* source, const char* reason, const char* hostmask);
310 * @param duration The duration of the line
311 * @param source The source of the line
312 * @param reason The reason for the line
313 * @param hostmask The hostmask
314 * @return True if the line was added successfully
316 bool add_eline(long duration, const char* source, const char* reason, const char* hostmask);
319 * @return hostmask The host to remove
320 * @return True if the line was deleted successfully
322 bool del_gline(const char* hostmask);
325 * @return nickname The nick to remove
326 * @return True if the line was deleted successfully
328 bool del_qline(const char* nickname);
331 * @return ipaddr The IP to remove
332 * @return True if the line was deleted successfully
334 bool del_zline(const char* ipaddr);
337 * @return hostmask The host to remove
338 * @return True if the line was deleted successfully
340 bool del_kline(const char* hostmask);
343 * @return hostmask The host to remove
344 * @return True if the line was deleted successfully
346 bool del_eline(const char* hostmask);
348 /** Check if a nickname matches a QLine
349 * @return nick The nick to check against
350 * @return The reason for the line if there is a match, or NULL if there is no match
352 QLine* matches_qline(const char* nick, bool permonly = false);
354 /** Check if a hostname matches a GLine
355 * @param user The user to check against
356 * @return The reason for the line if there is a match, or NULL if there is no match
358 GLine* matches_gline(userrec* user, bool permonly = false);
360 /** Check if a IP matches a ZLine
361 * @param ipaddr The IP to check against
362 * @return The reason for the line if there is a match, or NULL if there is no match
364 ZLine* matches_zline(const char* ipaddr, bool permonly = false);
366 /** Check if a hostname matches a KLine
367 * @param user The user to check against
368 * @return The reason for the line if there is a match, or NULL if there is no match
370 KLine* matches_kline(userrec* user, bool permonly = false);
372 /** Check if a hostname matches a ELine
373 * @param user The user to check against
374 * @return The reason for the line if there is a match, or NULL if there is no match
376 ELine* matches_exception(userrec* user, bool permonly = false);
378 /** Expire any pending non-permenant lines
382 /** Apply any new lines
383 * @param What The types of lines to apply, from the set
384 * APPLY_GLINES | APPLY_KLINES | APPLY_QLINES | APPLY_ZLINES | APPLY_ALL
387 void apply_lines(const int What);
390 * @param user The username making the query
391 * @param results The string_list to receive the results
393 void stats_k(userrec* user, string_list &results);
396 * @param user The username making the query
397 * @param results The string_list to receive the results
399 void stats_g(userrec* user, string_list &results);
402 * @param user The username making the query
403 * @param results The string_list to receive the results
405 void stats_q(userrec* user, string_list &results);
408 * @param user The username making the query
409 * @param results The string_list to receive the results
411 void stats_z(userrec* user, string_list &results);
414 * @param user The username making the query
415 * @param results The string_list to receive the results
417 void stats_e(userrec* user, string_list &results);
419 /** Change creation time of a GLine
420 * @param host The hostname to change
421 * @param create_Time The new creation time
423 void gline_set_creation_time(const char* host, time_t create_time);
425 /** Change creation time of a QLine
426 * @param nick The nickmask to change
427 * @param create_Time The new creation time
429 void qline_set_creation_time(const char* nick, time_t create_time);
431 /** Change creation time of a ZLine
432 * @param ip The ipmask to change
433 * @param create_Time The new creation time
435 void zline_set_creation_time(const char* ip, time_t create_time);
437 /** Change creation time of a ELine
438 * @param host The hostname to change
439 * @param create_Time The new creation time
441 void eline_set_creation_time(const char* host, time_t create_time);