]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Fix various issues with the cgiirc module.
authorPeter Powell <petpow@saberuk.com>
Wed, 27 Dec 2017 13:06:12 +0000 (13:06 +0000)
committerPeter Powell <petpow@saberuk.com>
Wed, 27 Dec 2017 13:15:43 +0000 (13:15 +0000)
- Respect the value of <cgiirc:opernotice> when sending snotices
  to operators.
- Write to the log file if opernotice is disabled.
- Log to the correct snomask in all cases. This was caused by an
  oversight when merging insp20 into master.
- Replace the full user mask in log messages with a uuid/ip. The
  WEBIRC command is sent as the first command so there will not be
  a nickname or username at this point.

src/modules/m_cgiirc.cpp

index 4c57c6fdff4260b3ee4e7913a54125b82a12b39f..984c3da04fc39f84c355296039059c4de98af272 100644 (file)
 
 
 #include "inspircd.h"
-#include "modules/dns.h"
 #include "modules/ssl.h"
 
 enum
 {
+       // InspIRCd-specific.
        RPL_WHOISGATEWAY = 350
 };
 
@@ -118,7 +118,8 @@ class CommandWebIRC : public SplitCommand
                if (!irc::sockets::aptosa(parameters[3], 0, ipaddr))
                {
                        user->CommandFloodPenalty += 5000;
-                       ServerInstance->SNO->WriteGlobalSno('a', "Connecting user %s tried to use WEBIRC but gave an invalid IP address.", user->GetFullRealHost().c_str());
+                       WriteLog("Connecting user %s (%s) tried to use WEBIRC but gave an invalid IP address.",
+                               user->uuid.c_str(), user->GetIPString().c_str());
                        return CMD_FAILURE;
                }
 
@@ -133,9 +134,8 @@ class CommandWebIRC : public SplitCommand
                        realhost.set(user, user->GetRealHost());
                        realip.set(user, user->GetIPString());
 
-                       if (notify)
-                               ServerInstance->SNO->WriteGlobalSno('w', "Connecting user %s is using a WebIRC gateway; changing their IP from %s to %s.",
-                                       user->nick.c_str(), user->GetIPString().c_str(), parameters[3].c_str());
+                       WriteLog("Connecting user %s is using a WebIRC gateway; changing their IP from %s to %s.",
+                               user->uuid.c_str(), user->GetIPString().c_str(), parameters[3].c_str());
 
                        // Set the IP address sent via WEBIRC. We ignore the hostname and lookup
                        // instead do our own DNS lookups because of unreliable gateways.
@@ -144,9 +144,23 @@ class CommandWebIRC : public SplitCommand
                }
 
                user->CommandFloodPenalty += 5000;
-               ServerInstance->SNO->WriteGlobalSno('w', "Connecting user %s tried to use WEBIRC but didn't match any configured WebIRC hosts.", user->GetFullRealHost().c_str());
+               WriteLog("Connecting user %s (%s) tried to use WEBIRC but didn't match any configured WebIRC hosts.",
+                       user->uuid.c_str(), user->GetIPString().c_str());
                return CMD_FAILURE;
        }
+
+       void WriteLog(const char* message, ...) CUSTOM_PRINTF(2, 3)
+       {
+               std::string buffer;
+               VAFORMAT(buffer, message, message);
+
+               // If we are sending a snotice then the message will already be
+               // written to the logfile.
+               if (notify)
+                       ServerInstance->SNO->WriteGlobalSno('w', buffer);
+               else
+                       ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, buffer);
+       }
 };
 
 class ModuleCgiIRC : public Module, public Whois::EventListener
@@ -166,10 +180,8 @@ class ModuleCgiIRC : public Module, public Whois::EventListener
                cmd.realhost.set(user, user->GetRealHost());
                cmd.realip.set(user, user->GetIPString());
 
-               if (cmd.notify)
-                       ServerInstance->SNO->WriteGlobalSno('w', "Connecting user %s is using an ident gateway; changing their IP from %s to %s.",
-                               user->nick.c_str(), user->GetIPString().c_str(), newip.c_str());
-
+               cmd.WriteLog("Connecting user %s is using an ident gateway; changing their IP from %s to %s.",
+                       user->uuid.c_str(), user->GetIPString().c_str(), newip.c_str());
                ChangeIP(user, newip);
                RecheckClass(user);
        }