From b764aa7b425da080645fd5bb236438f8d1ae6406 Mon Sep 17 00:00:00 2001 From: psychon Date: Mon, 15 Mar 2010 16:06:56 +0000 Subject: [PATCH] Fix WebModules with auth modules When e.g. imapauth started handling a login from WebMods it opened a new TCP connection etc. This took time, but WebMods didn't actually wait for the login to finish which caused the login to fail later on since the HTTP socket was already destroyed. This fixes it by letting the HTTP sock just hang. Once the login finishes, CHTTPSock::Redirect() is called to let it come back to life again. Thanks to DarthGandalf for finding this issue. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1834 726aef4b-f618-498e-8847-2d620e286838 --- WebModules.cpp | 9 +++++++-- WebModules.h | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/WebModules.cpp b/WebModules.cpp index b7dc2d8a..206e71a7 100644 --- a/WebModules.cpp +++ b/WebModules.cpp @@ -87,6 +87,7 @@ void CWebAuth::AcceptedLogin(CUser& User) { m_pWebSock->SetLoggedIn(true); m_pWebSock->UnPauseRead(); + m_pWebSock->Redirect("/"); DEBUG("Successful login attempt ==> USER [" + User.GetUserName() + "] ==> SESSION [" + spSession->GetId() + "]"); } @@ -102,6 +103,7 @@ void CWebAuth::RefusedLogin(const CString& sReason) { m_pWebSock->SetLoggedIn(false); m_pWebSock->UnPauseRead(); + m_pWebSock->Redirect("/"); DEBUG("UNSUCCESSFUL login attempt ==> REASON [" + sReason + "] ==> SESSION [" + spSession->GetId() + "]"); } @@ -508,6 +510,9 @@ void CWebSock::OnPageRequest(const CString& sURI) { case PAGE_PRINT: PrintPage(sPageRet); break; + case PAGE_DEFERRED: + // Something else will later do these calls + break; default: PrintNotFound(); break; @@ -541,8 +546,8 @@ CWebSock::EPageReqResult CWebSock::OnPageRequestInternal(const CString& sURI, CS m_sPass = GetParam("pass"); m_bLoggedIn = OnLogin(m_sUser, m_sPass); - Redirect("/"); - return PAGE_PRINT; + // AcceptedLogin()/RefusedLogin() will call Redirect() + return PAGE_DEFERRED; } return PrintTemplate("login", sPageRet); diff --git a/WebModules.h b/WebModules.h index 06ba7d9f..35b80d41 100644 --- a/WebModules.h +++ b/WebModules.h @@ -114,7 +114,8 @@ class CWebSock : public CHTTPSock { public: enum EPageReqResult { PAGE_NOTFOUND, - PAGE_PRINT + PAGE_PRINT, + PAGE_DEFERRED }; CWebSock(CModule* pModule);