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 /** The time the line was added.
44 /** The duration of the ban, or 0 if permenant
48 /** Source of the ban. This can be a servername or an oper nickname
52 /** Reason for the ban
56 /** Number of times the core matches the ban, for statistics
64 class KLine : public XLine
67 /** Hostmask (ident@host) to match against
68 * May contain wildcards.
75 class GLine : public XLine
78 /** Hostmask (ident@host) to match against
79 * May contain wildcards.
86 class ELine : public XLine
89 /** Hostmask (ident@host) to match against
90 * May contain wildcards.
97 class ZLine : public XLine
100 /** IP Address (xx.yy.zz.aa) to match against
101 * May contain wildcards.
104 /** Set if this is a global Z:line
105 * (e.g. it came from another server)
112 class QLine : public XLine
115 /** Nickname to match against.
116 * May contain wildcards.
119 /** Set if this is a global Z:line
120 * (e.g. it came from another server)
128 bool InitXLine(ServerConfig* conf, const char* tag);
129 bool DoneXLine(ServerConfig* conf, const char* tag);
131 bool DoZLine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types);
132 bool DoQLine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types);
133 bool DoKLine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types);
134 bool DoELine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types);
136 /** XLineManager is a class used to manage glines, klines, elines, zlines and qlines.
141 /** The owner/creator of this class
143 InspIRCd* ServerInstance;
145 /** This functor is used by the std::sort() function to keep glines in order
147 static bool GSortComparison ( const GLine one, const GLine two );
149 /** This functor is used by the std::sort() function to keep elines in order
151 static bool ESortComparison ( const ELine one, const ELine two );
153 /** This functor is used by the std::sort() function to keep zlines in order
155 static bool ZSortComparison ( const ZLine one, const ZLine two );
157 /** This functor is used by the std::sort() function to keep klines in order
159 static bool KSortComparison ( const KLine one, const KLine two );
161 /** This functor is used by the std::sort() function to keep qlines in order
163 static bool QSortComparison ( const QLine one, const QLine two );
165 /* Lists for temporary lines with an expiry time */
167 /** Temporary KLines */
168 std::vector<KLine> klines;
170 /** Temporary Glines */
171 std::vector<GLine> glines;
173 /** Temporary Zlines */
174 std::vector<ZLine> zlines;
176 /** Temporary QLines */
177 std::vector<QLine> qlines;
179 /** Temporary ELines */
180 std::vector<ELine> elines;
182 /* Seperate lists for perm XLines that isnt checked by expiry functions */
184 /** Permenant KLines */
185 std::vector<KLine> pklines;
187 /** Permenant GLines */
188 std::vector<GLine> pglines;
190 /** Permenant ZLines */
191 std::vector<ZLine> pzlines;
193 /** Permenant QLines */
194 std::vector<QLine> pqlines;
196 /** Permenant ELines */
197 std::vector<ELine> pelines;
200 * @param Instance A pointer to the creator object
202 XLineManager(InspIRCd* Instance);
205 * @param duration The duration of the line
206 * @param source The source of the line
207 * @param reason The reason for the line
208 * @param hostmask The hostmask
209 * @return True if the line was added successfully
211 bool add_gline(long duration, const char* source, const char* reason, const char* hostmask);
214 * @param duration The duration of the line
215 * @param source The source of the line
216 * @param reason The reason for the line
217 * @param nickname The nickmask
218 * @return True if the line was added successfully
220 bool add_qline(long duration, const char* source, const char* reason, const char* nickname);
223 * @param duration The duration of the line
224 * @param source The source of the line
225 * @param reason The reason for the line
226 * @param ipaddr The IP mask
227 * @return True if the line was added successfully
229 bool add_zline(long duration, const char* source, const char* reason, const char* ipaddr);
232 * @param duration The duration of the line
233 * @param source The source of the line
234 * @param reason The reason for the line
235 * @param hostmask The hostmask
236 * @return True if the line was added successfully
238 bool add_kline(long duration, const char* source, const char* reason, const char* hostmask);
241 * @param duration The duration of the line
242 * @param source The source of the line
243 * @param reason The reason for the line
244 * @param hostmask The hostmask
245 * @return True if the line was added successfully
247 bool add_eline(long duration, const char* source, const char* reason, const char* hostmask);
250 * @return hostmask The host to remove
251 * @return True if the line was deleted successfully
253 bool del_gline(const char* hostmask);
256 * @return nickname The nick to remove
257 * @return True if the line was deleted successfully
259 bool del_qline(const char* nickname);
262 * @return ipaddr The IP to remove
263 * @return True if the line was deleted successfully
265 bool del_zline(const char* ipaddr);
268 * @return hostmask The host to remove
269 * @return True if the line was deleted successfully
271 bool del_kline(const char* hostmask);
274 * @return hostmask The host to remove
275 * @return True if the line was deleted successfully
277 bool del_eline(const char* hostmask);
279 /** Check if a nickname matches a QLine
280 * @return nick The nick to check against
281 * @return The reason for the line if there is a match, or NULL if there is no match
283 char* matches_qline(const char* nick);
285 /** Check if a hostname matches a GLine
286 * @return host The host to check against
287 * @return The reason for the line if there is a match, or NULL if there is no match
289 char* matches_gline(const char* host);
291 /** Check if a IP matches a ZLine
292 * @return ipaddr The IP to check against
293 * @return The reason for the line if there is a match, or NULL if there is no match
295 char* matches_zline(const char* ipaddr);
297 /** Check if a hostname matches a KLine
298 * @return host The host to check against
299 * @return The reason for the line if there is a match, or NULL if there is no match
301 char* matches_kline(const char* host);
303 /** Check if a hostname matches a ELine
304 * @return host The host to check against
305 * @return The reason for the line if there is a match, or NULL if there is no match
307 char* matches_exception(const char* host);
309 /** Expire any pending non-permenant lines
313 /** Apply any new lines
314 * @param What The types of lines to apply, from the set
315 * APPLY_GLINES | APPLY_KLINES | APPLY_QLINES | APPLY_ZLINES | APPLY_ALL
317 void apply_lines(const int What);
320 * @param user The username making the query
321 * @param results The string_list to receive the results
323 void stats_k(userrec* user, string_list &results);
326 * @param user The username making the query
327 * @param results The string_list to receive the results
329 void stats_g(userrec* user, string_list &results);
332 * @param user The username making the query
333 * @param results The string_list to receive the results
335 void stats_q(userrec* user, string_list &results);
338 * @param user The username making the query
339 * @param results The string_list to receive the results
341 void stats_z(userrec* user, string_list &results);
344 * @param user The username making the query
345 * @param results The string_list to receive the results
347 void stats_e(userrec* user, string_list &results);
349 /** Change creation time of a GLine
350 * @param host The hostname to change
351 * @param create_Time The new creation time
353 void gline_set_creation_time(const char* host, time_t create_time);
355 /** Change creation time of a QLine
356 * @param nick The nickmask to change
357 * @param create_Time The new creation time
359 void qline_set_creation_time(const char* nick, time_t create_time);
361 /** Change creation time of a ZLine
362 * @param ip The ipmask to change
363 * @param create_Time The new creation time
365 void zline_set_creation_time(const char* ip, time_t create_time);
367 /** Change creation time of a ELine
368 * @param host The hostname to change
369 * @param create_Time The new creation time
371 void eline_set_creation_time(const char* host, time_t create_time);
373 /** Make a ZLine global
374 * @param ipaddr The zline to change
375 * @return True if the zline was updated
377 bool zline_make_global(const char* ipaddr);
379 /** Make a QLine global
380 * @param nickname The qline to change
381 * @return True if the qline was updated
383 bool qline_make_global(const char* nickname);