X-Git-Url: https://git.pterodactylus.net/?p=fms.git;a=blobdiff_plain;f=src%2Fhttp%2Fpages%2Fpeertrustpage.cpp;h=b90a1060c0c6fb754b9e62e9d0b3642a4f510447;hp=4a451ed2dd37bf469fafe7ac05bfab8b1c88615c;hb=HEAD;hpb=37a8d59548287dcad78ef00e7b18058721eb9935 diff --git a/src/http/pages/peertrustpage.cpp b/src/http/pages/peertrustpage.cpp index 4a451ed..b90a106 100644 --- a/src/http/pages/peertrustpage.cpp +++ b/src/http/pages/peertrustpage.cpp @@ -1,10 +1,100 @@ #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="+StringFunctions::UriEncode(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; @@ -15,39 +105,110 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s 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 COUNT(*) FROM tblIdentity;"); + // get count of identities we are showing + sql="SELECT COUNT(*) FROM tblIdentity LEFT JOIN tblIdentityTrust ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID "; + sql+="WHERE tblIdentityTrust.LocalIdentityID=? AND tblIdentity.Hidden='false'"; + 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(); - st=m_db->Prepare("SELECT IdentityID,Name,LocalMessageTrust,PeerMessageTrust,LocalTrustListTrust,PeerTrustListTrust,PublicKey FROM tblIdentity ORDER BY Name COLLATE NOCASE LIMIT "+startrowstr+","+rowsperpagestr+";"); + 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 tblIdentityTrust.LocalIdentityID=? AND tblIdentity.Hidden='false'"; + 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()) @@ -93,6 +362,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); @@ -103,37 +376,56 @@ 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+=""; + if(publishtrustlist=="false") + { + content+="*"; + } + content+=""; + content+=""; content+=""; - content+=""; + content+=""; + content+="\r\n"; st.Step(); count++; } if(startrow>0 || startrow+rowsperpage0) { StringFunctions::Convert(startrow-rowsperpage,tempstr); - content+=""; - cols+=2; + content+=""; + cols+=3; } if(startrow+rowsperpageNext Page -->"; + content+=""; } content+=""; } - 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+=""; + content+=""; + content+=""; content+=peermessagetrust+""; content+=""; - content+=""; + content+=""; + content+=""; + content+=""; content+=peertrustlisttrust+"
"+messagecountstr+"
<-- Previous Page<-- Previous PageNext 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) @@ -183,14 +474,21 @@ const std::string PeerTrustPage::GetClassString(const std::string &trustlevel) } } -const bool PeerTrustPage::WillHandleURI(const std::string &uri) +const std::string PeerTrustPage::ReverseSort(const std::string &sortname, const std::string ¤tsortby, const std::string ¤tsortorder) { - if(uri.find("peertrust.")!=std::string::npos) + if(sortname==currentsortby) { - return true; + if(currentsortorder=="ASC") + { + return "DESC"; + } + else + { + return "ASC"; + } } else { - return false; + return currentsortorder; } }