version 0.2.17
[fms.git] / src / http / pages / localidentitiespage.cpp
index 84c28b3..f3a4967 100644 (file)
@@ -1,33 +1,12 @@
 #include "../../../include/http/pages/localidentitiespage.h"\r
 #include "../../../include/stringfunctions.h"\r
 #include "../../../include/http/identityexportxml.h"\r
+#include "../../../include/global.h"\r
 \r
 #ifdef XMEM\r
        #include <xmem.h>\r
 #endif\r
 \r
-const std::string LocalIdentitiesPage::CreateTrueFalseDropDown(const std::string &name, const std::string &selected)\r
-{\r
-       std::string rval="";\r
-\r
-       rval+="<select name=\""+name+"\">";\r
-       rval+="<option value=\"true\"";\r
-       if(selected=="true")\r
-       {\r
-               rval+=" SELECTED";\r
-       }\r
-       rval+=">true</option>";\r
-       rval+="<option value=\"false\"";\r
-       if(selected=="false")\r
-       {\r
-               rval+=" SELECTED";\r
-       }\r
-       rval+=">false</option>";\r
-       rval+="</select>";\r
-\r
-       return rval;\r
-}\r
-\r
 const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, const std::map<std::string,std::string> &queryvars)\r
 {\r
        int count;\r
@@ -40,22 +19,38 @@ const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, c
                std::vector<std::string> ids;\r
                std::vector<std::string> singleuse;\r
                std::vector<std::string> publishtrustlist;\r
+               std::vector<std::string> publishboardlist;\r
+               std::vector<std::string> publishfreesite;\r
+               std::vector<std::string> mindelay;\r
+               std::vector<std::string> maxdelay;\r
 \r
                CreateArgArray(queryvars,"chkidentityid",ids);\r
                CreateArgArray(queryvars,"singleuse",singleuse);\r
                CreateArgArray(queryvars,"publishtrustlist",publishtrustlist);\r
+               CreateArgArray(queryvars,"publishboardlist",publishboardlist);\r
+               CreateArgArray(queryvars,"publishfreesite",publishfreesite);\r
+               CreateArgArray(queryvars,"mindelay",mindelay);\r
+               CreateArgArray(queryvars,"maxdelay",maxdelay);\r
 \r
                if((*queryvars.find("formaction")).second=="update")\r
                {\r
-                       SQLite3DB::Statement update=m_db->Prepare("UPDATE tblLocalIdentity SET SingleUse=?, PublishTrustList=? WHERE LocalIdentityID=?;");\r
+                       SQLite3DB::Statement update=m_db->Prepare("UPDATE tblLocalIdentity SET SingleUse=?, PublishTrustList=?, PublishBoardList=?, PublishFreesite=?, MinMessageDelay=?, MaxMessageDelay=? WHERE LocalIdentityID=?;");\r
                        for(int i=0; i<ids.size(); i++)\r
                        {\r
                                if(ids[i]!="")\r
                                {\r
+                                       int minmessagedelay=0;\r
+                                       int maxmessagedelay=0;\r
                                        StringFunctions::Convert(ids[i],id);\r
+                                       StringFunctions::Convert(mindelay[i],minmessagedelay);\r
+                                       StringFunctions::Convert(maxdelay[i],maxmessagedelay);\r
                                        update.Bind(0,singleuse[i]);\r
                                        update.Bind(1,publishtrustlist[i]);\r
-                                       update.Bind(2,id);\r
+                                       update.Bind(2,publishboardlist[i]);\r
+                                       update.Bind(3,publishfreesite[i]);\r
+                                       update.Bind(4,minmessagedelay);\r
+                                       update.Bind(5,maxmessagedelay);\r
+                                       update.Bind(6,id);\r
                                        update.Step();\r
                                        update.Reset();\r
                                }\r
@@ -78,7 +73,7 @@ const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, c
                if((*queryvars.find("formaction")).second=="export")\r
                {\r
                        IdentityExportXML xml;\r
-                       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
+                       SQLite3DB::Statement exp=m_db->Prepare("SELECT Name,PublicKey,PrivateKey,SingleUse,PublishTrustList,PublishBoardList,PublishFreesite FROM tblLocalIdentity WHERE PublicKey IS NOT NULL AND PrivateKey IS NOT NULL;");\r
                        exp.Step();\r
                        while(exp.RowReturned())\r
                        {\r
@@ -89,6 +84,7 @@ const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, c
                                bool singleuse=false;\r
                                bool publishtrustlist=false;\r
                                bool publishboardlist=false;\r
+                               bool publishfreesite=false;\r
 \r
                                exp.ResultText(0,name);\r
                                exp.ResultText(1,publickey);\r
@@ -108,8 +104,13 @@ const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, c
                                {\r
                                        publishboardlist=true;\r
                                }\r
+                               exp.ResultText(6,tempval);\r
+                               if(tempval=="true")\r
+                               {\r
+                                       publishfreesite=true;\r
+                               }\r
 \r
-                               xml.AddIdentity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist);\r
+                               xml.AddIdentity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist,publishfreesite);\r
 \r
                                exp.Step();\r
                        }\r
@@ -122,7 +123,7 @@ const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, c
                                IdentityExportXML xml;\r
                                if(xml.ParseXML((*queryvars.find("file")).second))\r
                                {\r
-                                       SQLite3DB::Statement imp=m_db->Prepare("INSERT INTO tblLocalIdentity(Name,PublicKey,PrivateKey,SingleUse,PublishTrustList,PublishBoardList) VALUES(?,?,?,?,?,?);");\r
+                                       SQLite3DB::Statement imp=m_db->Prepare("INSERT INTO tblLocalIdentity(Name,PublicKey,PrivateKey,SingleUse,PublishTrustList,PublishBoardList,PublishFreesite) VALUES(?,?,?,?,?,?,?);");\r
                                        for(int i=0; i<xml.GetCount(); i++)\r
                                        {\r
                                                std::string tempval="false";\r
@@ -156,6 +157,15 @@ const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, c
                                                        tempval="false";\r
                                                }\r
                                                imp.Bind(5,tempval);\r
+                                               if(xml.GetPublishFreesite(i))\r
+                                               {\r
+                                                       tempval="true";\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       tempval="false";\r
+                                               }\r
+                                               imp.Bind(6,tempval);\r
                                                imp.Step();\r
                                                imp.Reset();\r
                                        }\r
@@ -180,40 +190,66 @@ const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, c
        content+="</form>";\r
        content+="</td></tr></table>";\r
 \r
-       content+="<form name=\"frmlocalidentity\" method=\"POST\">";\r
-       content+="<input type=\"hidden\" name=\"formaction\" value=\"update\">";\r
-       content+="<table><tr><td></td><th>Name</th><th>Single Use</th><th>Publish Trust List</th><th>Announced? *</th></tr>";\r
+       content+="<hr>";\r
+\r
+//     content+="<form name=\"frmlocalidentity\" method=\"POST\">";\r
+//     content+="<input type=\"hidden\" name=\"formaction\" value=\"update\">";\r
+       content+="<table><tr><th>Name</th><th>Single Use</th><th>Publish Trust List</th><th>Publish Board List</th><th>Publish Freesite</th><th>Min Message Delay</th><th>Max Message Delay</th><th>Announced? *</th></tr>";\r
 \r
-       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
+       SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID,tblLocalIdentity.Name,tblLocalIdentity.PublicKey,tbLLocalIdentity.PublishTrustList,tblLocalIdentity.SingleUse,tblLocalIdentity.PublishBoardList,tblIdentity.IdentityID,tblLocalIdentity.PublishFreesite,tblLocalIdentity.MinMessageDelay,tblLocalIdentity.MaxMessageDelay FROM tblLocalIdentity LEFT JOIN tblIdentity ON tblLocalIdentity.PublicKey=tblIdentity.PublicKey ORDER BY tblLocalIdentity.Name;");\r
        st.Step();\r
 \r
+       SQLite3DB::Statement trustst=m_db->Prepare("SELECT COUNT(*) FROM tblPeerTrust LEFT JOIN tblIdentity ON tblPeerTrust.TargetIdentityID=tblIdentity.IdentityID WHERE tblIdentity.PublicKey=? GROUP BY tblPeerTrust.TargetIdentityID;");\r
+\r
        count=0;\r
        while(st.RowReturned())\r
        {\r
                StringFunctions::Convert(count,countstr);\r
-               std::string id;\r
-               std::string name;\r
-               std::string publickey;\r
-               std::string publishtrustlist;\r
-               std::string singleuse;\r
-               std::string keypart;\r
+               std::string id="";\r
+               std::string name="";\r
+               std::string publickey="";\r
+               std::string publishtrustlist="";\r
+               std::string singleuse="";\r
+               std::string publishboardlist="";\r
+               std::string publishfreesite="";\r
+               std::string minmessagedelay="0";\r
+               std::string maxmessagedelay="0";\r
 \r
                st.ResultText(0,id);\r
                st.ResultText(1,name);\r
                st.ResultText(2,publickey);\r
                st.ResultText(3,publishtrustlist);\r
                st.ResultText(4,singleuse);\r
-\r
-               if(publickey.size()>8)\r
-               {\r
-                       keypart=publickey.substr(3,5);\r
-               }\r
+               st.ResultText(5,publishboardlist);\r
+               st.ResultText(7,publishfreesite);\r
+               st.ResultText(8,minmessagedelay);\r
+               st.ResultText(9,maxmessagedelay);\r
 \r
                content+="<tr>";\r
-               content+="<td><input type=\"checkbox\" name=\"chkidentityid["+countstr+"]\" value=\""+id+"\"></td>";\r
-               content+="<td title=\""+publickey+"\">"+SanitizeOutput(name+keypart)+"...</td>";\r
+//             content+="<td><input type=\"checkbox\" name=\"chkidentityid["+countstr+"]\" value=\""+id+"\"></td>";\r
+               content+="<td title=\""+publickey+"\"><form name=\"frmupdate\""+countstr+"\" method=\"POST\"><input type=\"hidden\" name=\"formaction\" value=\"update\"><input type=\"hidden\" name=\"chkidentityid["+countstr+"]\" value=\""+id+"\">"+SanitizeOutput(CreateShortIdentityName(name,publickey))+"</td>";\r
                content+="<td>"+CreateTrueFalseDropDown("singleuse["+countstr+"]",singleuse)+"</td>";\r
                content+="<td>"+CreateTrueFalseDropDown("publishtrustlist["+countstr+"]",publishtrustlist)+"</td>";\r
+               content+="<td>"+CreateTrueFalseDropDown("publishboardlist["+countstr+"]",publishboardlist)+"</td>";\r
+               content+="<td>"+CreateTrueFalseDropDown("publishfreesite["+countstr+"]",publishfreesite)+"</td>";\r
+               content+="<td><input type=\"text\" size=\"2\" name=\"mindelay["+countstr+"]\" value=\""+minmessagedelay+"\"></td>";\r
+               content+="<td><input type=\"text\" size=\"2\" name=\"maxdelay["+countstr+"]\" value=\""+maxmessagedelay+"\"></td>";\r
+               \r
+               trustst.Bind(0,publickey);\r
+               trustst.Step();\r
+               if(trustst.RowReturned())\r
+               {\r
+                       std::string numlists="";\r
+                       trustst.ResultText(0,numlists);\r
+                       content+="<td>Yes ("+numlists+")</td>";\r
+               }\r
+               else\r
+               {\r
+                       content+="<td>No</td>";\r
+               }\r
+               trustst.Reset();\r
+\r
+/*\r
                if(st.ResultNull(6))\r
                {\r
                        content+="<td>No</td>";\r
@@ -222,14 +258,21 @@ const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, c
                {\r
                        content+="<td>Yes</td>";\r
                }\r
+*/\r
+\r
+               content+="<td><input type=\"submit\" value=\"Update\"></form></td>";\r
+               content+="<td><form name=\"frmdel\""+countstr+"\" method=\"POST\"><input type=\"hidden\" name=\"formaction\" value=\"delete\"><input type=\"hidden\" name=\"chkidentityid["+countstr+"]\" value=\""+id+"\"><input type=\"submit\" value=\"Delete\"></form></td>";\r
                content+="</tr>";\r
+               content+="<tr><td></td><td colspan=\"7\" class=\"smaller\">"+publickey+"</td></tr>";\r
                st.Step();\r
                count++;\r
        }\r
 \r
-       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
+//     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
        content+="</table>";\r
-       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
+       content+="<p class=\"paragraph\">* An identity is considered successfully announced when you have downloaded a trust list from someone that contains the identity.  The number in parenthesis is how many trust lists that identity appears in.</p>";\r
+       content+="<p class=\"paragraph\">Single Use Identities will automatically be deleted 7 days after creation.</p>";\r
+       content+="<p class=\"paragraph\">Messages that each identity sends may be delayed by a random number of minutes between min and max.  Set both to 0 to send messages as soon as possible.</p>";\r
 \r
        return "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"+StringFunctions::Replace(m_template,"[CONTENT]",content);\r
 }\r