X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fhttp%2Fpages%2Fpeertrustpage.cpp;h=ac6b053adc7caecfb63e9f32385d54bac8f5cafa;hb=6836fbb5db8464f56e682989996b2210b14231d0;hp=4a451ed2dd37bf469fafe7ac05bfab8b1c88615c;hpb=37a8d59548287dcad78ef00e7b18058721eb9935;p=fms.git diff --git a/src/http/pages/peertrustpage.cpp b/src/http/pages/peertrustpage.cpp index 4a451ed..ac6b053 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="+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,93 @@ 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); + } + else + { + SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID FROM tblLocalIdentity;"); + st.Step(); + if(st.RowReturned()) + { + st.ResultInt(0,localidentityid); + StringFunctions::Convert(localidentityid,localidentityidstr); + } + } + + if(localidentityid!=-1 && queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="update") { 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+=""; + 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 (SELECT IdentityID FROM tblIdentityTrust WHERE LocalIdentityID=?) AS 'tblIdentityTrust' ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID "; + sql+="WHERE 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 (SELECT LocalIdentityID,IdentityID,LocalMessageTrust,LocalTrustListTrust,MessageTrustComment,TrustListTrustComment FROM tblIdentityTrust WHERE LocalIdentityID=?) AS tblIdentityTrust ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID "; + sql+="WHERE 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 +336,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 +350,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+="
"; @@ -183,6 +448,25 @@ const std::string PeerTrustPage::GetClassString(const std::string &trustlevel) } } +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) { if(uri.find("peertrust.")!=std::string::npos)