From 3dc3ac3cfe10b7196a7977e9c041c29fa141c35e Mon Sep 17 00:00:00 2001 From: SomeDude Date: Mon, 10 Mar 2008 18:05:00 +0100 Subject: [PATCH] version 0.2.0 --- CMakeLists.txt | 10 +++- include/freenet/periodicdbmaintenance.h | 2 + include/global.h | 5 +- include/message.h | 2 + readme.txt | 81 +++++++++++++++++++++++++++++++++ src/board.cpp | 59 +++++++++++++++++++++++- src/freenet/messagelistxml.cpp | 4 +- src/freenet/messagerequester.cpp | 4 +- src/freenet/messagexml.cpp | 1 + src/freenet/periodicdbmaintenance.cpp | 14 ++++++ src/global.cpp | 73 +++++++++++++++++++++++++++++ src/http/pages/controlboardpage.cpp | 4 +- src/http/pages/execquerypage.cpp | 6 ++- src/http/pages/peertrustpage.cpp | 4 ++ src/message.cpp | 12 +++-- 15 files changed, 268 insertions(+), 13 deletions(-) create mode 100644 readme.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c0e66a..0cfa932 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,7 @@ PROJECT(fms) +OPTION(USE_BUNDLED_SQLITE "Use the bundled SQLite3 library" OFF) + SET(FMS_SRC src/base64.cpp src/board.cpp @@ -123,7 +125,9 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS") TARGET_LINK_LIBRARIES(fms socket) ENDIF(CMAKE_SYSTEM_NAME STREQUAL "SunOS") -FIND_LIBRARY(SQLITE3_LIBRARY NAMES sqlite3 sqlite3_s) +IF(NOT USE_BUNDLED_SQLITE) + FIND_LIBRARY(SQLITE3_LIBRARY NAMES sqlite3 sqlite3_s) +ENDIF(NOT USE_BUNDLED_SQLITE) FIND_LIBRARY(TINYXML_LIBRARY NAMES tinyxml tinyxml_s) FIND_LIBRARY(PTHREADS_LIBRARY NAMES pthread pthreads pthreadvc2) FIND_LIBRARY(SHTTPD_LIBRARY NAMES shttpd) @@ -131,7 +135,9 @@ FIND_LIBRARY(SHTTPD_LIBRARY NAMES shttpd) IF(SQLITE3_LIBRARY) TARGET_LINK_LIBRARIES(fms ${SQLITE3_LIBRARY}) ELSE(SQLITE3_LIBRARY) - MESSAGE(STATUS "Could not find system SQLite library. Will compile from included source.") + IF(NOT USE_BUNDLED_SQLITE) + MESSAGE(STATUS "Could not find system SQLite library. Will compile from included source.") + ENDIF(NOT USE_BUNDLED_SQLITE) ADD_LIBRARY(sqlite3 libs/sqlite3/sqlite3.c) TARGET_LINK_LIBRARIES(fms sqlite3) INCLUDE_DIRECTORIES(libs/sqlite3) diff --git a/include/freenet/periodicdbmaintenance.h b/include/freenet/periodicdbmaintenance.h index cf80285..575cef4 100644 --- a/include/freenet/periodicdbmaintenance.h +++ b/include/freenet/periodicdbmaintenance.h @@ -28,6 +28,8 @@ private: DateTime m_check1hour; DateTime m_check6hours; DateTime m_check1day; + + long m_deletemessagesolderthan; }; diff --git a/include/global.h b/include/global.h index 3e26f37..30934a8 100644 --- a/include/global.h +++ b/include/global.h @@ -5,7 +5,7 @@ //#include #include "pthreadwrapper/thread.h" -#define FMS_VERSION "0.1.15" +#define FMS_VERSION "0.2.0" // opens database and creates tables and initial inserts if necessary void SetupDB(); @@ -17,6 +17,9 @@ void SetupDefaultOptions(); // opens logfile and sets it up void SetupLogFile(); +// TODO remove sometime after 0.1.17 +void FixCapitalBoardNames(); + void SigHandler(int signum); void MainFunction(); diff --git a/include/message.h b/include/message.h index 9cda4a9..3033229 100644 --- a/include/message.h +++ b/include/message.h @@ -67,6 +67,8 @@ private: std::vector m_boards; std::map m_inreplyto; long m_changemessagetrustonreply; + long m_minlocalmessagetrust; + long m_minlocaltrustlisttrust; }; diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..26b2dab --- /dev/null +++ b/readme.txt @@ -0,0 +1,81 @@ +COMPILING +--------- +Compiling FMS requires CMake, and pthreads. Other required libraries are +bundled with FMS. + +To compile, run these commands from the source directory: +cmake . +make + +If you want to use the bundled SQLite3 library, add a -D USE_BUNDLED_SQLITE=ON +to the cmake command. + +UPGRADING +--------- +It is always a good idea to make copies of your current FMS installation before +continuing. First shut down FMS and then replace the binary and template.htm +with those from the new version. You may keep the same database unless +otherwise noted. + +INSTALLATION +------------ +Place the binary and template.htm in a directory of your choice. On the first +run, a database file will also be created in this directory. Make sure the +user that runs FMS has read/write access to this directory. + +RUNNING +------- +You may run FMS in console mode by running the binary directly. If you are +running *nix and would like to run as a daemon, use the -d argument. On +Windows, -i will install FMS as a service, and -u will uninstall the service. + +EXITING +------- +To exist FMS running in console mode, press CTRL+C while at the console. You +can also use the shutdown button on the web interface to close FMS. As a last +resort, you may kill the process. + +WEB INTERFACE +------------- +By default, a web interface for administration will be running at http:// +localhost:8888. You can use the interface to configure and administer FMS. + +NNTP CONFIGURATION +------------------ +By default, the NNTP server will listen on port 1119. Configure your +newsreader to connect to the machine running FMS on this port. Use the web +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 +---------------- +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 +with the message body. Cross posting is fine, but remember that each identity +can set a limit to the number of boards each message may be cross posted to. + +CONTROL BOARDS +-------------- +Control boards are special boards that will add/remove trust from an identity. +Create control boards in the web interface, and then reply to an identity's +message to a control board to change the trust of the identity as per the +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. + +TRUST +----- +Trust is the most important element of FMS. It determines which identities you +will download messages from and thus your overall experience. Do not give +trust to arbitrary identities. Pick whom you trust wisely. There settings for +minimum trust before downloading messages and trust lists can be changed on the +web interface. + +A note on NULL trust: If you neither trust or distrust an identity, they will +have NULL trust (no trust at all). You will download messages and trust lists +from identities with NULL peer trust as long as the local trust level is above +your configured minimum. You will also download messages from identities with +NULL local message trust (the peer message trust must be NULL or > your +configured minimum as well), but you will not download trust lists from +identities with NULL local trust list trust. diff --git a/src/board.cpp b/src/board.cpp index aee9339..99350f5 100644 --- a/src/board.cpp +++ b/src/board.cpp @@ -97,8 +97,9 @@ const bool Board::Load(const long boardid) } } -const bool Board::Load(const std::string &boardname) +const bool Board::Load(const std::string &boardname) // same as loading form boardid - but using name { + /* SQLite3DB::Statement st=m_db->Prepare("SELECT BoardID FROM tblBoard WHERE BoardName=?;"); st.Bind(0,boardname); st.Step(); @@ -112,6 +113,62 @@ const bool Board::Load(const std::string &boardname) { return false; } + */ + + // clear current values + m_boardid=-1; + m_boardname=""; + m_boarddescription=""; + m_datecreated.Set(1970,1,1); + m_lowmessageid=0; + m_highmessageid=0; + m_messagecount=0; + int tempint=-1; + + SQLite3DB::Statement st=m_db->Prepare("SELECT BoardName, BoardDescription, DateAdded, HighMessageID, LowMessageID, MessageCount, SaveReceivedMessages, tblBoard.BoardID FROM tblBoard LEFT JOIN vwBoardStats ON tblBoard.BoardID=vwBoardStats.BoardID WHERE tblBoard.BoardName=?;"); + st.Bind(0,boardname); + st.Step(); + + if(st.RowReturned()) + { + int tempint; + std::string tempstr; + std::vector dateparts; + + st.ResultText(0,m_boardname); + st.ResultText(1,m_boarddescription); + st.ResultText(2,tempstr); + st.ResultInt(7,tempint); // boardid + m_boardid=tempint; + + SetDateFromString(tempstr); + + tempint=0; + st.ResultInt(3,tempint); + m_highmessageid=tempint; + tempint=0; + st.ResultInt(4,tempint); + m_lowmessageid=tempint; + tempint=0; + st.ResultInt(5,tempint); + m_messagecount=tempint; + st.ResultText(6,tempstr); + if(tempstr=="true") + { + m_savereceivedmessages=true; + } + else + { + m_savereceivedmessages=false; + } + + return true; + } + else + { + return false; + } + } void Board::SetDateFromString(const std::string &datestring) diff --git a/src/freenet/messagelistxml.cpp b/src/freenet/messagelistxml.cpp index c2a9c82..4eed479 100644 --- a/src/freenet/messagelistxml.cpp +++ b/src/freenet/messagelistxml.cpp @@ -232,7 +232,9 @@ const bool MessageListXML::ParseXML(const std::string &xml) { if(node2->FirstChild()) { - boards.push_back(node2->FirstChild()->ValueStr()); + std::string boardname=node2->FirstChild()->ValueStr(); + StringFunctions::LowerCase(boardname,boardname); + boards.push_back(boardname); } node2=node2->NextSibling("Board"); } diff --git a/src/freenet/messagerequester.cpp b/src/freenet/messagerequester.cpp index 6680b8b..13cc1f2 100644 --- a/src/freenet/messagerequester.cpp +++ b/src/freenet/messagerequester.cpp @@ -19,8 +19,10 @@ MessageRequester::MessageRequester(FCPv2 *fcp):IIndexRequester(fcp) const long MessageRequester::GetBoardID(const std::string &boardname) { + std::string lowerboard=boardname; + StringFunctions::LowerCase(lowerboard,lowerboard); SQLite3DB::Statement st=m_db->Prepare("SELECT BoardID FROM tblBoard WHERE BoardName=?;"); - st.Bind(0,boardname); + st.Bind(0,lowerboard); st.Step(); if(st.RowReturned()) diff --git a/src/freenet/messagexml.cpp b/src/freenet/messagexml.cpp index 994ebd4..8f5006e 100644 --- a/src/freenet/messagexml.cpp +++ b/src/freenet/messagexml.cpp @@ -103,6 +103,7 @@ const bool MessageXML::ParseXML(const std::string &xml) if(txt) { m_replyboard=txt->ValueStr(); + StringFunctions::LowerCase(m_replyboard,m_replyboard); } txt=hnd.FirstChild("Message").FirstChild("Body").FirstChild().ToText(); if(txt) diff --git a/src/freenet/periodicdbmaintenance.cpp b/src/freenet/periodicdbmaintenance.cpp index dad043e..f6f501b 100644 --- a/src/freenet/periodicdbmaintenance.cpp +++ b/src/freenet/periodicdbmaintenance.cpp @@ -1,5 +1,6 @@ #include "../../include/freenet/periodicdbmaintenance.h" #include "../../include/stringfunctions.h" +#include "../../include/option.h" #ifdef XMEM #include @@ -7,6 +8,8 @@ PeriodicDBMaintenance::PeriodicDBMaintenance() { + std::string tempval; + m_check10mins.SetToGMTime(); m_check30mins.SetToGMTime(); m_check1hour.SetToGMTime(); @@ -19,6 +22,10 @@ PeriodicDBMaintenance::PeriodicDBMaintenance() m_check6hours.Add(0,-1,-5); m_check1day.Add(0,0,-23); + tempval="180"; + Option::Instance()->Get("DeleteMessagesOlderThan",tempval); + StringFunctions::Convert(tempval,m_deletemessagesolderthan); + } void PeriodicDBMaintenance::Do10MinuteMaintenance() @@ -185,6 +192,13 @@ void PeriodicDBMaintenance::Do1DayMaintenance() st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S")); st.Step(); + // delete old messages + date.SetToGMTime(); + date.Add(0,0,0,-m_deletemessagesolderthan); + st=m_db->Prepare("DELETE FROM tblMessage WHERE MessageDateExecute("INSERT INTO tblIdentity(PublicKey,DateAdded) VALUES('SSK@T8l1IEGU4-PoASFzgc2GYhIgRzUvZsKdoQWeuLHuTmM,QLxAPfkGis8l5NafNpSCdbxzXhBlu9WL8svcqJw9Mpo,AQACAAE/','"+date.Format("%Y-%m-%d %H:%M:%S")+"');"); + // TODO remove sometime after 0.1.17 + FixCapitalBoardNames(); + } void ConvertDB0100To0101() @@ -645,6 +648,12 @@ void SetupDefaultOptions() st.Step(); st.Reset(); + st.Bind(0,"DeleteMessagesOlderThan"); + st.Bind(1,"180"); + st.Bind(2,"Automatically delete messages older than this many days."); + st.Step(); + st.Reset(); + } void SetupLogFile() @@ -770,3 +779,67 @@ void StartThreads(std::vector &threads) } */ + +void FixCapitalBoardNames() +{ + SQLite3DB::DB *db=SQLite3DB::DB::Instance(); + + SQLite3DB::Statement st=db->Prepare("SELECT BoardID,BoardName FROM tblBoard WHERE BoardID NOT IN (SELECT BoardID FROM tblAdministrationBoard);"); + SQLite3DB::Statement st2=db->Prepare("SELECT BoardID FROM tblBoard WHERE BoardName=?;"); + SQLite3DB::Statement del=db->Prepare("DELTE FROM tblBoard WHERE BoardID=?;"); + SQLite3DB::Statement upd=db->Prepare("UPDATE tblBoard SET BoardName=? WHERE BoardID=?;"); + SQLite3DB::Statement upd2=db->Prepare("UPDATE tblMessage SET ReplyBoardID=? WHERE ReplyBoardID=?;"); + SQLite3DB::Statement upd3=db->Prepare("UPDATE tblMessageBoard SET BoardID=? WHERE BoardID=?;"); + + st.Step(); + while(st.RowReturned()) + { + int boardid=0; + int newboardid=0; + std::string name=""; + std::string lowername=""; + + st.ResultInt(0,boardid); + st.ResultText(1,name); + + lowername=name; + StringFunctions::LowerCase(lowername,lowername); + + if(name!=lowername) + { + st2.Bind(0,lowername); + st2.Step(); + + if(st2.RowReturned()) + { + st2.ResultInt(0,newboardid); + + upd2.Bind(0,newboardid); + upd2.Bind(1,boardid); + upd2.Step(); + upd2.Reset(); + + upd3.Bind(0,newboardid); + upd3.Bind(1,boardid); + upd3.Step(); + upd3.Reset(); + + del.Bind(0,boardid); + del.Step(); + del.Reset(); + } + else + { + upd.Bind(0,lowername); + upd.Bind(1,boardid); + upd.Step(); + upd.Reset(); + } + + st2.Reset(); + } + + st.Step(); + } + +} diff --git a/src/http/pages/controlboardpage.cpp b/src/http/pages/controlboardpage.cpp index c685ca4..5fbc10b 100644 --- a/src/http/pages/controlboardpage.cpp +++ b/src/http/pages/controlboardpage.cpp @@ -104,9 +104,9 @@ const std::string ControlBoardPage::GeneratePage(const std::string &method, cons content+=""; content+=""; content+="\r\n"; - content+=""; + content+=""; content+="\r\n"; - content+=""; + content+=""; content+="\r\n"; content+=""; content+=""; diff --git a/src/http/pages/execquerypage.cpp b/src/http/pages/execquerypage.cpp index 50d3f0c..8ef4c48 100644 --- a/src/http/pages/execquerypage.cpp +++ b/src/http/pages/execquerypage.cpp @@ -8,10 +8,12 @@ const std::string ExecQueryPage::GeneratePage(const std::string &method, const std::map &queryvars) { std::string content=""; + std::string query=""; 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); + query=(*queryvars.find("query")).second; + SQLite3DB::Recordset rs=m_db->Query(query); content+=""; if(rs.Count()>0) @@ -49,7 +51,7 @@ const std::string ExecQueryPage::GeneratePage(const std::string &method, const s content+="

Execute Query

"; content+=""; content+=""; - content+=""; + content+=""; content+=""; content+=""; diff --git a/src/http/pages/peertrustpage.cpp b/src/http/pages/peertrustpage.cpp index 48a19e8..ee087f3 100644 --- a/src/http/pages/peertrustpage.cpp +++ b/src/http/pages/peertrustpage.cpp @@ -165,6 +165,10 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s content+=""; content+=""; content+=""; + if(namesearch!="") + { + content+=""; + } content+="
"; content+=""; content+=""; diff --git a/src/message.cpp b/src/message.cpp index f4a6ea6..0004bf1 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -146,7 +146,7 @@ void Message::HandleAdministrationMessage() } else { - origmessagetrust=50; + origmessagetrust=m_minlocalmessagetrust; } if(origmess.ResultNull(3)==false) { @@ -154,7 +154,7 @@ void Message::HandleAdministrationMessage() } else { - origtrustlisttrust=50; + origtrustlisttrust=m_minlocaltrustlisttrust; } origmessagetrust+=changemessagetrust; @@ -242,7 +242,7 @@ void Message::HandleChangeTrust() } else { - localmessagetrust=50; + localmessagetrust=m_minlocalmessagetrust; } localmessagetrust+=m_changemessagetrustonreply; @@ -288,6 +288,12 @@ void Message::Initialize() { m_addnewpostfromidentities=false; } + tempval="50"; + Option::Instance()->Get("MinLocalMessageTrust",tempval); + StringFunctions::Convert(tempval,m_minlocalmessagetrust); + tempval="51"; + Option::Instance()->Get("MinLocalTrustListTrust",tempval); + StringFunctions::Convert(tempval,m_minlocaltrustlisttrust); } const bool Message::Load(const long messageid, const long boardid) -- 2.7.4
NameLocal Message Trust