1 #include "../../../include/http/pages/peermaintenancepage.h"
\r
2 #include "../../../include/stringfunctions.h"
\r
3 #include "../../../include/datetime.h"
\r
9 const std::string PeerMaintenancePage::GeneratePage(const std::string &method, const std::map<std::string,std::string> &queryvars)
\r
11 std::string content="";
\r
12 SQLite3DB::Statement st;
\r
13 std::string tempval;
\r
16 if(queryvars.find("formaction")!=queryvars.end())
\r
18 if((*queryvars.find("formaction")).second=="removenotseen")
\r
20 m_db->Execute("DELETE FROM tblIdentity WHERE LastSeen IS NULL;");
\r
22 else if((*queryvars.find("formaction")).second=="removelastseen20")
\r
25 date.Add(0,0,0,-20);
\r
26 st=m_db->Prepare("DELETE FROM tblIdentity WHERE LastSeen<?;");
\r
27 st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S"));
\r
30 else if((*queryvars.find("formaction")).second=="removeneversent")
\r
32 m_db->Execute("DELETE FROM tblIdentity WHERE IdentityID NOT IN (SELECT IdentityID FROM tblMessage GROUP BY IdentityID);");
\r
34 else if((*queryvars.find("formaction")).second=="removelastseenneversent20")
\r
37 date.Add(0,0,0,-20);
\r
38 st=m_db->Prepare("DELETE FROM tblIdentity WHERE IdentityID NOT IN (SELECT IdentityID FROM tblMessage GROUP BY IdentityID) AND LastSeen<?;");
\r
39 st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S"));
\r
42 else if((*queryvars.find("formaction")).second=="removedaysago" && queryvars.find("daysago")!=queryvars.end() && (*queryvars.find("daysago")).second!="")
\r
45 StringFunctions::Convert((*queryvars.find("daysago")).second,tempint);
\r
47 date.Add(0,0,0,-tempint);
\r
48 st=m_db->Prepare("DELETE FROM tblIdentity WHERE LastSeen<?;");
\r
49 st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S"));
\r
52 else if((*queryvars.find("formaction")).second=="removenulldaysago" && queryvars.find("daysago")!=queryvars.end() && (*queryvars.find("daysago")).second!="")
\r
55 StringFunctions::Convert((*queryvars.find("daysago")).second,tempint);
\r
57 date.Add(0,0,0,-tempint);
\r
58 st=m_db->Prepare("DELETE FROM tblIdentity WHERE LastSeen<? AND LocalMessageTrust IS NULL AND LocalTrustListTrust IS NULL;");
\r
59 st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S"));
\r
62 else if((*queryvars.find("formaction")).second=="removeposted30daysago")
\r
65 date.Add(0,0,0,-30);
\r
66 st=m_db->Prepare("DELETE FROM tblIdentity WHERE IdentityID IN (SELECT tblIdentity.IdentityID FROM tblIdentity INNER JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE (SELECT MAX(MessageDate) FROM tblMessage WHERE tblMessage.IdentityID=tblIdentity.IdentityID)<=? GROUP BY tblIdentity.IdentityID);");
\r
67 st.Bind(0,date.Format("%Y-%m-%d"));
\r
70 else if((*queryvars.find("formaction")).second=="removeadded20daysneversent")
\r
73 date.Add(0,0,0,-20);
\r
74 st=m_db->Prepare("DELETE FROM tblIdentity WHERE IdentityID IN (SELECT tblIdentity.IdentityID FROM tblIdentity LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE tblMessage.IdentityID IS NULL AND tblIdentity.DateAdded<?);");
\r
75 st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S"));
\r
80 content+="<h2>Peer Maintenance</h2>";
\r
81 content+="<p class=\"paragraph\">Removing a peer will not remove the messages they sent, but will remove everything else about that peer, including their trust levels.</p>";
\r
83 content+="<tr><th colspan=\"3\">Stats</th></tr>";
\r
86 st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity;");
\r
88 st.ResultText(0,tempval);
\r
89 content+="<td>"+tempval+"</td>";
\r
90 content+="<td>known peers</td>";
\r
94 st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity WHERE LastSeen IS NULL;");
\r
96 st.ResultText(0,tempval);
\r
97 content+="<td>"+tempval+"</td>";
\r
98 content+="<td>never seen</td>";
\r
100 content+="<form name=\"frmremove\" method=\"POST\">";
\r
101 content+="<input type=\"hidden\" name=\"formaction\" value=\"removenotseen\">";
\r
102 content+="<input type=\"submit\" value=\"Remove\">";
\r
103 content+="</form>";
\r
107 date.SetToGMTime();
\r
108 date.Add(0,0,0,-20);
\r
109 st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity WHERE LastSeen<?;");
\r
110 st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S"));
\r
112 st.ResultText(0,tempval);
\r
114 content+="<td>"+tempval+"</td>";
\r
115 content+="<td>last seen more than 20 days ago</td>";
\r
117 content+="<form name=\"frmremove\" method=\"POST\">";
\r
118 content+="<input type=\"hidden\" name=\"formaction\" value=\"removelastseen20\">";
\r
119 content+="<input type=\"submit\" value=\"Remove\">";
\r
120 content+="</form>";
\r
124 date.SetToGMTime();
\r
125 date.Add(0,0,0,-30);
\r
126 st=m_db->Prepare("SELECT COUNT(*) FROM (SELECT tblIdentity.IdentityID FROM tblIdentity INNER JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE (SELECT MAX(MessageDate) FROM tblMessage WHERE tblMessage.IdentityID=tblIdentity.IdentityID)<=? GROUP BY tblIdentity.IdentityID);");
\r
127 st.Bind(0,date.Format("%Y-%m-%d"));
\r
129 st.ResultText(0,tempval);
\r
131 content+="<td>"+tempval+"</td>";
\r
132 content+="<td>last sent a message more than 30 days ago</td>";
\r
134 content+="<form name=\"frmremove\" method=\"POST\">";
\r
135 content+="<input type=\"hidden\" name=\"formaction\" value=\"removeposted30daysago\">";
\r
136 content+="<input type=\"submit\" value=\"Remove\">";
\r
137 content+="</form>";
\r
141 st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE tblMessage.IdentityID IS NULL;");
\r
143 st.ResultText(0,tempval);
\r
145 content+="<td>"+tempval+"</td>";
\r
146 content+="<td>never sent a message</td>";
\r
148 content+="<form name=\"frmremove\" method=\"POST\">";
\r
149 content+="<input type=\"hidden\" name=\"formaction\" value=\"removeneversent\">";
\r
150 content+="<input type=\"submit\" value=\"Remove\">";
\r
151 content+="</form>";
\r
155 date.SetToGMTime();
\r
156 date.Add(0,0,0,-20);
\r
157 st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE tblMessage.IdentityID IS NULL AND tblIdentity.DateAdded<?;");
\r
158 st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S"));
\r
160 st.ResultText(0,tempval);
\r
162 content+="<td>"+tempval+"</td>";
\r
163 content+="<td>added more than 20 days ago and never sent a message</td>";
\r
165 content+="<form name=\"frmremove\" method=\"POST\">";
\r
166 content+="<input type=\"hidden\" name=\"formaction\" value=\"removeadded20daysneversent\">";
\r
167 content+="<input type=\"submit\" value=\"Remove\">";
\r
168 content+="</form>";
\r
172 date.SetToGMTime();
\r
173 date.Add(0,0,0,-20);
\r
174 st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE tblMessage.IdentityID IS NULL AND tblIdentity.LastSeen<?;");
\r
175 st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S"));
\r
177 st.ResultText(0,tempval);
\r
179 content+="<td>"+tempval+"</td>";
\r
180 content+="<td>last seen more than 20 days ago and never sent a message</td>";
\r
182 content+="<form name=\"frmremove\" method=\"POST\">";
\r
183 content+="<input type=\"hidden\" name=\"formaction\" value=\"removelastseenneversent20\">";
\r
184 content+="<input type=\"submit\" value=\"Remove\">";
\r
185 content+="</form>";
\r
190 content+="<td><form name=\"frmdelete\" method=\"POST\"><input type=\"hidden\" name=\"formaction\" value=\"removedaysago\"></td>";
\r
191 content+="<td>last seen <input type=\"text\" name=\"daysago\" size=\"2\"> days ago</td>";
\r
192 content+="<td><input type=\"submit\" value=\"Remove\"></form></td>";
\r
196 content+="<td><form name=\"frmdelete\" method=\"POST\"><input type=\"hidden\" name=\"formaction\" value=\"removenulldaysago\"></td>";
\r
197 content+="<td>last seen <input type=\"text\" name=\"daysago\" size=\"2\"> days ago, and have null local trust</td>";
\r
198 content+="<td><input type=\"submit\" value=\"Remove\"></form></td>";
\r
201 content+="</table>";
\r
203 return "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"+StringFunctions::Replace(m_template,"[CONTENT]",content);
\r
206 const bool PeerMaintenancePage::WillHandleURI(const std::string &uri)
\r
208 if(uri.find("peermaintenance.")!=std::string::npos)
\r