mirror of
https://github.com/znc/znc.git
synced 2026-05-04 04:22:37 +02:00
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
This commit is contained in:
@@ -16,6 +16,24 @@
|
|||||||
|
|
||||||
// Sessions are valid for a day, (24h, ...)
|
// Sessions are valid for a day, (24h, ...)
|
||||||
CWebSessionMap CWebSock::m_mspSessions(24 * 60 * 60 * 1000);
|
CWebSessionMap CWebSock::m_mspSessions(24 * 60 * 60 * 1000);
|
||||||
|
static std::multimap<CString, CWebSession*> mIPSessions;
|
||||||
|
typedef std::multimap<CString, CWebSession*>::iterator mIPSessionsIterator;
|
||||||
|
|
||||||
|
CWebSession::~CWebSession() {
|
||||||
|
// Find our entry in mIPSessions
|
||||||
|
pair<mIPSessionsIterator, mIPSessionsIterator> 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) {
|
CZNCTagHandler::CZNCTagHandler(CWebSock& WebSock) : CTemplateTagHandler(), m_WebSock(WebSock) {
|
||||||
}
|
}
|
||||||
@@ -30,8 +48,9 @@ bool CZNCTagHandler::HandleTag(CTemplate& Tmpl, const CString& sName, const CStr
|
|||||||
return false;
|
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;
|
m_pUser = NULL;
|
||||||
|
mIPSessions.insert(make_pair(sIP, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWebSession::IsAdmin() const { return IsLoggedIn() && m_pUser->IsAdmin(); }
|
bool CWebSession::IsAdmin() const { return IsLoggedIn() && m_pUser->IsAdmin(); }
|
||||||
@@ -676,7 +695,7 @@ CSmartPtr<CWebSession> CWebSock::GetSession() {
|
|||||||
DEBUG("Auto generated session: [" + sSessionID + "]");
|
DEBUG("Auto generated session: [" + sSessionID + "]");
|
||||||
} while (m_mspSessions.HasItem(sSessionID));
|
} while (m_mspSessions.HasItem(sSessionID));
|
||||||
|
|
||||||
CSmartPtr<CWebSession> spSession(new CWebSession(sSessionID));
|
CSmartPtr<CWebSession> spSession(new CWebSession(sSessionID, GetRemoteIP()));
|
||||||
m_mspSessions.AddItem(spSession->GetId(), spSession);
|
m_mspSessions.AddItem(spSession->GetId(), spSession);
|
||||||
|
|
||||||
m_spSession = spSession;
|
m_spSession = spSession;
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ private:
|
|||||||
|
|
||||||
class CWebSession {
|
class CWebSession {
|
||||||
public:
|
public:
|
||||||
CWebSession(const CString& sId);
|
CWebSession(const CString& sId, const CString& sIP);
|
||||||
virtual ~CWebSession() {}
|
~CWebSession();
|
||||||
|
|
||||||
const CString& GetId() const { return m_sId; }
|
const CString& GetId() const { return m_sId; }
|
||||||
CUser* GetUser() const { return m_pUser; }
|
CUser* GetUser() const { return m_pUser; }
|
||||||
@@ -51,6 +51,7 @@ public:
|
|||||||
size_t AddSuccess(const CString& sMessage);
|
size_t AddSuccess(const CString& sMessage);
|
||||||
private:
|
private:
|
||||||
CString m_sId;
|
CString m_sId;
|
||||||
|
CString m_sIP;
|
||||||
CUser* m_pUser;
|
CUser* m_pUser;
|
||||||
VCString m_vsErrorMsgs;
|
VCString m_vsErrorMsgs;
|
||||||
VCString m_vsSuccessMsgs;
|
VCString m_vsSuccessMsgs;
|
||||||
|
|||||||
Reference in New Issue
Block a user