From 577a097e3283bd978fda8210277fe20fe1dcfa24 Mon Sep 17 00:00:00 2001 From: psychon Date: Fri, 14 Jan 2011 20:22:02 +0000 Subject: [PATCH] Keep a list of web sessions per IP address git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@2261 726aef4b-f618-498e-8847-2d620e286838 --- WebModules.cpp | 23 +++++++++++++++++++++-- WebModules.h | 5 +++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/WebModules.cpp b/WebModules.cpp index c612c31d..59477e5e 100644 --- a/WebModules.cpp +++ b/WebModules.cpp @@ -16,6 +16,24 @@ // Sessions are valid for a day, (24h, ...) CWebSessionMap CWebSock::m_mspSessions(24 * 60 * 60 * 1000); +static std::multimap mIPSessions; +typedef std::multimap::iterator mIPSessionsIterator; + +CWebSession::~CWebSession() { + // Find our entry in mIPSessions + pair p = + mIPSessions.equal_range(m_sIP); + mIPSessionsIterator it = p.first; + mIPSessionsIterator end = p.second; + + while (it != end) { + if (it->second == this) { + mIPSessions.erase(it++); + } else { + ++it; + } + } +} CZNCTagHandler::CZNCTagHandler(CWebSock& WebSock) : CTemplateTagHandler(), m_WebSock(WebSock) { } @@ -30,8 +48,9 @@ bool CZNCTagHandler::HandleTag(CTemplate& Tmpl, const CString& sName, const CStr return false; } -CWebSession::CWebSession(const CString& sId) : m_sId(sId) { +CWebSession::CWebSession(const CString& sId, const CString& sIP) : m_sId(sId), m_sIP(sIP) { m_pUser = NULL; + mIPSessions.insert(make_pair(sIP, this)); } bool CWebSession::IsAdmin() const { return IsLoggedIn() && m_pUser->IsAdmin(); } @@ -676,7 +695,7 @@ CSmartPtr CWebSock::GetSession() { DEBUG("Auto generated session: [" + sSessionID + "]"); } while (m_mspSessions.HasItem(sSessionID)); - CSmartPtr spSession(new CWebSession(sSessionID)); + CSmartPtr spSession(new CWebSession(sSessionID, GetRemoteIP())); m_mspSessions.AddItem(spSession->GetId(), spSession); m_spSession = spSession; diff --git a/WebModules.h b/WebModules.h index 5c9b9c61..d0a5d506 100644 --- a/WebModules.h +++ b/WebModules.h @@ -35,8 +35,8 @@ private: class CWebSession { public: - CWebSession(const CString& sId); - virtual ~CWebSession() {} + CWebSession(const CString& sId, const CString& sIP); + ~CWebSession(); const CString& GetId() const { return m_sId; } CUser* GetUser() const { return m_pUser; } @@ -51,6 +51,7 @@ public: size_t AddSuccess(const CString& sMessage); private: CString m_sId; + CString m_sIP; CUser* m_pUser; VCString m_vsErrorMsgs; VCString m_vsSuccessMsgs;