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
31 const int APPLY_GLINES = 1;
32 const int APPLY_KLINES = 2;
33 const int APPLY_QLINES = 4;
34 const int APPLY_ZLINES = 8;
35 const int APPLY_ALL = APPLY_GLINES | APPLY_KLINES | APPLY_QLINES | APPLY_ZLINES;
37 /** XLine is the base class for ban lines such as G lines and K lines.
39 class XLine : public classbase
43 /** The time the line was added.
47 /** The duration of the ban, or 0 if permenant
51 /** Source of the ban. This can be a servername or an oper nickname
55 /** Reason for the ban
59 /** Number of times the core matches the ban, for statistics
67 class KLine : public XLine
70 /** Hostmask (ident@host) to match against
71 * May contain wildcards.
78 class GLine : public XLine
81 /** Hostmask (ident@host) to match against
82 * May contain wildcards.
87 class ELine : public XLine
90 /** Hostmask (ident@host) to match against
91 * May contain wildcards.
98 class ZLine : public XLine
101 /** IP Address (xx.yy.zz.aa) to match against
102 * May contain wildcards.
105 /** Set if this is a global Z:line
106 * (e.g. it came from another server)
113 class QLine : public XLine
116 /** Nickname to match against.
117 * May contain wildcards.
120 /** Set if this is a global Z:line
121 * (e.g. it came from another server)
129 bool InitXLine(ServerConfig* conf, const char* tag);
130 bool DoneXLine(ServerConfig* conf, const char* tag);
132 bool DoZLine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types);
133 bool DoQLine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types);
134 bool DoKLine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types);
135 bool DoELine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types);
137 /** XLineManager is a class used to manage glines, klines, elines, zlines and qlines.
142 /** The owner/creator of this class
144 InspIRCd* ServerInstance;
146 /** This functor is used by the std::sort() function to keep glines in order
148 static bool XLineManager::GSortComparison ( const GLine one, const GLine two );
150 /** This functor is used by the std::sort() function to keep elines in order
152 static bool XLineManager::ESortComparison ( const ELine one, const ELine two );
154 /** This functor is used by the std::sort() function to keep zlines in order
156 static bool XLineManager::ZSortComparison ( const ZLine one, const ZLine two );
158 /** This functor is used by the std::sort() function to keep klines in order
160 static bool XLineManager::KSortComparison ( const KLine one, const KLine two );
162 /** This functor is used by the std::sort() function to keep qlines in order
164 static bool XLineManager::QSortComparison ( const QLine one, const QLine two );
166 /* Lists for temporary lines with an expiry time */
168 /** Temporary KLines */
169 std::vector<KLine> klines;
171 /** Temporary Glines */
172 std::vector<GLine> glines;
174 /** Temporary Zlines */
175 std::vector<ZLine> zlines;
177 /** Temporary QLines */
178 std::vector<QLine> qlines;
180 /** Temporary ELines */
181 std::vector<ELine> elines;
183 /* Seperate lists for perm XLines that isnt checked by expiry functions */
185 /** Permenant KLines */
186 std::vector<KLine> pklines;
188 /** Permenant GLines */
189 std::vector<GLine> pglines;
191 /** Permenant ZLines */
192 std::vector<ZLine> pzlines;
194 /** Permenant QLines */
195 std::vector<QLine> pqlines;
197 /** Permenant ELines */
198 std::vector<ELine> pelines;
201 * @param Instance A pointer to the creator object
203 XLineManager(InspIRCd* Instance);
206 * @param duration The duration of the line
207 * @param source The source of the line
208 * @param reason The reason for the line
209 * @param hostmask The hostmask
210 * @return True if the line was added successfully
212 bool add_gline(long duration, const char* source, const char* reason, const char* hostmask);
215 * @param duration The duration of the line
216 * @param source The source of the line
217 * @param reason The reason for the line
218 * @param nickname The nickmask
219 * @return True if the line was added successfully
221 bool add_qline(long duration, const char* source, const char* reason, const char* nickname);
224 * @param duration The duration of the line
225 * @param source The source of the line
226 * @param reason The reason for the line
227 * @param ipaddr The IP mask
228 * @return True if the line was added successfully
230 bool add_zline(long duration, const char* source, const char* reason, const char* ipaddr);
233 * @param duration The duration of the line
234 * @param source The source of the line
235 * @param reason The reason for the line
236 * @param hostmask The hostmask
237 * @return True if the line was added successfully
239 bool add_kline(long duration, const char* source, const char* reason, const char* hostmask);
242 * @param duration The duration of the line
243 * @param source The source of the line
244 * @param reason The reason for the line
245 * @param hostmask The hostmask
246 * @return True if the line was added successfully
248 bool add_eline(long duration, const char* source, const char* reason, const char* hostmask);
251 * @return hostmask The host to remove
252 * @return True if the line was deleted successfully
254 bool del_gline(const char* hostmask);
257 * @return nickname The nick to remove
258 * @return True if the line was deleted successfully
260 bool del_qline(const char* nickname);
263 * @return ipaddr The IP to remove
264 * @return True if the line was deleted successfully
266 bool del_zline(const char* ipaddr);
269 * @return hostmask The host to remove
270 * @return True if the line was deleted successfully
272 bool del_kline(const char* hostmask);
275 * @return hostmask The host to remove
276 * @return True if the line was deleted successfully
278 bool del_eline(const char* hostmask);
280 /** Check if a nickname matches a QLine
281 * @return nick The nick to check against
282 * @return The reason for the line if there is a match, or NULL if there is no match
284 char* matches_qline(const char* nick);
286 /** Check if a hostname matches a GLine
287 * @return host The host to check against
288 * @return The reason for the line if there is a match, or NULL if there is no match
290 char* matches_gline(const char* host);
292 /** Check if a IP matches a ZLine
293 * @return ipaddr The IP to check against
294 * @return The reason for the line if there is a match, or NULL if there is no match
296 char* matches_zline(const char* ipaddr);
298 /** Check if a hostname matches a KLine
299 * @return host The host to check against
300 * @return The reason for the line if there is a match, or NULL if there is no match
302 char* matches_kline(const char* host);
304 /** Check if a hostname matches a ELine
305 * @return host The host to check against
306 * @return The reason for the line if there is a match, or NULL if there is no match
308 char* matches_exception(const char* host);
310 /** Expire any pending non-permenant lines
314 /** Apply any new lines
315 * @param What The types of lines to apply, from the set
316 * APPLY_GLINES | APPLY_KLINES | APPLY_QLINES | APPLY_ZLINES | APPLY_ALL
318 void apply_lines(const int What);
321 * @param user The username making the query
322 * @param results The string_list to receive the results
324 void stats_k(userrec* user, string_list &results);
327 * @param user The username making the query
328 * @param results The string_list to receive the results
330 void stats_g(userrec* user, string_list &results);
333 * @param user The username making the query
334 * @param results The string_list to receive the results
336 void stats_q(userrec* user, string_list &results);
339 * @param user The username making the query
340 * @param results The string_list to receive the results
342 void stats_z(userrec* user, string_list &results);
345 * @param user The username making the query
346 * @param results The string_list to receive the results
348 void stats_e(userrec* user, string_list &results);
350 /** Change creation time of a GLine
351 * @param host The hostname to change
352 * @param create_Time The new creation time
354 void gline_set_creation_time(const char* host, time_t create_time);
356 /** Change creation time of a QLine
357 * @param nick The nickmask to change
358 * @param create_Time The new creation time
360 void qline_set_creation_time(const char* nick, time_t create_time);
362 /** Change creation time of a ZLine
363 * @param ip The ipmask to change
364 * @param create_Time The new creation time
366 void zline_set_creation_time(const char* ip, time_t create_time);
368 /** Change creation time of a ELine
369 * @param host The hostname to change
370 * @param create_Time The new creation time
372 void eline_set_creation_time(const char* host, time_t create_time);
374 /** Make a ZLine global
375 * @param ipaddr The zline to change
376 * @return True if the zline was updated
378 bool zline_make_global(const char* ipaddr);
380 /** Make a QLine global
381 * @param nickname The qline to change
382 * @return True if the qline was updated
384 bool qline_make_global(const char* nickname);