void CSkinInfo::LoadIncludes() { std::string includesPath = CSpecialProtocol::TranslatePathConvertCase(GetSkinPath("includes.xml")); CLog::Log(LOGINFO, "Loading skin includes from %s", includesPath.c_str()); m_includes.ClearIncludes(); m_includes.LoadIncludes(includesPath); }
void CWebSock::GetAvailSkins(VCString& vRet) const { vRet.clear(); CString sRoot(GetSkinPath("_default_")); sRoot.TrimRight("/"); sRoot.TrimRight("_default_"); sRoot.TrimRight("/"); if (!sRoot.empty()) { sRoot += "/"; } if (!sRoot.empty() && CFile::IsDir(sRoot)) { CDir Dir(sRoot); for (unsigned int d = 0; d < Dir.size(); d++) { const CFile& SubDir = *Dir[d]; if (SubDir.IsDir() && SubDir.GetShortName() == "_default_") { vRet.push_back(SubDir.GetShortName()); break; } } for (unsigned int e = 0; e < Dir.size(); e++) { const CFile& SubDir = *Dir[e]; if (SubDir.IsDir() && SubDir.GetShortName() != "_default_" && SubDir.GetShortName() != ".svn") { vRet.push_back(SubDir.GetShortName()); } } } }
void CSkinInfo::LoadIncludes() { CStdString includesPath = PTH_IC(GetSkinPath("includes.xml")); CLog::Log(LOGINFO, "Loading skin includes from %s", includesPath.c_str()); m_includes.ClearIncludes(); m_includes.LoadIncludes(includesPath); }
bool CWin::ExistsSkinFile(STRINGorID xml, LPCTSTR type) {//busy to do it return false; CDuiString strResourcePath = GetSkinPath(); strResourcePath += GetSkinFolder().GetData(); CMarkup m_xml; switch (GetResourceType()) { case UILIB_FILE: { if (HIWORD(xml.m_lpstr) != NULL) { if (*(xml.m_lpstr) == _T('<')) { return true; } else { CDuiString sFile = strResourcePath + xml.m_lpstr; HANDLE hFile = ::CreateFile(sFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) return false; DWORD dwSize = ::GetFileSize(hFile, NULL); if (dwSize == 0) return false; if (dwSize > 4096 * 1024) return false; DWORD dwRead = 0; BYTE* pByte = new BYTE[dwSize]; ::ReadFile(hFile, pByte, dwSize, &dwRead, NULL); ::CloseHandle(hFile); if (dwRead != dwSize) { delete[] pByte; return false; } delete[] pByte; return true; } } else{ } } break; case UILIB_ZIP: { } break; case UILIB_RESOURCE: { } break; case UILIB_ZIPRESOURCE: { } } return false; }
void CSkinInfo::GetSkinPaths(std::vector<std::string> &paths) const { RESOLUTION_INFO res; GetSkinPath("Home.xml", &res); if (!res.strMode.empty()) paths.push_back(URIUtils::AddFileToFolder(Path(), res.strMode)); if (res.strMode != m_defaultRes.strMode) paths.push_back(URIUtils::AddFileToFolder(Path(), m_defaultRes.strMode)); }
//通知界面刷新皮肤 void CSkinMgr::Notify() { CString s = CBcfFile::GetAppPath ();/////本地路径 CString strSkin = GetSkinBcfFileName(); CBcfFile f(s + "skin.bcf"); TCHAR szUIPath[MAX_PATH]; CString skinfolder; skinfolder = f.GetKeyVal(GetKeyVal(strSkin),"skinfolder","..\\" + GetSkinPath()); wsprintf(szUIPath,"%s",skinfolder); BzDui::CPaintManagerUI::SetResourcePath(szUIPath); BzDui::CPaintManagerUI::ReloadSkin(); }
VCString CWebSock::GetDirs(CModule* pModule, bool bIsTemplate) { CString sHomeSkinsDir(CZNC::Get().GetZNCPath() + "/webskins/"); CString sSkinName(GetSkinName()); VCString vsResult; // Module specific paths if (pModule) { const CString& sModName(pModule->GetModName()); // 1. ~/.znc/webskins/<user_skin_setting>/mods/<mod_name>/ // if (!sSkinName.empty()) { vsResult.push_back(GetSkinPath(sSkinName) + "/mods/" + sModName + "/"); } // 2. ~/.znc/webskins/_default_/mods/<mod_name>/ // vsResult.push_back(GetSkinPath("_default_") + "/mods/" + sModName + "/"); // 3. ./modules/<mod_name>/tmpl/ // vsResult.push_back(pModule->GetModDataDir() + "/tmpl/"); // 4. ~/.znc/webskins/<user_skin_setting>/mods/<mod_name>/ // if (!sSkinName.empty()) { vsResult.push_back(GetSkinPath(sSkinName) + "/mods/" + sModName + "/"); } // 5. ~/.znc/webskins/_default_/mods/<mod_name>/ // vsResult.push_back(GetSkinPath("_default_") + "/mods/" + sModName + "/"); } // 6. ~/.znc/webskins/<user_skin_setting>/ // if (!sSkinName.empty()) { vsResult.push_back(GetSkinPath(sSkinName) + CString(bIsTemplate ? "/tmpl/" : "/")); } // 7. ~/.znc/webskins/_default_/ // vsResult.push_back(GetSkinPath("_default_") + CString(bIsTemplate ? "/tmpl/" : "/")); return vsResult; }
CWebSock::EPageReqResult CWebSock::OnPageRequestInternal(const CString& sURI, CString& sPageRet) { if (CZNC::Get().GetProtectWebSessions() && GetSession()->GetIP() != GetRemoteIP()) { DEBUG("Expected IP: " << GetSession()->GetIP()); DEBUG("Remote IP: " << GetRemoteIP()); PrintErrorPage(403, "Access denied", "This session does not belong to your IP."); return PAGE_DONE; } // Check that they really POSTed from one our forms by checking if they // know the "secret" CSRF check value. Don't do this for login since // CSRF against the login form makes no sense and the login form does a // cookies-enabled check which would break otherwise. if (IsPost() && GetParam("_CSRF_Check") != GetCSRFCheck() && sURI != "/login") { DEBUG("Expected _CSRF_Check: " << GetCSRFCheck()); DEBUG("Actual _CSRF_Check: " << GetParam("_CSRF_Check")); PrintErrorPage(403, "Access denied", "POST requests need to send " "a secret token to prevent cross-site request forgery attacks."); return PAGE_DONE; } SendCookie("SessionId", GetSession()->GetId()); if (GetSession()->IsLoggedIn()) { m_sUser = GetSession()->GetUser()->GetUserName(); m_bLoggedIn = true; } // Handle the static pages that don't require a login if (sURI == "/") { if(!m_bLoggedIn && GetParam("cookie_check", false).ToBool() && GetRequestCookie("SessionId").empty()) { GetSession()->AddError("Your browser does not have cookies enabled for this site!"); } return PrintTemplate("index", sPageRet); } else if (sURI == "/favicon.ico") { return PrintStaticFile("/pub/favicon.ico", sPageRet); } else if (sURI == "/robots.txt") { return PrintStaticFile("/pub/robots.txt", sPageRet); } else if (sURI == "/logout") { GetSession()->SetUser(NULL); SetLoggedIn(false); Redirect("/"); // We already sent a reply return PAGE_DONE; } else if (sURI == "/login") { if (GetParam("submitted").ToBool()) { m_sUser = GetParam("user"); m_sPass = GetParam("pass"); m_bLoggedIn = OnLogin(m_sUser, m_sPass); // AcceptedLogin()/RefusedLogin() will call Redirect() return PAGE_DEFERRED; } Redirect("/"); // the login form is here return PAGE_DONE; } else if (sURI.Left(5) == "/pub/") { return PrintStaticFile(sURI, sPageRet); } else if (sURI.Left(11) == "/skinfiles/") { CString sSkinName = sURI.substr(11); CString::size_type uPathStart = sSkinName.find("/"); if (uPathStart != CString::npos) { CString sFilePath = sSkinName.substr(uPathStart + 1); sSkinName.erase(uPathStart); m_Template.ClearPaths(); m_Template.AppendPath(GetSkinPath(sSkinName) + "pub"); if (PrintFile(m_Template.ExpandFile(sFilePath))) { return PAGE_DONE; } else { return PAGE_NOTFOUND; } } 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; pModule = GetSession()->GetUser()->GetModules().FindModule(m_sModName); } if (!pModule) { return PAGE_NOTFOUND; } else if (pModule->WebRequiresLogin() && !ForceLogin()) { return PAGE_PRINT; } else if (pModule->WebRequiresAdmin() && !GetSession()->IsAdmin()) { PrintErrorPage(403, "Forbidden", "You need to be an admin to access this module"); return PAGE_DONE; } else if (!pModule->IsGlobal() && pModule->GetUser() != GetSession()->GetUser()) { PrintErrorPage(403, "Forbidden", "You must login as " + pModule->GetUser()->GetUserName() + " in order to view this page"); return PAGE_DONE; } else if (pModule->OnWebPreRequest(*this, m_sPage)) { return PAGE_DEFERRED; } VWebSubPages& vSubPages = pModule->GetSubPages(); for (unsigned int a = 0; a < vSubPages.size(); a++) { TWebSubPage& SubPage = vSubPages[a]; bool bActive = (m_sModName == pModule->GetModName() && m_sPage == SubPage->GetName()); if (bActive && SubPage->RequiresAdmin() && !GetSession()->IsAdmin()) { PrintErrorPage(403, "Forbidden", "You need to be an admin to access this page"); return PAGE_DONE; } } if (pModule && !pModule->IsGlobal() && (!IsLoggedIn() || pModule->GetUser() != GetSession()->GetUser())) { AddModLoop("UserModLoop", *pModule); } if (sURI.Left(10) == "/modfiles/") { m_Template.AppendPath(GetSkinPath(GetSkinName()) + "/mods/" + m_sModName + "/files/"); m_Template.AppendPath(pModule->GetModDataDir() + "/files/"); if (PrintFile(m_Template.ExpandFile(m_sPage.TrimLeft_n("/")))) { return PAGE_PRINT; } else { return PAGE_NOTFOUND; } } else { SetPaths(pModule, true); /* if a module returns false from OnWebRequest, it does not want the template to be printed, usually because it did a redirect. */ if (pModule->OnWebRequest(*this, m_sPage, m_Template)) { // If they already sent a reply, let's assume // they did what they wanted to do. if (SentHeader()) { return PAGE_DONE; } return PrintTemplate(m_sPage, sPageRet, pModule); } if (!SentHeader()) { PrintErrorPage(404, "Not Implemented", "The requested module does not acknowledge web requests"); } return PAGE_DONE; } } else { CString sPage(sURI.Trim_n("/")); if (sPage.length() < 32) { for (unsigned int a = 0; a < sPage.length(); a++) { unsigned char c = sPage[a]; if ((c < '0' || c > '9') && (c < 'a' || c > 'z') && (c < 'A' || c > 'Z') && c != '_') { return PAGE_NOTFOUND; } } return PrintTemplate(sPage, sPageRet); } } return PAGE_NOTFOUND; }
CControlUI* IDuiWindow::CreateRoot() { CDialogBuilder builder; CDuiString strResourcePath = GetSkinPath(); strResourcePath += GetSkinFolder().GetData(); m_PaintManager.SetResourcePath(strResourcePath.GetData()); CControlUI* pRoot = NULL; switch (GetResourceType()) { case UILIB_FILE: { pRoot = builder.Create(GetSkinFile().GetData(), (UINT)0, this, &m_PaintManager); } break; case UILIB_ZIP: { m_PaintManager.SetResourceZip(GetZIPFileName().GetData(), true); pRoot = builder.Create(GetSkinFile().GetData(), (UINT)0, this, &m_PaintManager); } break; case UILIB_RESOURCE: { HINSTANCE hCurInst = CPaintManagerUI::GetResourceDll(); m_PaintManager.SetCurResInstance(hCurInst); pRoot = builder.Create(_ttoi(GetSkinFile().GetData()), _T("xml"), this, &m_PaintManager); } break; case UILIB_ZIPRESOURCE: { HINSTANCE hCurInst = m_PaintManager.GetCurResInstance(); if (!hCurInst) hCurInst = CPaintManagerUI::GetResourceDll(); m_PaintManager.SetCurResInstance(hCurInst); HRSRC hResource = ::FindResource(hCurInst, GetResourceID(), _T("ZIPRES")); if (hResource == NULL) return NULL; DWORD dwSize = 0; HGLOBAL hGlobal = ::LoadResource(hCurInst, hResource); if (hGlobal == NULL) { #if defined(WIN32) && !defined(UNDER_CE) ::FreeResource(hResource); #endif return NULL; } dwSize = ::SizeofResource(hCurInst, hResource); if (dwSize == 0) return NULL; m_lpResourceZIPBuffer = new BYTE[dwSize]; if (m_lpResourceZIPBuffer != NULL) { ::CopyMemory(m_lpResourceZIPBuffer, (LPBYTE)::LockResource(hGlobal), dwSize); } #if defined(WIN32) && !defined(UNDER_CE) ::FreeResource(hResource); #endif m_PaintManager.SetResourceZip(m_lpResourceZIPBuffer, dwSize); pRoot = builder.Create(GetSkinFile().GetData(), (UINT)0, this, &m_PaintManager); } } ASSERT(pRoot); if (pRoot == NULL) { MessageBox(NULL, _T("加载资源文件失败"), _T("Duilib"), MB_OK | MB_ICONERROR); ExitProcess(1); return NULL; } return pRoot; }
bool CSkinInfo::HasSkinFile(const std::string &strFile) const { return CFile::Exists(GetSkinPath(strFile)); }
CControlUI* CWin::CreateRoot(STRINGorID xml, LPCTSTR type /* = NULL */, IDialogBuilderCallback* pCallback /* = NULL */, CControlUI* pParent /* = NULL */) { CDialogBuilder builder; CDuiString strResourcePath = GetSkinPath(); strResourcePath += GetSkinFolder().GetData(); _paintManager->SetResourcePath(strResourcePath.GetData()); CControlUI* pRoot = NULL; switch (GetResourceType()) { case UILIB_FILE: { pRoot = builder.Create(xml, type, pCallback, _paintManager, pParent); } break; case UILIB_ZIP: { _paintManager->SetResourceZip(GetZIPFileName().GetData(), true); pRoot = builder.Create(xml, type, pCallback, _paintManager, pParent); } break; case UILIB_RESOURCE: { HINSTANCE hCurInst = CPaintManagerUI::GetResourceDll(); _paintManager->SetCurResInstance(hCurInst); pRoot = builder.Create(xml, type, pCallback, _paintManager, pParent); } break; case UILIB_ZIPRESOURCE: { HINSTANCE hCurInst = _paintManager->GetCurResInstance(); if (!hCurInst) hCurInst = CPaintManagerUI::GetResourceDll(); _paintManager->SetCurResInstance(hCurInst); HRSRC hResource = ::FindResource(hCurInst, GetResourceID(), _T("ZIPRES")); if (hResource == NULL) return NULL; DWORD dwSize = 0; HGLOBAL hGlobal = ::LoadResource(hCurInst, hResource); if (hGlobal == NULL) { #if defined(WIN32) && !defined(UNDER_CE) ::FreeResource(hResource); #endif return NULL; } dwSize = ::SizeofResource(hCurInst, hResource); if (dwSize == 0) return NULL; m_lpResourceZIPBuffer = new BYTE[dwSize]; if (m_lpResourceZIPBuffer != NULL) { ::CopyMemory(m_lpResourceZIPBuffer, (LPBYTE)::LockResource(hGlobal), dwSize); } #if defined(WIN32) && !defined(UNDER_CE) ::FreeResource(hResource); #endif _paintManager->SetResourceZip(m_lpResourceZIPBuffer, dwSize); pRoot = builder.Create(xml, type, pCallback, _paintManager, pParent); } } ASSERT(pRoot); if (pRoot == NULL) { MessageBox(NULL, _T("加载资源文件失败"), _T("Duilib"), MB_OK | MB_ICONERROR); ExitProcess(1); return NULL; } return pRoot; }