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_ALL = APPLY_GLINES | APPLY_KLINES | APPLY_QLINES | APPLY_ZLINES;
31 /** XLine is the base class for ban lines such as G lines and K lines.
33 class XLine : public classbase
37 XLine(time_t s_time, long d, const char* src, const char* re)
38 : set_time(s_time), duration(d)
42 expiry = set_time + duration;
50 /** The time the line was added.
54 /** The duration of the ban, or 0 if permenant
58 /** Source of the ban. This can be a servername or an oper nickname
62 /** Reason for the ban
73 class KLine : public XLine
76 /** Hostmask (ident@host) to match against
77 * May contain wildcards.
79 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)
81 identmask = strdup(ident);
82 hostmask = strdup(host);
97 class GLine : public XLine
100 /** Hostmask (ident@host) to match against
101 * May contain wildcards.
103 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)
105 identmask = strdup(ident);
106 hostmask = strdup(host);
121 class ELine : public XLine
124 /** Hostmask (ident@host) to match against
125 * May contain wildcards.
127 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)
129 identmask = strdup(ident);
130 hostmask = strdup(host);
145 class ZLine : public XLine
148 /** IP Address (xx.yy.zz.aa) to match against
149 * May contain wildcards.
151 ZLine(time_t s_time, long d, const char* src, const char* re, const char* ip) : XLine(s_time, d, src, re)
166 class QLine : public XLine
169 /** Nickname to match against.
170 * May contain wildcards.
172 QLine(time_t s_time, long d, const char* src, const char* re, const char* nickname) : XLine(s_time, d, src, re)
174 nick = strdup(nickname);
188 bool InitXLine(ServerConfig* conf, const char* tag);
189 bool DoneXLine(ServerConfig* conf, const char* tag);
191 bool DoZLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
192 bool DoQLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
193 bool DoKLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
194 bool DoELine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
196 typedef std::pair<std::string, std::string> IdentHostPair;
198 /** XLineManager is a class used to manage glines, klines, elines, zlines and qlines.
203 /** The owner/creator of this class
205 InspIRCd* ServerInstance;
207 /** This functor is used by the std::sort() function to keep glines in order
209 static bool GSortComparison ( const GLine* one, const GLine* two );
211 /** This functor is used by the std::sort() function to keep elines in order
213 static bool ESortComparison ( const ELine* one, const ELine* two );
215 /** This functor is used by the std::sort() function to keep zlines in order
217 static bool ZSortComparison ( const ZLine* one, const ZLine* two );
219 /** This functor is used by the std::sort() function to keep klines in order
221 static bool KSortComparison ( const KLine* one, const KLine* two );
223 /** This functor is used by the std::sort() function to keep qlines in order
225 static bool QSortComparison ( const QLine* one, const QLine* two );
227 /* Lists for temporary lines with an expiry time */
229 /** Temporary KLines */
230 std::vector<KLine*> klines;
232 /** Temporary Glines */
233 std::vector<GLine*> glines;
235 /** Temporary Zlines */
236 std::vector<ZLine*> zlines;
238 /** Temporary QLines */
239 std::vector<QLine*> qlines;
241 /** Temporary ELines */
242 std::vector<ELine*> elines;
244 /* Seperate lists for perm XLines that isnt checked by expiry functions */
246 /** Permenant KLines */
247 std::vector<KLine*> pklines;
249 /** Permenant GLines */
250 std::vector<GLine*> pglines;
252 /** Permenant ZLines */
253 std::vector<ZLine*> pzlines;
255 /** Permenant QLines */
256 std::vector<QLine*> pqlines;
258 /** Permenant ELines */
259 std::vector<ELine*> pelines;
262 * @param Instance A pointer to the creator object
264 XLineManager(InspIRCd* Instance);
266 IdentHostPair IdentSplit(const std::string &ident_and_host);
269 * @param duration The duration of the line
270 * @param source The source of the line
271 * @param reason The reason for the line
272 * @param hostmask The hostmask
273 * @return True if the line was added successfully
275 bool add_gline(long duration, const char* source, const char* reason, const char* hostmask);
278 * @param duration The duration of the line
279 * @param source The source of the line
280 * @param reason The reason for the line
281 * @param nickname The nickmask
282 * @return True if the line was added successfully
284 bool add_qline(long duration, const char* source, const char* reason, const char* nickname);
287 * @param duration The duration of the line
288 * @param source The source of the line
289 * @param reason The reason for the line
290 * @param ipaddr The IP mask
291 * @return True if the line was added successfully
293 bool add_zline(long duration, const char* source, const char* reason, const char* ipaddr);
296 * @param duration The duration of the line
297 * @param source The source of the line
298 * @param reason The reason for the line
299 * @param hostmask The hostmask
300 * @return True if the line was added successfully
302 bool add_kline(long duration, const char* source, const char* reason, const char* hostmask);
305 * @param duration The duration of the line
306 * @param source The source of the line
307 * @param reason The reason for the line
308 * @param hostmask The hostmask
309 * @return True if the line was added successfully
311 bool add_eline(long duration, const char* source, const char* reason, const char* hostmask);
314 * @return hostmask The host to remove
315 * @return True if the line was deleted successfully
317 bool del_gline(const char* hostmask);
320 * @return nickname The nick to remove
321 * @return True if the line was deleted successfully
323 bool del_qline(const char* nickname);
326 * @return ipaddr The IP to remove
327 * @return True if the line was deleted successfully
329 bool del_zline(const char* ipaddr);
332 * @return hostmask The host to remove
333 * @return True if the line was deleted successfully
335 bool del_kline(const char* hostmask);
338 * @return hostmask The host to remove
339 * @return True if the line was deleted successfully
341 bool del_eline(const char* hostmask);
343 /** Check if a nickname matches a QLine
344 * @return nick The nick to check against
345 * @return The reason for the line if there is a match, or NULL if there is no match
347 QLine* matches_qline(const char* nick);
349 /** Check if a hostname matches a GLine
350 * @param user The user to check against
351 * @return The reason for the line if there is a match, or NULL if there is no match
353 GLine* matches_gline(userrec* user);
355 /** Check if a IP matches a ZLine
356 * @param ipaddr The IP to check against
357 * @return The reason for the line if there is a match, or NULL if there is no match
359 ZLine* matches_zline(const char* ipaddr);
361 /** Check if a hostname matches a KLine
362 * @param user The user to check against
363 * @return The reason for the line if there is a match, or NULL if there is no match
365 KLine* matches_kline(userrec* user);
367 /** Check if a hostname matches a ELine
368 * @param user The user to check against
369 * @return The reason for the line if there is a match, or NULL if there is no match
371 ELine* matches_exception(userrec* user);
373 /** Expire any pending non-permenant lines
377 /** Apply any new lines
378 * @param What The types of lines to apply, from the set
379 * APPLY_GLINES | APPLY_KLINES | APPLY_QLINES | APPLY_ZLINES | APPLY_ALL
381 void apply_lines(const int What);
384 * @param user The username making the query
385 * @param results The string_list to receive the results
387 void stats_k(userrec* user, string_list &results);
390 * @param user The username making the query
391 * @param results The string_list to receive the results
393 void stats_g(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_q(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_z(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_e(userrec* user, string_list &results);
413 /** Change creation time of a GLine
414 * @param host The hostname to change
415 * @param create_Time The new creation time
417 void gline_set_creation_time(const char* host, time_t create_time);
419 /** Change creation time of a QLine
420 * @param nick The nickmask to change
421 * @param create_Time The new creation time
423 void qline_set_creation_time(const char* nick, time_t create_time);
425 /** Change creation time of a ZLine
426 * @param ip The ipmask to change
427 * @param create_Time The new creation time
429 void zline_set_creation_time(const char* ip, time_t create_time);
431 /** Change creation time of a ELine
432 * @param host The hostname to change
433 * @param create_Time The new creation time
435 void eline_set_creation_time(const char* host, time_t create_time);