From dce2be6d7f9af7dcc0133ee7f0f42e9ef47be568 Mon Sep 17 00:00:00 2001 From: Shane Synan Date: Sun, 2 Sep 2018 23:36:23 -0500 Subject: [PATCH] common: Add "--debug-irc" to log raw IRC messages 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 | 6 ++++++ src/core/corenetwork.cpp | 15 +++++++++++++-- src/core/corenetwork.h | 3 +++ src/core/ircparser.cpp | 13 +++++++++++++ src/core/ircparser.h | 3 +++ 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/common/main.cpp b/src/common/main.cpp index 6c4b5a42..eb7a140c 100644 --- a/src/common/main.cpp +++ b/src/common/main.cpp @@ -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 diff --git a/src/core/corenetwork.cpp b/src/core/corenetwork.cpp index b30ac241..06c769c8 100644 --- a/src/core/corenetwork.cpp +++ b/src/core/corenetwork.cpp @@ -18,10 +18,11 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#include - #include "corenetwork.h" +#include +#include + #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) { diff --git a/src/core/corenetwork.h b/src/core/corenetwork.h index 6ad77b68..f2f7c4d7 100644 --- a/src/core/corenetwork.h +++ b/src/core/corenetwork.h @@ -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 diff --git a/src/core/ircparser.cpp b/src/core/ircparser.cpp index 871816dd..25d16f81 100644 --- a/src/core/ircparser.cpp +++ b/src/core/ircparser.cpp @@ -20,6 +20,8 @@ #include "ircparser.h" +#include + #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; diff --git a/src/core/ircparser.h b/src/core/ircparser.h index e5290a25..c0b17eaf 100644 --- a/src/core/ircparser.h +++ b/src/core/ircparser.h @@ -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 }; -- 2.20.1