1 #include "../../../include/http/pages/announceidentitypage.h"
\r
2 #include "../../../include/stringfunctions.h"
\r
3 #include "../../../include/datetime.h"
\r
9 const std::string AnnounceIdentityPage::CreateLocalIdentityDropDown(const std::string &name, const std::string &selected)
\r
11 std::string rval="";
\r
12 SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID, Name, PublicKey FROM tblLocalIdentity ORDER BY Name;");
\r
15 rval+="<select name=\""+name+"\">";
\r
16 while(st.RowReturned())
\r
21 std::string keypart="";
\r
23 st.ResultText(0,id);
\r
24 st.ResultText(1,name);
\r
25 st.ResultText(2,pubkey);
\r
29 keypart=pubkey.substr(3,5);
\r
32 rval+="<option value=\""+id+"\" title=\""+pubkey+"\">"+SanitizeOutput(name+keypart)+"...</option>";
\r
39 const std::string AnnounceIdentityPage::GeneratePage(const std::string &method, const std::map<std::string,std::string> &queryvars)
\r
42 std::string content;
\r
44 std::string countstr="";
\r
46 std::string lastid="";
\r
47 std::string thisid="";
\r
50 if(queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="announce")
\r
52 SQLite3DB::Statement insert=m_db->Prepare("INSERT INTO tblIdentityIntroductionInserts(LocalIdentityID,Day,UUID,Solution) VALUES(?,?,?,?);");
\r
53 std::string localidentityidstr="";
\r
54 int localidentityid=0;
\r
55 std::vector<std::string> uuids;
\r
56 std::vector<std::string> days;
\r
57 std::vector<std::string> solutions;
\r
59 if(queryvars.find("localidentityid")!=queryvars.end())
\r
61 localidentityidstr=(*queryvars.find("localidentityid")).second;
\r
62 StringFunctions::Convert(localidentityidstr,localidentityid);
\r
64 CreateArgArray(queryvars,"uuid",uuids);
\r
65 CreateArgArray(queryvars,"day",days);
\r
66 CreateArgArray(queryvars,"solution",solutions);
\r
68 for(int i=0; i<solutions.size(); i++)
\r
70 if(solutions[i]!="")
\r
72 insert.Bind(0,localidentityid);
\r
73 insert.Bind(1,days[i]);
\r
74 insert.Bind(2,uuids[i]);
\r
75 insert.Bind(3,solutions[i]);
\r
83 content+="<h2>Announce Identity</h2>";
\r
84 content+="<form name=\"frmannounce\" method=\"POST\">";
\r
85 content+="<input type=\"hidden\" name=\"formaction\" value=\"announce\">";
\r
87 content+="<tr><td colspan=\"4\"><center>Select Identity : ";
\r
88 content+=CreateLocalIdentityDropDown("localidentityid","");
\r
89 content+="</td></tr>";
\r
90 content+="<tr><td colspan=\"4\"><center>Type the answers of a few puzzles. The puzzles are case sensitive.</td></tr>";
\r
93 //TODO if we are already inserting a solution for an identity - we shouldn't select any puzzles that are older than the one we are inserting
\r
97 SQLite3DB::Statement st=m_db->Prepare("SELECT UUID,Day,IdentityID FROM tblIntroductionPuzzleRequests WHERE UUID NOT IN (SELECT UUID FROM tblIdentityIntroductionInserts) AND UUID NOT IN (SELECT UUID FROM tblIntroductionPuzzleInserts) AND Day>='"+date.Format("%Y-%m-%d")+"' AND Found='true' ORDER BY IdentityID, Day DESC, RequestIndex DESC;");
\r
100 if(st.RowReturned()==false)
\r
102 content+="<td colspan=\"4\"><center>You must wait for some puzzles to be downloaded. Check back later.</td>";
\r
105 while(st.RowReturned() && shown<20)
\r
107 st.ResultText(0,uuid);
\r
108 st.ResultText(1,day);
\r
109 st.ResultText(2,thisid);
\r
113 StringFunctions::Convert(shown,countstr);
\r
114 if(shown>0 && shown%4==0)
\r
116 content+="</tr>\r\n<tr>";
\r
119 content+="<img src=\"showcaptcha.htm?UUID="+uuid+"\"><br>";
\r
120 content+="<input type=\"hidden\" name=\"uuid["+countstr+"]\" value=\""+uuid+"\">";
\r
121 content+="<input type=\"hidden\" name=\"day["+countstr+"]\" value=\""+day+"\">";
\r
122 content+="<input type=\"text\" name=\"solution["+countstr+"]\">";
\r
123 content+="</td>\r\n";
\r
131 content+="</tr><td colspan=\"4\"><center><input type=\"submit\" value=\"Announce\"></td></tr>";
\r
132 content+="</table>";
\r
133 content+="</form>";
\r
135 return "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"+StringFunctions::Replace(m_template,"[CONTENT]",content);
\r
138 const bool AnnounceIdentityPage::WillHandleURI(const std::string &uri)
\r
140 if(uri.find("announceidentity.")!=std::string::npos)
\r