From 8a0a83a78390f22f99d4487cda2569909dfbc28e Mon Sep 17 00:00:00 2001 From: SomeDude Date: Sat, 29 Mar 2008 09:41:00 +0100 Subject: [PATCH] version 0.2.4 --- CMakeLists.txt | 1 + include/freenet/boardlistrequester.h | 3 + include/freenet/iindexrequester.h | 2 +- include/freenet/messagerequester.h | 1 + include/freenet/siteinserter.h | 27 +++ include/global.h | 3 +- include/http/identityexportxml.h | 6 +- readme.txt | 12 +- site-template.htm | 251 ++++++++++++++++++++++ src/freenet/boardlistrequester.cpp | 21 +- src/freenet/captcha/simplecaptcha.cpp | 2 +- src/freenet/freenetmasterthread.cpp | 2 + src/freenet/messagerequester.cpp | 19 +- src/freenet/periodicdbmaintenance.cpp | 42 +++- src/freenet/siteinserter.cpp | 366 +++++++++++++++++++++++++++++++++ src/global.cpp | 33 ++- src/http/identityexportxml.cpp | 22 +- src/http/pages/addpeerpage.cpp | 3 +- src/http/pages/boardspage.cpp | 10 + src/http/pages/localidentitiespage.cpp | 37 +++- src/http/pages/peerdetailspage.cpp | 4 +- src/message.cpp | 20 +- 22 files changed, 843 insertions(+), 44 deletions(-) create mode 100644 include/freenet/siteinserter.h create mode 100644 site-template.htm create mode 100644 src/freenet/siteinserter.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 00b85c5..c81d5cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,7 @@ src/freenet/messagelistxml.cpp src/freenet/messagerequester.cpp src/freenet/messagexml.cpp src/freenet/periodicdbmaintenance.cpp +src/freenet/siteinserter.cpp src/freenet/trustlistinserter.cpp src/freenet/trustlistrequester.cpp src/freenet/trustlistxml.cpp diff --git a/include/freenet/boardlistrequester.h b/include/freenet/boardlistrequester.h index a920e60..580b4f8 100644 --- a/include/freenet/boardlistrequester.h +++ b/include/freenet/boardlistrequester.h @@ -15,6 +15,9 @@ private: void StartRequest(const long &identityid); const bool HandleAllData(FCPMessage &message); const bool HandleGetFailed(FCPMessage &message); + + bool m_savemessagesfromnewboards; + }; #endif // _boardlistrequester_ diff --git a/include/freenet/iindexrequester.h b/include/freenet/iindexrequester.h index e3845e3..aecc00a 100644 --- a/include/freenet/iindexrequester.h +++ b/include/freenet/iindexrequester.h @@ -82,9 +82,9 @@ void IIndexRequester::FCPConnected() m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IIndexRequester::FCPConnected fcpuniquename contains | character! This is not a valid character!"); } + m_lastreceived.SetToGMTime(); m_requesting.clear(); PopulateIDList(); - m_lastreceived.SetToGMTime(); m_lastpopulated.SetToGMTime(); } diff --git a/include/freenet/messagerequester.h b/include/freenet/messagerequester.h index e840635..fd453ee 100644 --- a/include/freenet/messagerequester.h +++ b/include/freenet/messagerequester.h @@ -23,6 +23,7 @@ private: long m_maxdaysbackward; long m_maxpeermessages; long m_maxboardspermessage; + bool m_savemessagesfromnewboards; }; diff --git a/include/freenet/siteinserter.h b/include/freenet/siteinserter.h new file mode 100644 index 0000000..fe501f3 --- /dev/null +++ b/include/freenet/siteinserter.h @@ -0,0 +1,27 @@ +#ifndef _site_inserter_ +#define _site_inserter_ + +#include "iindexinserter.h" + +class SiteInserter:public IIndexInserter +{ +public: + SiteInserter(); + SiteInserter(FCPv2 *fcp); + +private: + void Initialize(); + const bool HandlePutSuccessful(FCPMessage &message); + const bool HandlePutFailed(FCPMessage &message); + void StartInsert(const long &localidentityid); + void CheckForNeededInsert(); + const std::string SanitizeOutput(const std::string &input); + void GeneratePages(const long localidentityid, std::string &uskkey, std::map &pages); + std::string GenerateLinks(const bool publishtrustlist, const bool publishboardlist); + std::string GenerateIndex(const std::string &htmltemplate, const long localidentityid, const std::string &name); + std::string GenerateTrustList(const std::string &htmltemplate, const long localidentityid, const std::string &name); + const std::string GetClassString(const std::string &trustlevel); + +}; + +#endif // _site_inserter_ diff --git a/include/global.h b/include/global.h index db939a4..0c1be3b 100644 --- a/include/global.h +++ b/include/global.h @@ -4,7 +4,7 @@ #include #include "pthreadwrapper/thread.h" -#define FMS_VERSION "0.2.3" +#define FMS_VERSION "0.2.4" // opens database and creates tables and initial inserts if necessary void SetupDB(); @@ -12,6 +12,7 @@ void ConvertDB0100To0101(); void ConvertDB0101To0103(); void ConvertDB0103To0104(); void ConvertDB0104To0105(); +void ConvertDB0105To0106(); // inserts default options into the database void SetupDefaultOptions(); // opens logfile and sets it up diff --git a/include/http/identityexportxml.h b/include/http/identityexportxml.h index 6d6db3a..d314a90 100644 --- a/include/http/identityexportxml.h +++ b/include/http/identityexportxml.h @@ -11,7 +11,7 @@ public: std::string GetXML(); const bool ParseXML(const std::string &xml); - void AddIdentity(const std::string &name, const std::string &publickey, const std::string &privatekey, const bool singleuse=false, const bool publishtrustlist=false, const bool publishboardlist=false); + void AddIdentity(const std::string &name, const std::string &publickey, const std::string &privatekey, const bool singleuse=false, const bool publishtrustlist=false, const bool publishboardlist=false, const bool publishfreesite=false); const long GetCount() { return m_identities.size(); } @@ -21,19 +21,21 @@ public: const bool GetSingleUse(const long index); const bool GetPublishTrustList(const long index); const bool GetPublishBoardList(const long index); + const bool GetPublishFreesite(const long index); private: void Initialize(); struct identity { - identity(const std::string &name, const std::string &publickey, const std::string &privatekey, const bool singleuse, const bool publishtrustlist, const bool publishboardlist):m_name(name),m_publickey(publickey),m_privatekey(privatekey),m_singleuse(singleuse),m_publishtrustlist(publishtrustlist),m_publishboardlist(publishboardlist) {} + identity(const std::string &name, const std::string &publickey, const std::string &privatekey, const bool singleuse, const bool publishtrustlist, const bool publishboardlist, const bool publishfreesite):m_name(name),m_publickey(publickey),m_privatekey(privatekey),m_singleuse(singleuse),m_publishtrustlist(publishtrustlist),m_publishboardlist(publishboardlist),m_publishfreesite(publishfreesite) {} std::string m_name; std::string m_publickey; std::string m_privatekey; bool m_singleuse; bool m_publishtrustlist; bool m_publishboardlist; + bool m_publishfreesite; }; std::vector m_identities; diff --git a/readme.txt b/readme.txt index 4cbc6d9..c9cca81 100644 --- a/readme.txt +++ b/readme.txt @@ -48,7 +48,7 @@ interface to create an identity and use the name of the identity as the username for the newsgroup account. The email address may be anything, as it is discarded when posting messages. -Posting Messages +POSTING MESSAGES ---------------- Use must set your newsreader to use UTF-8 when posting messages. Any non-text attachment to the message will be stripped. Text attachments will be inlined @@ -64,6 +64,16 @@ settings for the board. You may cross post to a regular board and a control board with the same message. The control boards will be stripped from the message before inserting into Freenet. +FREESITES +--------- +Each identity has the option to publish a freesite. A generic HTML template +called site-template.htm is used to insert the site. You can customize the +template by placing an HTML file called identityname-template.htm in the same +directory as the fms binary. In the template, the string [LINKS] will be +replaced by a
    list of links and [CONTENT] will be replaced by the page +content. The Freesite will be inserted once a day and contain your last 10 +posts and your trust list if you are publishing it. + TRUST ----- Trust is the most important element of FMS. It determines which identities you diff --git a/site-template.htm b/site-template.htm new file mode 100644 index 0000000..57170f3 --- /dev/null +++ b/site-template.htm @@ -0,0 +1,251 @@ + + +FMS : Freenet Message System + + + + + + + + + +
    + +
    +
    +
    Links
    + [LINKS] +
    + +
    + +
    + + [CONTENT] + +
    + +
    + + + + diff --git a/src/freenet/boardlistrequester.cpp b/src/freenet/boardlistrequester.cpp index 5029460..099242d 100644 --- a/src/freenet/boardlistrequester.cpp +++ b/src/freenet/boardlistrequester.cpp @@ -53,7 +53,7 @@ const bool BoardListRequester::HandleAllData(FCPMessage &message) { SQLite3DB::Statement brd=m_db->Prepare("SELECT BoardID,BoardName,BoardDescription FROM tblBoard WHERE BoardName=?;"); - SQLite3DB::Statement ins=m_db->Prepare("INSERT INTO tblBoard(BoardName,BoardDescription,DateAdded) VALUES(?,?,?);"); + SQLite3DB::Statement ins=m_db->Prepare("INSERT INTO tblBoard(BoardName,BoardDescription,DateAdded,SaveReceivedMessages) VALUES(?,?,?,?);"); SQLite3DB::Statement upd=m_db->Prepare("UPDATE tblBoard SET BoardDescription=? WHERE BoardID=?;"); for(long i=0; iWriteLog(LogFile::LOGLEVEL_WARNING,"Option MaxBoardListRequests is currently set at "+tempval+". This value might be incorrectly configured."); } + + Option::Instance()->Get("SaveMessagesFromNewBoards",tempval); + if(tempval=="true") + { + m_savemessagesfromnewboards=true; + } + else + { + m_savemessagesfromnewboards=false; + } + } void BoardListRequester::PopulateIDList() diff --git a/src/freenet/captcha/simplecaptcha.cpp b/src/freenet/captcha/simplecaptcha.cpp index c84010f..41d7166 100644 --- a/src/freenet/captcha/simplecaptcha.cpp +++ b/src/freenet/captcha/simplecaptcha.cpp @@ -10,7 +10,7 @@ void SimpleCaptcha::Generate() { BMP bmp; - int bmpwidth=100; + int bmpwidth=110; int bmpheight=50; RGBApixel lettercols[5]; std::string puzzlestring; diff --git a/src/freenet/freenetmasterthread.cpp b/src/freenet/freenetmasterthread.cpp index f30cbf1..4ca447e 100644 --- a/src/freenet/freenetmasterthread.cpp +++ b/src/freenet/freenetmasterthread.cpp @@ -18,6 +18,7 @@ #include "../../include/freenet/periodicdbmaintenance.h" #include "../../include/freenet/boardlistinserter.h" #include "../../include/freenet/boardlistrequester.h" +#include "../../include/freenet/siteinserter.h" //#include #include "../../include/pthreadwrapper/thread.h" @@ -273,6 +274,7 @@ void FreenetMasterThread::Setup() m_registrables.push_back(new MessageInserter(&m_fcp)); m_registrables.push_back(new BoardListInserter(&m_fcp)); m_registrables.push_back(new BoardListRequester(&m_fcp)); + m_registrables.push_back(new SiteInserter(&m_fcp)); m_registrables.push_back(new PeriodicDBMaintenance()); for(std::vector::iterator i=m_registrables.begin(); i!=m_registrables.end(); i++) diff --git a/src/freenet/messagerequester.cpp b/src/freenet/messagerequester.cpp index 13cc1f2..e298271 100644 --- a/src/freenet/messagerequester.cpp +++ b/src/freenet/messagerequester.cpp @@ -35,9 +35,17 @@ const long MessageRequester::GetBoardID(const std::string &boardname) { DateTime now; now.SetToGMTime(); - st=m_db->Prepare("INSERT INTO tblBoard(BoardName,DateAdded) VALUES(?,?);"); + st=m_db->Prepare("INSERT INTO tblBoard(BoardName,DateAdded,SaveReceivedMessages) VALUES(?,?,?);"); st.Bind(0,boardname); st.Bind(1,now.Format("%Y-%m-%d %H:%M:%S")); + if(m_savemessagesfromnewboards) + { + st.Bind(2,"true"); + } + else + { + st.Bind(2,"false"); + } st.Step(true); return st.GetLastInsertRowID(); } @@ -339,6 +347,15 @@ void MessageRequester::Initialize() { m_log->WriteLog(LogFile::LOGLEVEL_WARNING,"Option MaxBoardsPerMessage is currently set at "+tempval+". This value might be incorrectly configured."); } + Option::Instance()->Get("SaveMessagesFromNewBoards",tempval); + if(tempval=="true") + { + m_savemessagesfromnewboards=true; + } + else + { + m_savemessagesfromnewboards=false; + } } void MessageRequester::PopulateIDList() diff --git a/src/freenet/periodicdbmaintenance.cpp b/src/freenet/periodicdbmaintenance.cpp index f6f501b..2ac1e07 100644 --- a/src/freenet/periodicdbmaintenance.cpp +++ b/src/freenet/periodicdbmaintenance.cpp @@ -82,7 +82,19 @@ void PeriodicDBMaintenance::Do1HourMaintenance() st.Step(); } - + // set null peer trust for identities without a calculated trust + st=m_db->Prepare("SELECT IdentityID FROM tblIdentity WHERE IdentityID NOT IN (SELECT TargetIdentityID FROM vwCalculatedPeerTrust);"); + upd=m_db->Prepare("UPDATE tblIdentity SET PeerMessageTrust=NULL, PeerTrustListTrust=NULL WHERE IdentityID=?;"); + st.Step(); + while(st.RowReturned()) + { + int identityid=0; + st.ResultInt(0,identityid); + upd.Bind(0,identityid); + upd.Step(); + upd.Reset(); + st.Step(); + } m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"PeriodicDBMaintenance::Do1HourMaintenance"); } @@ -90,6 +102,34 @@ void PeriodicDBMaintenance::Do1HourMaintenance() void PeriodicDBMaintenance::Do6HourMaintenance() { + // if we remove a board and the reply boardid is still set to it, we need to replace it with a boardid that does exist + SQLite3DB::Statement st=m_db->Prepare("SELECT MessageID FROM tblMessage WHERE ReplyBoardID NOT IN (SELECT BoardID FROM tblBoard);"); + SQLite3DB::Statement st2=m_db->Prepare("SELECT BoardID FROM tblMessageBoard WHERE MessageID=?;"); + SQLite3DB::Statement upd=m_db->Prepare("UPDATE tblMessage SET ReplyBoardID=? WHERE MessageID=?;"); + st.Step(); + while(st.RowReturned()) + { + // find a valid boardid for the message + int messageid=0; + int boardid=0; + + st.ResultInt(0,messageid); + + st2.Bind(0,messageid); + st2.Step(); + if(st2.RowReturned()) + { + st2.ResultInt(0,boardid); + upd.Bind(0,boardid); + upd.Bind(1,messageid); + upd.Step(); + upd.Reset(); + } + st2.Reset(); + + st.Step(); + } + m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"PeriodicDBMaintenance::Do6HourMaintenance"); } diff --git a/src/freenet/siteinserter.cpp b/src/freenet/siteinserter.cpp new file mode 100644 index 0000000..f943f56 --- /dev/null +++ b/src/freenet/siteinserter.cpp @@ -0,0 +1,366 @@ +#include "../../include/freenet/siteinserter.h" + +#ifdef XMEM + #include +#endif + +SiteInserter::SiteInserter() +{ + Initialize(); +} + +SiteInserter::SiteInserter(FCPv2 *fcp):IIndexInserter(fcp) +{ + Initialize(); +} + +void SiteInserter::CheckForNeededInsert() +{ + // only do 1 insert at a time + if(m_inserting.size()==0) + { + DateTime date; + date.SetToGMTime(); + + SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID FROM tblLocalIdentity WHERE PublishFreesite='true' AND (LastInsertedFreesite IS NULL OR LastInsertedFreesiteFMS site of "+SanitizeOutput(name)+""; + + content+="

    My last few posts

    "; + + SQLite3DB::Statement boardst=m_db->Prepare("SELECT tblBoard.BoardName FROM tblBoard INNER JOIN tblMessageBoard ON tblBoard.BoardID=tblMessageBoard.BoardID WHERE tblMessageBoard.MessageID=? ORDER BY tblBoard.BoardName COLLATE NOCASE;"); + SQLite3DB::Statement st=m_db->Prepare("SELECT tblMessage.Body, tblMessage.Subject, tblMessage.MessageID FROM tblMessage INNER JOIN tblIdentity ON tblMessage.IdentityID=tblIdentity.IdentityID INNER JOIN tblLocalIdentity ON tblIdentity.PublicKey=tblLocalIdentity.PublicKey WHERE tblLocalIdentity.LocalIdentityID=? ORDER BY tblMessage.MessageDate DESC, tblMessage.MessageTime DESC LIMIT 0,10;"); + st.Bind(0,localidentityid); + st.Step(); + + while(st.RowReturned()) + { + std::string post=""; + std::string subject=""; + std::string boards=""; + int messageid=0; + + st.ResultText(0,post); + st.ResultText(1,subject); + st.ResultInt(2,messageid); + + boardst.Bind(0,messageid); + boardst.Step(); + while(boardst.RowReturned()) + { + std::string board=""; + boardst.ResultText(0,board); + if(boards!="") + { + boards+=","; + } + boards+=board; + boardst.Step(); + } + boardst.Reset(); + + content+="
    "; + content+="
    "; + content+=SanitizeOutput(boards); + content+="
    "; + content+="
    "; + content+=SanitizeOutput(subject); + content+="
    "; + content+="
    "; + content+=SanitizeOutput(post); + content+="
    "; + content+="
    "; + + st.Step(); + } + + return StringFunctions::Replace(htmltemplate,"[CONTENT]",content); + +} + +std::string SiteInserter::GenerateLinks(const bool publishtrustlist, const bool publishboardlist) +{ + std::string links=""; + links+="
      "; + links+="
    • Home
    • "; + if(publishtrustlist) + { + links+="
    • Trust List
    • "; + } + if(publishboardlist) + { +// links+="
    • Board List
    • "; + } + links+="
    "; + return links; +} + +void SiteInserter::GeneratePages(const long localidentityid, std::string &uskkey, std::map &pages) +{ + SQLite3DB::Statement st=m_db->Prepare("SELECT Name, PrivateKey, PublishTrustList, PublishBoardList FROM tblLocalIdentity WHERE LocalIdentityID=?;"); + st.Bind(0,localidentityid); + st.Step(); + + if(st.RowReturned()) + { + std::string htmltemplate=""; + std::string filename=""; + std::string name=""; + std::string key=""; + std::string publishtrustliststr=""; + std::string publishboardliststr=""; + bool publishtrustlist=false; + bool publishboardlist=false; + + st.ResultText(0,name); + st.ResultText(1,key); + st.ResultText(2,publishtrustliststr); + st.ResultText(3,publishboardliststr); + + publishtrustliststr=="true" ? publishtrustlist=true : publishtrustlist=false; + publishboardliststr=="true" ? publishboardlist=true : publishboardlist=false; + + filename=name+"-template.htm"; + FILE *infile=fopen(filename.c_str(),"r+b"); + if(!infile) + { + infile=fopen("site-template.htm","r+b"); + } + if(infile) + { + fseek(infile,0,SEEK_END); + long len=ftell(infile); + fseek(infile,0,SEEK_SET); + + std::vector data; + data.resize(len); + fread(&data[0],1,data.size(),infile); + fclose(infile); + + htmltemplate.append(data.begin(),data.end()); + + htmltemplate=StringFunctions::Replace(htmltemplate,"[LINKS]",GenerateLinks(publishtrustlist,publishboardlist)); + + pages["index.htm"]=GenerateIndex(htmltemplate,localidentityid,name); + if(publishtrustlist) + { + pages["trustlist.htm"]=GenerateTrustList(htmltemplate,localidentityid,name); + } + if(publishboardlist) + { +// pages["boardlist.htm"]=GenerateBoardList(htmltemplate,localidentityid,name); + } + + // make SSK a USK + if(key.find("SSK@")==0) + { + key.erase(0,3); + key="USK"+key; + } + key+=m_messagebase+"/0/"; + uskkey=key; + + } + else + { + LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_ERROR,"SiteInserter::GeneratePages unable to open "+filename+" or site-template.htm."); + } + + } +} + +std::string SiteInserter::GenerateTrustList(const std::string &htmltemplate, const long localidentityid, const std::string &name) +{ + std::string content=""; + DateTime date; + + date.SetToGMTime(); + date.Add(0,0,0,-20); + SQLite3DB::Statement st=m_db->Prepare("SELECT Name,PublicKey,LocalMessageTrust,LocalTrustListTrust,IdentityID,MessageTrustComment,TrustListTrustComment FROM tblIdentity WHERE PublicKey IS NOT NULL AND LastSeen IS NOT NULL AND LastSeen>=? ORDER BY Name COLLATE NOCASE;"); + st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S")); + st.Step(); + + content+=""; + content+=""; + content+=""; + while(st.RowReturned()) + { + std::string idname=""; + std::string thisid=""; + std::string messagetrustcomment=""; + std::string trustlisttrustcomment=""; + std::string messagetrust=""; + std::string trustlisttrust=""; + std::string publickey=""; + std::string keypart=""; + std::string uskkey=""; + + st.ResultText(0,idname); + st.ResultText(1,publickey); + st.ResultText(2,messagetrust); + st.ResultText(3,trustlisttrust); + st.ResultText(4,thisid); + st.ResultText(5,messagetrustcomment); + st.ResultText(6,trustlisttrustcomment); + + if(publickey.size()>8) + { + keypart=publickey.substr(3,5); + } + + if(publickey.find("SSK@")==0) + { + uskkey=publickey; + uskkey.erase(0,3); + uskkey="USK"+uskkey; + uskkey+=m_messagebase+"/0/"; + } + + content+=""; + content+=""; + content+=""; + content+=""; + content+=""; + content+=""; + content+="\r\n"; + + st.Step(); + } + + return StringFunctions::Replace(htmltemplate,"[CONTENT]",content); + +} + +const std::string SiteInserter::GetClassString(const std::string &trustlevel) +{ + int tempint=0; + std::string tempstr; + + StringFunctions::Convert(trustlevel,tempint); + tempint/=10; + StringFunctions::Convert(tempint,tempstr); + + if(trustlevel!="") + { + return "class=\"trust"+tempstr+"\""; + } + else + { + return ""; + } +} + +const bool SiteInserter::HandlePutFailed(FCPMessage &message) +{ + std::vector idparts; + long localidentityid; + + StringFunctions::Split(message["Identifier"],"|",idparts); + StringFunctions::Convert(idparts[1],localidentityid); + + RemoveFromInsertList(localidentityid); + + return true; +} + +const bool SiteInserter::HandlePutSuccessful(FCPMessage &message) +{ + std::vector idparts; + long localidentityid; + DateTime now; + + now.SetToGMTime(); + + StringFunctions::Split(message["Identifier"],"|",idparts); + StringFunctions::Convert(idparts[1],localidentityid); + + SQLite3DB::Statement st=m_db->Prepare("UPDATE tblLocalIdentity SET LastInsertedFreesite=? WHERE LocalIdentityID=?;"); + st.Bind(0,now.Format("%Y-%m-%d %H:%M:%S")); + st.Bind(1,localidentityid); + st.Step(); + + m_log->WriteLog(LogFile::LOGLEVEL_INFO,"SiteInserter::HandlePutSuccessful successfully inserted Freesite."); + + RemoveFromInsertList(localidentityid); + + return true; +} + +void SiteInserter::Initialize() +{ + m_fcpuniquename="SiteInserter"; +} + +const std::string SiteInserter::SanitizeOutput(const std::string &input) +{ + // must do & first because all other elements have & in them! + std::string output=StringFunctions::Replace(input,"&","&"); + output=StringFunctions::Replace(output,"<","<"); + output=StringFunctions::Replace(output,">",">"); + output=StringFunctions::Replace(output,"\"","""); + output=StringFunctions::Replace(output," "," "); + return output; +} + +void SiteInserter::StartInsert(const long &localidentityid) +{ + FCPMessage message; + std::string localidentityidstr=""; + std::string sizestr=""; + std::string uskkey=""; + std::map pages; + int filenum=0; + + StringFunctions::Convert(localidentityid,localidentityidstr); + + GeneratePages(localidentityid,uskkey,pages); + + message.SetName("ClientPutComplexDir"); + message["URI"]=uskkey; + message["Identifier"]=m_fcpuniquename+"|"+localidentityidstr+"|"+message["URI"]; + message["DefaultName"]="index.htm"; + + // add each page to the message + for(std::map::iterator pagei=pages.begin(); pagei!=pages.end(); pagei++) + { + std::string filenumstr; + StringFunctions::Convert(filenum,filenumstr); + + sizestr="0"; + StringFunctions::Convert((*pagei).second.size(),sizestr); + + message["Files."+filenumstr+".Name"]=(*pagei).first; + message["Files."+filenumstr+".UploadFrom"]="direct"; + message["Files."+filenumstr+".DataLength"]=sizestr; + + filenum++; + } + + m_fcp->SendMessage(message); + + // send data of each page + for(std::map::iterator pagei=pages.begin(); pagei!=pages.end(); pagei++) + { + m_fcp->SendRaw(&(*pagei).second[0],(*pagei).second.size()); + } + + m_inserting.push_back(localidentityid); + +} diff --git a/src/global.cpp b/src/global.cpp index 251ea2a..d241f06 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -67,13 +67,19 @@ void SetupDB() major=1; minor=5; } + if(major==1 && minor==5) + { + ConvertDB0105To0106(); + major=1; + minor=6; + } } else { - db->Execute("INSERT INTO tblDBVersion(Major,Minor) VALUES(1,5);"); + db->Execute("INSERT INTO tblDBVersion(Major,Minor) VALUES(1,6);"); } - db->Execute("UPDATE tblDBVersion SET Major=1, Minor=4;"); + db->Execute("UPDATE tblDBVersion SET Major=1, Minor=6;"); db->Execute("CREATE TABLE IF NOT EXISTS tblOption(\ Option TEXT UNIQUE,\ @@ -89,6 +95,7 @@ void SetupDB() SingleUse BOOL CHECK(SingleUse IN('true','false')) DEFAULT 'false',\ PublishTrustList BOOL CHECK(PublishTrustList IN('true','false')) DEFAULT 'false',\ PublishBoardList BOOL CHECK(PublishBoardList IN('true','false')) DEFAULT 'false',\ + PublishFreesite BOOL CHECK(PublishFreesite IN('true','false')) DEFAULT 'false',\ InsertingIdentity BOOL CHECK(InsertingIdentity IN('true','false')) DEFAULT 'false',\ LastInsertedIdentity DATETIME,\ InsertingPuzzle BOOL CHECK(InsertingPuzzle IN('true','false')) DEFAULT 'false',\ @@ -99,6 +106,7 @@ void SetupDB() LastInsertedBoardList DATETIME,\ InsertingMessageList BOOL CHECK(InsertingMessageList IN('true','false')) DEFAULT 'false',\ LastInsertedMessageList DATETIME,\ + LastInsertedFreesite DATETIME,\ DateCreated DATETIME\ );"); @@ -484,6 +492,15 @@ void ConvertDB0104To0105() db->Execute("UPDATE tblDBVersion SET Major=1, Minor=5;"); } +void ConvertDB0105To0106() +{ + // add Publish Freesite + SQLite3DB::DB *db=SQLite3DB::DB::Instance(); + db->Execute("ALTER TABLE tblLocalIdentity ADD COLUMN PublishFreesite BOOL CHECK(PublishFreesite IN('true','false')) DEFAULT 'false';"); + db->Execute("ALTER TABLE tblLocalIdentity ADD COLUMN LastInsertedFreesite DATETIME;"); + db->Execute("UPDATE tblDBVersion SET Major=1, Minor=6;"); +} + void SetupDefaultOptions() { // OptionValue should always be inserted as a string, even if the option really isn't a string - just to keep the field data type consistent @@ -530,7 +547,7 @@ void SetupDefaultOptions() st.Bind(0,"StartHTTP"); st.Bind(1,"true"); - st.Bind(2,"Start HTTP server."); + st.Bind(2,"Start HTTP server. WARNING: If you turn this off, you won't be able to access the administration pages."); st.Step(); st.Reset(); @@ -549,7 +566,7 @@ void SetupDefaultOptions() // StartFreenetUpdater st.Bind(0,"StartFreenetUpdater"); st.Bind(1,"true"); - st.Bind(2,"Start Freenet Updater thread."); + st.Bind(2,"Set to true to start the Freenet Updater thread and connect to Freenet. Set to false to prevent communication with Freenet."); st.Step(); st.Reset(); @@ -622,7 +639,7 @@ void SetupDefaultOptions() st.Reset(); st.Bind(0,"MinLocalTrustListTrust"); - st.Bind(1,"51"); + st.Bind(1,"50"); st.Bind(2,"Specifies a local trust list trust level that a peer must have before its trust list will be included in the weighted average. Any peers below this number will be excluded from the results."); st.Step(); st.Reset(); @@ -663,6 +680,12 @@ void SetupDefaultOptions() st.Step(); st.Reset(); + st.Bind(0,"SaveMessagesFromNewBoards"); + st.Bind(1,"true"); + st.Bind(2,"Set to true to automatically save messages posted to new boards. Set to false to ignore messages to new boards."); + 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."); diff --git a/src/http/identityexportxml.cpp b/src/http/identityexportxml.cpp index 1f87e85..e8d9d0b 100644 --- a/src/http/identityexportxml.cpp +++ b/src/http/identityexportxml.cpp @@ -9,9 +9,9 @@ IdentityExportXML::IdentityExportXML() Initialize(); } -void IdentityExportXML::AddIdentity(const std::string &name, const std::string &publickey, const std::string &privatekey, const bool singleuse, const bool publishtrustlist, const bool publishboardlist) +void IdentityExportXML::AddIdentity(const std::string &name, const std::string &publickey, const std::string &privatekey, const bool singleuse, const bool publishtrustlist, const bool publishboardlist, const bool publishfreesite) { - m_identities.push_back(identity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist)); + m_identities.push_back(identity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist,publishfreesite)); } const std::string IdentityExportXML::GetName(const long index) @@ -62,6 +62,18 @@ const bool IdentityExportXML::GetPublishBoardList(const long index) } } +const bool IdentityExportXML::GetPublishFreesite(const long index) +{ + if(index>=0 && index=0 && indexLinkEndChild(XMLCreateBooleanElement("SingleUse",(*i).m_singleuse)); tr->LinkEndChild(XMLCreateBooleanElement("PublishTrustList",(*i).m_publishtrustlist)); tr->LinkEndChild(XMLCreateBooleanElement("PublishBoardList",(*i).m_publishboardlist)); + tr->LinkEndChild(XMLCreateBooleanElement("PublishFreesite",(*i).m_publishfreesite)); } td.Accept(&tp); @@ -131,6 +144,7 @@ const bool IdentityExportXML::ParseXML(const std::string &xml) bool singleuse=false; bool publishtrustlist=false; bool publishboardlist=false; + bool publishfreesite=false; TiXmlText *txt; TiXmlHandle hnd(&td); TiXmlNode *node; @@ -146,6 +160,7 @@ const bool IdentityExportXML::ParseXML(const std::string &xml) singleuse=false; publishtrustlist=false; publishboardlist=false; + publishfreesite=false; TiXmlHandle hnd2(node); txt=hnd2.FirstChild("Name").FirstChild().ToText(); @@ -167,10 +182,11 @@ const bool IdentityExportXML::ParseXML(const std::string &xml) singleuse=XMLGetBooleanElement(node->ToElement(),"SingleUse"); publishtrustlist=XMLGetBooleanElement(node->ToElement(),"PublishTrustList"); publishboardlist=XMLGetBooleanElement(node->ToElement(),"PublishBoardList"); + publishfreesite=XMLGetBooleanElement(node->ToElement(),"PublishFreesite"); if(name!="" && publickey!="" && privatekey!="") { - m_identities.push_back(identity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist)); + m_identities.push_back(identity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist,publishfreesite)); } node=node->NextSibling("Identity"); diff --git a/src/http/pages/addpeerpage.cpp b/src/http/pages/addpeerpage.cpp index 7b4d706..d97d596 100644 --- a/src/http/pages/addpeerpage.cpp +++ b/src/http/pages/addpeerpage.cpp @@ -21,9 +21,10 @@ const std::string AddPeerPage::GeneratePage(const std::string &method, const std if(publickey!="" && publickey.find("SSK@")==0 && publickey[publickey.size()-1]=='/') { date.SetToGMTime(); - SQLite3DB::Statement st=m_db->Prepare("INSERT INTO tblIdentity(PublicKey,DateAdded) VALUES(?,?);"); + SQLite3DB::Statement st=m_db->Prepare("INSERT INTO tblIdentity(PublicKey,DateAdded,AddedMethod) VALUES(?,?,?);"); st.Bind(0,publickey); st.Bind(1,date.Format("%Y-%m-%d %H:%M:%S")); + st.Bind(2,"manually"); st.Step(); st.Reset(); } diff --git a/src/http/pages/boardspage.cpp b/src/http/pages/boardspage.cpp index af3baad..ed8d469 100644 --- a/src/http/pages/boardspage.cpp +++ b/src/http/pages/boardspage.cpp @@ -61,6 +61,10 @@ const std::string BoardsPage::GeneratePage(const std::string &method, const std: addst.Bind(2,now.Format("%Y-%m-%d %H:%M:%S")); addst.Step(); } + if((*queryvars.find("formaction")).second=="remove0messages") + { + m_db->Execute("DELETE FROM tblBoard WHERE BoardID IN (SELECT BoardID FROM vwBoardStats WHERE MessageCount=0);"); + } if((*queryvars.find("formaction")).second=="update") { int boardid; @@ -173,6 +177,12 @@ const std::string BoardsPage::GeneratePage(const std::string &method, const std: content+=""; content+=""; + content+=""; + content+=""; + + content+=""; content+=""; content+=""; diff --git a/src/http/pages/localidentitiespage.cpp b/src/http/pages/localidentitiespage.cpp index 8d5ab48..8b6afcb 100644 --- a/src/http/pages/localidentitiespage.cpp +++ b/src/http/pages/localidentitiespage.cpp @@ -41,15 +41,17 @@ const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, c std::vector singleuse; std::vector publishtrustlist; std::vector publishboardlist; + std::vector publishfreesite; CreateArgArray(queryvars,"chkidentityid",ids); CreateArgArray(queryvars,"singleuse",singleuse); CreateArgArray(queryvars,"publishtrustlist",publishtrustlist); CreateArgArray(queryvars,"publishboardlist",publishboardlist); + CreateArgArray(queryvars,"publishfreesite",publishfreesite); if((*queryvars.find("formaction")).second=="update") { - SQLite3DB::Statement update=m_db->Prepare("UPDATE tblLocalIdentity SET SingleUse=?, PublishTrustList=?, PublishBoardList=? WHERE LocalIdentityID=?;"); + SQLite3DB::Statement update=m_db->Prepare("UPDATE tblLocalIdentity SET SingleUse=?, PublishTrustList=?, PublishBoardList=?, PublishFreesite=? WHERE LocalIdentityID=?;"); for(int i=0; iPrepare("SELECT Name,PublicKey,PrivateKey,SingleUse,PublishTrustList,PublishBoardList FROM tblLocalIdentity WHERE PublicKey IS NOT NULL AND PrivateKey IS NOT NULL;"); + SQLite3DB::Statement exp=m_db->Prepare("SELECT Name,PublicKey,PrivateKey,SingleUse,PublishTrustList,PublishBoardList,PublishFreesite FROM tblLocalIdentity WHERE PublicKey IS NOT NULL AND PrivateKey IS NOT NULL;"); exp.Step(); while(exp.RowReturned()) { @@ -92,6 +95,7 @@ const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, c bool singleuse=false; bool publishtrustlist=false; bool publishboardlist=false; + bool publishfreesite=false; exp.ResultText(0,name); exp.ResultText(1,publickey); @@ -111,8 +115,13 @@ const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, c { publishboardlist=true; } + exp.ResultText(6,tempval); + if(tempval=="true") + { + publishfreesite=true; + } - xml.AddIdentity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist); + xml.AddIdentity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist,publishfreesite); exp.Step(); } @@ -125,7 +134,7 @@ const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, c IdentityExportXML xml; if(xml.ParseXML((*queryvars.find("file")).second)) { - SQLite3DB::Statement imp=m_db->Prepare("INSERT INTO tblLocalIdentity(Name,PublicKey,PrivateKey,SingleUse,PublishTrustList,PublishBoardList) VALUES(?,?,?,?,?,?);"); + SQLite3DB::Statement imp=m_db->Prepare("INSERT INTO tblLocalIdentity(Name,PublicKey,PrivateKey,SingleUse,PublishTrustList,PublishBoardList,PublishFreesite) VALUES(?,?,?,?,?,?,?);"); for(int i=0; i"; content+=""; - content+="
    "; + content+="Trust List of "+SanitizeOutput(name); + content+="
    Message TrustMessage CommentTrust List TrustTrust Comment
    "+SanitizeOutput(idname+keypart)+"..."+messagetrust+""+SanitizeOutput(messagetrustcomment)+""+trustlisttrust+""+SanitizeOutput(trustlisttrustcomment)+"
    "; + content+="
    Remove boards with 0 messages
    "; + content+="
    "; + content+="
    NameSingle UsePublish Trust ListPublish Board ListAnnounced? *
    "; - SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID,tblLocalIdentity.Name,tblLocalIdentity.PublicKey,tbLLocalIdentity.PublishTrustList,tblLocalIdentity.SingleUse,tblLocalIdentity.PublishBoardList,tblIdentity.IdentityID FROM tblLocalIdentity LEFT JOIN tblIdentity ON tblLocalIdentity.PublicKey=tblIdentity.PublicKey ORDER BY tblLocalIdentity.Name;"); + SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID,tblLocalIdentity.Name,tblLocalIdentity.PublicKey,tbLLocalIdentity.PublishTrustList,tblLocalIdentity.SingleUse,tblLocalIdentity.PublishBoardList,tblIdentity.IdentityID,tblLocalIdentity.PublishFreesite FROM tblLocalIdentity LEFT JOIN tblIdentity ON tblLocalIdentity.PublicKey=tblIdentity.PublicKey ORDER BY tblLocalIdentity.Name;"); st.Step(); count=0; @@ -203,6 +221,7 @@ const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, c std::string singleuse=""; std::string keypart=""; std::string publishboardlist=""; + std::string publishfreesite=""; st.ResultText(0,id); st.ResultText(1,name); @@ -210,6 +229,7 @@ const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, c st.ResultText(3,publishtrustlist); st.ResultText(4,singleuse); st.ResultText(5,publishboardlist); + st.ResultText(7,publishfreesite); if(publickey.size()>8) { @@ -222,6 +242,7 @@ const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, c content+=""; content+=""; content+=""; + content+=""; if(st.ResultNull(6)) { content+=""; @@ -235,7 +256,7 @@ const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, c count++; } - content+=""; + content+=""; content+="
    NameSingle UsePublish Trust ListPublish Board ListPublish FreesiteAnnounced? *
    "+CreateTrueFalseDropDown("singleuse["+countstr+"]",singleuse)+""+CreateTrueFalseDropDown("publishtrustlist["+countstr+"]",publishtrustlist)+""+CreateTrueFalseDropDown("publishboardlist["+countstr+"]",publishboardlist)+""+CreateTrueFalseDropDown("publishfreesite["+countstr+"]",publishfreesite)+"No
    "; content+="

    * An identity is considered successfully announced when you have downloaded a trust list from someone that contains the identity.

    "; content+="

    Single Use Identities will automatically be deleted 7 days after creation.

    "; diff --git a/src/http/pages/peerdetailspage.cpp b/src/http/pages/peerdetailspage.cpp index 1ff0493..9a8fd1b 100644 --- a/src/http/pages/peerdetailspage.cpp +++ b/src/http/pages/peerdetailspage.cpp @@ -81,7 +81,7 @@ const std::string PeerDetailsPage::GeneratePage(const std::string &method, const st.Step(); content+=""; - content+=""; content+=""; @@ -119,7 +119,7 @@ const std::string PeerDetailsPage::GeneratePage(const std::string &method, const st.Bind(0,identityid); st.Step(); - content+=""; content+=""; diff --git a/src/message.cpp b/src/message.cpp index 0004bf1..f95f541 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -160,22 +160,10 @@ void Message::HandleAdministrationMessage() origmessagetrust+=changemessagetrust; origtrustlisttrust+=changetrustlisttrust; - if(origmessagetrust<0) - { - origmessagetrust=0; - } - if(origmessagetrust>100) - { - origmessagetrust=100; - } - if(origtrustlisttrust<0) - { - origtrustlisttrust=0; - } - if(origtrustlisttrust>100) - { - origtrustlisttrust=100; - } + origmessagetrust<0 ? origmessagetrust=0 : false; + origmessagetrust>100 ? origmessagetrust=100 : false; + origtrustlisttrust<0 ? origtrustlisttrust=0 : false; + origtrustlisttrust>100 ? origtrustlisttrust=100 : false; // update new trust levels SQLite3DB::Statement update=m_db->Prepare("UPDATE tblIdentity SET LocalMessageTrust=?, LocalTrustListTrust=? WHERE IdentityID=?;"); -- 2.7.4
    "; + content+="
    "; content+="Trust List of this identity"; content+="
    Message TrustMessage CommentTrust List TrustTrust Comment
    "; + content+="
    "; content+="Trust of this identity from other identities"; content+="
    Message TrustMessage CommentTrust List TrustTrust Comment