mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01: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, ...)
|
||||
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) {
|
||||
}
|
||||
@@ -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<CWebSession> CWebSock::GetSession() {
|
||||
DEBUG("Auto generated session: [" + 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_spSession = spSession;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user