X-Git-Url: https://git.pterodactylus.net/?p=fms.git;a=blobdiff_plain;f=src%2Fhttp%2Fpages%2Flocalidentitiespage.cpp;h=5fa76b5053c239d1ac667b646238835821a4ac0a;hp=9aca3f3f226f015601f3b792d5b7838d714ab73b;hb=dec33c63afafabf83c3039e916725cac6faef9b3;hpb=9b22dd53fe62e312c1647310b7ec43aa127090af diff --git a/src/http/pages/localidentitiespage.cpp b/src/http/pages/localidentitiespage.cpp index 9aca3f3..5fa76b5 100644 --- a/src/http/pages/localidentitiespage.cpp +++ b/src/http/pages/localidentitiespage.cpp @@ -13,167 +13,6 @@ const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, c std::string countstr; std::string content=""; - if(queryvars.find("formaction")!=queryvars.end()) - { - 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); - - if((*queryvars.find("formaction")).second=="update") - { - SQLite3DB::Statement update=m_db->Prepare("UPDATE tblLocalIdentity SET SingleUse=?, PublishTrustList=?, PublishBoardList=?, PublishFreesite=?, MinMessageDelay=?, MaxMessageDelay=? WHERE LocalIdentityID=?;"); - for(int i=0; iPrepare("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 "HTTP/1.1 200 OK\r\nContent-Type: text/xml\r\nContent-Disposition: attachment; filename=identities.xml\r\n\r\n"+xml.GetXML(); - } - if((*queryvars.find("formaction")).second=="import") - { - 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; i"; -// content+=""; content+=""; 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;"); @@ -226,7 +63,6 @@ const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, c st.ResultText(9,maxmessagedelay); content+=""; -// content+=""; content+=""; content+=""; content+=""; @@ -249,17 +85,6 @@ const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, c } trustst.Reset(); -/* - if(st.ResultNull(6)) - { - content+=""; - } - else - { - content+=""; - } -*/ - content+=""; content+=""; content+=""; @@ -268,13 +93,218 @@ const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, c count++; } -// content+=""; content+="
NameSingle UsePublish Trust ListPublish Board ListPublish FreesiteMin Message DelayMax Message DelayAnnounced? *
"+SanitizeOutput(CreateShortIdentityName(name,publickey))+"
"+CreateTrueFalseDropDown("singleuse["+countstr+"]",singleuse)+""+CreateTrueFalseDropDown("publishtrustlist["+countstr+"]",publishtrustlist)+"NoYes
"; 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 "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"+StringFunctions::Replace(m_template,"[CONTENT]",content); + 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()) + { + 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