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
43 std::vector<std::string> publishboardlist;
\r
45 CreateArgArray(queryvars,"chkidentityid",ids);
\r
46 CreateArgArray(queryvars,"singleuse",singleuse);
\r
47 CreateArgArray(queryvars,"publishtrustlist",publishtrustlist);
\r
48 CreateArgArray(queryvars,"publishboardlist",publishboardlist);
\r
50 if((*queryvars.find("formaction")).second=="update")
\r
52 SQLite3DB::Statement update=m_db->Prepare("UPDATE tblLocalIdentity SET SingleUse=?, PublishTrustList=?, PublishBoardList=? WHERE LocalIdentityID=?;");
\r
53 for(int i=0; i<ids.size(); i++)
\r
57 StringFunctions::Convert(ids[i],id);
\r
58 update.Bind(0,singleuse[i]);
\r
59 update.Bind(1,publishtrustlist[i]);
\r
60 update.Bind(2,publishboardlist[i]);
\r
67 if((*queryvars.find("formaction")).second=="delete")
\r
69 SQLite3DB::Statement del=m_db->Prepare("DELETE FROM tblLocalIdentity WHERE LocalIdentityID=?;");
\r
70 for(int i=0; i<ids.size(); i++)
\r
74 StringFunctions::Convert(ids[i],id);
\r
81 if((*queryvars.find("formaction")).second=="export")
\r
83 IdentityExportXML xml;
\r
84 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
86 while(exp.RowReturned())
\r
88 std::string name="";
\r
89 std::string publickey="";
\r
90 std::string privatekey="";
\r
91 std::string tempval="";
\r
92 bool singleuse=false;
\r
93 bool publishtrustlist=false;
\r
94 bool publishboardlist=false;
\r
96 exp.ResultText(0,name);
\r
97 exp.ResultText(1,publickey);
\r
98 exp.ResultText(2,privatekey);
\r
99 exp.ResultText(3,tempval);
\r
100 if(tempval=="true")
\r
104 exp.ResultText(4,tempval);
\r
105 if(tempval=="true")
\r
107 publishtrustlist=true;
\r
109 exp.ResultText(5,tempval);
\r
110 if(tempval=="true")
\r
112 publishboardlist=true;
\r
115 xml.AddIdentity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist);
\r
119 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
121 if((*queryvars.find("formaction")).second=="import")
\r
123 if(queryvars.find("file")!=queryvars.end())
\r
125 IdentityExportXML xml;
\r
126 if(xml.ParseXML((*queryvars.find("file")).second))
\r
128 SQLite3DB::Statement imp=m_db->Prepare("INSERT INTO tblLocalIdentity(Name,PublicKey,PrivateKey,SingleUse,PublishTrustList,PublishBoardList) VALUES(?,?,?,?,?,?);");
\r
129 for(int i=0; i<xml.GetCount(); i++)
\r
131 std::string tempval="false";
\r
132 imp.Bind(0,xml.GetName(i));
\r
133 imp.Bind(1,xml.GetPublicKey(i));
\r
134 imp.Bind(2,xml.GetPrivateKey(i));
\r
135 if(xml.GetSingleUse(i))
\r
143 imp.Bind(3,tempval);
\r
144 if(xml.GetPublishTrustList(i))
\r
152 imp.Bind(4,tempval);
\r
153 if(xml.GetPublishBoardList(i))
\r
161 imp.Bind(5,tempval);
\r
170 content+="<h2>Local Identities</h2>";
\r
172 content+="<table><tr><th>Export Identities</th><th>Import Identities</th></tr>";
\r
173 content+="<tr><td>";
\r
174 content+="<form name=\"frmexport\" method=\"POST\">";
\r
175 content+="<input type=\"hidden\" name=\"formaction\" value=\"export\">";
\r
176 content+="<input type=\"submit\" value=\"Export Identities\">";
\r
177 content+="</form>";
\r
178 content+="</td><td>";
\r
179 content+="<form name=\"frmimport\" method=\"POST\" enctype=\"multipart/form-data\">";
\r
180 content+="<input type=\"hidden\" name=\"formaction\" value=\"import\">";
\r
181 content+="<input type=\"file\" name=\"file\">";
\r
182 content+="<input type=\"submit\" value=\"Import Identities\">";
\r
183 content+="</form>";
\r
184 content+="</td></tr></table>";
\r
188 content+="<form name=\"frmlocalidentity\" method=\"POST\">";
\r
189 content+="<input type=\"hidden\" name=\"formaction\" value=\"update\">";
\r
190 content+="<table><tr><td></td><th>Name</th><th>Single Use</th><th>Publish Trust List</th><th>Publish Board List</th><th>Announced? *</th></tr>";
\r
192 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
196 while(st.RowReturned())
\r
198 StringFunctions::Convert(count,countstr);
\r
200 std::string name="";
\r
201 std::string publickey="";
\r
202 std::string publishtrustlist="";
\r
203 std::string singleuse="";
\r
204 std::string keypart="";
\r
205 std::string publishboardlist="";
\r
207 st.ResultText(0,id);
\r
208 st.ResultText(1,name);
\r
209 st.ResultText(2,publickey);
\r
210 st.ResultText(3,publishtrustlist);
\r
211 st.ResultText(4,singleuse);
\r
212 st.ResultText(5,publishboardlist);
\r
214 if(publickey.size()>8)
\r
216 keypart=publickey.substr(3,5);
\r
220 content+="<td><input type=\"checkbox\" name=\"chkidentityid["+countstr+"]\" value=\""+id+"\"></td>";
\r
221 content+="<td title=\""+publickey+"\">"+SanitizeOutput(name+keypart)+"...</td>";
\r
222 content+="<td>"+CreateTrueFalseDropDown("singleuse["+countstr+"]",singleuse)+"</td>";
\r
223 content+="<td>"+CreateTrueFalseDropDown("publishtrustlist["+countstr+"]",publishtrustlist)+"</td>";
\r
224 content+="<td>"+CreateTrueFalseDropDown("publishboardlist["+countstr+"]",publishboardlist)+"</td>";
\r
225 if(st.ResultNull(6))
\r
227 content+="<td>No</td>";
\r
231 content+="<td>Yes</td>";
\r
238 content+="<tr><td colspan=\"5\"><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
239 content+="</table>";
\r
240 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
241 content+="<p class=\"paragraph\">Single Use Identities will automatically be deleted 7 days after creation.</p>";
\r
243 return "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"+StringFunctions::Replace(m_template,"[CONTENT]",content);
\r
246 const bool LocalIdentitiesPage::WillHandleURI(const std::string &uri)
\r
248 if(uri.find("localidentities.")!=std::string::npos)
\r