X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fhttp%2Fpages%2Flocalidentitiespage.cpp;h=400260f6cf0091f2932d266cfc2d0f0abf56602e;hb=dabd19d7f764b8275c9c8370c7b89675b6a78243;hp=8b6afcb8ff317691ec4e01968db8866010e99753;hpb=8a0a83a78390f22f99d4487cda2569909dfbc28e;p=fms.git diff --git a/src/http/pages/localidentitiespage.cpp b/src/http/pages/localidentitiespage.cpp index 8b6afcb..400260f 100644 --- a/src/http/pages/localidentitiespage.cpp +++ b/src/http/pages/localidentitiespage.cpp @@ -1,200 +1,30 @@ #include "../../../include/http/pages/localidentitiespage.h" #include "../../../include/stringfunctions.h" #include "../../../include/http/identityexportxml.h" +#include "../../../include/global.h" #ifdef XMEM #include #endif -const std::string LocalIdentitiesPage::CreateTrueFalseDropDown(const std::string &name, const std::string &selected) -{ - std::string rval=""; - - rval+=""; content+=""; content+=""; content+=""; content+="
"; + content+=CreateFormPassword(); content+=""; content+=""; content+=""; @@ -203,12 +33,13 @@ const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, c content+="
"; - content+=""; - content+=""; - content+=""; + content+="
NameSingle UsePublish Trust ListPublish Board ListPublish FreesiteAnnounced? *
"; - SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID,tblLocalIdentity.Name,tblLocalIdentity.PublicKey,tbLLocalIdentity.PublishTrustList,tblLocalIdentity.SingleUse,tblLocalIdentity.PublishBoardList,tblIdentity.IdentityID,tblLocalIdentity.PublishFreesite FROM tblLocalIdentity LEFT JOIN tblIdentity ON tblLocalIdentity.PublicKey=tblIdentity.PublicKey ORDER BY tblLocalIdentity.Name;"); + 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;"); st.Step(); + SQLite3DB::Statement st2=m_db->Prepare("SELECT IdentityID FROM tblIdentity WHERE PublicKey=?;"); + + 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;"); count=0; while(st.RowReturned()) @@ -219,9 +50,11 @@ const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, c std::string publickey=""; std::string publishtrustlist=""; std::string singleuse=""; - std::string keypart=""; std::string publishboardlist=""; std::string publishfreesite=""; + std::string minmessagedelay="0"; + std::string maxmessagedelay="0"; + std::string identityidstr=""; st.ResultText(0,id); st.ResultText(1,name); @@ -230,38 +63,270 @@ const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, c st.ResultText(4,singleuse); st.ResultText(5,publishboardlist); st.ResultText(7,publishfreesite); + st.ResultText(8,minmessagedelay); + st.ResultText(9,maxmessagedelay); - if(publickey.size()>8) + st2.Bind(0,publickey); + st2.Step(); + if(st2.RowReturned()) { - keypart=publickey.substr(3,5); + st2.ResultText(0,identityidstr); } + st2.Reset(); content+=""; - content+=""; - content+=""; + content+=""; content+=""; content+=""; content+=""; content+=""; - if(st.ResultNull(6)) + content+=""; + content+=""; + + trustst.Bind(0,publickey); + trustst.Step(); + if(trustst.RowReturned()) { - content+=""; + std::string numlists=""; + trustst.ResultText(0,numlists); + content+=""; } else { - content+=""; + content+=""; } + trustst.Reset(); + + content+=""; + content+=""; content+=""; + content+=""; st.Step(); count++; } - content+=""; content+="
NameSingle UsePublish Trust ListPublish Board ListPublish FreesiteMin Message DelayMax Message DelayAnnounced? *
"+SanitizeOutput(name+keypart)+"..."+CreateFormPassword()+""; + if(identityidstr!="") + { + content+=""; + } + content+=SanitizeOutput(CreateShortIdentityName(name,publickey)); + if(identityidstr!="") + { + content+=""; + } + content+=""+CreateTrueFalseDropDown("singleuse["+countstr+"]",singleuse)+""+CreateTrueFalseDropDown("publishtrustlist["+countstr+"]",publishtrustlist)+""+CreateTrueFalseDropDown("publishboardlist["+countstr+"]",publishboardlist)+""+CreateTrueFalseDropDown("publishfreesite["+countstr+"]",publishfreesite)+"NoYes ("+numlists+")YesNo
"+CreateFormPassword()+"
"+publickey+"
"; - content+="

* An identity is considered successfully announced when you have downloaded a trust list from someone that contains the identity.

"; + content+="

* 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.

"; content+="

Single Use Identities will automatically be deleted 7 days after creation.

"; + content+="

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.

"; + + return StringFunctions::Replace(m_template,"[CONTENT]",content); +} + +void LocalIdentitiesPage::HandleDelete(const std::map &queryvars) +{ + int id=0; + std::vector ids; + CreateArgArray(queryvars,"chkidentityid",ids); + + SQLite3DB::Statement del=m_db->Prepare("DELETE FROM tblLocalIdentity WHERE LocalIdentityID=?;"); + for(int i=0; iPrepare("SELECT Name,PublicKey,PrivateKey,SingleUse,PublishTrustList,PublishBoardList,PublishFreesite FROM tblLocalIdentity WHERE PublicKey IS NOT NULL AND PrivateKey IS NOT NULL;"); + exp.Step(); + while(exp.RowReturned()) + { + std::string name=""; + std::string publickey=""; + std::string privatekey=""; + std::string tempval=""; + bool singleuse=false; + bool publishtrustlist=false; + bool publishboardlist=false; + bool publishfreesite=false; + + exp.ResultText(0,name); + exp.ResultText(1,publickey); + exp.ResultText(2,privatekey); + exp.ResultText(3,tempval); + if(tempval=="true") + { + singleuse=true; + } + exp.ResultText(4,tempval); + if(tempval=="true") + { + publishtrustlist=true; + } + exp.ResultText(5,tempval); + if(tempval=="true") + { + publishboardlist=true; + } + exp.ResultText(6,tempval); + if(tempval=="true") + { + publishfreesite=true; + } + + xml.AddIdentity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist,publishfreesite); + + exp.Step(); + } + return xml.GetXML(); +} + +void LocalIdentitiesPage::HandleImport(const std::map &queryvars) +{ + if(queryvars.find("file")!=queryvars.end()) + { + IdentityExportXML xml; + if(xml.ParseXML((*queryvars.find("file")).second)) + { + SQLite3DB::Statement imp=m_db->Prepare("INSERT INTO tblLocalIdentity(Name,PublicKey,PrivateKey,SingleUse,PublishTrustList,PublishBoardList,PublishFreesite) VALUES(?,?,?,?,?,?,?);"); + for(int i=0; itrace("LocalIdentitiesPages::handleRequest from "+request.clientAddress().toString()); + + std::map vars; + CreateQueryVarMap(request,vars); + + std::string formaction=""; + if(vars.find("formaction")!=vars.end() && ValidateFormPassword(vars)) + { + formaction=(*vars.find("formaction")).second; + if(formaction=="update") + { + HandleUpdate(vars); + } + else if(formaction=="delete") + { + HandleDelete(vars); + } + else if(formaction=="export") + { + response.setChunkedTransferEncoding(true); + response.setContentType("application/xml"); + response.set("Content-Disposition","attachment; filename=identities.xml"); + std::ostream &out=response.send(); + out << HandleExport(); + return; + } + else if(formaction=="import") + { + HandleImport(vars); + } + } + + response.setChunkedTransferEncoding(true); + response.setContentType("text/html"); + + std::ostream &ostr = response.send(); + ostr << GeneratePage(request.getMethod(),vars); +} + +void LocalIdentitiesPage::HandleUpdate(const std::map &queryvars) +{ + int id; + std::vector ids; + std::vector singleuse; + std::vector publishtrustlist; + std::vector publishboardlist; + std::vector publishfreesite; + std::vector mindelay; + std::vector maxdelay; + + CreateArgArray(queryvars,"chkidentityid",ids); + CreateArgArray(queryvars,"singleuse",singleuse); + CreateArgArray(queryvars,"publishtrustlist",publishtrustlist); + CreateArgArray(queryvars,"publishboardlist",publishboardlist); + CreateArgArray(queryvars,"publishfreesite",publishfreesite); + CreateArgArray(queryvars,"mindelay",mindelay); + CreateArgArray(queryvars,"maxdelay",maxdelay); + + SQLite3DB::Statement update=m_db->Prepare("UPDATE tblLocalIdentity SET SingleUse=?, PublishTrustList=?, PublishBoardList=?, PublishFreesite=?, MinMessageDelay=?, MaxMessageDelay=? WHERE LocalIdentityID=?;"); + for(int i=0; i