diff --git a/include/znc/WebModules.h b/include/znc/WebModules.h index 79df2492..e94721e2 100644 --- a/include/znc/WebModules.h +++ b/include/znc/WebModules.h @@ -113,8 +113,6 @@ public: virtual bool OnLogin(const CString& sUser, const CString& sPass); virtual void OnPageRequest(const CString& sURI); - void ParsePath(); // This parses the path portion of the url into some member vars - EPageReqResult PrintTemplate(const CString& sPageName, CString& sPageRet, CModule* pModule = NULL); EPageReqResult PrintStaticFile(const CString& sPath, CString& sPageRet, CModule* pModule = NULL); @@ -150,9 +148,9 @@ private: bool m_bPathsSet; CTemplate m_Template; CSmartPtr m_spAuth; - CString m_sModName; // Gets filled by ParsePath() - CString m_sPath; // Gets filled by ParsePath() - CString m_sPage; // Gets filled by ParsePath() + CString m_sModName; + CString m_sPath; + CString m_sPage; CSmartPtr m_spSession; static const unsigned int m_uiMaxSessions; diff --git a/src/WebModules.cpp b/src/WebModules.cpp index 11b4606a..63d9e9e2 100644 --- a/src/WebModules.cpp +++ b/src/WebModules.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -194,25 +195,6 @@ CWebSock::~CWebSock() { ResetBytesRead(); } -void CWebSock::ParsePath() { - // The URI looks like: - // /[module][/page][?arg1=val1&arg2=val2...] - - m_sPath = GetPath().TrimLeft_n("/"); - - m_sPath.TrimPrefix("mods/"); - m_sPath.TrimPrefix("modfiles/"); - - m_sModName = m_sPath.Token(0, false, "/"); - m_sPage = m_sPath.Token(1, true, "/"); - - if (m_sPage.empty()) { - m_sPage = "index"; - } - - DEBUG("Path [" + m_sPath + "], Module [" + m_sModName + "], Page [" + m_sPage + "]"); -} - void CWebSock::GetAvailSkins(VCString& vRet) const { vRet.clear(); @@ -615,21 +597,74 @@ CWebSock::EPageReqResult CWebSock::OnPageRequestInternal(const CString& sURI, CS } return PAGE_NOTFOUND; } else if (sURI.Left(6) == "/mods/" || sURI.Left(10) == "/modfiles/") { - ParsePath(); // Make sure modules are treated as directories if (sURI.Right(1) != "/" && sURI.find(".") == CString::npos && sURI.TrimLeft_n("/mods/").TrimLeft_n("/").find("/") == CString::npos) { Redirect(sURI + "/"); return PAGE_DONE; } - CModule *pModule = CZNC::Get().GetModules().FindModule(m_sModName); - if (!pModule) { - // Check if GetSession()->GetUser() is NULL and display - // an error in that case - if (!ForceLogin()) - return PAGE_DONE; + // The URI looks like: + // /mods/[type]/([network]/)?[module][/page][?arg1=val1&arg2=val2...] - pModule = GetSession()->GetUser()->GetModules().FindModule(m_sModName); + m_sPath = GetPath().TrimLeft_n("/"); + + m_sPath.TrimPrefix("mods/"); + m_sPath.TrimPrefix("modfiles/"); + + CString sType = m_sPath.Token(0, false, "/"); + m_sPath = m_sPath.Token(1, true, "/"); + + CModInfo::EModuleType eModType; + if (sType.Equals("global")) { + eModType = CModInfo::GlobalModule; + } else if (sType.Equals("user")) { + eModType = CModInfo::UserModule; + } else if (sType.Equals("network")) { + eModType = CModInfo::NetworkModule; + } else { + PrintErrorPage(403, "Forbidden", "Unknown module type [" + sType + "]"); + return PAGE_DONE; + } + + if ((eModType != CModInfo::GlobalModule) && !ForceLogin()) { + // Make sure we have a valid user + return PAGE_DONE; + } + + CIRCNetwork *pNetwork = NULL; + if (eModType == CModInfo::NetworkModule) { + CString sNetwork = m_sPath.Token(0, false, "/"); + m_sPath = m_sPath.Token(1, true, "/"); + + pNetwork = GetSession()->GetUser()->FindNetwork(sNetwork); + + if (!pNetwork) { + PrintErrorPage(404, "Not Found", "Network [" + sNetwork + "] not found."); + return PAGE_DONE; + } + } + + m_sModName = m_sPath.Token(0, false, "/"); + m_sPage = m_sPath.Token(1, true, "/"); + + if (m_sPage.empty()) { + m_sPage = "index"; + } + + DEBUG("Path [" + m_sPath + "], Module [" + m_sModName + "], Page [" + m_sPage + "]"); + + CModule *pModule = NULL; + + switch (eModType) { + case CModInfo::GlobalModule: + pModule = CZNC::Get().GetModules().FindModule(m_sModName); + break; + case CModInfo::UserModule: + pModule = GetSession()->GetUser()->GetModules().FindModule(m_sModName); + break; + case CModInfo::NetworkModule: + pModule = pNetwork->GetModules().FindModule(m_sModName); + break; } if (!pModule) { diff --git a/webskins/_default_/tmpl/Menu.tmpl b/webskins/_default_/tmpl/Menu.tmpl index 71d21bf7..5d2856c2 100644 --- a/webskins/_default_/tmpl/Menu.tmpl +++ b/webskins/_default_/tmpl/Menu.tmpl @@ -6,9 +6,9 @@
  • Global Modules
      -
    • +
    • -
    • +
    @@ -19,9 +19,9 @@
  • User Modules
      -
    • +
    • -
    • +