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.
89 class ELine : public XLine
92 /** Hostmask (ident@host) to match against
93 * 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 /** XLineManager is a class used to manage glines, klines, elines, zlines and qlines.
144 /** The owner/creator of this class
146 InspIRCd* ServerInstance;
148 /** This functor is used by the std::sort() function to keep glines in order
150 static bool XLineManager::GSortComparison ( const GLine one, const GLine two );
152 /** This functor is used by the std::sort() function to keep elines in order
154 static bool XLineManager::ESortComparison ( const ELine one, const ELine two );
156 /** This functor is used by the std::sort() function to keep zlines in order
158 static bool XLineManager::ZSortComparison ( const ZLine one, const ZLine two );
160 /** This functor is used by the std::sort() function to keep klines in order
162 static bool XLineManager::KSortComparison ( const KLine one, const KLine two );
164 /** This functor is used by the std::sort() function to keep qlines in order
166 static bool XLineManager::QSortComparison ( const QLine one, const QLine two );
168 /* Lists for temporary lines with an expiry time */
170 /** Temporary KLines */
171 std::vector<KLine> klines;
173 /** Temporary Glines */
174 std::vector<GLine> glines;
176 /** Temporary Zlines */
177 std::vector<ZLine> zlines;
179 /** Temporary QLines */
180 std::vector<QLine> qlines;
182 /** Temporary ELines */
183 std::vector<ELine> elines;
185 /* Seperate lists for perm XLines that isnt checked by expiry functions */
187 /** Permenant KLines */
188 std::vector<KLine> pklines;
190 /** Permenant GLines */
191 std::vector<GLine> pglines;
193 /** Permenant ZLines */
194 std::vector<ZLine> pzlines;
196 /** Permenant QLines */
197 std::vector<QLine> pqlines;
199 /** Permenant ELines */
200 std::vector<ELine> pelines;
203 * @param Instance A pointer to the creator object
205 XLineManager(InspIRCd* Instance);
208 * @param duration The duration of the line
209 * @param source The source of the line
210 * @param reason The reason for the line
211 * @param hostmask The hostmask
212 * @return True if the line was added successfully
214 bool add_gline(long duration, const char* source, const char* reason, const char* hostmask);
217 * @param duration The duration of the line
218 * @param source The source of the line
219 * @param reason The reason for the line
220 * @param nickname The nickmask
221 * @return True if the line was added successfully
223 bool add_qline(long duration, const char* source, const char* reason, const char* nickname);
226 * @param duration The duration of the line
227 * @param source The source of the line
228 * @param reason The reason for the line
229 * @param ipaddr The IP mask
230 * @return True if the line was added successfully
232 bool add_zline(long duration, const char* source, const char* reason, const char* ipaddr);
235 * @param duration The duration of the line
236 * @param source The source of the line
237 * @param reason The reason for the line
238 * @param hostmask The hostmask
239 * @return True if the line was added successfully
241 bool add_kline(long duration, const char* source, const char* reason, const char* hostmask);
244 * @param duration The duration of the line
245 * @param source The source of the line
246 * @param reason The reason for the line
247 * @param hostmask The hostmask
248 * @return True if the line was added successfully
250 bool add_eline(long duration, const char* source, const char* reason, const char* hostmask);
253 * @return hostmask The host to remove
254 * @return True if the line was deleted successfully
256 bool del_gline(const char* hostmask);
259 * @return nickname The nick to remove
260 * @return True if the line was deleted successfully
262 bool del_qline(const char* nickname);
265 * @return ipaddr The IP to remove
266 * @return True if the line was deleted successfully
268 bool del_zline(const char* ipaddr);
271 * @return hostmask The host to remove
272 * @return True if the line was deleted successfully
274 bool del_kline(const char* hostmask);
277 * @return hostmask The host to remove
278 * @return True if the line was deleted successfully
280 bool del_eline(const char* hostmask);
282 /** Check if a nickname matches a QLine
283 * @return nick The nick to check against
284 * @return The reason for the line if there is a match, or NULL if there is no match
286 char* matches_qline(const char* nick);
288 /** Check if a hostname matches a GLine
289 * @return host The host to check against
290 * @return The reason for the line if there is a match, or NULL if there is no match
292 char* matches_gline(const char* host);
294 /** Check if a IP matches a ZLine
295 * @return ipaddr The IP to check against
296 * @return The reason for the line if there is a match, or NULL if there is no match
298 char* matches_zline(const char* ipaddr);
300 /** Check if a hostname matches a KLine
301 * @return host The host to check against
302 * @return The reason for the line if there is a match, or NULL if there is no match
304 char* matches_kline(const char* host);
306 /** Check if a hostname matches a ELine
307 * @return host The host to check against
308 * @return The reason for the line if there is a match, or NULL if there is no match
310 char* matches_exception(const char* host);
312 /** Expire any pending non-permenant lines
316 /** Apply any new lines
317 * @param What The types of lines to apply, from the set
318 * APPLY_GLINES | APPLY_KLINES | APPLY_QLINES | APPLY_ZLINES | APPLY_ALL
320 void apply_lines(const int What);
323 * @param user The username making the query
324 * @param results The string_list to receive the results
326 void stats_k(userrec* user, string_list &results);
329 * @param user The username making the query
330 * @param results The string_list to receive the results
332 void stats_g(userrec* user, string_list &results);
335 * @param user The username making the query
336 * @param results The string_list to receive the results
338 void stats_q(userrec* user, string_list &results);
341 * @param user The username making the query
342 * @param results The string_list to receive the results
344 void stats_z(userrec* user, string_list &results);
347 * @param user The username making the query
348 * @param results The string_list to receive the results
350 void stats_e(userrec* user, string_list &results);
352 /** Change creation time of a GLine
353 * @param host The hostname to change
354 * @param create_Time The new creation time
356 void gline_set_creation_time(const char* host, time_t create_time);
358 /** Change creation time of a QLine
359 * @param nick The nickmask to change
360 * @param create_Time The new creation time
362 void qline_set_creation_time(const char* nick, time_t create_time);
364 /** Change creation time of a ZLine
365 * @param ip The ipmask to change
366 * @param create_Time The new creation time
368 void zline_set_creation_time(const char* ip, time_t create_time);
370 /** Change creation time of a ELine
371 * @param host The hostname to change
372 * @param create_Time The new creation time
374 void eline_set_creation_time(const char* host, time_t create_time);
376 /** Make a ZLine global
377 * @param ipaddr The zline to change
378 * @return True if the zline was updated
380 bool zline_make_global(const char* ipaddr);
382 /** Make a QLine global
383 * @param nickname The qline to change
384 * @return True if the qline was updated
386 bool qline_make_global(const char* nickname);