1 #include "../../../include/http/pages/localidentitiespage.h"
\r
2 #include "../../../include/stringfunctions.h"
\r
3 #include "../../../include/http/identityexportxml.h"
\r
9 const std::string LocalIdentitiesPage::CreateTrueFalseDropDown(const std::string &name, const std::string &selected)
\r
11 std::string rval="";
\r
13 rval+="<select name=\""+name+"\">";
\r
14 rval+="<option value=\"true\"";
\r
15 if(selected=="true")
\r
19 rval+=">true</option>";
\r
20 rval+="<option value=\"false\"";
\r
21 if(selected=="false")
\r
25 rval+=">false</option>";
\r
31 const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, const std::map<std::string,std::string> &queryvars)
\r
34 std::string countstr;
\r
35 std::string content="";
\r
37 if(queryvars.find("formaction")!=queryvars.end())
\r
40 std::vector<std::string> ids;
\r
41 std::vector<std::string> singleuse;
\r
42 std::vector<std::string> publishtrustlist;
\r
44 CreateArgArray(queryvars,"chkidentityid",ids);
\r
45 CreateArgArray(queryvars,"singleuse",singleuse);
\r
46 CreateArgArray(queryvars,"publishtrustlist",publishtrustlist);
\r
48 if((*queryvars.find("formaction")).second=="update")
\r
50 SQLite3DB::Statement update=m_db->Prepare("UPDATE tblLocalIdentity SET SingleUse=?, PublishTrustList=? WHERE LocalIdentityID=?;");
\r
51 for(int i=0; i<ids.size(); i++)
\r
55 StringFunctions::Convert(ids[i],id);
\r
56 update.Bind(0,singleuse[i]);
\r
57 update.Bind(1,publishtrustlist[i]);
\r
64 if((*queryvars.find("formaction")).second=="delete")
\r
66 SQLite3DB::Statement del=m_db->Prepare("DELETE FROM tblLocalIdentity WHERE LocalIdentityID=?;");
\r
67 for(int i=0; i<ids.size(); i++)
\r
71 StringFunctions::Convert(ids[i],id);
\r
78 if((*queryvars.find("formaction")).second=="export")
\r
80 IdentityExportXML xml;
\r
81 SQLite3DB::Statement exp=m_db->Prepare("SELECT Name,PublicKey,PrivateKey,SingleUse,PublishTrustList,PublishBoardList FROM tblLocalIdentity WHERE PublicKey IS NOT NULL AND PrivateKey IS NOT NULL;");
\r
83 while(exp.RowReturned())
\r
85 std::string name="";
\r
86 std::string publickey="";
\r
87 std::string privatekey="";
\r
88 std::string tempval="";
\r
89 bool singleuse=false;
\r
90 bool publishtrustlist=false;
\r
91 bool publishboardlist=false;
\r
93 exp.ResultText(0,name);
\r
94 exp.ResultText(1,publickey);
\r
95 exp.ResultText(2,privatekey);
\r
96 exp.ResultText(3,tempval);
\r
101 exp.ResultText(4,tempval);
\r
102 if(tempval=="true")
\r
104 publishtrustlist=true;
\r
106 exp.ResultText(5,tempval);
\r
107 if(tempval=="true")
\r
109 publishboardlist=true;
\r
112 xml.AddIdentity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist);
\r
116 return "HTTP/1.1 200 OK\r\nContent-Type: text/xml\r\nContent-Disposition: attachment; filename=identities.xml\r\n\r\n"+xml.GetXML();
\r
118 if((*queryvars.find("formaction")).second=="import")
\r
120 if(queryvars.find("file")!=queryvars.end())
\r
122 IdentityExportXML xml;
\r
123 if(xml.ParseXML((*queryvars.find("file")).second))
\r
125 SQLite3DB::Statement imp=m_db->Prepare("INSERT INTO tblLocalIdentity(Name,PublicKey,PrivateKey,SingleUse,PublishTrustList,PublishBoardList) VALUES(?,?,?,?,?,?);");
\r
126 for(int i=0; i<xml.GetCount(); i++)
\r
128 std::string tempval="false";
\r
129 imp.Bind(0,xml.GetName(i));
\r
130 imp.Bind(1,xml.GetPublicKey(i));
\r
131 imp.Bind(2,xml.GetPrivateKey(i));
\r
132 if(xml.GetSingleUse(i))
\r
140 imp.Bind(3,tempval);
\r
141 if(xml.GetPublishTrustList(i))
\r
149 imp.Bind(4,tempval);
\r
150 if(xml.GetPublishBoardList(i))
\r
158 imp.Bind(5,tempval);
\r
167 content+="<h2>Local Identities</h2>";
\r
169 content+="<table><tr><th>Export Identities</th><th>Import Identities</th></tr>";
\r
170 content+="<tr><td>";
\r
171 content+="<form name=\"frmexport\" method=\"POST\">";
\r
172 content+="<input type=\"hidden\" name=\"formaction\" value=\"export\">";
\r
173 content+="<input type=\"submit\" value=\"Export Identities\">";
\r
174 content+="</form>";
\r
175 content+="</td><td>";
\r
176 content+="<form name=\"frmimport\" method=\"POST\" enctype=\"multipart/form-data\">";
\r
177 content+="<input type=\"hidden\" name=\"formaction\" value=\"import\">";
\r
178 content+="<input type=\"file\" name=\"file\">";
\r
179 content+="<input type=\"submit\" value=\"Import Identities\">";
\r
180 content+="</form>";
\r
181 content+="</td></tr></table>";
\r
183 content+="<form name=\"frmlocalidentity\" method=\"POST\">";
\r
184 content+="<input type=\"hidden\" name=\"formaction\" value=\"update\">";
\r
185 content+="<table><tr><td></td><th>Name</th><th>Single Use</th><th>Publish Trust List</th><th>Announced? *</th></tr>";
\r
187 SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID,tblLocalIdentity.Name,tblLocalIdentity.PublicKey,tbLLocalIdentity.PublishTrustList,tblLocalIdentity.SingleUse,tblLocalIdentity.PublishBoardList,tblIdentity.IdentityID FROM tblLocalIdentity LEFT JOIN tblIdentity ON tblLocalIdentity.PublicKey=tblIdentity.PublicKey ORDER BY tblLocalIdentity.Name;");
\r
191 while(st.RowReturned())
\r
193 StringFunctions::Convert(count,countstr);
\r
196 std::string publickey;
\r
197 std::string publishtrustlist;
\r
198 std::string singleuse;
\r
199 std::string keypart;
\r
201 st.ResultText(0,id);
\r
202 st.ResultText(1,name);
\r
203 st.ResultText(2,publickey);
\r
204 st.ResultText(3,publishtrustlist);
\r
205 st.ResultText(4,singleuse);
\r
207 if(publickey.size()>8)
\r
209 keypart=publickey.substr(3,5);
\r
213 content+="<td><input type=\"checkbox\" name=\"chkidentityid["+countstr+"]\" value=\""+id+"\"></td>";
\r
214 content+="<td title=\""+publickey+"\">"+SanitizeOutput(name+keypart)+"...</td>";
\r
215 content+="<td>"+CreateTrueFalseDropDown("singleuse["+countstr+"]",singleuse)+"</td>";
\r
216 content+="<td>"+CreateTrueFalseDropDown("publishtrustlist["+countstr+"]",publishtrustlist)+"</td>";
\r
217 if(st.ResultNull(6))
\r
219 content+="<td>No</td>";
\r
223 content+="<td>Yes</td>";
\r
230 content+="<tr><td colspan=\"4\"><center><input type=\"submit\" value=\"Update Selected\"> <input type=\"submit\" value=\"Delete Selected\" onClick=\"if(confirm('Delete Selected Identities?')){frmlocalidentity.formaction.value='delete';}else{return false;}\"></td></tr>";
\r
231 content+="</table>";
\r
232 content+="<p class=\"paragraph=\">* An identity is considered successfully announced when you have downloaded a trust list from someone that contains the identity.</p>";
\r
234 return "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"+StringFunctions::Replace(m_template,"[CONTENT]",content);
\r
237 const bool LocalIdentitiesPage::WillHandleURI(const std::string &uri)
\r
239 if(uri.find("localidentities.")!=std::string::npos)
\r