From 52c0819bfc1d083c6e0738f75f0d7eeba521295a Mon Sep 17 00:00:00 2001 From: SomeDude Date: Tue, 19 Feb 2008 18:28:00 +0100 Subject: [PATCH] version 0.1.12 --- CMakeLists.txt | 1 + include/db/sqlite3db/sqlite3recordset.h | 1 + include/global.h | 2 +- include/http/pages/execquerypage.h | 18 +++++ include/http/pages/peertrustpage.h | 2 + include/message.h | 2 + src/freenet/boardlistxml.cpp | 2 +- src/freenet/introductionpuzzleinserter.cpp | 17 ++++- src/freenet/introductionpuzzlerequester.cpp | 3 + src/freenet/introductionpuzzlexml.cpp | 2 +- src/freenet/messageinserter.cpp | 46 ++++++++++-- src/freenet/messagerequester.cpp | 3 + src/freenet/messagexml.cpp | 4 +- src/freenet/periodicdbmaintenance.cpp | 44 +++++++++++ src/global.cpp | 12 +++ src/http/httpthread.cpp | 4 +- src/http/pages/execquerypage.cpp | 55 ++++++++++++++ src/http/pages/peermaintenancepage.cpp | 2 +- src/http/pages/peertrustpage.cpp | 111 ++++++++++++++++++++++++++-- src/message.cpp | 88 +++++++++++++++++++++- src/nntp/nntpconnection.cpp | 19 ++++- template.htm | 5 +- 22 files changed, 418 insertions(+), 25 deletions(-) create mode 100644 include/http/pages/execquerypage.h create mode 100644 src/http/pages/execquerypage.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 994d5e1..455a73d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,7 @@ src/http/pages/addpeerpage.cpp src/http/pages/announceidentitypage.cpp src/http/pages/controlboardpage.cpp src/http/pages/createidentitypage.cpp +src/http/pages/execquerypage.cpp src/http/pages/homepage.cpp src/http/pages/localidentitiespage.cpp src/http/pages/optionspage.cpp diff --git a/include/db/sqlite3db/sqlite3recordset.h b/include/db/sqlite3db/sqlite3recordset.h index 69ad5e5..33d56e2 100644 --- a/include/db/sqlite3db/sqlite3recordset.h +++ b/include/db/sqlite3db/sqlite3recordset.h @@ -19,6 +19,7 @@ public: virtual const int Count() { return m_rows; } virtual const bool AtBeginning() { return m_currentrow==0; } virtual const bool AtEnd() { return m_currentrow>=m_rows; } + virtual const int Cols() { return m_cols; } virtual const bool Next() { if(m_currentrow=0) { m_currentrow--; return true; } else { return false; } } diff --git a/include/global.h b/include/global.h index be6dec6..d9a82e0 100644 --- a/include/global.h +++ b/include/global.h @@ -5,7 +5,7 @@ //#include #include "pthreadwrapper/thread.h" -#define FMS_VERSION "0.1.11" +#define FMS_VERSION "0.1.12" // opens database and creates tables and initial inserts if necessary void SetupDB(); diff --git a/include/http/pages/execquerypage.h b/include/http/pages/execquerypage.h new file mode 100644 index 0000000..4679ec2 --- /dev/null +++ b/include/http/pages/execquerypage.h @@ -0,0 +1,18 @@ +#ifndef _execquerypage_ +#define _execquerypage_ + +#include "../ipagehandler.h" +#include "../../idatabase.h" + +class ExecQueryPage:public IPageHandler,public IDatabase +{ +public: + ExecQueryPage(const std::string &templatestr):IPageHandler(templatestr) {} + +private: + const bool WillHandleURI(const std::string &uri); + const std::string GeneratePage(const std::string &method, const std::map &queryvars); + +}; + +#endif // _execquerypage_ diff --git a/include/http/pages/peertrustpage.h b/include/http/pages/peertrustpage.h index eb780e0..8f91446 100644 --- a/include/http/pages/peertrustpage.h +++ b/include/http/pages/peertrustpage.h @@ -14,6 +14,8 @@ private: const std::string GeneratePage(const std::string &method, const std::map &queryvars); const std::string GetClassString(const std::string &trustlevel); + const std::string BuildQueryString(const long startrow, const std::string &namesearch, const std::string &sortby, const std::string &sortorder); + const std::string ReverseSort(const std::string &sortname, const std::string ¤tsortby, const std::string ¤tsortorder); }; diff --git a/include/message.h b/include/message.h index f30f33b..74c25d4 100644 --- a/include/message.h +++ b/include/message.h @@ -53,6 +53,7 @@ private: void Initialize(); // checks vector of boards for any special administration boards - if it finds one true is returned, otherwise false const bool CheckForAdministrationBoard(const std::vector &boards); + void HandleChangeTrust(); long m_messageid; std::string m_messageuuid; @@ -63,6 +64,7 @@ private: std::string m_fromname; std::vector m_boards; std::map m_inreplyto; + long m_changemessagetrustonreply; }; diff --git a/src/freenet/boardlistxml.cpp b/src/freenet/boardlistxml.cpp index eb9ca8c..4307c71 100644 --- a/src/freenet/boardlistxml.cpp +++ b/src/freenet/boardlistxml.cpp @@ -116,4 +116,4 @@ const bool BoardListXML::ParseXML(const std::string &xml) { return false; } -} \ No newline at end of file +} diff --git a/src/freenet/introductionpuzzleinserter.cpp b/src/freenet/introductionpuzzleinserter.cpp index fef42f1..66635bb 100644 --- a/src/freenet/introductionpuzzleinserter.cpp +++ b/src/freenet/introductionpuzzleinserter.cpp @@ -201,7 +201,9 @@ void IntroductionPuzzleInserter::StartInsert(const long localidentityid) FCPMessage message; std::string xmldata; std::string xmldatasizestr; - std::string privatekey; + std::string privatekey=""; + std::string publickey=""; + std::string keypart=""; StringFunctions::Convert(localidentityid,idstring); now.SetToGMTime(); @@ -217,10 +219,19 @@ void IntroductionPuzzleInserter::StartInsert(const long localidentityid) } StringFunctions::Convert(index,indexstr); - SQLite3DB::Recordset rs2=m_db->Query("SELECT PrivateKey FROM tblLocalIdentity WHERE LocalIdentityID="+idstring+";"); + SQLite3DB::Recordset rs2=m_db->Query("SELECT PrivateKey,PublicKey FROM tblLocalIdentity WHERE LocalIdentityID="+idstring+";"); if(rs2.Empty()==false && rs2.GetField(0)!=NULL) { privatekey=rs2.GetField(0); + if(rs2.GetField(1)) + { + publickey=rs2.GetField(1); + } + if(publickey.size()>=50) + { + // remove - and ~ + keypart=StringFunctions::Replace(StringFunctions::Replace(publickey.substr(4,43),"-",""),"~",""); + } } Option::Instance()->Get("MessageBase",messagebase); @@ -228,7 +239,7 @@ void IntroductionPuzzleInserter::StartInsert(const long localidentityid) GenerateCaptcha(encodedpuzzle,solutionstring); xml.SetType("captcha"); - xml.SetUUID(uuid.Generate()); + xml.SetUUID(uuid.Generate()+"@"+keypart); xml.SetPuzzleData(encodedpuzzle); xml.SetMimeType("image/bmp"); diff --git a/src/freenet/introductionpuzzlerequester.cpp b/src/freenet/introductionpuzzlerequester.cpp index 830bdb3..03d4a41 100644 --- a/src/freenet/introductionpuzzlerequester.cpp +++ b/src/freenet/introductionpuzzlerequester.cpp @@ -64,6 +64,9 @@ const bool IntroductionPuzzleRequester::HandleAllData(FCPMessage &message) // parse file into xml and update the database if(xml.ParseXML(std::string(data.begin(),data.end()))==true) { + + // TODO - check if last part of UUID matches public key of identity who inserted it + st=m_db->Prepare("INSERT INTO tblIntroductionPuzzleRequests(IdentityID,Day,RequestIndex,Found,UUID,Type,MimeType,PuzzleData) VALUES(?,?,?,?,?,?,?,?);"); st.Bind(0,identityid); st.Bind(1,idparts[4]); diff --git a/src/freenet/introductionpuzzlexml.cpp b/src/freenet/introductionpuzzlexml.cpp index 348b7ca..1dea038 100644 --- a/src/freenet/introductionpuzzlexml.cpp +++ b/src/freenet/introductionpuzzlexml.cpp @@ -22,7 +22,7 @@ std::string IntroductionPuzzleXML::GetXML() tid->LinkEndChild(XMLCreateTextElement("Type",m_type)); - tid->LinkEndChild(XMLCreateTextElement("UUID",m_uuid)); + tid->LinkEndChild(XMLCreateCDATAElement("UUID",m_uuid)); tid->LinkEndChild(XMLCreateTextElement("MimeType",m_mimetype)); diff --git a/src/freenet/messageinserter.cpp b/src/freenet/messageinserter.cpp index cc7cfd5..3d5af9a 100644 --- a/src/freenet/messageinserter.cpp +++ b/src/freenet/messageinserter.cpp @@ -1,4 +1,5 @@ #include "../../include/freenet/messageinserter.h" +#include "../../include/freenet/messagexml.h" MessageInserter::MessageInserter() { @@ -41,7 +42,7 @@ const bool MessageInserter::HandlePutFailed(FCPMessage &message) { SQLite3DB::Statement st=m_db->Prepare("INSERT INTO tblMessageInserts(LocalIdentityID,Day,InsertIndex,Inserted) VALUES(?,?,?,'true');"); st.Bind(0,localidentityid); - st.Bind(1,idparts[5]); + st.Bind(1,idparts[6]); st.Bind(2,index); st.Step(); } @@ -53,6 +54,7 @@ const bool MessageInserter::HandlePutFailed(FCPMessage &message) const bool MessageInserter::HandlePutSuccessful(FCPMessage &message) { + MessageXML xml; DateTime date; int localidentityid; int index; @@ -62,7 +64,7 @@ const bool MessageInserter::HandlePutSuccessful(FCPMessage &message) StringFunctions::Convert(idparts[2],localidentityid); SQLite3DB::Statement st=m_db->Prepare("UPDATE tblMessageInserts SET Day=?, InsertIndex=?, Inserted='true' WHERE MessageUUID=?;"); - st.Bind(0,idparts[5]); + st.Bind(0,idparts[6]); st.Bind(1,index); st.Bind(2,idparts[1]); st.Step(); @@ -74,6 +76,24 @@ const bool MessageInserter::HandlePutSuccessful(FCPMessage &message) st.Bind(1,date.Format("%Y-%m-%d")); st.Step(); + // update the messageuuid to the real messageuuid + st=m_db->Prepare("SELECT MessageXML FROM tblMessageInserts WHERE MessageUUID=?;"); + st.Bind(0,idparts[1]); + st.Step(); + if(st.RowReturned()) + { + std::string xmldata=""; + st.ResultText(0,xmldata); + xml.ParseXML(xmldata); + xml.SetMessageID(idparts[4]); + + SQLite3DB::Statement st2=m_db->Prepare("UPDATE tblMessageInserts SET MessageUUID=?, MessageXML=? WHERE MessageUUID=?;"); + st2.Bind(0,idparts[4]); + st2.Bind(1,xml.GetXML()); + st2.Bind(2,idparts[1]); + st2.Step(); + } + RemoveFromInsertList(idparts[1]); m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"MessageInserter::HandlePutSuccessful successfully inserted message "+message["Identifier"]); @@ -88,9 +108,10 @@ void MessageInserter::Initialize() void MessageInserter::StartInsert(const std::string &messageuuid) { + MessageXML xmlfile; DateTime now; now.SetToGMTime(); - SQLite3DB::Statement st=m_db->Prepare("SELECT MessageXML,PrivateKey,tblLocalIdentity.LocalIdentityID FROM tblMessageInserts INNER JOIN tblLocalIdentity ON tblMessageInserts.LocalIdentityID=tblLocalIdentity.LocalIdentityID WHERE MessageUUID=?;"); + SQLite3DB::Statement st=m_db->Prepare("SELECT MessageXML,PrivateKey,tblLocalIdentity.LocalIdentityID,PublicKey FROM tblMessageInserts INNER JOIN tblLocalIdentity ON tblMessageInserts.LocalIdentityID=tblLocalIdentity.LocalIdentityID WHERE MessageUUID=?;"); st.Bind(0,messageuuid); st.Step(); @@ -101,6 +122,7 @@ void MessageInserter::StartInsert(const std::string &messageuuid) std::string xml; std::string xmlsizestr; std::string privatekey; + std::string publickey; FCPMessage message; std::string indexstr; int index=0; @@ -108,7 +130,7 @@ void MessageInserter::StartInsert(const std::string &messageuuid) st.ResultText(0,xml); st.ResultText(1,privatekey); st.ResultInt(2,localidentityid); - StringFunctions::Convert(xml.size(),xmlsizestr); + st.ResultText(3,publickey); StringFunctions::Convert(localidentityid,idstr); st=m_db->Prepare("SELECT MAX(InsertIndex) FROM tblMessageInserts WHERE Day=? AND LocalIdentityID=?;"); @@ -123,9 +145,23 @@ void MessageInserter::StartInsert(const std::string &messageuuid) } StringFunctions::Convert(index,indexstr); + // recreate messageuuid in xml - UUID of message will not match entry in MessageInserts table until we successfully insert it + // see HandlePutSuccessful + xmlfile.ParseXML(xml); + // if we don't already have an @sskpart - add it + if(xmlfile.GetMessageID().find("@")==std::string::npos) + { + // remove - and ~ from publickey part + std::string publickeypart=StringFunctions::Replace(StringFunctions::Replace(publickey.substr(4,43),"-",""),"~",""); + xmlfile.SetMessageID(xmlfile.GetMessageID()+"@"+publickeypart); + } + xml=xmlfile.GetXML(); + + StringFunctions::Convert(xml.size(),xmlsizestr); + message.SetName("ClientPut"); message["URI"]=privatekey+m_messagebase+"|"+now.Format("%Y-%m-%d")+"|Message|"+indexstr+".xml"; - message["Identifier"]=m_fcpuniquename+"|"+messageuuid+"|"+idstr+"|"+indexstr+"|"+message["URI"]; + message["Identifier"]=m_fcpuniquename+"|"+messageuuid+"|"+idstr+"|"+indexstr+"|"+xmlfile.GetMessageID()+"|"+message["URI"]; message["UploadFrom"]="direct"; message["DataLength"]=xmlsizestr; m_fcp->SendMessage(message); diff --git a/src/freenet/messagerequester.cpp b/src/freenet/messagerequester.cpp index 07faaf9..54b0d26 100644 --- a/src/freenet/messagerequester.cpp +++ b/src/freenet/messagerequester.cpp @@ -137,6 +137,9 @@ const bool MessageRequester::HandleAllData(FCPMessage &message) boards[boards.size()-1]=xml.GetReplyBoard(); } + // TODO make sure domain of message id match 43 characters of public key of identity (remove - and ~) - if not, discard message + // implement after 0.1.12 is released + st=m_db->Prepare("INSERT INTO tblMessage(IdentityID,FromName,MessageDate,MessageTime,Subject,MessageUUID,ReplyBoardID,Body) VALUES(?,?,?,?,?,?,?,?);"); st.Bind(0,identityid); st.Bind(1,GetIdentityName(identityid)); diff --git a/src/freenet/messagexml.cpp b/src/freenet/messagexml.cpp index 8de3077..0de84c3 100644 --- a/src/freenet/messagexml.cpp +++ b/src/freenet/messagexml.cpp @@ -25,7 +25,9 @@ std::string MessageXML::GetXML() tid->LinkEndChild(XMLCreateCDATAElement("Subject",m_subject)); tid->LinkEndChild(XMLCreateCDATAElement("MessageID",m_messageid)); tid->LinkEndChild(XMLCreateCDATAElement("ReplyBoard",m_replyboard)); - tid->LinkEndChild(XMLCreateCDATAElement("Body",m_body)); + // a little hack because TinyXML doesn't handle ]]> inside a CDATA section - manually separate into multiple CDATA sections + // TinyXML still won't be able to parse past the 1st CDATA section, but other implementations might + tid->LinkEndChild(XMLCreateCDATAElement("Body",StringFunctions::Replace(m_body,"]]>","]]]]>"))); TiXmlElement *brds=new TiXmlElement("Boards"); tid->LinkEndChild(brds); diff --git a/src/freenet/periodicdbmaintenance.cpp b/src/freenet/periodicdbmaintenance.cpp index 01a76c7..c615d60 100644 --- a/src/freenet/periodicdbmaintenance.cpp +++ b/src/freenet/periodicdbmaintenance.cpp @@ -1,4 +1,5 @@ #include "../../include/freenet/periodicdbmaintenance.h" +#include "../../include/stringfunctions.h" #ifdef XMEM #include @@ -89,6 +90,49 @@ void PeriodicDBMaintenance::Do1DayMaintenance() // delete trust lists from identities we aren't trusting anymore m_db->Execute("DELETE FROM tblPeerTrust WHERE IdentityID NOT IN (SELECT IdentityID FROM tblIdentity WHERE (LocalTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalTrustListTrust')) AND (PeerTrustListTrust IS NULL OR PeerTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinPeerTrustListTrust')));"); + // remove identityid from messages where the identity has been deleted + m_db->Execute("UPDATE tblMessage SET IdentityID=NULL WHERE IdentityID NOT IN (SELECT IdentityID FROM tblIdentity);"); + + // try to re-attach messages from identities that were previously deleted, but have been since re-added + // first get the names from messages that have a NULL IdentityID + SQLite3DB::Statement st=m_db->Prepare("SELECT FromName FROM tblMessage WHERE IdentityID IS NULL GROUP BY FromName;"); + st.Step(); + while(st.RowReturned()) + { + std::string name=""; + std::string publickey=""; + int identityid=0; + st.ResultText(0,name); + + std::vector parts; + StringFunctions::Split(name,"@",parts); + + // find identities with this name + SQLite3DB::Statement st2=m_db->Prepare("SELECT IdentityID,PublicKey FROM tblIdentity WHERE Name=?;"); + st2.Bind(0,name); + st2.Step(); + while(st2.RowReturned()) + { + publickey=""; + identityid=0; + st2.ResultText(1,publickey); + // check if public key matches 2nd part + if(parts.size()>1 && publickey.find(parts[1])==4) + { + // we have the identity - so update the messages table with the identityid + st2.ResultInt(0,identityid); + + SQLite3DB::Statement st3=m_db->Prepare("UPDATE tblMessage SET IdentityID=? WHERE Name=? AND IdentityID IS NULL;"); + st3.Bind(0,identityid); + st3.Bind(1,name); + st3.Step(); + } + st2.Step(); + } + + st.Step(); + } + } void PeriodicDBMaintenance::Process() diff --git a/src/global.cpp b/src/global.cpp index 7f63579..0c6f913 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -343,6 +343,12 @@ void SetupDB() DELETE FROM tblTrustListInserts WHERE LocalIdentityID=old.LocalIdentityID;\ END;"); + db->Execute("CREATE TRIGGER IF NOT EXISTS trgDeleteBoard AFTER DELETE ON tblBoard \ + FOR EACH ROW \ + BEGIN \ + DELETE FROM tblMessageBoard WHERE BoardID=old.BoardID;\ + END;"); + // delete introduction puzzles that were half-way inserted db->Execute("DELETE FROM tblIntroductionPuzzleInserts WHERE Day IS NULL AND InsertIndex IS NULL;"); @@ -565,6 +571,12 @@ void SetupDefaultOptions() st.Step(); st.Reset(); + st.Bind(0,"ChangeMessageTrustOnReply"); + st.Bind(1,"0"); + st.Bind(2,"How much the local message trust level of an identity should change when you reply to one of their messages."); + st.Step(); + st.Reset(); + } void SetupLogFile() diff --git a/src/http/httpthread.cpp b/src/http/httpthread.cpp index 5bb9988..6ad6ef9 100644 --- a/src/http/httpthread.cpp +++ b/src/http/httpthread.cpp @@ -12,6 +12,7 @@ #include "../../include/http/pages/controlboardpage.h" #include "../../include/http/pages/peerdetailspage.h" #include "../../include/http/pages/peermaintenancepage.h" +#include "../../include/http/pages/execquerypage.h" #include @@ -28,7 +29,7 @@ HTTPThread::HTTPThread() StringFunctions::Convert(portstr,port); // set template - templatestr="Home
[CONTENT]"; + templatestr="Home

Could not find template.htm! Place in program directory and restart!


[CONTENT]"; FILE *infile=fopen("template.htm","r+b"); if(infile) { @@ -56,6 +57,7 @@ HTTPThread::HTTPThread() m_pagehandlers.push_back(new ControlBoardPage(templatestr)); m_pagehandlers.push_back(new PeerDetailsPage(templatestr)); m_pagehandlers.push_back(new PeerMaintenancePage(templatestr)); + m_pagehandlers.push_back(new ExecQueryPage(templatestr)); // homepage must be last - catch all page handler m_pagehandlers.push_back(new HomePage(templatestr)); diff --git a/src/http/pages/execquerypage.cpp b/src/http/pages/execquerypage.cpp new file mode 100644 index 0000000..f86579a --- /dev/null +++ b/src/http/pages/execquerypage.cpp @@ -0,0 +1,55 @@ +#include "../../../include/http/pages/execquerypage.h" +#include "../../../include/stringfunctions.h" + +#ifdef XMEM + #include +#endif + +const std::string ExecQueryPage::GeneratePage(const std::string &method, const std::map &queryvars) +{ + std::string content=""; + + if(queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="execute" && queryvars.find("query")!=queryvars.end() && (*queryvars.find("query")).second!="") + { + SQLite3DB::Recordset rs=m_db->Query((*queryvars.find("query")).second); + + content+=""; + while(!rs.AtEnd()) + { + content+=""; + for(int i=0; i"; + content+=""; + content+=""; + content+=""; + content+=""; + + return "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"+StringFunctions::Replace(m_template,"[CONTENT]",content); +} + +const bool ExecQueryPage::WillHandleURI(const std::string &uri) +{ + if(uri.find("execquery.")!=std::string::npos) + { + return true; + } + else + { + return false; + } +} diff --git a/src/http/pages/peermaintenancepage.cpp b/src/http/pages/peermaintenancepage.cpp index f794600..f6cf386 100644 --- a/src/http/pages/peermaintenancepage.cpp +++ b/src/http/pages/peermaintenancepage.cpp @@ -147,4 +147,4 @@ const bool PeerMaintenancePage::WillHandleURI(const std::string &uri) { return false; } -} \ No newline at end of file +} diff --git a/src/http/pages/peertrustpage.cpp b/src/http/pages/peertrustpage.cpp index 38bddbf..667595d 100644 --- a/src/http/pages/peertrustpage.cpp +++ b/src/http/pages/peertrustpage.cpp @@ -5,6 +5,48 @@ #include #endif +const std::string PeerTrustPage::BuildQueryString(const long startrow, const std::string &namesearch, const std::string &sortby, const std::string &sortorder) +{ + std::string returnval=""; + std::string tempval=""; + + if(startrow>=0) + { + StringFunctions::Convert(startrow,tempval); + returnval+="startrow="+tempval; + } + + if(namesearch!="") + { + if(returnval!="") + { + returnval+="&"; + } + returnval+="namesearch="+namesearch; + } + + if(sortby!="") + { + if(returnval!="") + { + returnval+="&"; + } + returnval+="sortby="+sortby; + } + + if(sortorder!="") + { + if(returnval!="") + { + returnval+="&"; + } + returnval+="sortorder="+sortorder; + } + + return returnval; + +} + const std::string PeerTrustPage::GeneratePage(const std::string &method, const std::map &queryvars) { int count=0; @@ -17,6 +59,8 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s std::string startrowstr="0"; std::string namesearch=""; std::string sql; + std::string sortby=""; + std::string sortorder=""; StringFunctions::Convert(rowsperpage,rowsperpagestr); @@ -70,6 +114,26 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s StringFunctions::Convert(startrow,startrowstr); } + // sort by + if(queryvars.find("sortby")!=queryvars.end()) + { + sortby=(*queryvars.find("sortby")).second; + } + else + { + sortby="Name"; + } + + // sort order + if(queryvars.find("sortorder")!=queryvars.end()) + { + sortorder=(*queryvars.find("sortorder")).second; + } + else + { + sortorder="ASC"; + } + // if we are searching by name if(queryvars.find("namesearch")!=queryvars.end()) { @@ -77,7 +141,7 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s } content+="

Peer Trust

"; - content+="Message Trust is how much you trust the identity to post good messages. Trust List Trust is how much weight you want the trust list of that identity to have when calculating the total. The local trust levels are set by you, and the peer trust levels are calculated by a weighted average using other identities trust lists."; + content+="Message Trust is how much you trust the identity to post good messages. Trust List Trust is how much weight you want the trust list of that identity to have when calculating the total. The local trust levels are set by you, and the peer trust levels are calculated by a weighted average using other identities' trust lists."; content+="
"; content+="
"; content+=""; @@ -88,7 +152,11 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s content+=""; content+=""; content+="
"; - content+=""; + content+=""; + content+=""; + content+=""; + content+=""; + content+=""; // get count of identities we are showing sql="SELECT COUNT(*) FROM tblIdentity"; @@ -111,7 +179,20 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s { sql+=" WHERE Name LIKE '%' || ? || '%'"; } - sql+=" ORDER BY Name COLLATE NOCASE LIMIT "+startrowstr+","+rowsperpagestr+";"; + sql+=" ORDER BY"; + if(sortby=="Name") + { + sql+=" Name COLLATE NOCASE"; + } + else + { + sql+=" "+sortby; + } + if(sortorder!="") + { + sql+=" "+sortorder; + } + sql+=" LIMIT "+startrowstr+","+rowsperpagestr+";"; st=m_db->Prepare(sql); if(namesearch!="") { @@ -183,18 +264,17 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s if(startrow>0) { StringFunctions::Convert(startrow-rowsperpage,tempstr); - content+=""; + content+=""; cols+=2; } if(startrow+rowsperpageNext Page -->"; + content+=""; } content+=""; } @@ -225,6 +305,25 @@ const std::string PeerTrustPage::GetClassString(const std::string &trustlevel) } } +const std::string PeerTrustPage::ReverseSort(const std::string &sortname, const std::string ¤tsortby, const std::string ¤tsortorder) +{ + if(sortname==currentsortby) + { + if(currentsortorder=="ASC") + { + return "DESC"; + } + else + { + return "ASC"; + } + } + else + { + return currentsortorder; + } +} + const bool PeerTrustPage::WillHandleURI(const std::string &uri) { if(uri.find("peertrust.")!=std::string::npos) diff --git a/src/message.cpp b/src/message.cpp index 123d370..41add10 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -3,6 +3,7 @@ #include "../include/uuidgenerator.h" #include "../include/stringfunctions.h" #include "../include/freenet/messagexml.h" +#include "../include/option.h" #include @@ -43,7 +44,15 @@ const bool Message::CheckForAdministrationBoard(const std::vector & const std::string Message::GetNNTPArticleID() const { - return "<"+m_messageuuid+"@freenetproject.org>"; + // old message - before 0.1.12 - doesn't have @domain so add @freenetproject.org + if(m_messageuuid.find("@")==std::string::npos) + { + return "<"+m_messageuuid+"@freenetproject.org>"; + } + else + { + return "<"+m_messageuuid+">"; + } } const std::string Message::GetNNTPBody() const @@ -78,7 +87,15 @@ const std::string Message::GetNNTPHeaders() const { rval+=" "; } - rval+="<"+(*j).second+"@freenetproject.org>"; + // old message - before 0.1.12 - doesn't have @domain so add @freenetproject.org + if((*j).second.find("@")==std::string::npos) + { + rval+="<"+(*j).second+"@freenetproject.org>"; + } + else + { + rval+="<"+(*j).second+">"; + } } rval+="\r\n"; } @@ -192,8 +209,43 @@ void Message::HandleAdministrationMessage() } +void Message::HandleChangeTrust() +{ + if(m_changemessagetrustonreply!=0 && m_inreplyto.size()>0) + { + SQLite3DB::Statement st=m_db->Prepare("SELECT tblIdentity.IdentityID,tblIdentity.LocalMessageTrust FROM tblIdentity INNER JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE tblMessage.MessageUUID=?;"); + st.Bind(0,m_inreplyto[0]); + st.Step(); + if(st.RowReturned()) + { + int identityid=0; + int localmessagetrust=0; + + st.ResultInt(0,identityid); + st.ResultInt(1,localmessagetrust); + + localmessagetrust+=m_changemessagetrustonreply; + if(localmessagetrust<0) + { + localmessagetrust=0; + } + if(localmessagetrust>100) + { + localmessagetrust=100; + } + + SQLite3DB::Statement st2=m_db->Prepare("UPDATE tblIdentity SET LocalMessageTrust=? WHERE IdentityID=?;"); + st2.Bind(0,localmessagetrust); + st2.Bind(1,identityid); + st2.Step(); + + } + } +} + void Message::Initialize() { + std::string tempval=""; m_messageid=-1; m_messageuuid=""; m_subject=""; @@ -203,6 +255,9 @@ void Message::Initialize() m_fromname=""; m_boards.clear(); m_inreplyto.clear(); + m_changemessagetrustonreply=0; + Option::Instance()->Get("ChangeMessageTrustOnReply",tempval); + StringFunctions::Convert(tempval,m_changemessagetrustonreply); } const bool Message::Load(const long messageid, const long boardid) @@ -286,8 +341,24 @@ const bool Message::Load(const long messageid, const long boardid) const bool Message::Load(const std::string &messageuuid) { + + std::string uuid=messageuuid; + + if(uuid.size()>0 && uuid[0]=='<') + { + uuid.erase(0,1); + } + if(uuid.size()>0 && uuid[uuid.size()-1]=='>') + { + uuid.erase(uuid.size()-1); + } + if(uuid.find("@freenetproject.org")!=std::string::npos) + { + uuid.erase(uuid.find("@freenetproject.org")); + } + SQLite3DB::Statement st=m_db->Prepare("SELECT MessageID FROM tblMessage WHERE MessageUUID=?;"); - st.Bind(0,messageuuid); + st.Bind(0,uuid); st.Step(); if(st.RowReturned()) @@ -375,8 +446,10 @@ const bool Message::ParseNNTPMessage(const std::string &nntpmessage) // get header info // date is always set to now regardless of what message has m_datetime.SetToGMTime(); + // messageuuid is always a unique id we generate regardless of message message-id m_messageuuid=uuid.Generate(); + // get from if(mime.GetFieldValue("From")) { @@ -480,11 +553,18 @@ const bool Message::ParseNNTPMessage(const std::string &nntpmessage) (*i)=StringFunctions::Replace((*i),"<",""); (*i)=StringFunctions::Replace((*i),">",""); (*i)=StringFunctions::TrimWhitespace((*i)); + /* // erase @ and everything after if((*i).find("@")!=std::string::npos) { (*i).erase((*i).find("@")); } + */ + // only erase after @ if message is old type with @freenetproject.org + if((*i).find("@freenetproject.org")!=std::string::npos) + { + (*i).erase((*i).find("@")); + } if((*i)!="") { m_inreplyto[count++]=(*i); @@ -556,4 +636,6 @@ void Message::StartFreenetInsert() st.Bind(2,xml.GetXML()); st.Step(); + HandleChangeTrust(); + } diff --git a/src/nntp/nntpconnection.cpp b/src/nntp/nntpconnection.cpp index 3fffad7..078c1c3 100644 --- a/src/nntp/nntpconnection.cpp +++ b/src/nntp/nntpconnection.cpp @@ -635,11 +635,13 @@ const bool NNTPConnection::HandleOverCommand(const NNTPCommand &command) messageuuid=command.m_arguments[0]; messageuuid=StringFunctions::Replace(messageuuid,"<",""); messageuuid=StringFunctions::Replace(messageuuid,">",""); + /* // get rid of @ and everything after if(messageuuid.find("@")!=std::string::npos) { messageuuid.erase(messageuuid.find("@")); } + */ } // single article or range else @@ -955,7 +957,7 @@ void NNTPConnection::SendArticleOverInfo(Message &message) { line+=" "; } - line+="<"+(*i).second+"@freenetproject.org>"; + line+="<"+(*i).second+">"; //+"@freenetproject.org>"; } line+="\t"; } @@ -1015,6 +1017,21 @@ void NNTPConnection::SendArticleParts(const NNTPConnection::NNTPCommand &command else { articleid=command.m_arguments[0]; + //strip off < and > and everthing after @ + if(articleid.size()>0 && articleid[0]=='<') + { + articleid.erase(0,1); + } + if(articleid.size()>0 && articleid[articleid.size()-1]=='>') + { + articleid.erase(articleid.size()-1); + } + /* + if(articleid.size()>0 && articleid.find('@')!=std::string::npos) + { + articleid.erase(articleid.find('@')); + } + */ message.Load(articleid); type=2; } diff --git a/template.htm b/template.htm index 2ed3403..157b1b2 100644 --- a/template.htm +++ b/template.htm @@ -1,7 +1,7 @@ FMS : Freenet Message System - + -- 2.7.4
NameLocal Message TrustPeer Message TrustLocal Trust List TrustPeer Trust List Trust
NameLocal Message TrustPeer Message TrustLocal Trust List TrustPeer Trust List Trust
<-- Previous Page<-- Previous PageNext Page -->