mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
Limit the number of web sessions per IP to 5
git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@2263 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
@@ -19,6 +19,8 @@ CWebSessionMap CWebSock::m_mspSessions(24 * 60 * 60 * 1000);
|
||||
static std::multimap<CString, CWebSession*> mIPSessions;
|
||||
typedef std::multimap<CString, CWebSession*>::iterator mIPSessionsIterator;
|
||||
|
||||
const unsigned int CWebSock::m_uiMaxSessions = 5;
|
||||
|
||||
CWebSession::~CWebSession() {
|
||||
// Find our entry in mIPSessions
|
||||
pair<mIPSessionsIterator, mIPSessionsIterator> p =
|
||||
@@ -689,6 +691,11 @@ CSmartPtr<CWebSession> CWebSock::GetSession() {
|
||||
return *pSession;
|
||||
}
|
||||
|
||||
if (mIPSessions.count(GetRemoteIP()) > m_uiMaxSessions) {
|
||||
mIPSessionsIterator it = mIPSessions.find(GetRemoteIP());
|
||||
mIPSessions.erase(it);
|
||||
}
|
||||
|
||||
CString sSessionID;
|
||||
do {
|
||||
sSessionID = CString::RandomString(32);
|
||||
|
||||
@@ -172,6 +172,7 @@ private:
|
||||
CSmartPtr<CWebSession> m_spSession;
|
||||
|
||||
static CWebSessionMap m_mspSessions;
|
||||
static const unsigned int m_uiMaxSessions;
|
||||
};
|
||||
|
||||
#endif // !_WEBMODULES_H
|
||||
|
||||
Reference in New Issue
Block a user