From 3f624667515410ec2adb3aa229bed063fa8be64d Mon Sep 17 00:00:00 2001 From: psychon Date: Fri, 31 Dec 2010 15:52:54 +0000 Subject: [PATCH] WebMods: Remove some dead code Using some module as another user didn't actually work. For user modules, the following code stops you: else if (!pModule->IsGlobal() && pModule->GetUser() != GetSession()->GetUser()) { PrintErrorPage(403, "Forbidden", "You must login as " + pModule->GetUser()->GetUserName() + " in order to view this page"); For global modules this didn't work either. Once a "forced" user name was specified, OnPageRequestInternal() stopped looking at global modules: CModule* pModule = CZNC::Get().FindModule(m_sModName, m_sForceUser); if (!pModule && m_sForceUser.empty()) { [snip] if (!pModule) { return PAGE_NOTFOUND; So, whatever m_sForceUser was supposed to do, it never did that. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@2235 726aef4b-f618-498e-8847-2d620e286838 --- WebModules.cpp | 49 ++++++++++++------------------------------------- WebModules.h | 1 - 2 files changed, 12 insertions(+), 38 deletions(-) diff --git a/WebModules.cpp b/WebModules.cpp index 3141f8c9..f4ddb1b2 100644 --- a/WebModules.cpp +++ b/WebModules.cpp @@ -143,9 +143,7 @@ CWebSock::~CWebSock() { void CWebSock::ParsePath() { // The URI looks like: - // /[user:][module][/page][?arg1=val1&arg2=val2...] - - m_sForceUser.clear(); + // /[module][/page][?arg1=val1&arg2=val2...] m_sPath = GetPath().TrimLeft_n("/"); @@ -155,16 +153,11 @@ void CWebSock::ParsePath() { m_sModName = m_sPath.Token(0, false, "/"); m_sPage = m_sPath.Token(1, true, "/"); - if (m_sModName.find(":") != CString::npos) { - m_sForceUser = m_sModName.Token(0, false, ":"); - m_sModName = m_sModName.Token(1, false, ":"); - } - if (m_sPage.empty()) { m_sPage = "index"; } - DEBUG("Path [" + m_sPath + "], User [" + m_sForceUser + "], Module [" + m_sModName + "], Page [" + m_sPage + "]"); + DEBUG("Path [" + m_sPath + "], Module [" + m_sModName + "], Page [" + m_sPage + "]"); } CModule* CWebSock::ResolveModule() { @@ -176,28 +169,15 @@ CModule* CWebSock::ResolveModule() { return NULL; } - // First look for forced user-mods - if (!m_sForceUser.empty()) { - CUser* pUser = CZNC::Get().FindUser(m_sForceUser); + // This could be user level or global level, check both + pModRet = CZNC::Get().GetModules().FindModule(m_sModName); - if (pUser) { - pModRet = pUser->GetModules().FindModule(m_sModName); - } else { - DEBUG("User not found while trying to handle web request for [" + m_sPage + "]"); + if (!pModRet) { + if (!ForceLogin()) { + return NULL; } - } else { - // This could be user level or global level, check both - pModRet = CZNC::Get().GetModules().FindModule(m_sModName); - if (!pModRet) { - // It's not a loaded global module and it has no forced username so we - // have to force a login to try a module loaded by the current user - if (!ForceLogin()) { - return NULL; - } - - pModRet = GetSession()->GetUser()->GetModules().FindModule(m_sModName); - } + pModRet = GetSession()->GetUser()->GetModules().FindModule(m_sModName); } if (!pModRet) { @@ -605,17 +585,12 @@ CWebSock::EPageReqResult CWebSock::OnPageRequestInternal(const CString& sURI, CS return PrintTemplate("modlist", sPageRet); } - DEBUG("FindModule(" + m_sModName + ", " + m_sForceUser + ")"); - CModule* pModule = CZNC::Get().FindModule(m_sModName, m_sForceUser); - - if (!pModule && m_sForceUser.empty()) { - if (!ForceLogin()) { - return PAGE_DONE; - } - - pModule = CZNC::Get().FindModule(m_sModName, GetSession()->GetUser()); + if (!ForceLogin()) { + return PAGE_DONE; } + CModule* pModule = CZNC::Get().FindModule(m_sModName, GetSession()->GetUser()); + if (!pModule) { return PAGE_NOTFOUND; } else if (pModule->WebRequiresLogin() && !ForceLogin()) { diff --git a/WebModules.h b/WebModules.h index a21f1708..a8b8e7af 100644 --- a/WebModules.h +++ b/WebModules.h @@ -172,7 +172,6 @@ private: bool m_bPathsSet; CTemplate m_Template; CSmartPtr m_spAuth; - CString m_sForceUser; // Gets filled by ResolveModule() CString m_sModName; // Gets filled by ResolveModule() CString m_sPath; // Gets filled by ResolveModule() CString m_sPage; // Gets filled by ResolveModule()