]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add an option to the filter module to ignore self messages.
authorPeter Powell <petpow@saberuk.com>
Fri, 7 Jun 2019 19:11:40 +0000 (20:11 +0100)
committerPeter Powell <petpow@saberuk.com>
Fri, 7 Jun 2019 19:22:43 +0000 (20:22 +0100)
docs/conf/modules.conf.example
src/modules/m_filter.cpp

index ed5638932cdbf2b6ed7d054c4da0e0f0e97b6dc0..9c5c157bae44f8f82c8b194e19c02f1230940d2f 100644 (file)
 #                                                                     #
 # If notifyuser is set to no, the user will not be notified when      #
 # their message is blocked.                                           #
-#<filteropts engine="glob" notifyuser="yes">
+#                                                                     #
+# If warnonselfmsg is set to yes when a user sends a message to       #
+# themself that matches a filter the filter will be ignored and a     #
+# warning will be sent to opers instead. This stops spambots which    #
+# send their spam message to themselves first to check if it is being #
+# filtered by the server.                                             #
+#<filteropts engine="glob" notifyuser="yes" warnonselfmsg="no">
 #                                                                     #
 # Your choice of regex engine must match on all servers network-wide. #
 #                                                                     #
index c0798f7d0353452a9b8a8d89bd6fa37cfcd92386..a036052f67dca6c55718a78c26bf59c47e5f1819 100644 (file)
@@ -179,6 +179,7 @@ class ModuleFilter : public Module, public ServerEventListener, public Stats::Ev
 
        bool initing;
        bool notifyuser;
+       bool warnonselfmsg;
        RegexFactory* factory;
        void FreeFilters();
 
@@ -369,6 +370,7 @@ ModResult ModuleFilter::OnUserPreMessage(User* user, const MessageTarget& msgtar
        FilterResult* f = this->FilterMatch(user, details.text, flags);
        if (f)
        {
+               bool is_selfmsg = false;
                std::string target;
                if (msgtarget.type == MessageTarget::TYPE_USER)
                {
@@ -377,6 +379,9 @@ ModResult ModuleFilter::OnUserPreMessage(User* user, const MessageTarget& msgtar
                        if (exemptednicks.count(t->nick))
                                return MOD_RES_PASSTHRU;
 
+                       if (user == t)
+                               is_selfmsg = true;
+
                        target = t->nick;
                }
                else if (msgtarget.type == MessageTarget::TYPE_CHANNEL)
@@ -387,13 +392,20 @@ ModResult ModuleFilter::OnUserPreMessage(User* user, const MessageTarget& msgtar
 
                        target = t->name;
                }
-               if (f->action == FA_WARN)
+
+               if (is_selfmsg & warnonselfmsg)
+               {
+                       ServerInstance->SNO->WriteGlobalSno('f', InspIRCd::Format("WARNING: %s's self message matched %s (%s)",
+                               user->nick.c_str(), f->freeform.c_str(), f->reason.c_str()));
+                       return MOD_RES_PASSTHRU;
+               }
+               else if (f->action == FA_WARN)
                {
                        ServerInstance->SNO->WriteGlobalSno('f', InspIRCd::Format("WARNING: %s's message to %s matched %s (%s)",
                                user->nick.c_str(), target.c_str(), f->freeform.c_str(), f->reason.c_str()));
                        return MOD_RES_PASSTHRU;
                }
-               if (f->action == FA_BLOCK)
+               else if (f->action == FA_BLOCK)
                {
                        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()));
@@ -609,6 +621,7 @@ void ModuleFilter::ReadConfig(ConfigStatus& status)
        ConfigTag* tag = ServerInstance->Config->ConfValue("filteropts");
        std::string newrxengine = tag->getString("engine");
        notifyuser = tag->getBool("notifyuser", true);
+       warnonselfmsg = tag->getBool("warnonselfmsg");
 
        factory = RegexEngine ? (RegexEngine.operator->()) : NULL;