X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fhttp%2Fpages%2Fpeermaintenancepage.cpp;h=240c12e822ac2ad77da3966da4bc4a713de2f445;hb=05ef25de71be91442b4cbd22dc7cc45629c5d5bb;hp=f6cf38627d466fb1b229232ca8f74a56eaf4b225;hpb=52c0819bfc1d083c6e0738f75f0d7eeba521295a;p=fms.git diff --git a/src/http/pages/peermaintenancepage.cpp b/src/http/pages/peermaintenancepage.cpp index f6cf386..240c12e 100644 --- a/src/http/pages/peermaintenancepage.cpp +++ b/src/http/pages/peermaintenancepage.cpp @@ -1,6 +1,10 @@ #include "../../../include/http/pages/peermaintenancepage.h" #include "../../../include/stringfunctions.h" -#include "../../../include/datetime.h" + +#include +#include +#include +#include #ifdef XMEM #include @@ -11,9 +15,9 @@ const std::string PeerMaintenancePage::GeneratePage(const std::string &method, c std::string content=""; SQLite3DB::Statement st; std::string tempval; - DateTime date; + Poco::DateTime date; - if(queryvars.find("formaction")!=queryvars.end()) + if(queryvars.find("formaction")!=queryvars.end() && ValidateFormPassword(queryvars)) { if((*queryvars.find("formaction")).second=="removenotseen") { @@ -21,38 +25,67 @@ const std::string PeerMaintenancePage::GeneratePage(const std::string &method, c } else if((*queryvars.find("formaction")).second=="removelastseen20") { - date.SetToGMTime(); - date.Add(0,0,0,-20); + date=Poco::Timestamp(); + date-=Poco::Timespan(20,0,0,0,0); st=m_db->Prepare("DELETE FROM tblIdentity WHERE LastSeenExecute("DELETE FROM tblIdentity WHERE IdentityID NOT IN (SELECT IdentityID FROM tblMessage GROUP BY IdentityID);"); + m_db->Execute("DELETE FROM tblIdentity WHERE IdentityID NOT IN (SELECT IdentityID FROM tblMessage WHERE IdentityID IS NOT NULL GROUP BY IdentityID);"); } else if((*queryvars.find("formaction")).second=="removelastseenneversent20") { - date.SetToGMTime(); - date.Add(0,0,0,-20); - st=m_db->Prepare("DELETE FROM tblIdentity WHERE IdentityID NOT IN (SELECT IdentityID FROM tblMessage GROUP BY IdentityID) AND LastSeenPrepare("DELETE FROM tblIdentity WHERE IdentityID NOT IN (SELECT IdentityID FROM tblMessage WHERE IdentityID IS NOT NULL GROUP BY IdentityID) AND LastSeenPrepare("DELETE FROM tblIdentity WHERE IdentityID NOT IN (SELECT IdentityID FROM tblMessage GROUP BY IdentityID) AND LastSeenPrepare("DELETE FROM tblIdentity WHERE LastSeenPrepare("DELETE FROM tblIdentity WHERE LastSeenPrepare("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);"); + st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d")); + st.Step(); + } + else if((*queryvars.find("formaction")).second=="removeadded20daysneversent") + { + date=Poco::Timestamp(); + date-=Poco::Timespan(20,0,0,0,0); + 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.DateAddedPeer Maintenance"; content+="

Removing a peer will not remove the messages they sent, but will remove everything else about that peer, including their trust levels.

"; + content+="

"; + content+="Recently Added Peers"; + content+="

"; content+=""; content+=""; @@ -72,16 +105,17 @@ const std::string PeerMaintenancePage::GeneratePage(const std::string &method, c content+=""; content+=""; content+=""; - date.SetToGMTime(); - date.Add(0,0,0,-20); + date=Poco::Timestamp(); + date-=Poco::Timespan(20,0,0,0,0); st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity WHERE LastSeen"; @@ -89,12 +123,31 @@ const std::string PeerMaintenancePage::GeneratePage(const std::string &method, c content+=""; content+=""; content+=""; + date=Poco::Timestamp(); + date-=Poco::Timespan(30,0,0,0,0); + 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);"); + st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d")); + st.Step(); + st.ResultText(0,tempval); + content+=""; + content+=""; + content+=""; + content+=""; + content+=""; + st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE tblMessage.IdentityID IS NULL;"); st.Step(); st.ResultText(0,tempval); @@ -103,16 +156,35 @@ const std::string PeerMaintenancePage::GeneratePage(const std::string &method, c content+=""; content+=""; content+=""; - date.SetToGMTime(); - date.Add(0,0,0,-20); + date=Poco::Timestamp(); + date-=Poco::Timespan(20,0,0,0,0); + st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE tblMessage.IdentityID IS NULL AND tblIdentity.DateAdded"; + content+=""; + content+=""; + content+=""; + content+=""; + + date=Poco::Timestamp(); + date-=Poco::Timespan(20,0,0,0,0); st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE tblMessage.IdentityID IS NULL AND tblIdentity.LastSeen"; @@ -120,6 +192,7 @@ const std::string PeerMaintenancePage::GeneratePage(const std::string &method, c content+=""; content+=""; content+=""; - content+=""; + content+=""; content+=""; content+=""; content+=""; + content+=""; + content+=""; + content+=""; + content+=""; + content+=""; + content+="
Stats
never seen"; content+="
"; + content+=CreateFormPassword(); content+=""; content+=""; content+="
"; content+="
last seen more than 20 days ago"; content+="
"; + content+=CreateFormPassword(); content+=""; content+=""; content+="
"; content+="
"+tempval+"last sent a message more than 30 days ago"; + content+="
"; + content+=CreateFormPassword(); + content+=""; + content+=""; + content+="
"; + content+="
never sent a message"; content+="
"; + content+=CreateFormPassword(); content+=""; content+=""; content+="
"; content+="
"+tempval+"added more than 20 days ago and never sent a message"; + content+="
"; + content+=CreateFormPassword(); + content+=""; + content+=""; + content+="
"; + content+="
last seen more than 20 days ago and never sent a message"; content+="
"; + content+=CreateFormPassword(); content+=""; content+=""; content+="
"; @@ -127,14 +200,24 @@ const std::string PeerMaintenancePage::GeneratePage(const std::string &method, c content+="
"; + content+=CreateFormPassword(); + content+="last seen days ago
"; + content+=CreateFormPassword(); + content+="
last seen days ago, and have null local trust
"; - return "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"+StringFunctions::Replace(m_template,"[CONTENT]",content); + return StringFunctions::Replace(m_template,"[CONTENT]",content); } const bool PeerMaintenancePage::WillHandleURI(const std::string &uri)