X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_filter.cpp;h=f49694e81744fc47e7636e9541504733f92c7d58;hb=7d84771f49973d7091789a8b5f0f6295d288a673;hp=584bfef002fc259afdb57ba019f9fed1283cf6ff;hpb=705853459e7170316fde62f25e40398b35bd4870;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp index 584bfef00..f49694e81 100644 --- a/src/modules/m_filter.cpp +++ b/src/modules/m_filter.cpp @@ -54,7 +54,7 @@ class FilterResult std::string freeform; std::string reason; FilterAction action; - long duration; + unsigned long duration; bool from_config; bool flag_no_opers; @@ -64,7 +64,7 @@ class FilterResult bool flag_notice; bool flag_strip_color; - FilterResult(dynamic_reference& RegexEngine, const std::string& free, const std::string& rea, FilterAction act, long gt, const std::string& fla, bool cfg) + FilterResult(dynamic_reference& RegexEngine, const std::string& free, const std::string& rea, FilterAction act, unsigned long gt, const std::string& fla, bool cfg) : freeform(free) , reason(rea) , action(act) @@ -155,7 +155,7 @@ class CommandFilter : public Command : Command(f, "FILTER", 1, 5) { flags_needed = 'o'; - this->syntax = " [] :"; + this->syntax = " [ [] :]"; } CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE; @@ -192,8 +192,8 @@ class ModuleFilter : public Module, public ServerEventListener, public Stats::Ev 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); - bool DeleteFilter(const std::string &freeform); - std::pair AddFilter(const std::string &freeform, FilterAction type, const std::string &reason, long duration, const std::string &flags); + bool DeleteFilter(const std::string& freeform, std::string& reason); + std::pair AddFilter(const std::string& freeform, FilterAction type, const std::string& reason, unsigned long duration, const std::string& flags); void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE; Version GetVersion() CXX11_OVERRIDE; std::string EncodeFilter(FilterResult* filter); @@ -214,11 +214,14 @@ CmdResult CommandFilter::Handle(User* user, const Params& parameters) if (parameters.size() == 1) { /* Deleting a filter */ - Module *me = creator; - if (static_cast(me)->DeleteFilter(parameters[0])) + Module* me = creator; + std::string reason; + + if (static_cast(me)->DeleteFilter(parameters[0], reason)) { - user->WriteNotice("*** Removed filter '" + parameters[0] + "'"); - ServerInstance->SNO->WriteToSnoMask(IS_LOCAL(user) ? 'f' : 'F', "FILTER: "+user->nick+" removed filter '"+parameters[0]+"'"); + user->WriteNotice("*** Removed filter '" + parameters[0] + "': " + reason); + ServerInstance->SNO->WriteToSnoMask(IS_LOCAL(user) ? 'f' : 'F', "%s removed filter '%s': %s", + user->nick.c_str(), parameters[0].c_str(), reason.c_str()); return CMD_SUCCESS; } else @@ -236,7 +239,7 @@ CmdResult CommandFilter::Handle(User* user, const Params& parameters) FilterAction type; const std::string& flags = parameters[2]; unsigned int reasonindex; - long duration = 0; + unsigned long duration = 0; if (!ModuleFilter::StringToFilterAction(parameters[1], type)) { @@ -251,7 +254,11 @@ CmdResult CommandFilter::Handle(User* user, const Params& parameters) { if (parameters.size() >= 5) { - duration = InspIRCd::Duration(parameters[3]); + if (!InspIRCd::Duration(parameters[3], duration)) + { + user->WriteNotice("*** Invalid duration for filter"); + return CMD_FAILURE; + } reasonindex = 4; } else @@ -265,15 +272,19 @@ CmdResult CommandFilter::Handle(User* user, const Params& parameters) reasonindex = 3; } - Module *me = creator; - std::pair result = static_cast(me)->AddFilter(freeform, type, parameters[reasonindex], duration, flags); + Module* me = creator; + std::pair result = static_cast(me)->AddFilter(freeform, type, parameters[reasonindex], duration, flags); if (result.first) { - user->WriteNotice("*** Added filter '" + freeform + "', type '" + parameters[1] + "'" + - (duration ? ", duration " + parameters[3] : "") + ", flags '" + flags + "', reason: '" + - parameters[reasonindex] + "'"); + const std::string message = InspIRCd::Format("'%s', type '%s'%s, flags '%s', reason: %s", + freeform.c_str(), parameters[1].c_str(), + (duration ? InspIRCd::Format(", duration '%s'", + InspIRCd::DurationString(duration).c_str()).c_str() + : ""), flags.c_str(), parameters[reasonindex].c_str()); - 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]); + user->WriteNotice("*** Added filter " + message); + ServerInstance->SNO->WriteToSnoMask(IS_LOCAL(user) ? 'f' : 'F', + "%s added filter %s", user->nick.c_str(), message.c_str()); return CMD_SUCCESS; } @@ -405,8 +416,10 @@ ModResult ModuleFilter::OnUserPreMessage(User* user, const MessageTarget& msgtar 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('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())); + ServerInstance->SNO->WriteGlobalSno('f', InspIRCd::Format("%s (%s) was shunned for %s (expires on %s) because their message to %s matched %s (%s)", + user->nick.c_str(), sh->Displayable().c_str(), InspIRCd::DurationString(f->duration).c_str(), + InspIRCd::TimeString(ServerInstance->Time() + f->duration).c_str(), + target.c_str(), f->freeform.c_str(), f->reason.c_str())); if (ServerInstance->XLines->AddLine(sh, NULL)) { ServerInstance->XLines->ApplyLines(); @@ -417,8 +430,10 @@ 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('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())); + ServerInstance->SNO->WriteGlobalSno('f', InspIRCd::Format("%s (%s) was G-lined for %s (expires on %s) because their message to %s matched %s (%s)", + user->nick.c_str(), gl->Displayable().c_str(), InspIRCd::DurationString(f->duration).c_str(), + InspIRCd::TimeString(ServerInstance->Time() + f->duration).c_str(), + target.c_str(), f->freeform.c_str(), f->reason.c_str())); if (ServerInstance->XLines->AddLine(gl,NULL)) { ServerInstance->XLines->ApplyLines(); @@ -429,8 +444,10 @@ ModResult ModuleFilter::OnUserPreMessage(User* user, const MessageTarget& msgtar else if (f->action == FA_ZLINE) { ZLine* zl = new ZLine(ServerInstance->Time(), f->duration, ServerInstance->Config->ServerName.c_str(), f->reason.c_str(), user->GetIPString()); - ServerInstance->SNO->WriteGlobalSno('f', InspIRCd::Format("%s was zlined because their message to %s matched %s (%s)", - user->nick.c_str(), target.c_str(), f->freeform.c_str(), f->reason.c_str())); + ServerInstance->SNO->WriteGlobalSno('f', InspIRCd::Format("%s (%s) was Z-lined for %s (expires on %s) because their message to %s matched %s (%s)", + user->nick.c_str(), zl->Displayable().c_str(), InspIRCd::DurationString(f->duration).c_str(), + InspIRCd::TimeString(ServerInstance->Time() + f->duration).c_str(), + target.c_str(), f->freeform.c_str(), f->reason.c_str())); if (ServerInstance->XLines->AddLine(zl,NULL)) { ServerInstance->XLines->ApplyLines(); @@ -502,10 +519,13 @@ ModResult ModuleFilter::OnPreCommand(std::string& command, CommandBase::Params& } if (f->action == FA_GLINE) { - /* Note: We gline *@IP so that if their host doesnt resolve the gline still applies. */ + /* Note: We G-line *@IP so that if their host doesn't resolve the G-line still applies. */ GLine* gl = new GLine(ServerInstance->Time(), f->duration, ServerInstance->Config->ServerName.c_str(), f->reason.c_str(), "*", user->GetIPString()); - 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())); + ServerInstance->SNO->WriteGlobalSno('f', InspIRCd::Format("%s (%s) was G-lined for %s (expires on %s) because their %s message matched %s (%s)", + user->nick.c_str(), gl->Displayable().c_str(), + InspIRCd::DurationString(f->duration).c_str(), + InspIRCd::TimeString(ServerInstance->Time() + f->duration).c_str(), + command.c_str(), f->freeform.c_str(), f->reason.c_str())); if (ServerInstance->XLines->AddLine(gl,NULL)) { @@ -517,8 +537,11 @@ ModResult ModuleFilter::OnPreCommand(std::string& command, CommandBase::Params& if (f->action == FA_ZLINE) { ZLine* zl = new ZLine(ServerInstance->Time(), f->duration, ServerInstance->Config->ServerName.c_str(), f->reason.c_str(), user->GetIPString()); - ServerInstance->SNO->WriteGlobalSno('f', InspIRCd::Format("%s was zlined because their %s message matched %s (%s)", - user->nick.c_str(), command.c_str(), f->freeform.c_str(), f->reason.c_str())); + ServerInstance->SNO->WriteGlobalSno('f', InspIRCd::Format("%s (%s) was Z-lined for %s (expires on %s) because their %s message matched %s (%s)", + user->nick.c_str(), zl->Displayable().c_str(), + InspIRCd::DurationString(f->duration).c_str(), + InspIRCd::TimeString(ServerInstance->Time() + f->duration).c_str(), + command.c_str(), f->freeform.c_str(), f->reason.c_str())); if (ServerInstance->XLines->AddLine(zl,NULL)) { @@ -531,8 +554,12 @@ 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('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())); + ServerInstance->SNO->WriteGlobalSno('f', InspIRCd::Format("%s (%s) was shunned for %s (expires on %s) because their %s message matched %s (%s)", + user->nick.c_str(), sh->Displayable().c_str(), + InspIRCd::DurationString(f->duration).c_str(), + InspIRCd::TimeString(ServerInstance->Time() + f->duration).c_str(), + command.c_str(), f->freeform.c_str(), f->reason.c_str())); + if (ServerInstance->XLines->AddLine(sh, NULL)) { ServerInstance->XLines->ApplyLines(); @@ -637,7 +664,7 @@ FilterResult ModuleFilter::DecodeFilter(const std::string &data) std::string duration; tokens.GetMiddle(duration); - res.duration = ConvToInt(duration); + res.duration = ConvToNum(duration); tokens.GetTrailing(res.reason); @@ -702,12 +729,13 @@ FilterResult* ModuleFilter::FilterMatch(User* user, const std::string &text, int return NULL; } -bool ModuleFilter::DeleteFilter(const std::string &freeform) +bool ModuleFilter::DeleteFilter(const std::string& freeform, std::string& reason) { for (std::vector::iterator i = filters.begin(); i != filters.end(); i++) { if (i->freeform == freeform) { + reason.assign(i->reason); delete i->regex; filters.erase(i); return true; @@ -716,7 +744,7 @@ bool ModuleFilter::DeleteFilter(const std::string &freeform) return false; } -std::pair ModuleFilter::AddFilter(const std::string &freeform, FilterAction type, const std::string &reason, long duration, const std::string &flgs) +std::pair ModuleFilter::AddFilter(const std::string& freeform, FilterAction type, const std::string& reason, unsigned long duration, const std::string& flgs) { for (std::vector::iterator i = filters.begin(); i != filters.end(); i++) { @@ -783,7 +811,7 @@ void ModuleFilter::ReadFilters() { if (filter->from_config) { - ServerInstance->SNO->WriteGlobalSno('f', "FILTER: removing filter '" + filter->freeform + "' due to config rehash."); + ServerInstance->SNO->WriteGlobalSno('f', "Removing filter '" + filter->freeform + "' due to config rehash."); delete filter->regex; filter = filters.erase(filter); continue;