X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fhttp%2Fpages%2Fpeertrustpage.cpp;h=3fee7ace757741dc23d2f27acfc657d63a9604a0;hb=fcb124f8d6d3f5678e82049fb8e5e23c8cfaec6d;hp=a9ac96f60feede26466a5ba8f46d5406f61e2758;hpb=f208e33c29132aacaec448e74341edea1b925a2a;p=fms.git diff --git a/src/http/pages/peertrustpage.cpp b/src/http/pages/peertrustpage.cpp index a9ac96f..3fee7ac 100644 --- a/src/http/pages/peertrustpage.cpp +++ b/src/http/pages/peertrustpage.cpp @@ -1,46 +1,214 @@ #include "../../../include/http/pages/peertrustpage.h" #include "../../../include/stringfunctions.h" +#include "../../../include/global.h" #ifdef XMEM #include #endif +const std::string PeerTrustPage::BuildQueryString(const long startrow, const std::string &namesearch, const std::string &sortby, const std::string &sortorder, const int localidentityid) +{ + std::string returnval=""; + std::string tempval=""; + + if(startrow>=0) + { + StringFunctions::Convert(startrow,tempval); + returnval+="startrow="+tempval; + } + + if(namesearch!="") + { + if(returnval!="") + { + returnval+="&"; + } + returnval+="namesearch="+namesearch; + } + + if(sortby!="") + { + if(returnval!="") + { + returnval+="&"; + } + returnval+="sortby="+sortby; + } + + if(sortorder!="") + { + if(returnval!="") + { + returnval+="&"; + } + returnval+="sortorder="+sortorder; + } + + if(localidentityid>=0) + { + std::string localidentityidstr=""; + StringFunctions::Convert(localidentityid,localidentityidstr); + if(returnval!="") + { + returnval+="&"; + } + returnval+="localidentityid="+localidentityidstr; + } + + return returnval; + +} + +const std::string PeerTrustPage::CreateLocalIdentityDropDown(const std::string &name, const int selectedlocalidentityid) +{ + std::string result=""; + + result+=""; + + return result; +} + const std::string PeerTrustPage::GeneratePage(const std::string &method, const std::map &queryvars) { int count=0; std::string countstr; std::string content=""; + int identitycount=0; // total number of ids we know + int rowsperpage=25; // how many ids to show per page + std::string rowsperpagestr; + int startrow=0; + std::string startrowstr="0"; + std::string namesearch=""; + std::string sql; + std::string sortby=""; + std::string sortorder=""; + std::string localidentityidstr=""; + int localidentityid=-1; + + StringFunctions::Convert(rowsperpage,rowsperpagestr); - if(queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="update") + // get localidentityid from querystring or load one from the database + if(queryvars.find("localidentityid")!=queryvars.end()) + { + localidentityidstr=(*queryvars.find("localidentityid")).second; + StringFunctions::Convert(localidentityidstr,localidentityid); + // insert the ID into the temporary table so we remember the identity if we load the page later + m_db->Execute("DELETE FROM tmpLocalIdentityPeerTrustPage;"); + SQLite3DB::Statement st=m_db->Prepare("INSERT INTO tmpLocalIdentityPeerTrustPage(LocalIdentityID) VALUES(?);"); + st.Bind(0,localidentityid); + st.Step(); + } + else + { + // try to get the localidentityid if it exists in the temp table, otherwise load the first identity in the database + SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID FROM tmpLocalIdentityPeerTrustPage;"); + st.Step(); + if(st.RowReturned()) + { + st.ResultInt(0,localidentityid); + StringFunctions::Convert(localidentityid,localidentityidstr); + } + else + { + st=m_db->Prepare("SELECT LocalIdentityID FROM tblLocalIdentity;"); + st.Step(); + if(st.RowReturned()) + { + st.ResultInt(0,localidentityid); + StringFunctions::Convert(localidentityid,localidentityidstr); + } + st.Finalize(); + } + } + + if(localidentityid!=-1 && queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="update" && ValidateFormPassword(queryvars)) { std::vector identityids; std::vector oldlmt; std::vector lmt; std::vector oldltlt; std::vector ltlt; + std::vector oldmtc; + std::vector mtc; + std::vector oldtltc; + std::vector tltc; int localmessagetrust=0; int localtrustlisttrust=0; - int identityid; + int identityid=-1; CreateArgArray(queryvars,"identityid",identityids); CreateArgArray(queryvars,"oldlocalmessagetrust",oldlmt); CreateArgArray(queryvars,"localmessagetrust",lmt); CreateArgArray(queryvars,"oldlocaltrustlisttrust",oldltlt); CreateArgArray(queryvars,"localtrustlisttrust",ltlt); - - SQLite3DB::Statement update=m_db->Prepare("UPDATE tblIdentity SET LocalMessageTrust=?, LocalTrustListTrust=? WHERE IdentityID=?;"); + CreateArgArray(queryvars,"oldmessagetrustcomment",oldmtc); + CreateArgArray(queryvars,"messagetrustcomment",mtc); + CreateArgArray(queryvars,"oldtrustlisttrustcomment",oldtltc); + CreateArgArray(queryvars,"trustlisttrustcomment",tltc); + + SQLite3DB::Statement ins=m_db->Prepare("INSERT INTO tblIdentityTrust(LocalIdentityID,IdentityID) VALUES(?,?);"); + SQLite3DB::Statement update=m_db->Prepare("UPDATE tblIdentityTrust SET LocalMessageTrust=?, LocalTrustListTrust=?, MessageTrustComment=?, TrustListTrustComment=? WHERE LocalIdentityID=? AND IdentityID=?;"); for(int i=0; i"; + content+="
"; + content+=""; + content+=""; + content+="
"; + content+=""; + + content+="
"; + content+="
"; + content+="Load Trust List of "; + content+=CreateLocalIdentityDropDown("localidentityid",localidentityid); + content+=""; + content+="
"; + content+="
"; + content+="
"; + content+=CreateFormPassword(); content+=""; - content+=""; - content+=""; + content+=""; + content+=""; + if(namesearch!="") + { + content+=""; + } + content+="
NameLocal Message TrustPeer Message TrustLocal Trust List TrustPeer Trust List Trust
"; + content+=""; + content+=""; + content+=""; + content+=""; + content+=""; + content+=""; + content+=""; + content+=""; + content+="\r\n"; - SQLite3DB::Statement st=m_db->Prepare("SELECT IdentityID,Name,LocalMessageTrust,PeerMessageTrust,LocalTrustListTrust,PeerTrustListTrust,PublicKey FROM tblIdentity ORDER BY Name;"); + // get count of identities we are showing + sql="SELECT COUNT(*) FROM tblIdentity LEFT JOIN tblIdentityTrust ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID "; + sql+="WHERE tblIdentity.Hidden='false' AND tblIdentityTrust.LocalIdentityID=?"; + if(namesearch!="") + { + sql+=" AND (Name LIKE '%' || ? || '%' OR PublicKey LIKE '%' || ? || '%')"; + } + sql+=";"; + SQLite3DB::Statement st=m_db->Prepare(sql); + st.Bind(0,localidentityid); + if(namesearch!="") + { + st.Bind(1,namesearch); + st.Bind(2,namesearch); + } + st.Step(); + st.ResultInt(0,identitycount); + st.Finalize(); + + sql="SELECT tblIdentity.IdentityID,Name,tblIdentityTrust.LocalMessageTrust,PeerMessageTrust,tblIdentityTrust.LocalTrustListTrust,PeerTrustListTrust,PublicKey,tblIdentityTrust.MessageTrustComment,tblIdentityTrust.TrustListTrustComment,COUNT(MessageID) AS 'MessageCount',tblIdentity.PublishTrustList "; + sql+="FROM tblIdentity LEFT JOIN tblIdentityTrust ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID "; + sql+="WHERE tblIdentity.Hidden='false' AND tblIdentityTrust.LocalIdentityID=?"; + if(namesearch!="") + { + sql+=" AND (Name LIKE '%' || ? || '%' OR PublicKey LIKE '%' || ? || '%')"; + } + sql+=" GROUP BY tblIdentity.IdentityID"; + sql+=" ORDER BY"; + if(sortby=="Name") + { + sql+=" Name COLLATE NOCASE"; + } + else + { + sql+=" "+sortby; + } + if(sortorder!="") + { + sql+=" "+sortorder; + } + sql+=" LIMIT "+startrowstr+","+rowsperpagestr+";"; + st=m_db->Prepare(sql); + st.Bind(0,localidentityid); + if(namesearch!="") + { + st.Bind(1,namesearch); + st.Bind(2,namesearch); + } st.Step(); while(st.RowReturned()) @@ -67,6 +354,10 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s std::string localtrustlisttrust; std::string peertrustlisttrust; std::string publickey; + std::string messagetrustcomment=""; + std::string trustlisttrustcomment=""; + std::string messagecountstr=""; + std::string publishtrustlist=""; StringFunctions::Convert(count,countstr); @@ -77,37 +368,121 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s st.ResultText(4,localtrustlisttrust); st.ResultText(5,peertrustlisttrust); st.ResultText(6,publickey); + st.ResultText(7,messagetrustcomment); + st.ResultText(8,trustlisttrustcomment); + st.ResultText(9,messagecountstr); + st.ResultText(10,publishtrustlist); content+=""; content+=""; - content+=""; - content+=""; - content+=""; + content+=""; + content+=""; + content+=""; - content+=""; - content+=""; + content+=""; + if(publishtrustlist=="false") + { + content+="*"; + } + content+=""; + content+=""; + content+=""; + content+=""; + content+="\r\n"; st.Step(); count++; } + + if(startrow>0 || startrow+rowsperpage"; + content+=""; + if(startrow>0) + { + StringFunctions::Convert(startrow-rowsperpage,tempstr); + content+=""; + cols+=3; + } + if(startrow+rowsperpageNext Page -->"; + } + content+=""; + } + + content+=""; content+="
NameLocal Message TrustMessage CommentPeer Message TrustLocal Trust List TrustTrust CommentPeer Trust List TrustMessage Count
"; content+=""; + content+=""; if(name!="") { - content+=name; + content+=SanitizeOutput(CreateShortIdentityName(name,publickey)); } else { content+="[Unknown Name]"; } + content+=""; content+=""; + content+=""; content+=""; - content+=""+peermessagetrust+""; + content+=""; + content+=""; + content+=""; + content+=""; + content+=peermessagetrust+""; content+=""; - content+=""+peertrustlisttrust+"
"; + content+=""; + content+=""; + content+=""; + content+=peertrustlisttrust+""+messagecountstr+"
<-- Previous Page
"; content+="
"; - 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); +} + +const std::string PeerTrustPage::GetClassString(const std::string &trustlevel) +{ + int tempint=0; + std::string tempstr; + + StringFunctions::Convert(trustlevel,tempint); + tempint/=10; + StringFunctions::Convert(tempint,tempstr); + + if(trustlevel!="") + { + return "class=\"trust"+tempstr+"\""; + } + else + { + return ""; + } +} + +const std::string PeerTrustPage::ReverseSort(const std::string &sortname, const std::string ¤tsortby, const std::string ¤tsortorder) +{ + if(sortname==currentsortby) + { + if(currentsortorder=="ASC") + { + return "DESC"; + } + else + { + return "ASC"; + } + } + else + { + return currentsortorder; + } } const bool PeerTrustPage::WillHandleURI(const std::string &uri)