1 #include "../../../include/http/pages/peertrustpage.h"
\r
2 #include "../../../include/stringfunctions.h"
\r
3 #include "../../../include/global.h"
\r
9 const std::string PeerTrustPage::BuildQueryString(const long startrow, const std::string &namesearch, const std::string &sortby, const std::string &sortorder, const int localidentityid)
\r
11 std::string returnval="";
\r
12 std::string tempval="";
\r
16 StringFunctions::Convert(startrow,tempval);
\r
17 returnval+="startrow="+tempval;
\r
26 returnval+="namesearch="+namesearch;
\r
35 returnval+="sortby="+sortby;
\r
44 returnval+="sortorder="+sortorder;
\r
47 if(localidentityid>=0)
\r
49 std::string localidentityidstr="";
\r
50 StringFunctions::Convert(localidentityid,localidentityidstr);
\r
55 returnval+="localidentityid="+localidentityidstr;
\r
62 const std::string PeerTrustPage::CreateLocalIdentityDropDown(const std::string &name, const int selectedlocalidentityid)
\r
64 std::string result="";
\r
66 result+="<select name=\""+name+"\">";
\r
68 SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID,Name,PublicKey FROM tblLocalIdentity WHERE PublicKey IS NOT NULL ORDER BY Name COLLATE NOCASE;");
\r
71 while(st.RowReturned())
\r
73 int localidentityid=-1;
\r
74 std::string localidentityidstr="";
\r
75 std::string name="";
\r
76 std::string publickey="";
\r
78 st.ResultInt(0,localidentityid);
\r
79 st.ResultText(1,name);
\r
80 st.ResultText(2,publickey);
\r
82 StringFunctions::Convert(localidentityid,localidentityidstr);
\r
84 result+="<option value=\""+localidentityidstr+"\"";
\r
85 if(localidentityid==selectedlocalidentityid)
\r
87 result+=" SELECTED";
\r
89 result+=">"+SanitizeOutput(CreateShortIdentityName(name,publickey))+"</option>";
\r
93 result+="</select>";
\r
98 const std::string PeerTrustPage::GeneratePage(const std::string &method, const std::map<std::string,std::string> &queryvars)
\r
101 std::string countstr;
\r
102 std::string content="";
\r
103 int identitycount=0; // total number of ids we know
\r
104 int rowsperpage=25; // how many ids to show per page
\r
105 std::string rowsperpagestr;
\r
107 std::string startrowstr="0";
\r
108 std::string namesearch="";
\r
110 std::string sortby="";
\r
111 std::string sortorder="";
\r
112 std::string localidentityidstr="";
\r
113 int localidentityid=-1;
\r
115 StringFunctions::Convert(rowsperpage,rowsperpagestr);
\r
117 // get localidentityid from querystring or load one from the database
\r
118 if(queryvars.find("localidentityid")!=queryvars.end())
\r
120 localidentityidstr=(*queryvars.find("localidentityid")).second;
\r
121 StringFunctions::Convert(localidentityidstr,localidentityid);
\r
125 SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID FROM tblLocalIdentity;");
\r
127 if(st.RowReturned())
\r
129 st.ResultInt(0,localidentityid);
\r
130 StringFunctions::Convert(localidentityid,localidentityidstr);
\r
134 if(localidentityid!=-1 && queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="update")
\r
136 std::vector<std::string> identityids;
\r
137 std::vector<std::string> oldlmt;
\r
138 std::vector<std::string> lmt;
\r
139 std::vector<std::string> oldltlt;
\r
140 std::vector<std::string> ltlt;
\r
141 std::vector<std::string> oldmtc;
\r
142 std::vector<std::string> mtc;
\r
143 std::vector<std::string> oldtltc;
\r
144 std::vector<std::string> tltc;
\r
145 int localmessagetrust=0;
\r
146 int localtrustlisttrust=0;
\r
149 CreateArgArray(queryvars,"identityid",identityids);
\r
150 CreateArgArray(queryvars,"oldlocalmessagetrust",oldlmt);
\r
151 CreateArgArray(queryvars,"localmessagetrust",lmt);
\r
152 CreateArgArray(queryvars,"oldlocaltrustlisttrust",oldltlt);
\r
153 CreateArgArray(queryvars,"localtrustlisttrust",ltlt);
\r
154 CreateArgArray(queryvars,"oldmessagetrustcomment",oldmtc);
\r
155 CreateArgArray(queryvars,"messagetrustcomment",mtc);
\r
156 CreateArgArray(queryvars,"oldtrustlisttrustcomment",oldtltc);
\r
157 CreateArgArray(queryvars,"trustlisttrustcomment",tltc);
\r
159 SQLite3DB::Statement ins=m_db->Prepare("INSERT INTO tblIdentityTrust(LocalIdentityID,IdentityID) VALUES(?,?);");
\r
160 SQLite3DB::Statement update=m_db->Prepare("UPDATE tblIdentityTrust SET LocalMessageTrust=?, LocalTrustListTrust=?, MessageTrustComment=?, TrustListTrustComment=? WHERE LocalIdentityID=? AND IdentityID=?;");
\r
162 for(int i=0; i<identityids.size(); i++)
\r
164 if(oldlmt[i]!=lmt[i] || oldltlt[i]!=ltlt[i] || oldmtc[i]!=mtc[i] || oldtltc[i]!=tltc[i])
\r
166 StringFunctions::Convert(lmt[i],localmessagetrust);
\r
167 StringFunctions::Convert(ltlt[i],localtrustlisttrust);
\r
168 StringFunctions::Convert(identityids[i],identityid);
\r
170 ins.Bind(0,localidentityid);
\r
171 ins.Bind(1,identityid);
\r
177 update.Bind(0,localmessagetrust);
\r
185 update.Bind(1,localtrustlisttrust);
\r
191 update.Bind(2,mtc[i]);
\r
192 update.Bind(3,tltc[i]);
\r
193 update.Bind(4,localidentityid);
\r
194 update.Bind(5,identityid);
\r
202 // if startrow is specified
\r
203 if(queryvars.find("startrow")!=queryvars.end())
\r
205 startrowstr=(*queryvars.find("startrow")).second;
\r
206 // convert back and forth, just in case a number wasn't passed in startrow
\r
207 StringFunctions::Convert(startrowstr,startrow);
\r
212 StringFunctions::Convert(startrow,startrowstr);
\r
216 if(queryvars.find("sortby")!=queryvars.end())
\r
218 sortby=(*queryvars.find("sortby")).second;
\r
226 if(queryvars.find("sortorder")!=queryvars.end())
\r
228 sortorder=(*queryvars.find("sortorder")).second;
\r
235 // if we are searching by name
\r
236 if(queryvars.find("namesearch")!=queryvars.end())
\r
238 namesearch=(*queryvars.find("namesearch")).second;
\r
241 content+="<h2>Peer Trust</h2>";
\r
242 content+="Message Trust is how much you trust the identity to post good messages. Trust List Trust is how much weight you want the trust list of that identity to have when calculating the total. The local trust levels are set by you, and the peer trust levels are calculated by a weighted average using other identities' trust lists. Trust is recalculated once an hour from received trust lists. You must have at least 1 identity created and have received the SSK keypair for it from Freenet before setting trust.<br>";
\r
243 content+="* - This identity is not publishing a trust list<br>";
\r
245 // search drop down
\r
246 content+="<div style=\"text-align:center;margin-bottom:5px;\">";
\r
247 content+="<form name=\"frmsearch\" method=\"POST\" action=\"peertrust.htm?"+BuildQueryString(0,"","","",localidentityid)+"\">";
\r
248 content+="<input type=\"text\" name=\"namesearch\" value=\""+SanitizeOutput(namesearch)+"\">";
\r
249 content+="<input type=\"submit\" value=\"Search\">";
\r
250 content+="</form>";
\r
253 content+="<div style=\"text-align:center;\">";
\r
254 content+="<form name=\"frmlocalidentity\" method=\"POST\" action=\"peertrust.htm?"+BuildQueryString(startrow,namesearch,sortby,sortorder,-1)+"\">";
\r
255 content+="Load Trust List of ";
\r
256 content+=CreateLocalIdentityDropDown("localidentityid",localidentityid);
\r
257 content+="<input type=\"submit\" value=\"Load List\">";
\r
258 content+="</form>";
\r
261 content+="<form name=\"frmtrust\" method=\"POST\">";
\r
262 content+="<input type=\"hidden\" name=\"formaction\" value=\"update\">";
\r
263 content+="<input type=\"hidden\" name=\"localidentityid\" value=\""+localidentityidstr+"\">";
\r
264 content+="<input type=\"hidden\" name=\"startrow\" value=\""+startrowstr+"\">";
\r
267 content+="<input type=\"hidden\" name=\"namesearch\" value=\""+SanitizeOutput(namesearch)+"\">";
\r
269 content+="<table class=\"small90\">";
\r
270 content+="<tr><th><a href=\"peertrust.htm?"+BuildQueryString(startrow,namesearch,"Name",ReverseSort("Name",sortby,sortorder),localidentityid)+"\">Name</a></th>";
\r
271 content+="<th><a href=\"peertrust.htm?"+BuildQueryString(startrow,namesearch,"tblIdentityTrust.LocalMessageTrust",ReverseSort("tblIdentityTrust.LocalMessageTrust",sortby,sortorder),localidentityid)+"\">Local Message Trust</a></th>";
\r
272 content+="<th>Message Comment</th>";
\r
273 content+="<th><a href=\"peertrust.htm?"+BuildQueryString(startrow,namesearch,"PeerMessageTrust",ReverseSort("PeerMessageTrust",sortby,sortorder),localidentityid)+"\">Peer Message Trust</a></th>";
\r
274 content+="<th><a href=\"peertrust.htm?"+BuildQueryString(startrow,namesearch,"tblIdentityTrust.LocalTrustListTrust",ReverseSort("tblIdentityTrust.LocalTrustListTrust",sortby,sortorder),localidentityid)+"\">Local Trust List Trust</a></th>";
\r
275 content+="<th>Trust Comment</th>";
\r
276 content+="<th><a href=\"peertrust.htm?"+BuildQueryString(startrow,namesearch,"PeerTrustListTrust",ReverseSort("PeerTrustListTrust",sortby,sortorder),localidentityid)+"\">Peer Trust List Trust</a></th>";
\r
277 content+="<th><a href=\"peertrust.htm?"+BuildQueryString(startrow,namesearch,"MessageCount",ReverseSort("MessageCount",sortby,sortorder),localidentityid)+"\">Message Count</a></th>";
\r
278 content+="</tr>\r\n";
\r
280 // get count of identities we are showing
\r
281 sql="SELECT COUNT(*) FROM tblIdentity LEFT JOIN (SELECT IdentityID FROM tblIdentityTrust WHERE LocalIdentityID=?) AS 'tblIdentityTrust' ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID ";
\r
282 sql+="WHERE tblIdentity.Hidden='false'";
\r
285 sql+=" AND (Name LIKE '%' || ? || '%' OR PublicKey LIKE '%' || ? || '%')";
\r
288 SQLite3DB::Statement st=m_db->Prepare(sql);
\r
289 st.Bind(0,localidentityid);
\r
292 st.Bind(1,namesearch);
\r
293 st.Bind(2,namesearch);
\r
296 st.ResultInt(0,identitycount);
\r
299 sql="SELECT tblIdentity.IdentityID,Name,tblIdentityTrust.LocalMessageTrust,PeerMessageTrust,tblIdentityTrust.LocalTrustListTrust,PeerTrustListTrust,PublicKey,tblIdentityTrust.MessageTrustComment,tblIdentityTrust.TrustListTrustComment,COUNT(MessageID) AS 'MessageCount',tblIdentity.PublishTrustList ";
\r
300 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 ";
\r
301 sql+="WHERE tblIdentity.Hidden='false'";
\r
304 sql+=" AND (Name LIKE '%' || ? || '%' OR PublicKey LIKE '%' || ? || '%')";
\r
306 sql+=" GROUP BY tblIdentity.IdentityID";
\r
310 sql+=" Name COLLATE NOCASE";
\r
318 sql+=" "+sortorder;
\r
320 sql+=" LIMIT "+startrowstr+","+rowsperpagestr+";";
\r
321 st=m_db->Prepare(sql);
\r
322 st.Bind(0,localidentityid);
\r
325 st.Bind(1,namesearch);
\r
326 st.Bind(2,namesearch);
\r
330 while(st.RowReturned())
\r
332 std::string identityid;
\r
334 std::string localmessagetrust;
\r
335 std::string peermessagetrust;
\r
336 std::string localtrustlisttrust;
\r
337 std::string peertrustlisttrust;
\r
338 std::string publickey;
\r
339 std::string messagetrustcomment="";
\r
340 std::string trustlisttrustcomment="";
\r
341 std::string messagecountstr="";
\r
342 std::string publishtrustlist="";
\r
344 StringFunctions::Convert(count,countstr);
\r
346 st.ResultText(0,identityid);
\r
347 st.ResultText(1,name);
\r
348 st.ResultText(2,localmessagetrust);
\r
349 st.ResultText(3,peermessagetrust);
\r
350 st.ResultText(4,localtrustlisttrust);
\r
351 st.ResultText(5,peertrustlisttrust);
\r
352 st.ResultText(6,publickey);
\r
353 st.ResultText(7,messagetrustcomment);
\r
354 st.ResultText(8,trustlisttrustcomment);
\r
355 st.ResultText(9,messagecountstr);
\r
356 st.ResultText(10,publishtrustlist);
\r
359 content+="<td title=\""+publickey+"\">";
\r
360 content+="<input type=\"hidden\" name=\"identityid["+countstr+"]\" value=\""+identityid+"\">";
\r
361 content+="<a href=\"peerdetails.htm?identityid="+identityid+"\">";
\r
364 content+=SanitizeOutput(CreateShortIdentityName(name,publickey));
\r
368 content+="[Unknown Name]";
\r
372 content+="<td "+GetClassString(localmessagetrust)+">";
\r
373 content+="<input type=\"hidden\" name=\"oldlocalmessagetrust["+countstr+"]\" value=\""+localmessagetrust+"\">";
\r
374 content+="<input type=\"text\" name=\"localmessagetrust["+countstr+"]\" value=\""+localmessagetrust+"\" size=\"2\" maxlength=\"3\" class=\"small90\"></td>";
\r
375 content+="<td "+GetClassString(localmessagetrust)+">";
\r
376 content+="<input type=\"hidden\" name=\"oldmessagetrustcomment["+countstr+"]\" value=\""+SanitizeOutput(messagetrustcomment)+"\">";
\r
377 content+="<input type=\"text\" name=\"messagetrustcomment["+countstr+"]\" value=\""+SanitizeOutput(messagetrustcomment)+"\" maxlength=\"50\" class=\"small90\">";
\r
379 content+="<td "+GetClassString(peermessagetrust)+">";
\r
380 content+=peermessagetrust+"</td>";
\r
381 content+="<td "+GetClassString(localtrustlisttrust)+">";
\r
382 content+="<input type=\"hidden\" name=\"oldlocaltrustlisttrust["+countstr+"]\" value=\""+localtrustlisttrust+"\">";
\r
383 content+="<input type=\"text\" name=\"localtrustlisttrust["+countstr+"]\" value=\""+localtrustlisttrust+"\" size=\"2\" maxlength=\"3\" class=\"small90\">";
\r
384 if(publishtrustlist=="false")
\r
389 content+="<td "+GetClassString(localtrustlisttrust)+">";
\r
390 content+="<input type=\"hidden\" name=\"oldtrustlisttrustcomment["+countstr+"]\" value=\""+SanitizeOutput(trustlisttrustcomment)+"\">";
\r
391 content+="<input type=\"text\" name=\"trustlisttrustcomment["+countstr+"]\" value=\""+SanitizeOutput(trustlisttrustcomment)+"\" maxlength=\"50\" class=\"small90\">";
\r
393 content+="<td "+GetClassString(peertrustlisttrust)+">";
\r
394 content+=peertrustlisttrust+"</td>";
\r
395 content+="<td>"+messagecountstr+"</td>";
\r
396 content+="</tr>\r\n";
\r
401 if(startrow>0 || startrow+rowsperpage<identitycount)
\r
403 std::string tempstr;
\r
409 StringFunctions::Convert(startrow-rowsperpage,tempstr);
\r
410 content+="<td colspan=\"3\" align=\"left\"><a href=\"peertrust.htm?"+BuildQueryString(startrow-rowsperpage,namesearch,sortby,sortorder,localidentityid)+"\"><-- Previous Page</a></td>";
\r
413 if(startrow+rowsperpage<identitycount)
\r
417 content+="<td></td>";
\r
420 content+="<td colspan=\"3\" align=\"right\"><a href=\"peertrust.htm?"+BuildQueryString(startrow+rowsperpage,namesearch,sortby,sortorder,localidentityid)+"\">Next Page --></a></td>";
\r
425 content+="<tr><td colspan=\"8\"><center><input type=\"submit\" value=\"Update Trust\"></center></td></tr>";
\r
426 content+="</table>";
\r
427 content+="</form>";
\r
429 return "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"+StringFunctions::Replace(m_template,"[CONTENT]",content);
\r
432 const std::string PeerTrustPage::GetClassString(const std::string &trustlevel)
\r
435 std::string tempstr;
\r
437 StringFunctions::Convert(trustlevel,tempint);
\r
439 StringFunctions::Convert(tempint,tempstr);
\r
443 return "class=\"trust"+tempstr+"\"";
\r
451 const std::string PeerTrustPage::ReverseSort(const std::string &sortname, const std::string ¤tsortby, const std::string ¤tsortorder)
\r
453 if(sortname==currentsortby)
\r
455 if(currentsortorder=="ASC")
\r
466 return currentsortorder;
\r
470 const bool PeerTrustPage::WillHandleURI(const std::string &uri)
\r
472 if(uri.find("peertrust.")!=std::string::npos)
\r