]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_filter.cpp
MetaData rework
[user/henk/code/inspircd.git] / src / modules / m_filter.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *          the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "xline.h"
16 #include "m_regex.h"
17
18 /* $ModDesc: Text (spam) filtering */
19
20 static std::string RegexEngine = "";
21 static Module* rxengine = NULL;
22
23 enum FilterFlags
24 {
25         FLAG_PART = 2,
26         FLAG_QUIT = 4,
27         FLAG_PRIVMSG = 8,
28         FLAG_NOTICE = 16
29 };
30
31 class FilterResult : public classbase
32 {
33  public:
34         std::string freeform;
35         std::string reason;
36         std::string action;
37         long gline_time;
38         std::string flags;
39
40         bool flag_no_opers;
41         bool flag_part_message;
42         bool flag_quit_message;
43         bool flag_privmsg;
44         bool flag_notice;
45
46         FilterResult(const std::string free, const std::string &rea, const std::string &act, long gt, const std::string &fla) :
47                         freeform(free), reason(rea), action(act), gline_time(gt), flags(fla)
48         {
49                 this->FillFlags(fla);
50         }
51
52         int FillFlags(const std::string &fl)
53         {
54                 flags = fl;
55                 flag_no_opers = flag_part_message = flag_quit_message = flag_privmsg = flag_notice = false;
56                 size_t x = 0;
57
58                 for (std::string::const_iterator n = flags.begin(); n != flags.end(); ++n, ++x)
59                 {
60                         switch (*n)
61                         {
62                                 case 'o':
63                                         flag_no_opers = true;
64                                 break;
65                                 case 'P':
66                                         flag_part_message = true;
67                                 break;
68                                 case 'q':
69                                         flag_quit_message = true;
70                                 break;
71                                 case 'p':
72                                         flag_privmsg = true;
73                                 break;
74                                 case 'n':
75                                         flag_notice = true;
76                                 break;
77                                 case '*':
78                                         flag_no_opers = flag_part_message = flag_quit_message =
79                                                 flag_privmsg = flag_notice = true;
80                                 break;
81                                 default:
82                                         return x;
83                                 break;
84                         }
85                 }
86                 return 0;
87         }
88
89         FilterResult()
90         {
91         }
92
93         virtual ~FilterResult()
94         {
95         }
96 };
97
98 class FilterBase;
99
100 class CommandFilter : public Command
101 {
102         FilterBase* Base;
103  public:
104         CommandFilter(FilterBase* f, InspIRCd* Me, const std::string &ssource) : Command(Me, "FILTER", "o", 1, 5), Base(f)
105         {
106                 this->source = ssource;
107                 this->syntax = "<filter-definition> <action> <flags> [<gline-duration>] :<reason>";
108         }
109         CmdResult Handle(const std::vector<std::string>&, User*);
110
111         void TooFewParams(User* user, const std::string &extra_text)
112         {
113                 user->WriteServ("NOTICE %s :*** Not enough parameters%s", user->nick.c_str(), extra_text.c_str());
114         }
115 };
116
117 class FilterBase : public Module
118 {
119         CommandFilter filtcommand;
120         int flags;
121 protected:
122         std::vector<std::string> exemptfromfilter; // List of channel names excluded from filtering.
123  public:
124         FilterBase(InspIRCd* Me, const std::string &source);
125         virtual ~FilterBase();
126         virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list);
127         virtual FilterResult* FilterMatch(User* user, const std::string &text, int flags) = 0;
128         virtual bool DeleteFilter(const std::string &freeform) = 0;
129         virtual void SyncFilters(Module* proto, void* opaque) = 0;
130         virtual void SendFilter(Module* proto, void* opaque, FilterResult* iter);
131         virtual std::pair<bool, std::string> AddFilter(const std::string &freeform, const std::string &type, const std::string &reason, long duration, const std::string &flags) = 0;
132         virtual int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list);
133         virtual void OnRehash(User* user);
134         virtual Version GetVersion();
135         std::string EncodeFilter(FilterResult* filter);
136         FilterResult DecodeFilter(const std::string &data);
137         virtual void OnSyncNetwork(Module* proto, void* opaque);
138         virtual void OnDecodeMetaData(Extensible* target, const std::string &extname, const std::string &extdata);
139         virtual int OnStats(char symbol, User* user, string_list &results) = 0;
140         virtual int OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line);
141         bool AppliesToMe(User* user, FilterResult* filter, int flags);
142         void OnLoadModule(Module* mod, const std::string& name);
143         virtual void ReadFilters(ConfigReader &MyConf) = 0;
144 };
145
146 CmdResult CommandFilter::Handle(const std::vector<std::string> &parameters, User *user)
147 {
148         if (parameters.size() == 1)
149         {
150                 /* Deleting a filter */
151                 if (Base->DeleteFilter(parameters[0]))
152                 {
153                         user->WriteServ("NOTICE %s :*** Removed filter '%s'", user->nick.c_str(), parameters[0].c_str());
154                         ServerInstance->SNO->WriteToSnoMask(IS_LOCAL(user) ? 'a' : 'A', std::string("FILTER: ")+user->nick+" removed filter '"+parameters[0]+"'");
155                         return CMD_SUCCESS;
156                 }
157                 else
158                 {
159                         user->WriteServ("NOTICE %s :*** Filter '%s' not found in list, try /stats s.", user->nick.c_str(), parameters[0].c_str());
160                         return CMD_FAILURE;
161                 }
162         }
163         else
164         {
165                 /* Adding a filter */
166                 if (parameters.size() >= 4)
167                 {
168                         std::string freeform = parameters[0];
169                         std::string type = parameters[1];
170                         std::string flags = parameters[2];
171                         std::string reason;
172                         long duration = 0;
173
174
175                         if ((type != "gline") && (type != "none") && (type != "block") && (type != "kill") && (type != "silent"))
176                         {
177                                 user->WriteServ("NOTICE %s :*** Invalid filter type '%s'. Supported types are 'gline', 'none', 'block', 'silent' and 'kill'.", user->nick.c_str(), type.c_str());
178                                 return CMD_FAILURE;
179                         }
180
181                         if (type == "gline")
182                         {
183                                 if (parameters.size() >= 5)
184                                 {
185                                         duration = ServerInstance->Duration(parameters[3]);
186                                         reason = parameters[4];
187                                 }
188                                 else
189                                 {
190                                         this->TooFewParams(user, ": When setting a gline type filter, a gline duration must be specified as the third parameter.");
191                                         return CMD_FAILURE;
192                                 }
193                         }
194                         else
195                         {
196                                 reason = parameters[3];
197                         }
198                         std::pair<bool, std::string> result = Base->AddFilter(freeform, type, reason, duration, flags);
199                         if (result.first)
200                         {
201                                 user->WriteServ("NOTICE %s :*** Added filter '%s', type '%s'%s%s, flags '%s', reason: '%s'", user->nick.c_str(), freeform.c_str(),
202                                                 type.c_str(), (duration ? ", duration " : ""), (duration ? parameters[3].c_str() : ""),
203                                                 flags.c_str(), reason.c_str());
204
205                                 ServerInstance->SNO->WriteToSnoMask(IS_LOCAL(user) ? 'a' : 'A', std::string("FILTER: ")+user->nick+" added filter '"+freeform+"', type '"+type+"', "+(duration ? "duration "+parameters[3]+", " : "")+"flags '"+flags+"', reason: "+reason);
206
207                                 return CMD_SUCCESS;
208                         }
209                         else
210                         {
211                                 user->WriteServ("NOTICE %s :*** Filter '%s' could not be added: %s", user->nick.c_str(), freeform.c_str(), result.second.c_str());
212                                 return CMD_FAILURE;
213                         }
214                 }
215                 else
216                 {
217                         this->TooFewParams(user, ".");
218                         return CMD_FAILURE;
219                 }
220
221         }
222 }
223
224 bool FilterBase::AppliesToMe(User* user, FilterResult* filter, int iflags)
225 {
226         if ((filter->flag_no_opers) && IS_OPER(user))
227                 return false;
228         if ((iflags & FLAG_PRIVMSG) && (!filter->flag_privmsg))
229                 return false;
230         if ((iflags & FLAG_NOTICE) && (!filter->flag_notice))
231                 return false;
232         if ((iflags & FLAG_QUIT)   && (!filter->flag_quit_message))
233                 return false;
234         if ((iflags & FLAG_PART)   && (!filter->flag_part_message))
235                 return false;
236         return true;
237 }
238
239 FilterBase::FilterBase(InspIRCd* Me, const std::string &source) : Module(Me), filtcommand(this, Me, source)
240 {
241         Me->Modules->UseInterface("RegularExpression");
242         ServerInstance->AddCommand(&filtcommand);
243         Implementation eventlist[] = { I_OnPreCommand, I_OnStats, I_OnSyncNetwork, I_OnDecodeMetaData, I_OnUserPreMessage, I_OnUserPreNotice, I_OnRehash, I_OnLoadModule };
244         ServerInstance->Modules->Attach(eventlist, this, 8);
245 }
246
247 FilterBase::~FilterBase()
248 {
249         ServerInstance->Modules->DoneWithInterface("RegularExpression");
250 }
251
252 int FilterBase::OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
253 {
254         if (!IS_LOCAL(user))
255                 return 0;
256
257         flags = FLAG_PRIVMSG;
258         return OnUserPreNotice(user,dest,target_type,text,status,exempt_list);
259 }
260
261 int FilterBase::OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
262 {
263         /* Leave ulines alone */
264         if ((ServerInstance->ULine(user->server)) || (!IS_LOCAL(user)))
265                 return 0;
266
267         if (!flags)
268                 flags = FLAG_NOTICE;
269
270         FilterResult* f = this->FilterMatch(user, text, flags);
271         if (f)
272         {
273                 std::string target = "";
274                 if (target_type == TYPE_USER)
275                 {
276                         User* t = (User*)dest;
277                         target = std::string(t->nick);
278                 }
279                 else if (target_type == TYPE_CHANNEL)
280                 {
281                         Channel* t = (Channel*)dest;
282                         target = std::string(t->name);
283                         std::vector<std::string>::iterator i = find(exemptfromfilter.begin(), exemptfromfilter.end(), target);
284                         if (i != exemptfromfilter.end()) return 0;
285                 }
286                 if (f->action == "block")
287                 {
288                         ServerInstance->SNO->WriteGlobalSno('a', std::string("FILTER: ")+user->nick+" had their message filtered, target was "+target+": "+f->reason);
289                         if (target_type == TYPE_CHANNEL)
290                                 user->WriteNumeric(404, "%s %s :Message to channel blocked and opers notified (%s)",user->nick.c_str(), target.c_str(), f->reason.c_str());
291                         else
292                                 user->WriteServ("NOTICE "+std::string(user->nick)+" :Your message to "+target+" was blocked and opers notified: "+f->reason);
293                 }
294                 if (f->action == "silent")
295                 {
296                         if (target_type == TYPE_CHANNEL)
297                                 user->WriteNumeric(404, "%s %s :Message to channel blocked (%s)",user->nick.c_str(), target.c_str(), f->reason.c_str());
298                         else
299                                 user->WriteServ("NOTICE "+std::string(user->nick)+" :Your message to "+target+" was blocked: "+f->reason);
300                 }
301                 if (f->action == "kill")
302                 {
303                         ServerInstance->Users->QuitUser(user, "Filtered: " + f->reason);
304                 }
305                 if (f->action == "gline")
306                 {
307                         GLine* gl = new GLine(ServerInstance, ServerInstance->Time(), f->gline_time, ServerInstance->Config->ServerName, f->reason.c_str(), "*", user->GetIPString());
308                         if (ServerInstance->XLines->AddLine(gl,NULL))
309                         {
310                                 ServerInstance->XLines->ApplyLines();
311                         }
312                         else
313                                 delete gl;
314                 }
315
316                 ServerInstance->Logs->Log("FILTER",DEFAULT,"FILTER: "+ user->nick + " had their message filtered, target was " + target + ": " + f->reason + " Action: " + f->action);
317                 return 1;
318         }
319         return 0;
320 }
321
322 int FilterBase::OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
323 {
324         flags = 0;
325         if (validated && IS_LOCAL(user))
326         {
327                 std::string checkline;
328                 int replacepoint = 0;
329                 bool parting = false;
330
331                 if (command == "QUIT")
332                 {
333                         /* QUIT with no reason: nothing to do */
334                         if (parameters.size() < 1)
335                                 return 0;
336
337                         checkline = parameters[0];
338                         replacepoint = 0;
339                         parting = false;
340                         flags = FLAG_QUIT;
341                 }
342                 else if (command == "PART")
343                 {
344                         /* PART with no reason: nothing to do */
345                         if (parameters.size() < 2)
346                                 return 0;
347
348                         std::vector<std::string>::iterator i = find(exemptfromfilter.begin(), exemptfromfilter.end(), parameters[0]);
349                         if (i != exemptfromfilter.end()) return 0;
350                         checkline = parameters[1];
351                         replacepoint = 1;
352                         parting = true;
353                         flags = FLAG_PART;
354                 }
355                 else
356                         /* We're only messing with PART and QUIT */
357                         return 0;
358
359                 FilterResult* f = NULL;
360
361                 if (flags)
362                         f = this->FilterMatch(user, checkline, flags);
363
364                 if (!f)
365                         /* PART or QUIT reason doesnt match a filter */
366                         return 0;
367
368                 /* We cant block a part or quit, so instead we change the reason to 'Reason filtered' */
369                 Command* c = ServerInstance->Parser->GetHandler(command);
370                 if (c)
371                 {
372                         std::vector<std::string> params;
373                         for (int item = 0; item < (int)parameters.size(); item++)
374                                 params.push_back(parameters[item]);
375                         params[replacepoint] = "Reason filtered";
376
377                         /* We're blocking, OR theyre quitting and its a KILL action
378                          * (we cant kill someone whos already quitting, so filter them anyway)
379                          */
380                         if ((f->action == "block") || (((!parting) && (f->action == "kill"))) || (f->action == "silent"))
381                         {
382                                 c->Handle(params, user);
383                                 return 1;
384                         }
385                         else
386                         {
387                                 /* Are they parting, if so, kill is applicable */
388                                 if ((parting) && (f->action == "kill"))
389                                 {
390                                         user->WriteServ("NOTICE %s :*** Your PART message was filtered: %s", user->nick.c_str(), f->reason.c_str());
391                                         ServerInstance->Users->QuitUser(user, "Filtered: " + f->reason);
392                                 }
393                                 if (f->action == "gline")
394                                 {
395                                         /* Note: We gline *@IP so that if their host doesnt resolve the gline still applies. */
396                                         GLine* gl = new GLine(ServerInstance, ServerInstance->Time(), f->gline_time, ServerInstance->Config->ServerName, f->reason.c_str(), "*", user->GetIPString());
397                                         if (ServerInstance->XLines->AddLine(gl,NULL))
398                                         {
399                                                 ServerInstance->XLines->ApplyLines();
400                                         }
401                                         else
402                                                 delete gl;
403                                 }
404                                 return 1;
405                         }
406                 }
407                 return 0;
408         }
409         return 0;
410 }
411
412 void FilterBase::OnRehash(User* user)
413 {
414         ConfigReader MyConf(ServerInstance);
415         std::vector<std::string>().swap(exemptfromfilter);
416         for (int index = 0; index < MyConf.Enumerate("exemptfromfilter"); ++index)
417         {
418                 std::string chan = MyConf.ReadValue("exemptfromfilter", "channel", index);
419                 if (!chan.empty()) {
420                         exemptfromfilter.push_back(chan);
421                 }
422         }
423         std::string newrxengine = MyConf.ReadValue("filteropts", "engine", 0);
424         if (!RegexEngine.empty())
425         {
426                 if (RegexEngine == newrxengine)
427                         return;
428
429                 ServerInstance->SNO->WriteGlobalSno('a', "Dumping all filters due to regex engine change (was '%s', now '%s')", RegexEngine.c_str(), newrxengine.c_str());
430                 //ServerInstance->XLines->DelAll("R");
431         }
432         rxengine = NULL;
433
434         RegexEngine = newrxengine;
435         modulelist* ml = ServerInstance->Modules->FindInterface("RegularExpression");
436         if (ml)
437         {
438                 for (modulelist::iterator i = ml->begin(); i != ml->end(); ++i)
439                 {
440                         if (RegexNameRequest(this, *i).Send() == newrxengine)
441                         {
442                                 ServerInstance->SNO->WriteGlobalSno('a', "Filter now using engine '%s'", RegexEngine.c_str());
443                                 rxengine = *i;
444                         }
445                 }
446         }
447         if (!rxengine)
448         {
449                 ServerInstance->SNO->WriteGlobalSno('a', "WARNING: Regex engine '%s' is not loaded - Filter functionality disabled until this is corrected.", RegexEngine.c_str());
450         }
451 }
452
453 void FilterBase::OnLoadModule(Module* mod, const std::string& name)
454 {
455         if (ServerInstance->Modules->ModuleHasInterface(mod, "RegularExpression"))
456         {
457                 std::string rxname = RegexNameRequest(this, mod).Send();
458                 if (rxname == RegexEngine)
459                 {
460                         rxengine = mod;
461                         /* Force a rehash to make sure that any filters that couldnt be applied from the conf
462                          * on startup or on load are applied right now.
463                          */
464                         ConfigReader Config(ServerInstance);
465                         ServerInstance->SNO->WriteGlobalSno('a', "Found and activated regex module '%s' for m_filter.so.", RegexEngine.c_str());
466                         ReadFilters(Config);
467                 }
468         }
469 }
470
471
472 Version FilterBase::GetVersion()
473 {
474         return Version("$Id$", VF_VENDOR | VF_COMMON, API_VERSION);
475 }
476
477
478 std::string FilterBase::EncodeFilter(FilterResult* filter)
479 {
480         std::ostringstream stream;
481         std::string x = filter->freeform;
482
483         /* Hax to allow spaces in the freeform without changing the design of the irc protocol */
484         for (std::string::iterator n = x.begin(); n != x.end(); n++)
485                 if (*n == ' ')
486                         *n = '\7';
487
488         stream << x << " " << filter->action << " " << (filter->flags.empty() ? "-" : filter->flags) << " " << filter->gline_time << " :" << filter->reason;
489         return stream.str();
490 }
491
492 FilterResult FilterBase::DecodeFilter(const std::string &data)
493 {
494         FilterResult res;
495         irc::tokenstream tokens(data);
496         tokens.GetToken(res.freeform);
497         tokens.GetToken(res.action);
498         tokens.GetToken(res.flags);
499         if (res.flags == "-")
500                 res.flags = "";
501         res.FillFlags(res.flags);
502         tokens.GetToken(res.gline_time);
503         tokens.GetToken(res.reason);
504
505         /* Hax to allow spaces in the freeform without changing the design of the irc protocol */
506         for (std::string::iterator n = res.freeform.begin(); n != res.freeform.end(); n++)
507                 if (*n == '\7')
508                         *n = ' ';
509
510         return res;
511 }
512
513 void FilterBase::OnSyncNetwork(Module* proto, void* opaque)
514 {
515         this->SyncFilters(proto, opaque);
516 }
517
518 void FilterBase::SendFilter(Module* proto, void* opaque, FilterResult* iter)
519 {
520         proto->ProtoSendMetaData(opaque, NULL, "filter", EncodeFilter(iter));
521 }
522
523 void FilterBase::OnDecodeMetaData(Extensible* target, const std::string &extname, const std::string &extdata)
524 {
525         if ((target == NULL) && (extname == "filter"))
526         {
527                 FilterResult data = DecodeFilter(extdata);
528                 this->AddFilter(data.freeform, data.action, data.reason, data.gline_time, data.flags);
529         }
530 }
531
532 class ImplFilter : public FilterResult
533 {
534  public:
535         Regex* regex;
536
537         ImplFilter(Module* mymodule, const std::string &rea, const std::string &act, long glinetime, const std::string &pat, const std::string &flgs)
538                 : FilterResult(pat, rea, act, glinetime, flgs)
539         {
540                 if (!rxengine)
541                         throw ModuleException("Regex module implementing '"+RegexEngine+"' is not loaded!");
542
543                 regex = RegexFactoryRequest(mymodule, rxengine, pat).Create();
544         }
545
546         ImplFilter()
547         {
548         }
549 };
550
551 class ModuleFilter : public FilterBase
552 {
553         std::vector<ImplFilter> filters;
554         const char *error;
555         int erroffset;
556         ImplFilter fr;
557
558  public:
559         ModuleFilter(InspIRCd* Me)
560         : FilterBase(Me, "m_filter.so")
561         {
562                 OnRehash(NULL);
563         }
564
565         virtual ~ModuleFilter()
566         {
567         }
568
569         virtual FilterResult* FilterMatch(User* user, const std::string &text, int flgs)
570         {
571                 for (std::vector<ImplFilter>::iterator index = filters.begin(); index != filters.end(); index++)
572                 {
573                         /* Skip ones that dont apply to us */
574                         if (!FilterBase::AppliesToMe(user, dynamic_cast<FilterResult*>(&(*index)), flgs))
575                                 continue;
576
577                         //ServerInstance->Logs->Log("m_filter", DEBUG, "Match '%s' against '%s'", text.c_str(), index->freeform.c_str());
578                         if (index->regex->Matches(text))
579                         {
580                                 //ServerInstance->Logs->Log("m_filter", DEBUG, "MATCH");
581                                 fr = *index;
582                                 if (index != filters.begin())
583                                 {
584                                         /* Move to head of list for efficiency */
585                                         filters.erase(index);
586                                         filters.insert(filters.begin(), fr);
587                                 }
588                                 return &fr;
589                         }
590                         //ServerInstance->Logs->Log("m_filter", DEBUG, "NO MATCH");
591                 }
592                 return NULL;
593         }
594
595         virtual bool DeleteFilter(const std::string &freeform)
596         {
597                 for (std::vector<ImplFilter>::iterator i = filters.begin(); i != filters.end(); i++)
598                 {
599                         if (i->freeform == freeform)
600                         {
601                                 delete i->regex;
602                                 filters.erase(i);
603                                 return true;
604                         }
605                 }
606                 return false;
607         }
608
609         virtual void SyncFilters(Module* proto, void* opaque)
610         {
611                 for (std::vector<ImplFilter>::iterator i = filters.begin(); i != filters.end(); i++)
612                 {
613                         this->SendFilter(proto, opaque, &(*i));
614                 }
615         }
616
617         virtual std::pair<bool, std::string> AddFilter(const std::string &freeform, const std::string &type, const std::string &reason, long duration, const std::string &flgs)
618         {
619                 for (std::vector<ImplFilter>::iterator i = filters.begin(); i != filters.end(); i++)
620                 {
621                         if (i->freeform == freeform)
622                         {
623                                 return std::make_pair(false, "Filter already exists");
624                         }
625                 }
626
627                 try
628                 {
629                         filters.push_back(ImplFilter(this, reason, type, duration, freeform, flgs));
630                 }
631                 catch (ModuleException &e)
632                 {
633                         ServerInstance->Logs->Log("m_filter", DEFAULT, "Error in regular expression '%s': %s", freeform.c_str(), e.GetReason());
634                         return std::make_pair(false, e.GetReason());
635                 }
636                 return std::make_pair(true, "");
637         }
638
639         virtual void OnRehash(User* user)
640         {
641                 ConfigReader MyConf(ServerInstance);
642                 FilterBase::OnRehash(user);
643                 ReadFilters(MyConf);
644         }
645
646         void ReadFilters(ConfigReader &MyConf)
647         {
648                 for (int index = 0; index < MyConf.Enumerate("keyword"); index++)
649                 {
650                         this->DeleteFilter(MyConf.ReadValue("keyword", "pattern", index));
651
652                         std::string pattern = MyConf.ReadValue("keyword", "pattern", index);
653                         std::string reason = MyConf.ReadValue("keyword", "reason", index);
654                         std::string action = MyConf.ReadValue("keyword", "action", index);
655                         std::string flgs = MyConf.ReadValue("keyword", "flags", index);
656                         long gline_time = ServerInstance->Duration(MyConf.ReadValue("keyword", "duration", index));
657                         if (action.empty())
658                                 action = "none";
659                         if (flgs.empty())
660                                 flgs = "*";
661
662                         try
663                         {
664                                 filters.push_back(ImplFilter(this, reason, action, gline_time, pattern, flgs));
665                                 ServerInstance->Logs->Log("m_filter", DEFAULT, "Regular expression %s loaded.", pattern.c_str());
666                         }
667                         catch (ModuleException &e)
668                         {
669                                 ServerInstance->Logs->Log("m_filter", DEFAULT, "Error in regular expression '%s': %s", pattern.c_str(), e.GetReason());
670                         }
671                 }
672         }
673
674         virtual int OnStats(char symbol, User* user, string_list &results)
675         {
676                 if (symbol == 's')
677                 {
678                         std::string sn = ServerInstance->Config->ServerName;
679                         for (std::vector<ImplFilter>::iterator i = filters.begin(); i != filters.end(); i++)
680                         {
681                                 results.push_back(sn+" 223 "+user->nick+" :"+RegexEngine+":"+i->freeform+" "+i->flags+" "+i->action+" "+ConvToStr(i->gline_time)+" :"+i->reason);
682                         }
683                         for (std::vector<std::string>::iterator i = exemptfromfilter.begin(); i != exemptfromfilter.end(); ++i)
684                         {
685                                 results.push_back(sn+" 223 "+user->nick+" :EXEMPT "+(*i));
686                         }
687                 }
688                 return 0;
689         }
690 };
691
692 MODULE_INIT(ModuleFilter)