diff --git a/modules/admin.cpp b/modules/admin.cpp index 43eeee45..5a064f5b 100644 --- a/modules/admin.cpp +++ b/modules/admin.cpp @@ -19,21 +19,12 @@ public: virtual bool OnPageRequest(const CString& sURI, CString& sPageRet); virtual bool OnLogin(const CString& sUser, const CString& sPass); - CString Header(const CString& sTitle) { - return "\r\n" - "\r\n" + sTitle + "\r\n" - "\r\n" - "

" + sTitle + "



\r\n"; - } - - CString Footer() { - return "\r\n\r\n"; - } + CString Header(const CString& sTitle); + CString Footer(); void PrintMainPage(CString& sPageRet) { sPageRet = Header("Main Page"); - sPageRet += "Add a user
\r\n" - "List all users
\r\n"; + sPageRet += "Welcome to the ZNC admin module.\r\n"; sPageRet += Footer(); } @@ -44,6 +35,7 @@ public: } void ListUsersPage(CString& sPageRet); + bool SettingsPage(CString& sPageRet); bool UserPage(CString& sPageRet, CUser* pUser = NULL); CUser* GetNewUser(CString& sPageRet); @@ -138,6 +130,31 @@ private: set m_sSocks; }; +CString CAdminSock::Header(const CString& sTitle) { + CString sRet = "\r\n" + "\r\nZNC - " + sTitle + "\r\n" + "\r\n" + "\r\n" + "\r\n" + "\r\n" + "

" + sTitle + "

\r\n"; + + if (!m_pUser) { + sRet += "[Home]
\r\n" + "[ZNC Settings]
\r\n" + "[Add User]
\r\n" + "[List Users]
\r\n"; + } + + sRet += "
\r\n"; + + return sRet; +} + +CString CAdminSock::Footer() { + return "
" + m_pModule->GetZNC()->GetTag() + "
\r\n\r\n"; +} + bool CAdminSock::OnLogin(const CString& sUser, const CString& sPass) { if (GetUser() == m_pModule->GetUser() && GetPass() == m_pModule->GetPass()) { return true; @@ -160,16 +177,16 @@ void CAdminSock::ListUsersPage(CString& sPageRet) { if (!msUsers.size()) { sPageRet += "There are no users defined. Click here if you would like to add one.\r\n"; } else { - sPageRet += "\r\n" - "\t\r\n"; + sPageRet += "
ActionUsernameCurrent Server
\r\n" + "\t\r\n"; unsigned int a = 0; for (map::const_iterator it = msUsers.begin(); it != msUsers.end(); it++, a++) { CServer* pServer = it->second->GetCurrentServer(); - sPageRet += "\t\r\n\t\t\r\n" - "\t\t\r\n" - "\t\t\r\n" + sPageRet += "\t\r\n\t\t\r\n" + "\t\t\r\n" + "\t\t\r\n" "\t"; } @@ -216,6 +233,15 @@ bool CAdminSock::OnPageRequest(const CString& sURI, CString& sPageRet) { } PrintMainPage(sPageRet); + } else if (sURI == "/settings") { + if (m_pUser) { + return false; + } + + if (!SettingsPage(sPageRet)) { + DEBUG_ONLY(cout << "- 302 Redirect" << endl); + return false; + } } else if (sURI == "/adduser") { if (m_pUser) { return false; @@ -266,6 +292,18 @@ bool CAdminSock::OnPageRequest(const CString& sURI, CString& sPageRet) { return true; } +bool CAdminSock::SettingsPage(CString& sPageRet) { + if (!GetParam("submitted").ToUInt()) { + sPageRet = Header("Error"); + sPageRet += "The global settings page has not been implemented yet."; + sPageRet += Footer(); + return true; + } + + Redirect("/"); + return false; +} + bool CAdminSock::UserPage(CString& sPageRet, CUser* pUser) { if (!GetParam("submitted").ToUInt()) { sPageRet = Header((pUser) ? CString("Edit User [" + pUser->GetUserName().Escape_n(CString::EHTML) + "]") : CString("Add User")); @@ -297,7 +335,7 @@ bool CAdminSock::UserPage(CString& sPageRet, CUser* pUser) { } } - sPageRet += "\r\n"; + sPageRet += "
\r\n"; sPageRet += "\r\n" "
Authentication
\r\n"
ActionUsernameCurrent Server
[second->GetUserName().Escape_n(CString::EURL) + "\">Edit] [second->GetUserName().Escape_n(CString::EURL) + "\">Delete]" + it->second->GetUserName().Escape_n(CString::EHTML) + "" + CString((pServer) ? pServer->GetName().Escape_n(CString::EHTML) : "-N/A-") + "
[second->GetUserName().Escape_n(CString::EURL) + "\">Edit] [second->GetUserName().Escape_n(CString::EURL) + "\">Delete]" + it->second->GetUserName().Escape_n(CString::EHTML) + "" + CString((pServer) ? pServer->GetName().Escape_n(CString::EHTML) : "-N/A-") + "