common: Add "--debug-irc" to log raw IRC messages
authorShane Synan <digitalcircuit36939@gmail.com>
Mon, 3 Sep 2018 04:36:23 +0000 (23:36 -0500)
committerManuel Nickschas <sputnick@quassel-irc.org>
Mon, 3 Sep 2018 20:16:06 +0000 (22:16 +0200)
Add "--debug-irc" command-line option to Core and Monolithic to log
raw IRC messages to the log at Debug level.

Check for raw IRC logging in CoreNetwork and IrcParser, logging
anything sent and received with the Network ID and "<<" for received,
">>" for sent.

Add "--debug-irc-id" to limit raw logging to a specific Network ID,
handy for cores with multiple networks.  This option automatically
applies "--debug-irc".

These usually should be combined with "--loglevel Debug", though the
Monolithic build can show raw IRC messages in the "Debug Log" GUI
without setting that parameter.

CAUTION:  "--debug-irc" will leak all IRC passwords in plain text via
any configured logging receivers (file, syslog, etc) and should not
be used on production servers without taking special care to limit
access to logging output.

Note: The ideal approach is to have the core maintain the most recent
raw IRC logs on a rotating basis, allowing any client to request this
portion of logs on demand.  However, there's a lot more changes
involved, which might not be wise with the goal of stabilizing 0.13.

We should revisit this in the future.

src/common/main.cpp
src/core/corenetwork.cpp
src/core/corenetwork.h
src/core/ircparser.cpp
src/core/ircparser.h

index 6c4b5a4..eb7a140 100644 (file)
@@ -202,6 +202,12 @@ int main(int argc, char **argv)
     cliParser->addOption("ssl-cert", 0, "Specify the path to the SSL Certificate", "path", "configdir/quasselCert.pem");
     cliParser->addOption("ssl-key", 0, "Specify the path to the SSL key", "path", "ssl-cert-path");
 #endif
+    cliParser->addSwitch("debug-irc", 0,
+                         "Enable logging of all raw IRC messages to debug log, including "
+                         "passwords!  In most cases you should also set --loglevel Debug");
+    cliParser->addOption("debug-irc-id", 0,
+                         "Limit raw IRC logging to this network ID.  Implies --debug-irc",
+                         "database network ID", "-1");
     cliParser->addSwitch("enable-experimental-dcc", 0, "Enable highly experimental and unfinished support for CTCP DCC (DANGEROUS)");
 #endif
 
index b30ac24..06c769c 100644 (file)
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
  ***************************************************************************/
 
-#include <QHostInfo>
-
 #include "corenetwork.h"
 
+#include <QDebug>
+#include <QHostInfo>
+
 #include "core.h"
 #include "coreidentity.h"
 #include "corenetworkconfig.h"
@@ -46,6 +47,10 @@ CoreNetwork::CoreNetwork(const NetworkId &networkid, CoreSession *session)
 
     _requestedUserModes('-')
 {
+    // Check if raw IRC logging is enabled
+    _debugLogRawIrc = (Quassel::isOptionSet("debug-irc") || Quassel::isOptionSet("debug-irc-id"));
+    _debugLogRawNetId = Quassel::optionValue("debug-irc-id").toInt();
+
     _autoReconnectTimer.setSingleShot(true);
     connect(&_socketCloseTimer, SIGNAL(timeout()), this, SLOT(socketCloseTimeout()));
 
@@ -1460,6 +1465,12 @@ void CoreNetwork::fillBucketAndProcessQueue()
 
 void CoreNetwork::writeToSocket(const QByteArray &data)
 {
+    // Log the message if enabled and network ID matches or allows all
+    if (_debugLogRawIrc
+            && (_debugLogRawNetId == -1 || networkId().toInt() == _debugLogRawNetId)) {
+        // Include network ID
+        qDebug() << "IRC net" << networkId() << ">>" << data;
+    }
     socket.write(data);
     socket.write("\r\n");
     if (!_skipMessageRates) {
index 6ad77b6..f2f7c4d 100644 (file)
@@ -483,6 +483,9 @@ private slots:
 private:
     CoreSession *_coreSession;
 
+    bool _debugLogRawIrc;     ///< If true, include raw IRC socket messages in the debug log
+    qint32 _debugLogRawNetId; ///< Network ID for logging raw IRC socket messages, or -1 for all
+
 #ifdef HAVE_SSL
     QSslSocket socket;
 #else
index 871816d..25d16f8 100644 (file)
@@ -20,6 +20,8 @@
 
 #include "ircparser.h"
 
+#include <QDebug>
+
 #include "corenetwork.h"
 #include "eventmanager.h"
 #include "ircevent.h"
@@ -35,6 +37,10 @@ IrcParser::IrcParser(CoreSession *session) :
     QObject(session),
     _coreSession(session)
 {
+    // Check if raw IRC logging is enabled
+    _debugLogRawIrc = (Quassel::isOptionSet("debug-irc") || Quassel::isOptionSet("debug-irc-id"));
+    _debugLogRawNetId = Quassel::optionValue("debug-irc-id").toInt();
+
     connect(this, SIGNAL(newEvent(Event *)), coreSession()->eventManager(), SLOT(postEvent(Event *)));
 }
 
@@ -91,6 +97,13 @@ void IrcParser::processNetworkIncoming(NetworkDataEvent *e)
         return;
     }
 
+    // Log the message if enabled and network ID matches or allows all
+    if (_debugLogRawIrc
+            && (_debugLogRawNetId == -1 || net->networkId().toInt() == _debugLogRawNetId)) {
+        // Include network ID
+        qDebug() << "IRC net" << net->networkId() << "<<" << msg;
+    }
+
     // Now we split the raw message into its various parts...
     QString prefix;
     QByteArray trailing;
index e5290a2..c0b17ea 100644 (file)
@@ -51,6 +51,9 @@ protected:
 
 private:
     CoreSession *_coreSession;
+
+    bool _debugLogRawIrc;     ///< If true, include raw IRC socket messages in the debug log
+    qint32 _debugLogRawNetId; ///< Network ID for logging raw IRC socket messages, or -1 for all
 };