1 #include "../../../include/http/pages/peermaintenancepage.h"
\r
2 #include "../../../include/stringfunctions.h"
\r
4 #include <Poco/DateTime.h>
\r
5 #include <Poco/Timestamp.h>
\r
6 #include <Poco/Timespan.h>
\r
7 #include <Poco/DateTimeFormatter.h>
\r
13 const std::string PeerMaintenancePage::GeneratePage(const std::string &method, const std::map<std::string,std::string> &queryvars)
\r
15 std::string content="";
\r
16 SQLite3DB::Statement st;
\r
17 std::string tempval;
\r
18 Poco::DateTime date;
\r
20 if(queryvars.find("formaction")!=queryvars.end() && ValidateFormPassword(queryvars))
\r
22 if((*queryvars.find("formaction")).second=="removenotseen")
\r
24 m_db->Execute("DELETE FROM tblIdentity WHERE LastSeen IS NULL;");
\r
26 else if((*queryvars.find("formaction")).second=="removelastseen20")
\r
28 date=Poco::Timestamp();
\r
29 date-=Poco::Timespan(20,0,0,0,0);
\r
30 st=m_db->Prepare("DELETE FROM tblIdentity WHERE LastSeen<?;");
\r
31 st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));
\r
34 else if((*queryvars.find("formaction")).second=="removeneversent")
\r
36 m_db->Execute("DELETE FROM tblIdentity WHERE IdentityID NOT IN (SELECT IdentityID FROM tblMessage GROUP BY IdentityID);");
\r
38 else if((*queryvars.find("formaction")).second=="removelastseenneversent20")
\r
40 date=Poco::Timestamp();
\r
41 date-=Poco::Timespan(20,0,0,0,0);
\r
42 st=m_db->Prepare("DELETE FROM tblIdentity WHERE IdentityID NOT IN (SELECT IdentityID FROM tblMessage GROUP BY IdentityID) AND LastSeen<?;");
\r
43 st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));
\r
46 else if((*queryvars.find("formaction")).second=="removedaysago" && queryvars.find("daysago")!=queryvars.end() && (*queryvars.find("daysago")).second!="")
\r
49 StringFunctions::Convert((*queryvars.find("daysago")).second,tempint);
\r
50 date=Poco::Timestamp();
\r
51 date-=Poco::Timespan(tempint,0,0,0,0);
\r
52 st=m_db->Prepare("DELETE FROM tblIdentity WHERE LastSeen<?;");
\r
53 st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));
\r
56 else if((*queryvars.find("formaction")).second=="removenulldaysago" && queryvars.find("daysago")!=queryvars.end() && (*queryvars.find("daysago")).second!="")
\r
59 StringFunctions::Convert((*queryvars.find("daysago")).second,tempint);
\r
60 date=Poco::Timestamp();
\r
61 date-=Poco::Timespan(tempint,0,0,0,0);
\r
62 st=m_db->Prepare("DELETE FROM tblIdentity WHERE LastSeen<? AND LocalMessageTrust IS NULL AND LocalTrustListTrust IS NULL;");
\r
63 st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));
\r
66 else if((*queryvars.find("formaction")).second=="removeposted30daysago")
\r
68 date=Poco::Timestamp();
\r
69 date-=Poco::Timespan(30,0,0,0,0);
\r
70 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
71 st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d"));
\r
74 else if((*queryvars.find("formaction")).second=="removeadded20daysneversent")
\r
76 date=Poco::Timestamp();
\r
77 date-=Poco::Timespan(20,0,0,0,0);
\r
78 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
79 st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));
\r
84 content+="<h2>Peer Maintenance</h2>";
\r
85 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
87 content+="<a href=\"recentlyadded.htm\">Recently Added Peers</a>";
\r
90 content+="<tr><th colspan=\"3\">Stats</th></tr>";
\r
93 st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity;");
\r
95 st.ResultText(0,tempval);
\r
96 content+="<td>"+tempval+"</td>";
\r
97 content+="<td>known peers</td>";
\r
101 st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity WHERE LastSeen IS NULL;");
\r
103 st.ResultText(0,tempval);
\r
104 content+="<td>"+tempval+"</td>";
\r
105 content+="<td>never seen</td>";
\r
107 content+="<form name=\"frmremove\" method=\"POST\">";
\r
108 content+=CreateFormPassword();
\r
109 content+="<input type=\"hidden\" name=\"formaction\" value=\"removenotseen\">";
\r
110 content+="<input type=\"submit\" value=\"Remove\">";
\r
111 content+="</form>";
\r
115 date=Poco::Timestamp();
\r
116 date-=Poco::Timespan(20,0,0,0,0);
\r
117 st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity WHERE LastSeen<?;");
\r
118 st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));
\r
120 st.ResultText(0,tempval);
\r
122 content+="<td>"+tempval+"</td>";
\r
123 content+="<td>last seen more than 20 days ago</td>";
\r
125 content+="<form name=\"frmremove\" method=\"POST\">";
\r
126 content+=CreateFormPassword();
\r
127 content+="<input type=\"hidden\" name=\"formaction\" value=\"removelastseen20\">";
\r
128 content+="<input type=\"submit\" value=\"Remove\">";
\r
129 content+="</form>";
\r
133 date=Poco::Timestamp();
\r
134 date-=Poco::Timespan(30,0,0,0,0);
\r
135 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
136 st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d"));
\r
138 st.ResultText(0,tempval);
\r
140 content+="<td>"+tempval+"</td>";
\r
141 content+="<td>last sent a message more than 30 days ago</td>";
\r
143 content+="<form name=\"frmremove\" method=\"POST\">";
\r
144 content+=CreateFormPassword();
\r
145 content+="<input type=\"hidden\" name=\"formaction\" value=\"removeposted30daysago\">";
\r
146 content+="<input type=\"submit\" value=\"Remove\">";
\r
147 content+="</form>";
\r
151 st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE tblMessage.IdentityID IS NULL;");
\r
153 st.ResultText(0,tempval);
\r
155 content+="<td>"+tempval+"</td>";
\r
156 content+="<td>never sent a message</td>";
\r
158 content+="<form name=\"frmremove\" method=\"POST\">";
\r
159 content+=CreateFormPassword();
\r
160 content+="<input type=\"hidden\" name=\"formaction\" value=\"removeneversent\">";
\r
161 content+="<input type=\"submit\" value=\"Remove\">";
\r
162 content+="</form>";
\r
166 date=Poco::Timestamp();
\r
167 date-=Poco::Timespan(20,0,0,0,0);
\r
168 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
169 st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));
\r
171 st.ResultText(0,tempval);
\r
173 content+="<td>"+tempval+"</td>";
\r
174 content+="<td>added more than 20 days ago and never sent a message</td>";
\r
176 content+="<form name=\"frmremove\" method=\"POST\">";
\r
177 content+=CreateFormPassword();
\r
178 content+="<input type=\"hidden\" name=\"formaction\" value=\"removeadded20daysneversent\">";
\r
179 content+="<input type=\"submit\" value=\"Remove\">";
\r
180 content+="</form>";
\r
184 date=Poco::Timestamp();
\r
185 date-=Poco::Timespan(20,0,0,0,0);
\r
186 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
187 st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));
\r
189 st.ResultText(0,tempval);
\r
191 content+="<td>"+tempval+"</td>";
\r
192 content+="<td>last seen more than 20 days ago and never sent a message</td>";
\r
194 content+="<form name=\"frmremove\" method=\"POST\">";
\r
195 content+=CreateFormPassword();
\r
196 content+="<input type=\"hidden\" name=\"formaction\" value=\"removelastseenneversent20\">";
\r
197 content+="<input type=\"submit\" value=\"Remove\">";
\r
198 content+="</form>";
\r
203 content+="<td><form name=\"frmdelete\" method=\"POST\">";
\r
204 content+=CreateFormPassword();
\r
205 content+="<input type=\"hidden\" name=\"formaction\" value=\"removedaysago\"></td>";
\r
206 content+="<td>last seen <input type=\"text\" name=\"daysago\" size=\"2\"> days ago</td>";
\r
207 content+="<td><input type=\"submit\" value=\"Remove\"></form></td>";
\r
211 content+="<td><form name=\"frmdelete\" method=\"POST\">";
\r
212 content+=CreateFormPassword();
\r
213 content+="<input type=\"hidden\" name=\"formaction\" value=\"removenulldaysago\"></td>";
\r
214 content+="<td>last seen <input type=\"text\" name=\"daysago\" size=\"2\"> days ago, and have null local trust</td>";
\r
215 content+="<td><input type=\"submit\" value=\"Remove\"></form></td>";
\r
218 content+="</table>";
\r
220 return StringFunctions::Replace(m_template,"[CONTENT]",content);
\r
223 const bool PeerMaintenancePage::WillHandleURI(const std::string &uri)
\r
225 if(uri.find("peermaintenance.")!=std::string::npos)
\r