1 #include "../../../include/http/pages/announceidentitypage.h"
\r
2 #include "../../../include/stringfunctions.h"
\r
3 #include "../../../include/global.h"
\r
5 #include <Poco/DateTime.h>
\r
6 #include <Poco/DateTimeFormatter.h>
\r
12 const std::string AnnounceIdentityPage::CreateLocalIdentityDropDown(const std::string &name, const std::string &selected)
\r
14 std::string rval="";
\r
15 SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID, Name, PublicKey FROM tblLocalIdentity ORDER BY Name;");
\r
18 rval+="<select name=\""+name+"\">";
\r
19 while(st.RowReturned())
\r
25 st.ResultText(0,id);
\r
26 st.ResultText(1,name);
\r
27 st.ResultText(2,pubkey);
\r
29 rval+="<option value=\""+id+"\" title=\""+pubkey+"\">"+SanitizeOutput(CreateShortIdentityName(name,pubkey))+"</option>";
\r
36 const std::string AnnounceIdentityPage::GeneratePage(const std::string &method, const std::map<std::string,std::string> &queryvars)
\r
38 Poco::DateTime date;
\r
39 std::string content;
\r
41 std::string countstr="";
\r
43 std::string lastid="";
\r
44 std::string thisid="";
\r
46 std::string name="";
\r
47 std::string pubkey="";
\r
49 bool willshow=false;
\r
51 if(queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="announce" && ValidateFormPassword(queryvars))
\r
53 SQLite3DB::Statement insert=m_db->Prepare("INSERT INTO tblIdentityIntroductionInserts(LocalIdentityID,Day,UUID,Solution) VALUES(?,?,?,?);");
\r
54 std::string localidentityidstr="";
\r
55 int localidentityid=0;
\r
56 std::vector<std::string> uuids;
\r
57 std::vector<std::string> days;
\r
58 std::vector<std::string> solutions;
\r
60 if(queryvars.find("localidentityid")!=queryvars.end())
\r
62 localidentityidstr=(*queryvars.find("localidentityid")).second;
\r
63 StringFunctions::Convert(localidentityidstr,localidentityid);
\r
65 CreateArgArray(queryvars,"uuid",uuids);
\r
66 CreateArgArray(queryvars,"day",days);
\r
67 CreateArgArray(queryvars,"solution",solutions);
\r
69 for(int i=0; i<solutions.size(); i++)
\r
71 if(solutions[i]!="")
\r
73 insert.Bind(0,localidentityid);
\r
74 insert.Bind(1,days[i]);
\r
75 insert.Bind(2,uuids[i]);
\r
76 insert.Bind(3,solutions[i]);
\r
84 content+="<h2>Announce Identity</h2>";
\r
85 content+="<form name=\"frmannounce\" method=\"POST\">";
\r
86 content+=CreateFormPassword();
\r
87 content+="<input type=\"hidden\" name=\"formaction\" value=\"announce\">";
\r
89 content+="<tr><td colspan=\"4\"><center>Select Identity : ";
\r
90 content+=CreateLocalIdentityDropDown("localidentityid","");
\r
91 content+="</td></tr>";
\r
92 content+="<tr><td colspan=\"4\"><center>Type the answers of a few of the following puzzles. You don't need to get them all correct, but remember that they are case sensitive. Getting announced will take some time. DO NOT continuously solve captchas. Solve 30 at most, wait a day, and if your identity has not been announced, repeat until it is.</td></tr>";
\r
95 date-=Poco::Timespan(1,0,0,0,0);
\r
96 SQLite3DB::Statement st=m_db->Prepare("SELECT UUID,Day,tblIdentity.IdentityID,RequestIndex,tblIdentity.Name,tblIdentity.PublicKey FROM tblIntroductionPuzzleRequests INNER JOIN tblIdentity ON tblIntroductionPuzzleRequests.IdentityID=tblIdentity.IdentityID WHERE UUID NOT IN (SELECT UUID FROM tblIdentityIntroductionInserts WHERE UUID IS NOT NULL) AND UUID NOT IN (SELECT UUID FROM tblIntroductionPuzzleInserts WHERE UUID IS NOT NULL) AND Day>='"+Poco::DateTimeFormatter::format(date,"%Y-%m-%d")+"' AND Found='true' ORDER BY tblIdentity.IdentityID, Day DESC, RequestIndex DESC;");
\r
99 if(st.RowReturned()==false)
\r
101 content+="<td colspan=\"4\"><center>You must wait for some puzzles to be downloaded. Check back later.</td>";
\r
104 while(st.RowReturned() && shown<20)
\r
106 st.ResultText(0,uuid);
\r
107 st.ResultText(1,day);
\r
108 st.ResultText(2,thisid);
\r
109 st.ResultInt(3,requestindex);
\r
110 st.ResultText(4,name);
\r
111 st.ResultText(5,pubkey);
\r
113 // if we are already inserting a solution for an identity - we shouldn't show any puzzles that are older than the one we are inserting
\r
114 // get the last index # we are inserting this day from this identity
\r
115 // if the index here is greater than the index in the st statement, we will skip this puzzle because we are already inserting a puzzle with a greater index
\r
117 SQLite3DB::Statement st2=m_db->Prepare("SELECT MAX(RequestIndex) FROM tblIdentityIntroductionInserts INNER JOIN tblIntroductionPuzzleRequests ON tblIdentityIntroductionInserts.UUID=tblIntroductionPuzzleRequests.UUID WHERE tblIdentityIntroductionInserts.Day=? AND tblIdentityIntroductionInserts.UUID IN (SELECT UUID FROM tblIntroductionPuzzleRequests WHERE IdentityID=? AND Day=? AND UUID IS NOT NULL) GROUP BY tblIdentityIntroductionInserts.Day;");
\r
119 if(st2.RowReturned()==true)
\r
122 st2.ResultInt(0,index);
\r
123 if(index>=requestindex)
\r
129 if(willshow && thisid!=lastid)
\r
131 StringFunctions::Convert(shown,countstr);
\r
132 if(shown>0 && shown%4==0)
\r
134 content+="</tr>\r\n<tr>";
\r
136 content+="<td title=\"From "+SanitizeOutput(CreateShortIdentityName(name,pubkey))+"\">";
\r
137 content+="<img src=\"showcaptcha.htm?UUID="+uuid+"\"><br>";
\r
138 content+="<input type=\"hidden\" name=\"uuid["+countstr+"]\" value=\""+uuid+"\">";
\r
139 content+="<input type=\"hidden\" name=\"day["+countstr+"]\" value=\""+day+"\">";
\r
140 content+="<input type=\"text\" name=\"solution["+countstr+"]\">";
\r
141 content+="</td>\r\n";
\r
149 content+="</tr><td colspan=\"4\"><center><input type=\"submit\" value=\"Announce\"></td></tr>";
\r
150 content+="</table>";
\r
151 content+="</form>";
\r
153 return StringFunctions::Replace(m_template,"[CONTENT]",content);
\r
156 const bool AnnounceIdentityPage::WillHandleURI(const std::string &uri)
\r
158 if(uri.find("announceidentity.")!=std::string::npos)
\r