Permalink
Browse files

Add a web interface to the certauth module

  • Loading branch information...
1 parent 1c0edff commit 456dfde05f138d080acd88e9acba06b990edcecc @kylef kylef committed May 25, 2011
Showing with 94 additions and 3 deletions.
  1. +51 −3 modules/certauth.cpp
  2. +43 −0 modules/data/certauth/tmpl/index.tmpl
View
@@ -84,6 +84,16 @@ class CSSLClientCertMod : public CGlobalModule {
return SaveRegistry();
}
+ bool AddKey(CUser *pUser, CString sKey) {
+ pair<SCString::iterator, bool> pair = m_PubKeys[pUser->GetUserName()].insert(sKey);
+
+ if (pair.second) {
+ Save();
+ }
+
+ return pair.second;
+ }
+
virtual EModRet OnLoginAttempt(CSmartPtr<CAuthBase> Auth) {
CString sUser = Auth->GetUsername();
Csock *pSock = Auth->GetSocket();
@@ -139,10 +149,8 @@ class CSSLClientCertMod : public CGlobalModule {
if (sPubKey.empty()) {
PutModule("You did not supply a public key or connect with one.");
} else {
- pair<SCString::iterator, bool> 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 @@ class CSSLClientCertMod : public CGlobalModule {
}
}
+ 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<CString, set<CString> > MSCString;
@@ -0,0 +1,43 @@
+<? INC Header.tmpl ?>
+
+<form method="post" action="/mods/certauth/add">
+ <? INC _csrf_check.tmpl ?>
+ <div class="section">
+ <h3>Add A Note</h3>
+ <div class="sectionbg">
+ <div class="sectionbody">
+ <div class="subsection full">
+ <div class="inputlabel">Key:</div>
+ <div><input type="text" name="key" size="40" /></div>
+ </div>
+ <div class="subsection submitline">
+ <input type="submit" name="add" value="Add Key" />
+ </div>
+ </div>
+ </div>
+ </div>
+</form>
+
+<? IF !KeyLoop ?>
+<p>You have no keys.</p>
+<? ELSE ?>
+
+<table class="data">
+ <thead>
+ <tr>
+ <td style="width: 10px;">&nbsp;</td>
+ <td>Key</td>
+ </tr>
+ </thead>
+ <tbody>
+ <? LOOP KeyLoop ?>
+ <tr class="<? IF __EVEN__ ?>evenrow<? ELSE ?>oddrow<? ENDIF ?>">
+ <td>[<a href="/mods/certauth/delete?key=<? VAR Key ESC=URL,HTML ?>">del</a>]</td>
+ <td><? VAR Key ?></td>
+ </tr>
+ <? ENDLOOP ?>
+ </tbody>
+</table>
+<? ENDIF ?>
+
+<? INC Footer.tmpl ?>

0 comments on commit 456dfde

Please sign in to comment.