version 0.3.17
[fms.git] / src / http / pages / peermaintenancepage.cpp
index f794600..240c12e 100644 (file)
@@ -1,6 +1,10 @@
 #include "../../../include/http/pages/peermaintenancepage.h"\r
 #include "../../../include/stringfunctions.h"\r
-#include "../../../include/datetime.h"\r
+\r
+#include <Poco/DateTime.h>\r
+#include <Poco/Timestamp.h>\r
+#include <Poco/Timespan.h>\r
+#include <Poco/DateTimeFormatter.h>\r
 \r
 #ifdef XMEM\r
        #include <xmem.h>\r
@@ -11,9 +15,9 @@ const std::string PeerMaintenancePage::GeneratePage(const std::string &method, c
        std::string content="";\r
        SQLite3DB::Statement st;\r
        std::string tempval;\r
-       DateTime date;\r
+       Poco::DateTime date;\r
 \r
-       if(queryvars.find("formaction")!=queryvars.end())\r
+       if(queryvars.find("formaction")!=queryvars.end() && ValidateFormPassword(queryvars))\r
        {\r
                if((*queryvars.find("formaction")).second=="removenotseen")\r
                {\r
@@ -21,38 +25,67 @@ const std::string PeerMaintenancePage::GeneratePage(const std::string &method, c
                }\r
                else if((*queryvars.find("formaction")).second=="removelastseen20")\r
                {\r
-                       date.SetToGMTime();\r
-                       date.Add(0,0,0,-20);\r
+                       date=Poco::Timestamp();\r
+                       date-=Poco::Timespan(20,0,0,0,0);\r
                        st=m_db->Prepare("DELETE FROM tblIdentity WHERE LastSeen<?;");\r
-                       st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S"));\r
+                       st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));\r
                        st.Step();\r
                }\r
                else if((*queryvars.find("formaction")).second=="removeneversent")\r
                {\r
-                       m_db->Execute("DELETE FROM tblIdentity WHERE IdentityID NOT IN (SELECT IdentityID FROM tblMessage GROUP BY IdentityID);");\r
+                       m_db->Execute("DELETE FROM tblIdentity WHERE IdentityID NOT IN (SELECT IdentityID FROM tblMessage WHERE IdentityID IS NOT NULL GROUP BY IdentityID);");\r
                }\r
                else if((*queryvars.find("formaction")).second=="removelastseenneversent20")\r
                {\r
-                       date.SetToGMTime();\r
-                       date.Add(0,0,0,-20);\r
-                       st=m_db->Prepare("DELETE FROM tblIdentity WHERE IdentityID NOT IN (SELECT IdentityID FROM tblMessage GROUP BY IdentityID) AND LastSeen<?;");\r
-                       st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S"));\r
+                       date=Poco::Timestamp();\r
+                       date-=Poco::Timespan(20,0,0,0,0);\r
+                       st=m_db->Prepare("DELETE FROM tblIdentity WHERE IdentityID NOT IN (SELECT IdentityID FROM tblMessage WHERE IdentityID IS NOT NULL GROUP BY IdentityID) AND LastSeen<?;");\r
+                       st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));\r
                        st.Step();\r
                }\r
                else if((*queryvars.find("formaction")).second=="removedaysago" && queryvars.find("daysago")!=queryvars.end() && (*queryvars.find("daysago")).second!="")\r
                {\r
                        int tempint=10000;\r
                        StringFunctions::Convert((*queryvars.find("daysago")).second,tempint);\r
-                       date.SetToGMTime();\r
-                       date.Add(0,0,0,-tempint);\r
-                       st=m_db->Prepare("DELETE FROM tblIdentity WHERE IdentityID NOT IN (SELECT IdentityID FROM tblMessage GROUP BY IdentityID) AND LastSeen<?;");\r
-                       st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S"));\r
+                       date=Poco::Timestamp();\r
+                       date-=Poco::Timespan(tempint,0,0,0,0);\r
+                       st=m_db->Prepare("DELETE FROM tblIdentity WHERE LastSeen<?;");\r
+                       st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));\r
+                       st.Step();\r
+               }\r
+               else if((*queryvars.find("formaction")).second=="removenulldaysago" && queryvars.find("daysago")!=queryvars.end() && (*queryvars.find("daysago")).second!="")\r
+               {\r
+                       int tempint=10000;\r
+                       StringFunctions::Convert((*queryvars.find("daysago")).second,tempint);\r
+                       date=Poco::Timestamp();\r
+                       date-=Poco::Timespan(tempint,0,0,0,0);\r
+                       st=m_db->Prepare("DELETE FROM tblIdentity WHERE LastSeen<? AND LocalMessageTrust IS NULL AND LocalTrustListTrust IS NULL;");\r
+                       st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));\r
+                       st.Step();\r
+               }\r
+               else if((*queryvars.find("formaction")).second=="removeposted30daysago")\r
+               {\r
+                       date=Poco::Timestamp();\r
+                       date-=Poco::Timespan(30,0,0,0,0);\r
+                       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
+                       st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d"));\r
+                       st.Step();\r
+               }\r
+               else if((*queryvars.find("formaction")).second=="removeadded20daysneversent")\r
+               {\r
+                       date=Poco::Timestamp();\r
+                       date-=Poco::Timespan(20,0,0,0,0);\r
+                       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
+                       st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));\r
                        st.Step();\r
                }\r
        }\r
 \r
        content+="<h2>Peer Maintenance</h2>";\r
        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
+       content+="<p>";\r
+       content+="<a href=\"recentlyadded.htm\">Recently Added Peers</a>";\r
+       content+="</p>";\r
        content+="<table>";\r
        content+="<tr><th colspan=\"3\">Stats</th></tr>";\r
 \r
@@ -72,16 +105,17 @@ const std::string PeerMaintenancePage::GeneratePage(const std::string &method, c
        content+="<td>never seen</td>";\r
        content+="<td>";\r
        content+="<form name=\"frmremove\" method=\"POST\">";\r
+       content+=CreateFormPassword();\r
        content+="<input type=\"hidden\" name=\"formaction\" value=\"removenotseen\">";\r
        content+="<input type=\"submit\" value=\"Remove\">";\r
        content+="</form>";\r
        content+="</td>";\r
        content+="</tr>";\r
 \r
-       date.SetToGMTime();\r
-       date.Add(0,0,0,-20);\r
+       date=Poco::Timestamp();\r
+       date-=Poco::Timespan(20,0,0,0,0);\r
        st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity WHERE LastSeen<?;");\r
-       st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S"));\r
+       st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));\r
        st.Step();\r
        st.ResultText(0,tempval);\r
        content+="<tr>";\r
@@ -89,12 +123,31 @@ const std::string PeerMaintenancePage::GeneratePage(const std::string &method, c
        content+="<td>last seen more than 20 days ago</td>";\r
        content+="<td>";\r
        content+="<form name=\"frmremove\" method=\"POST\">";\r
+       content+=CreateFormPassword();\r
        content+="<input type=\"hidden\" name=\"formaction\" value=\"removelastseen20\">";\r
        content+="<input type=\"submit\" value=\"Remove\">";\r
        content+="</form>";\r
        content+="</td>";\r
        content+="</tr>";\r
 \r
+       date=Poco::Timestamp();\r
+       date-=Poco::Timespan(30,0,0,0,0);\r
+       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
+       st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d"));\r
+       st.Step();\r
+       st.ResultText(0,tempval);\r
+       content+="<tr>";\r
+       content+="<td>"+tempval+"</td>";\r
+       content+="<td>last sent a message more than 30 days ago</td>";\r
+       content+="<td>";\r
+       content+="<form name=\"frmremove\" method=\"POST\">";\r
+       content+=CreateFormPassword();\r
+       content+="<input type=\"hidden\" name=\"formaction\" value=\"removeposted30daysago\">";\r
+       content+="<input type=\"submit\" value=\"Remove\">";\r
+       content+="</form>";\r
+       content+="</td>";\r
+       content+="</tr>";\r
+\r
        st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE tblMessage.IdentityID IS NULL;");\r
        st.Step();\r
        st.ResultText(0,tempval);\r
@@ -103,16 +156,35 @@ const std::string PeerMaintenancePage::GeneratePage(const std::string &method, c
        content+="<td>never sent a message</td>";\r
        content+="<td>";\r
        content+="<form name=\"frmremove\" method=\"POST\">";\r
+       content+=CreateFormPassword();\r
        content+="<input type=\"hidden\" name=\"formaction\" value=\"removeneversent\">";\r
        content+="<input type=\"submit\" value=\"Remove\">";\r
        content+="</form>";\r
        content+="</td>";\r
        content+="</tr>";\r
 \r
-       date.SetToGMTime();\r
-       date.Add(0,0,0,-20);\r
+       date=Poco::Timestamp();\r
+       date-=Poco::Timespan(20,0,0,0,0);\r
+       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
+       st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));\r
+       st.Step();\r
+       st.ResultText(0,tempval);\r
+       content+="<tr>";\r
+       content+="<td>"+tempval+"</td>";\r
+       content+="<td>added more than 20 days ago and never sent a message</td>";\r
+       content+="<td>";\r
+       content+="<form name=\"frmremove\" method=\"POST\">";\r
+       content+=CreateFormPassword();\r
+       content+="<input type=\"hidden\" name=\"formaction\" value=\"removeadded20daysneversent\">";\r
+       content+="<input type=\"submit\" value=\"Remove\">";\r
+       content+="</form>";\r
+       content+="</td>";\r
+       content+="</tr>";\r
+\r
+       date=Poco::Timestamp();\r
+       date-=Poco::Timespan(20,0,0,0,0);\r
        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
-       st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S"));\r
+       st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));\r
        st.Step();\r
        st.ResultText(0,tempval);\r
        content+="<tr>";\r
@@ -120,6 +192,7 @@ const std::string PeerMaintenancePage::GeneratePage(const std::string &method, c
        content+="<td>last seen more than 20 days ago and never sent a message</td>";\r
        content+="<td>";\r
        content+="<form name=\"frmremove\" method=\"POST\">";\r
+       content+=CreateFormPassword();\r
        content+="<input type=\"hidden\" name=\"formaction\" value=\"removelastseenneversent20\">";\r
        content+="<input type=\"submit\" value=\"Remove\">";\r
        content+="</form>";\r
@@ -127,14 +200,24 @@ const std::string PeerMaintenancePage::GeneratePage(const std::string &method, c
        content+="</tr>";\r
 \r
        content+="<tr>";\r
-       content+="<td><form name=\"frmdelete\" method=\"POST\"><input type=\"hidden\" name=\"formaction\" value=\"removedaysago\"></td>";\r
+       content+="<td><form name=\"frmdelete\" method=\"POST\">";\r
+       content+=CreateFormPassword();\r
+       content+="<input type=\"hidden\" name=\"formaction\" value=\"removedaysago\"></td>";\r
        content+="<td>last seen <input type=\"text\" name=\"daysago\" size=\"2\"> days ago</td>";\r
        content+="<td><input type=\"submit\" value=\"Remove\"></form></td>";\r
        content+="</tr>";\r
 \r
+       content+="<tr>";\r
+       content+="<td><form name=\"frmdelete\" method=\"POST\">";\r
+       content+=CreateFormPassword();\r
+       content+="<input type=\"hidden\" name=\"formaction\" value=\"removenulldaysago\"></td>";\r
+       content+="<td>last seen <input type=\"text\" name=\"daysago\" size=\"2\"> days ago, and have null local trust</td>";\r
+       content+="<td><input type=\"submit\" value=\"Remove\"></form></td>";\r
+       content+="</tr>";\r
+\r
        content+="</table>";\r
 \r
-       return "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"+StringFunctions::Replace(m_template,"[CONTENT]",content);\r
+       return StringFunctions::Replace(m_template,"[CONTENT]",content);\r
 }\r
 \r
 const bool PeerMaintenancePage::WillHandleURI(const std::string &uri)\r
@@ -147,4 +230,4 @@ const bool PeerMaintenancePage::WillHandleURI(const std::string &uri)
        {\r
                return false;\r
        }\r
-}
\ No newline at end of file
+}\r