debugging: Add Filter method to hide filter sensitive data

This commit is contained in:
Jos Ahrens
2017-10-02 13:38:29 +02:00
parent 448f020a7a
commit f006e31fed
4 changed files with 30 additions and 8 deletions
+2
View File
@@ -47,6 +47,8 @@ class CDebug {
static void SetDebug(bool b) { debug = b; }
static bool Debug() { return debug; }
static CString Filter(const CString& sUnfilteredLine);
protected:
static bool stdoutIsTTY;
static bool debug;
+5 -2
View File
@@ -20,6 +20,7 @@
#include <znc/User.h>
#include <znc/IRCNetwork.h>
#include <znc/Query.h>
#include <znc/ZNCDebug.h>
using std::set;
using std::map;
@@ -105,7 +106,8 @@ void CClient::ReadLine(const CString& sData) {
sLine.TrimRight("\n\r");
DEBUG("(" << GetFullName() << ") CLI -> ZNC [" << sLine << "]");
DEBUG("(" << GetFullName() << ") CLI -> ZNC ["
<< CDebug::Filter(sLine) << "]");
MCString mssTags;
if (sLine.StartsWith("@")) {
@@ -586,7 +588,8 @@ bool CClient::PutClient(const CMessage& Message) {
&bReturn);
if (bReturn) return false;
DEBUG("(" << GetFullName() << ") ZNC -> CLI [" << sCopy << "]");
DEBUG("(" << GetFullName() << ") ZNC -> CLI ["
<< CDebug::Filter(sCopy) << "]");
Write(sCopy + "\r\n");
return true;
}
+7 -6
View File
@@ -20,6 +20,7 @@
#include <znc/IRCNetwork.h>
#include <znc/Server.h>
#include <znc/Query.h>
#include <znc/ZNCDebug.h>
#include <time.h>
using std::set;
@@ -1128,8 +1129,8 @@ void CIRCSock::PutIRC(const CString& sLine) {
// TrySend()!)
if (m_bFloodProtection && m_iSendsAllowed <= 0) {
DEBUG("(" << m_pNetwork->GetUser()->GetUserName() << "/"
<< m_pNetwork->GetName() << ") ZNC -> IRC [" << sLine
<< "] (queued)");
<< m_pNetwork->GetName() << ") ZNC -> IRC ["
<< CDebug::Filter(sLine) << "] (queued)");
}
m_vsSendQueue.push_back(sLine);
TrySend();
@@ -1140,8 +1141,8 @@ void CIRCSock::PutIRCQuick(const CString& sLine) {
// TrySend()!)
if (m_bFloodProtection && m_iSendsAllowed <= 0) {
DEBUG("(" << m_pNetwork->GetUser()->GetUserName() << "/"
<< m_pNetwork->GetName() << ") ZNC -> IRC [" << sLine
<< "] (queued to front)");
<< m_pNetwork->GetName() << ") ZNC -> IRC ["
<< CDebug::Filter(sLine) << "] (queued to front)");
}
m_vsSendQueue.push_front(sLine);
TrySend();
@@ -1164,8 +1165,8 @@ void CIRCSock::TrySend() {
IRCSOCKMODULECALL(OnSendToIRC(sCopy), &bSkip);
if (!bSkip) {
DEBUG("(" << m_pNetwork->GetUser()->GetUserName() << "/"
<< m_pNetwork->GetName() << ") ZNC -> IRC [" << sCopy
<< "]");
<< m_pNetwork->GetName() << ") ZNC -> IRC ["
<< CDebug::Filter(sCopy) << "]");
Write(sCopy + "\r\n");
}
}
+16
View File
@@ -29,6 +29,22 @@ bool CDebug::debug =
false;
#endif
CString CDebug::Filter(const CString& sUnfilteredLine) {
CString sFilteredLine = sUnfilteredLine;
// If the line is a PASS command to authenticate to a server / znc
if (sUnfilteredLine.StartsWith("PASS ")) {
VCString vsSafeCopy;
sUnfilteredLine.Split(":", vsSafeCopy);
if (vsSafeCopy.size() > 1) {
sFilteredLine = vsSafeCopy[0] + ":<censored>";
}
}
return sFilteredLine;
}
CDebugStream::~CDebugStream() {
timeval tTime = CUtils::GetTime();
time_t tSec = (time_t)tTime.tv_sec; // some systems (e.g. openbsd) define