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.
76 class GLine : public XLine
79 /** Hostmask (ident@host) to match against
80 * May contain wildcards.
88 class ELine : public XLine
91 /** Hostmask (ident@host) to match against
92 * May contain wildcards.
100 class ZLine : public XLine
103 /** IP Address (xx.yy.zz.aa) to match against
104 * May contain wildcards.
107 /** Set if this is a global Z:line
108 * (e.g. it came from another server)
115 class QLine : public XLine
118 /** Nickname to match against.
119 * May contain wildcards.
122 /** Set if this is a global Z:line
123 * (e.g. it came from another server)
131 bool InitXLine(ServerConfig* conf, const char* tag);
132 bool DoneXLine(ServerConfig* conf, const char* tag);
134 bool DoZLine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types);
135 bool DoQLine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types);
136 bool DoKLine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types);
137 bool DoELine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types);
139 typedef std::pair<std::string, std::string> IdentHostPair;
141 /** XLineManager is a class used to manage glines, klines, elines, zlines and qlines.
146 /** The owner/creator of this class
148 InspIRCd* ServerInstance;
150 /** This functor is used by the std::sort() function to keep glines in order
152 static bool GSortComparison ( const GLine one, const GLine two );
154 /** This functor is used by the std::sort() function to keep elines in order
156 static bool ESortComparison ( const ELine one, const ELine two );
158 /** This functor is used by the std::sort() function to keep zlines in order
160 static bool ZSortComparison ( const ZLine one, const ZLine two );
162 /** This functor is used by the std::sort() function to keep klines in order
164 static bool KSortComparison ( const KLine one, const KLine two );
166 /** This functor is used by the std::sort() function to keep qlines in order
168 static bool QSortComparison ( const QLine one, const QLine two );
170 /* Lists for temporary lines with an expiry time */
172 /** Temporary KLines */
173 std::vector<KLine> klines;
175 /** Temporary Glines */
176 std::vector<GLine> glines;
178 /** Temporary Zlines */
179 std::vector<ZLine> zlines;
181 /** Temporary QLines */
182 std::vector<QLine> qlines;
184 /** Temporary ELines */
185 std::vector<ELine> elines;
187 /* Seperate lists for perm XLines that isnt checked by expiry functions */
189 /** Permenant KLines */
190 std::vector<KLine> pklines;
192 /** Permenant GLines */
193 std::vector<GLine> pglines;
195 /** Permenant ZLines */
196 std::vector<ZLine> pzlines;
198 /** Permenant QLines */
199 std::vector<QLine> pqlines;
201 /** Permenant ELines */
202 std::vector<ELine> pelines;
205 * @param Instance A pointer to the creator object
207 XLineManager(InspIRCd* Instance);
209 IdentHostPair XLineManager::IdentSplit(const std::string &ident_and_host);
212 * @param duration The duration of the line
213 * @param source The source of the line
214 * @param reason The reason for the line
215 * @param hostmask The hostmask
216 * @return True if the line was added successfully
218 bool add_gline(long duration, const char* source, const char* reason, const char* hostmask);
221 * @param duration The duration of the line
222 * @param source The source of the line
223 * @param reason The reason for the line
224 * @param nickname The nickmask
225 * @return True if the line was added successfully
227 bool add_qline(long duration, const char* source, const char* reason, const char* nickname);
230 * @param duration The duration of the line
231 * @param source The source of the line
232 * @param reason The reason for the line
233 * @param ipaddr The IP mask
234 * @return True if the line was added successfully
236 bool add_zline(long duration, const char* source, const char* reason, const char* ipaddr);
239 * @param duration The duration of the line
240 * @param source The source of the line
241 * @param reason The reason for the line
242 * @param hostmask The hostmask
243 * @return True if the line was added successfully
245 bool add_kline(long duration, const char* source, const char* reason, const char* hostmask);
248 * @param duration The duration of the line
249 * @param source The source of the line
250 * @param reason The reason for the line
251 * @param hostmask The hostmask
252 * @return True if the line was added successfully
254 bool add_eline(long duration, const char* source, const char* reason, const char* hostmask);
257 * @return hostmask The host to remove
258 * @return True if the line was deleted successfully
260 bool del_gline(const char* hostmask);
263 * @return nickname The nick to remove
264 * @return True if the line was deleted successfully
266 bool del_qline(const char* nickname);
269 * @return ipaddr The IP to remove
270 * @return True if the line was deleted successfully
272 bool del_zline(const char* ipaddr);
275 * @return hostmask The host to remove
276 * @return True if the line was deleted successfully
278 bool del_kline(const char* hostmask);
281 * @return hostmask The host to remove
282 * @return True if the line was deleted successfully
284 bool del_eline(const char* hostmask);
286 /** Check if a nickname matches a QLine
287 * @return nick The nick 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_qline(const char* nick);
292 /** Check if a hostname matches a GLine
293 * @param user The user 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_gline(userrec* user);
298 /** Check if a IP matches a ZLine
299 * @param ipaddr The IP 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_zline(const char* ipaddr);
304 /** Check if a hostname matches a KLine
305 * @param user The user 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_kline(userrec* user);
310 /** Check if a hostname matches a ELine
311 * @param user The user to check against
312 * @return The reason for the line if there is a match, or NULL if there is no match
314 char* matches_exception(userrec* user);
316 /** Expire any pending non-permenant lines
320 /** Apply any new lines
321 * @param What The types of lines to apply, from the set
322 * APPLY_GLINES | APPLY_KLINES | APPLY_QLINES | APPLY_ZLINES | APPLY_ALL
324 void apply_lines(const int What);
327 * @param user The username making the query
328 * @param results The string_list to receive the results
330 void stats_k(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_g(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_q(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_z(userrec* user, string_list &results);
351 * @param user The username making the query
352 * @param results The string_list to receive the results
354 void stats_e(userrec* user, string_list &results);
356 /** Change creation time of a GLine
357 * @param host The hostname to change
358 * @param create_Time The new creation time
360 void gline_set_creation_time(const char* host, time_t create_time);
362 /** Change creation time of a QLine
363 * @param nick The nickmask to change
364 * @param create_Time The new creation time
366 void qline_set_creation_time(const char* nick, time_t create_time);
368 /** Change creation time of a ZLine
369 * @param ip The ipmask to change
370 * @param create_Time The new creation time
372 void zline_set_creation_time(const char* ip, time_t create_time);
374 /** Change creation time of a ELine
375 * @param host The hostname to change
376 * @param create_Time The new creation time
378 void eline_set_creation_time(const char* host, time_t create_time);
380 /** Make a ZLine global
381 * @param ipaddr The zline to change
382 * @return True if the zline was updated
384 bool zline_make_global(const char* ipaddr);
386 /** Make a QLine global
387 * @param nickname The qline to change
388 * @return True if the qline was updated
390 bool qline_make_global(const char* nickname);