version 0.3.24
[fms.git] / src / http / pages / announceidentitypage.cpp
index 81fad96..bf95295 100644 (file)
@@ -1,6 +1,9 @@
 #include "../../../include/http/pages/announceidentitypage.h"\r
 #include "../../../include/stringfunctions.h"\r
-#include "../../../include/datetime.h"\r
+#include "../../../include/global.h"\r
+\r
+#include <Poco/DateTime.h>\r
+#include <Poco/DateTimeFormatter.h>\r
 \r
 #ifdef XMEM\r
        #include <xmem.h>\r
@@ -18,18 +21,12 @@ const std::string AnnounceIdentityPage::CreateLocalIdentityDropDown(const std::s
                std::string id;\r
                std::string name;\r
                std::string pubkey;\r
-               std::string keypart="";\r
 \r
                st.ResultText(0,id);\r
                st.ResultText(1,name);\r
                st.ResultText(2,pubkey);\r
 \r
-               if(pubkey.size()>8)\r
-               {\r
-                       keypart=pubkey.substr(3,5);\r
-               }\r
-\r
-               rval+="<option value=\""+id+"\" title=\""+pubkey+"\">"+SanitizeOutput(name+keypart)+"...</option>";\r
+               rval+="<option value=\""+id+"\" title=\""+pubkey+"\""+(selected==id?" selected":"")+">"+SanitizeOutput(CreateShortIdentityName(name,pubkey))+"</option>";\r
                st.Step();\r
        }\r
        rval+="</select>";\r
@@ -38,7 +35,7 @@ const std::string AnnounceIdentityPage::CreateLocalIdentityDropDown(const std::s
 \r
 const std::string AnnounceIdentityPage::GeneratePage(const std::string &method, const std::map<std::string,std::string> &queryvars)\r
 {\r
-       DateTime date;\r
+       Poco::DateTime date;\r
        std::string content;\r
        int shown=0;\r
        std::string countstr="";\r
@@ -46,13 +43,15 @@ const std::string AnnounceIdentityPage::GeneratePage(const std::string &method,
        std::string lastid="";\r
        std::string thisid="";\r
        std::string day="";\r
+       std::string name="";\r
+       std::string pubkey="";\r
        int requestindex=0;\r
        bool willshow=false;\r
+       std::string localidentityidstr="";\r
 \r
-       if(queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="announce")\r
+       if(queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="announce" && ValidateFormPassword(queryvars))\r
        {\r
                SQLite3DB::Statement insert=m_db->Prepare("INSERT INTO tblIdentityIntroductionInserts(LocalIdentityID,Day,UUID,Solution) VALUES(?,?,?,?);");\r
-               std::string localidentityidstr="";\r
                int localidentityid=0;\r
                std::vector<std::string> uuids;\r
                std::vector<std::string> days;\r
@@ -84,23 +83,22 @@ const std::string AnnounceIdentityPage::GeneratePage(const std::string &method,
 \r
        content+="<h2>Announce Identity</h2>";\r
        content+="<form name=\"frmannounce\" method=\"POST\">";\r
+       content+=CreateFormPassword();\r
        content+="<input type=\"hidden\" name=\"formaction\" value=\"announce\">";\r
        content+="<table>";\r
        content+="<tr><td colspan=\"4\"><center>Select Identity : ";\r
-       content+=CreateLocalIdentityDropDown("localidentityid","");\r
+       content+=CreateLocalIdentityDropDown("localidentityid",localidentityidstr);\r
        content+="</td></tr>";\r
-       content+="<tr><td colspan=\"4\"><center>Type the answers of a few puzzles.  The puzzles are case sensitive.</td></tr>";\r
+       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 and you must assign trust to other identities to see yourself announced.  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
        content+="<tr>";\r
 \r
-\r
-       date.SetToGMTime();\r
-       date.Add(0,0,0,-1);\r
-       SQLite3DB::Statement st=m_db->Prepare("SELECT UUID,Day,IdentityID,RequestIndex 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
+       date-=Poco::Timespan(1,0,0,0,0);\r
+       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
        st.Step();\r
 \r
        if(st.RowReturned()==false)\r
        {\r
-               content+="<td colspan=\"4\"><center>You must wait for some puzzles to be downloaded.  Check back later.</td>";\r
+               content+="<td colspan=\"4\"><center>You must wait for some puzzles to be downloaded.  Make sure you have assigned trust to some other identities' trust lists and check back later.</td>";\r
        }\r
        \r
        while(st.RowReturned() && shown<20)\r
@@ -109,12 +107,14 @@ const std::string AnnounceIdentityPage::GeneratePage(const std::string &method,
                st.ResultText(1,day);\r
                st.ResultText(2,thisid);\r
                st.ResultInt(3,requestindex);\r
+               st.ResultText(4,name);\r
+               st.ResultText(5,pubkey);\r
 \r
                // 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
                // get the last index # we are inserting this day from this identity\r
                // 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
                willshow=true;\r
-               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=?) GROUP BY tblIdentityIntroductionInserts.Day;");\r
+               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
                st2.Step();\r
                if(st2.RowReturned()==true)\r
                {\r
@@ -133,7 +133,7 @@ const std::string AnnounceIdentityPage::GeneratePage(const std::string &method,
                        {\r
                                content+="</tr>\r\n<tr>";\r
                        }\r
-                       content+="<td>";\r
+                       content+="<td title=\"From "+SanitizeOutput(CreateShortIdentityName(name,pubkey))+"\">";\r
                        content+="<img src=\"showcaptcha.htm?UUID="+uuid+"\"><br>";\r
                        content+="<input type=\"hidden\" name=\"uuid["+countstr+"]\" value=\""+uuid+"\">";\r
                        content+="<input type=\"hidden\" name=\"day["+countstr+"]\" value=\""+day+"\">";\r
@@ -150,7 +150,7 @@ const std::string AnnounceIdentityPage::GeneratePage(const std::string &method,
        content+="</table>";\r
        content+="</form>";\r
 \r
-       return "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"+StringFunctions::Replace(m_template,"[CONTENT]",content);\r
+       return StringFunctions::Replace(m_template,"[CONTENT]",content);\r
 }\r
 \r
 const bool AnnounceIdentityPage::WillHandleURI(const std::string &uri)\r