From 9d1b92d927028dfd89acb5c71f671c9d7f203494 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Fri, 24 Aug 2018 13:40:15 +0100 Subject: [PATCH] Improve the snotices sent out by the filter module. - Switch to a module-specific snotice character (f). - Redo the format of the message to be easier to read and include the filter that the user matched. Closes #490. Closes #841. --- docs/conf/helpop-full.conf.example | 7 +++--- docs/conf/helpop.conf.example | 5 ++++- src/modules/m_filter.cpp | 35 ++++++++++++++++++++---------- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/docs/conf/helpop-full.conf.example b/docs/conf/helpop-full.conf.example index 840db56d5..c33b80fd7 100644 --- a/docs/conf/helpop-full.conf.example +++ b/docs/conf/helpop-full.conf.example @@ -1047,9 +1047,10 @@ Note that all /STATS use is broadcast to online IRC operators."> A Allows receipt of remote announcement messages. c Allows receipt of local connect messages. C Allows receipt of remote connect messages. - d Allows recript of local DNSBL messages. - D Allows recript of remote DNSBL messages. - f Allows receipt of flooding notices. + d Allows receipt of local DNSBL messages (requires the dnsbl module). + D Allows receipt of remote DNSBL messages (requires the dnsbl module). + f Allows receipt of local filter messages (requires the filter module). + F Allows receipt of remote filter messages (requires the filter module). g Allows receipt of globops (requires the globops module). j Allows receipt of channel creation notices (requires the chancreate module). J Allows receipt of remote channel creation notices (requires the chancreate module). diff --git a/docs/conf/helpop.conf.example b/docs/conf/helpop.conf.example index ada39c61d..89c2716a6 100644 --- a/docs/conf/helpop.conf.example +++ b/docs/conf/helpop.conf.example @@ -237,7 +237,10 @@ help channel if you have any questions."> A Allows receipt of remote announcement messages. c Allows receipt of local connect messages. C Allows receipt of remote connect messages. - f Allows receipt of flooding notices. + d Allows receipt of local DNSBL messages (requires the dnsbl module). + D Allows receipt of remote DNSBL messages (requires the dnsbl module). + f Allows receipt of local filter messages (requires the filter module). + F Allows receipt of remote filter messages (requires the filter module). g Allows receipt of globops (requires the globops module). j Allows receipt of channel creation notices (requires the chancreate module). J Allows receipt of remote channel creation notices (requires the chancreate module). diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp index 984a88559..2d0657c99 100644 --- a/src/modules/m_filter.cpp +++ b/src/modules/m_filter.cpp @@ -184,6 +184,7 @@ class ModuleFilter : public Module, public ServerEventListener, public Stats::Ev ExemptTargetSet exemptednicks; ModuleFilter(); + void init() CXX11_OVERRIDE; CullResult cull() CXX11_OVERRIDE; ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE; FilterResult* FilterMatch(User* user, const std::string &text, int flags); @@ -213,7 +214,7 @@ CmdResult CommandFilter::Handle(User* user, const Params& parameters) if (static_cast(me)->DeleteFilter(parameters[0])) { user->WriteNotice("*** Removed filter '" + parameters[0] + "'"); - ServerInstance->SNO->WriteToSnoMask(IS_LOCAL(user) ? 'a' : 'A', "FILTER: "+user->nick+" removed filter '"+parameters[0]+"'"); + ServerInstance->SNO->WriteToSnoMask(IS_LOCAL(user) ? 'f' : 'F', "FILTER: "+user->nick+" removed filter '"+parameters[0]+"'"); return CMD_SUCCESS; } else @@ -268,7 +269,7 @@ CmdResult CommandFilter::Handle(User* user, const Params& parameters) (duration ? ", duration " + parameters[3] : "") + ", flags '" + flags + "', reason: '" + parameters[reasonindex] + "'"); - ServerInstance->SNO->WriteToSnoMask(IS_LOCAL(user) ? 'a' : 'A', "FILTER: "+user->nick+" added filter '"+freeform+"', type '"+parameters[1]+"', "+(duration ? "duration "+parameters[3]+", " : "")+"flags '"+flags+"', reason: "+parameters[reasonindex]); + ServerInstance->SNO->WriteToSnoMask(IS_LOCAL(user) ? 'f' : 'F', "FILTER: "+user->nick+" added filter '"+freeform+"', type '"+parameters[1]+"', "+(duration ? "duration "+parameters[3]+", " : "")+"flags '"+flags+"', reason: "+parameters[reasonindex]); return CMD_SUCCESS; } @@ -311,6 +312,11 @@ ModuleFilter::ModuleFilter() { } +void ModuleFilter::init() +{ + ServerInstance->SNO->EnableSnomask('f', "FILTER"); +} + CullResult ModuleFilter::cull() { FreeFilters(); @@ -356,7 +362,8 @@ ModResult ModuleFilter::OnUserPreMessage(User* user, const MessageTarget& msgtar } if (f->action == FA_BLOCK) { - ServerInstance->SNO->WriteGlobalSno('a', "FILTER: "+user->nick+" had their message filtered, target was "+target+": "+f->reason); + ServerInstance->SNO->WriteGlobalSno('f', InspIRCd::Format("%s had their message to %s filtered as it matched %s (%s)", + user->nick.c_str(), target.c_str(), f->freeform.c_str(), f->reason.c_str())); if (notifyuser) { if (msgtarget.type == MessageTarget::TYPE_CHANNEL) @@ -381,13 +388,15 @@ ModResult ModuleFilter::OnUserPreMessage(User* user, const MessageTarget& msgtar } else if (f->action == FA_KILL) { - ServerInstance->SNO->WriteGlobalSno('a', "FILTER: " + user->nick + " had their message filtered and was killed, target was " + target + ": " + f->reason); + ServerInstance->SNO->WriteGlobalSno('f', InspIRCd::Format("%s was killed because their message to %s matched %s (%s)", + user->nick.c_str(), target.c_str(), f->freeform.c_str(), f->reason.c_str())); ServerInstance->Users->QuitUser(user, "Filtered: " + f->reason); } else if (f->action == FA_SHUN && (ServerInstance->XLines->GetFactory("SHUN"))) { Shun* sh = new Shun(ServerInstance->Time(), f->duration, ServerInstance->Config->ServerName.c_str(), f->reason.c_str(), user->GetIPString()); - ServerInstance->SNO->WriteGlobalSno('a', "FILTER: " + user->nick + " had their message filtered and was shunned, target was " + target + ": " + f->reason); + ServerInstance->SNO->WriteGlobalSno('f', InspIRCd::Format("%s was shunned because their message to %s matched %s (%s)", + user->nick.c_str(), target.c_str(), f->freeform.c_str(), f->reason.c_str())); if (ServerInstance->XLines->AddLine(sh, NULL)) { ServerInstance->XLines->ApplyLines(); @@ -398,7 +407,8 @@ ModResult ModuleFilter::OnUserPreMessage(User* user, const MessageTarget& msgtar else if (f->action == FA_GLINE) { GLine* gl = new GLine(ServerInstance->Time(), f->duration, ServerInstance->Config->ServerName.c_str(), f->reason.c_str(), "*", user->GetIPString()); - ServerInstance->SNO->WriteGlobalSno('a', "FILTER: " + user->nick + " had their message filtered and was G-Lined, target was " + target + ": " + f->reason); + ServerInstance->SNO->WriteGlobalSno('f', InspIRCd::Format("%s was glined because their message to %s matched %s (%s)", + user->nick.c_str(), target.c_str(), f->freeform.c_str(), f->reason.c_str())); if (ServerInstance->XLines->AddLine(gl,NULL)) { ServerInstance->XLines->ApplyLines(); @@ -472,7 +482,9 @@ ModResult ModuleFilter::OnPreCommand(std::string& command, CommandBase::Params& { /* Note: We gline *@IP so that if their host doesnt resolve the gline still applies. */ GLine* gl = new GLine(ServerInstance->Time(), f->duration, ServerInstance->Config->ServerName.c_str(), f->reason.c_str(), "*", user->GetIPString()); - ServerInstance->SNO->WriteGlobalSno('a', "FILTER: " + user->nick + " had their " + command + " message filtered and was G-Lined: " + f->reason); + ServerInstance->SNO->WriteGlobalSno('f', InspIRCd::Format("%s was glined because their %s message matched %s (%s)", + user->nick.c_str(), command.c_str(), f->freeform.c_str(), f->reason.c_str())); + if (ServerInstance->XLines->AddLine(gl,NULL)) { ServerInstance->XLines->ApplyLines(); @@ -484,7 +496,8 @@ ModResult ModuleFilter::OnPreCommand(std::string& command, CommandBase::Params& { /* Note: We shun *!*@IP so that if their host doesnt resolve the shun still applies. */ Shun* sh = new Shun(ServerInstance->Time(), f->duration, ServerInstance->Config->ServerName.c_str(), f->reason.c_str(), user->GetIPString()); - ServerInstance->SNO->WriteGlobalSno('a', "FILTER: " + user->nick + " had their " + command + " message filtered and was shunned: " + f->reason); + ServerInstance->SNO->WriteGlobalSno('f', InspIRCd::Format("%s was shunned because their %s message matched %s (%s)", + user->nick.c_str(), command.c_str(), f->freeform.c_str(), f->reason.c_str())); if (ServerInstance->XLines->AddLine(sh, NULL)) { ServerInstance->XLines->ApplyLines(); @@ -533,9 +546,9 @@ void ModuleFilter::ReadConfig(ConfigStatus& status) if (!RegexEngine) { if (newrxengine.empty()) - ServerInstance->SNO->WriteGlobalSno('a', "WARNING: No regex engine loaded - Filter functionality disabled until this is corrected."); + ServerInstance->SNO->WriteGlobalSno('f', "WARNING: No regex engine loaded - Filter functionality disabled until this is corrected."); else - ServerInstance->SNO->WriteGlobalSno('a', "WARNING: Regex engine '%s' is not loaded - Filter functionality disabled until this is corrected.", newrxengine.c_str()); + ServerInstance->SNO->WriteGlobalSno('f', "WARNING: Regex engine '%s' is not loaded - Filter functionality disabled until this is corrected.", newrxengine.c_str()); initing = false; FreeFilters(); @@ -544,7 +557,7 @@ void ModuleFilter::ReadConfig(ConfigStatus& status) if ((!initing) && (RegexEngine.operator->() != factory)) { - ServerInstance->SNO->WriteGlobalSno('a', "Dumping all filters due to regex engine change"); + ServerInstance->SNO->WriteGlobalSno('f', "Dumping all filters due to regex engine change"); FreeFilters(); } -- 2.39.5