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 IdentityID NOT IN (SELECT IdentityID FROM tblMessage GROUP BY IdentityID) AND LastSeen<?;");
\r
49 st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S"));
\r
54 content+="<h2>Peer Maintenance</h2>";
\r
55 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
57 content+="<tr><th colspan=\"3\">Stats</th></tr>";
\r
60 st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity;");
\r
62 st.ResultText(0,tempval);
\r
63 content+="<td>"+tempval+"</td>";
\r
64 content+="<td>known peers</td>";
\r
68 st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity WHERE LastSeen IS NULL;");
\r
70 st.ResultText(0,tempval);
\r
71 content+="<td>"+tempval+"</td>";
\r
72 content+="<td>never seen</td>";
\r
74 content+="<form name=\"frmremove\" method=\"POST\">";
\r
75 content+="<input type=\"hidden\" name=\"formaction\" value=\"removenotseen\">";
\r
76 content+="<input type=\"submit\" value=\"Remove\">";
\r
82 date.Add(0,0,0,-20);
\r
83 st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity WHERE LastSeen<?;");
\r
84 st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S"));
\r
86 st.ResultText(0,tempval);
\r
88 content+="<td>"+tempval+"</td>";
\r
89 content+="<td>last seen more than 20 days ago</td>";
\r
91 content+="<form name=\"frmremove\" method=\"POST\">";
\r
92 content+="<input type=\"hidden\" name=\"formaction\" value=\"removelastseen20\">";
\r
93 content+="<input type=\"submit\" value=\"Remove\">";
\r
98 st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE tblMessage.IdentityID IS NULL;");
\r
100 st.ResultText(0,tempval);
\r
102 content+="<td>"+tempval+"</td>";
\r
103 content+="<td>never sent a message</td>";
\r
105 content+="<form name=\"frmremove\" method=\"POST\">";
\r
106 content+="<input type=\"hidden\" name=\"formaction\" value=\"removeneversent\">";
\r
107 content+="<input type=\"submit\" value=\"Remove\">";
\r
108 content+="</form>";
\r
112 date.SetToGMTime();
\r
113 date.Add(0,0,0,-20);
\r
114 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
115 st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S"));
\r
117 st.ResultText(0,tempval);
\r
119 content+="<td>"+tempval+"</td>";
\r
120 content+="<td>last seen more than 20 days ago and never sent a message</td>";
\r
122 content+="<form name=\"frmremove\" method=\"POST\">";
\r
123 content+="<input type=\"hidden\" name=\"formaction\" value=\"removelastseenneversent20\">";
\r
124 content+="<input type=\"submit\" value=\"Remove\">";
\r
125 content+="</form>";
\r
130 content+="<td><form name=\"frmdelete\" method=\"POST\"><input type=\"hidden\" name=\"formaction\" value=\"removedaysago\"></td>";
\r
131 content+="<td>last seen <input type=\"text\" name=\"daysago\" size=\"2\"> days ago</td>";
\r
132 content+="<td><input type=\"submit\" value=\"Remove\"></form></td>";
\r
135 content+="</table>";
\r
137 return "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"+StringFunctions::Replace(m_template,"[CONTENT]",content);
\r
140 const bool PeerMaintenancePage::WillHandleURI(const std::string &uri)
\r
142 if(uri.find("peermaintenance.")!=std::string::npos)
\r