From 456dfde05f138d080acd88e9acba06b990edcecc Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Wed, 25 May 2011 13:24:14 +0100 Subject: [PATCH] Add a web interface to the certauth module --- modules/certauth.cpp | 54 +++++++++++++++++++++++++-- modules/data/certauth/tmpl/index.tmpl | 43 +++++++++++++++++++++ 2 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 modules/data/certauth/tmpl/index.tmpl diff --git a/modules/certauth.cpp b/modules/certauth.cpp index 456ec462..ec42cd66 100644 --- a/modules/certauth.cpp +++ b/modules/certauth.cpp @@ -84,6 +84,16 @@ public: return SaveRegistry(); } + bool AddKey(CUser *pUser, CString sKey) { + pair pair = m_PubKeys[pUser->GetUserName()].insert(sKey); + + if (pair.second) { + Save(); + } + + return pair.second; + } + virtual EModRet OnLoginAttempt(CSmartPtr Auth) { CString sUser = Auth->GetUsername(); Csock *pSock = Auth->GetSocket(); @@ -139,10 +149,8 @@ public: if (sPubKey.empty()) { PutModule("You did not supply a public key or connect with one."); } else { - pair res = m_PubKeys[m_pUser->GetUserName()].insert(sPubKey); - if (res.second) { + if (AddKey(m_pUser, sPubKey)) { PutModule("'" + sPubKey + "' added."); - Save(); } else { PutModule("The key '" + sPubKey + "' is already added."); } @@ -222,6 +230,46 @@ public: } } + virtual CString GetWebMenuTitle() { return "certauth"; } + + virtual bool OnWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl) { + CUser *pUser = WebSock.GetSession()->GetUser(); + + if (sPageName == "index") { + MSCString::iterator it = m_PubKeys.find(pUser->GetUserName()); + if (it != m_PubKeys.end()) { + SCString::iterator it2; + + for (it2 = it->second.begin(); it2 != it->second.end(); it2++) { + CTemplate& row = Tmpl.AddRow("KeyLoop"); + row["Key"] = *it2; + } + } + + return true; + } else if (sPageName == "add") { + AddKey(pUser, WebSock.GetParam("key")); + WebSock.Redirect("/mods/certauth/"); + return true; + } else if (sPageName == "delete") { + MSCString::iterator it = m_PubKeys.find(pUser->GetUserName()); + if (it != m_PubKeys.end()) { + if (it->second.erase(WebSock.GetParam("key", false))) { + if (it->second.size() == 0) { + m_PubKeys.erase(it); + } + + Save(); + } + } + + WebSock.Redirect("/mods/certauth/"); + return true; + } + + return false; + } + private: // Maps user names to a list of allowed pubkeys typedef map > MSCString; diff --git a/modules/data/certauth/tmpl/index.tmpl b/modules/data/certauth/tmpl/index.tmpl new file mode 100644 index 00000000..7cb9b136 --- /dev/null +++ b/modules/data/certauth/tmpl/index.tmpl @@ -0,0 +1,43 @@ + + +
+ +
+

Add A Note

+
+
+
+
Key:
+
+
+
+ +
+
+
+
+
+ + +

You have no keys.

+ + + + + + + + + + + + + + + + + +
 Key
[del]
+ + +