version 0.3.9
authorSomeDude <SomeDude@NuBL7aaJ6Cn4fB7GXFb9Zfi8w1FhPyW3oKgU9TweZMw>
Fri, 18 Jul 2008 12:33:00 +0000 (14:33 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Fri, 18 Jul 2008 12:33:00 +0000 (14:33 +0200)
CMakeLists.txt
include/global.h
src/charsetconverter.cpp
src/dbsetup.cpp
src/fmsapp.cpp
src/freenet/introductionpuzzleinserter.cpp
src/freenet/siteinserter.cpp
src/freenet/trustlistrequester.cpp
src/http/ipagehandler.cpp
src/http/pages/homepage.cpp
src/http/pages/optionspage.cpp

index db5f4f4..ebd70aa 100644 (file)
@@ -160,6 +160,7 @@ FIND_LIBRARY(ICONV_LIBRARY NAMES iconv iconv_s libiconv libiconv_s)
 \r
 IF(POCO_FOUNDATION_LIBRARY)\r
        TARGET_LINK_LIBRARIES(fms ${POCO_FOUNDATION_LIBRARY})\r
+       ADD_DEFINITIONS(-DPOCO_HAVE_IPv6)\r
        IF(WIN32)\r
                ADD_DEFINITIONS(-DPOCO_STATIC)\r
        ENDIF(WIN32)\r
index 8b4feab..de4e04b 100644 (file)
@@ -7,7 +7,7 @@
 \r
 #define VERSION_MAJOR          "0"\r
 #define VERSION_MINOR          "3"\r
-#define VERSION_RELEASE                "8"\r
+#define VERSION_RELEASE                "9"\r
 #define FMS_VERSION                    VERSION_MAJOR"."VERSION_MINOR"."VERSION_RELEASE\r
 \r
 typedef Poco::ScopedLock<Poco::FastMutex> Guard;\r
index 9e4ff6f..f49213e 100644 (file)
@@ -49,7 +49,7 @@ const bool CharsetConverter::Convert(const std::string &input, std::string &outp
        {\r
                std::vector<char> invec(input.begin(),input.end());\r
                std::vector<char> outvec(invec.size()*4,0);\r
-#if defined(_WIN32) //|| defined(__APPLE__) || defined(__DARWIN__)\r
+#if defined(_WIN32) || defined(__FreeBSD__)//|| defined(__APPLE__) || defined(__DARWIN__)\r
                const char *inptr=&invec[0];\r
 #else\r
                char *inptr=&invec[0];\r
index 68ee676..e6bdcf6 100644 (file)
@@ -17,13 +17,6 @@ void SetupDB()
        db->Open("fms.db3");\r
        db->SetBusyTimeout(20000);              // set timeout to 20 seconds\r
 \r
-       tempval="";\r
-       Option::Instance()->Get("VacuumOnStartup",tempval);\r
-       if(tempval=="true")\r
-       {\r
-               db->Execute("VACUUM;");\r
-       }\r
-\r
        db->Execute("CREATE TABLE IF NOT EXISTS tblDBVersion(\\r
                                Major                           INTEGER,\\r
                                Minor                           INTEGER\\r
index ebebe4a..8a462e2 100644 (file)
@@ -177,6 +177,14 @@ int FMSApp::main(const std::vector<std::string> &args)
        {\r
                logger().information("FMS startup v"FMS_VERSION);\r
 \r
+               std::string tempval="";\r
+               Option::Instance()->Get("VacuumOnStartup",tempval);\r
+               if(tempval=="true")\r
+               {\r
+                       logger().information("VACUUMing database");\r
+                       SQLite3DB::DB::Instance()->Execute("VACUUM;");\r
+               }\r
+\r
                StartThreads();\r
 \r
                if(isInteractive()==true)\r
index 409a0f7..1fa13c0 100644 (file)
@@ -173,70 +173,77 @@ const bool IntroductionPuzzleInserter::StartInsert(const long &localidentityid)
        }\r
        StringFunctions::Convert(index,indexstr);\r
 \r
-       SQLite3DB::Recordset rs2=m_db->Query("SELECT PrivateKey,PublicKey FROM tblLocalIdentity WHERE LocalIdentityID="+idstring+";");\r
-       if(rs2.Empty()==false && rs2.GetField(0)!=NULL)\r
+       if(index<50)\r
        {\r
-               privatekey=rs2.GetField(0);\r
-               if(rs2.GetField(1))\r
+               SQLite3DB::Recordset rs2=m_db->Query("SELECT PrivateKey,PublicKey FROM tblLocalIdentity WHERE LocalIdentityID="+idstring+";");\r
+               if(rs2.Empty()==false && rs2.GetField(0)!=NULL)\r
                {\r
-                       publickey=rs2.GetField(1);\r
-               }\r
-               if(publickey.size()>=50)\r
-               {\r
-                       // remove - and ~\r
-                       keypart=StringFunctions::Replace(StringFunctions::Replace(publickey.substr(4,43),"-",""),"~","");\r
+                       privatekey=rs2.GetField(0);\r
+                       if(rs2.GetField(1))\r
+                       {\r
+                               publickey=rs2.GetField(1);\r
+                       }\r
+                       if(publickey.size()>=50)\r
+                       {\r
+                               // remove - and ~\r
+                               keypart=StringFunctions::Replace(StringFunctions::Replace(publickey.substr(4,43),"-",""),"~","");\r
+                       }\r
                }\r
-       }\r
 \r
-       Option::Instance()->Get("MessageBase",messagebase);\r
+               Option::Instance()->Get("MessageBase",messagebase);\r
 \r
-       GenerateCaptcha(encodedpuzzle,solutionstring);\r
+               GenerateCaptcha(encodedpuzzle,solutionstring);\r
 \r
-       try\r
-       {\r
-               uuid=uuidgen.createRandom();\r
+               try\r
+               {\r
+                       uuid=uuidgen.createRandom();\r
+               }\r
+               catch(...)\r
+               {\r
+                       m_log->fatal("IntroductionPuzzleInserter::StartInsert could not create UUID");\r
+               }\r
+\r
+               xml.SetType("captcha");\r
+               std::string uuidstr=uuid.toString();\r
+               StringFunctions::UpperCase(uuidstr,uuidstr);\r
+               xml.SetUUID(uuidstr+"@"+keypart);\r
+               xml.SetPuzzleData(encodedpuzzle);\r
+               xml.SetMimeType("image/bmp");\r
+\r
+               xmldata=xml.GetXML();\r
+               StringFunctions::Convert(xmldata.size(),xmldatasizestr);\r
+\r
+               message.SetName("ClientPut");\r
+               message["URI"]=privatekey+messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"|IntroductionPuzzle|"+indexstr+".xml";\r
+               message["Identifier"]=m_fcpuniquename+"|"+idstring+"|"+indexstr+"|"+xml.GetUUID()+"|"+message["URI"];\r
+               message["UploadFrom"]="direct";\r
+               message["DataLength"]=xmldatasizestr;\r
+               m_fcp->SendMessage(message);\r
+               m_fcp->SendRaw(xmldata.c_str(),xmldata.size());\r
+\r
+               // insert to USK\r
+               message.Reset();\r
+               message.SetName("ClientPutComplexDir");\r
+               message["URI"]="USK"+privatekey.substr(3)+messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y.%m.%d")+"|IntroductionPuzzle/0/";\r
+               message["Identifier"]=m_fcpuniquename+"USK|"+message["URI"];\r
+               message["DefaultName"]="IntroductionPuzzle.xml";\r
+               message["Files.0.Name"]="IntroductionPuzzle.xml";\r
+               message["Files.0.UplaodFrom"]="direct";\r
+               message["Files.0.DataLength"]=xmldatasizestr;\r
+               m_fcp->SendMessage(message);\r
+               m_fcp->SendRaw(xmldata.c_str(),xmldata.size());\r
+\r
+               m_db->Execute("INSERT INTO tblIntroductionPuzzleInserts(UUID,Type,MimeType,LocalIdentityID,PuzzleData,PuzzleSolution) VALUES('"+xml.GetUUID()+"','captcha','image/bmp',"+idstring+",'"+encodedpuzzle+"','"+solutionstring+"');");\r
+\r
+               m_inserting.push_back(localidentityid);\r
+\r
+               m_log->debug("IntroductionPuzzleInserter::StartInsert started insert for id "+idstring);\r
        }\r
-       catch(...)\r
+       else\r
        {\r
-               m_log->fatal("IntroductionPuzzleInserter::StartInsert could not create UUID");\r
+               m_log->warning("IntroductionPuzzleInserter::StartInsert already inserted 50 puzzles for "+idstring);\r
        }\r
 \r
-       xml.SetType("captcha");\r
-       std::string uuidstr=uuid.toString();\r
-       StringFunctions::UpperCase(uuidstr,uuidstr);\r
-       xml.SetUUID(uuidstr+"@"+keypart);\r
-       xml.SetPuzzleData(encodedpuzzle);\r
-       xml.SetMimeType("image/bmp");\r
-\r
-       xmldata=xml.GetXML();\r
-       StringFunctions::Convert(xmldata.size(),xmldatasizestr);\r
-\r
-       message.SetName("ClientPut");\r
-       message["URI"]=privatekey+messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"|IntroductionPuzzle|"+indexstr+".xml";\r
-       message["Identifier"]=m_fcpuniquename+"|"+idstring+"|"+indexstr+"|"+xml.GetUUID()+"|"+message["URI"];\r
-       message["UploadFrom"]="direct";\r
-       message["DataLength"]=xmldatasizestr;\r
-       m_fcp->SendMessage(message);\r
-       m_fcp->SendRaw(xmldata.c_str(),xmldata.size());\r
-\r
-       // insert to USK\r
-       message.Reset();\r
-       message.SetName("ClientPutComplexDir");\r
-       message["URI"]="USK"+privatekey.substr(3)+messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y.%m.%d")+"|IntroductionPuzzle/0/";\r
-       message["Identifier"]=m_fcpuniquename+"USK|"+message["URI"];\r
-       message["DefaultName"]="IntroductionPuzzle.xml";\r
-       message["Files.0.Name"]="IntroductionPuzzle.xml";\r
-       message["Files.0.UplaodFrom"]="direct";\r
-       message["Files.0.DataLength"]=xmldatasizestr;\r
-       m_fcp->SendMessage(message);\r
-       m_fcp->SendRaw(xmldata.c_str(),xmldata.size());\r
-\r
-       m_db->Execute("INSERT INTO tblIntroductionPuzzleInserts(UUID,Type,MimeType,LocalIdentityID,PuzzleData,PuzzleSolution) VALUES('"+xml.GetUUID()+"','captcha','image/bmp',"+idstring+",'"+encodedpuzzle+"','"+solutionstring+"');");\r
-\r
-       m_inserting.push_back(localidentityid);\r
-\r
-       m_log->debug("IntroductionPuzzleInserter::StartInsert started insert for id "+idstring);\r
-\r
        return true;\r
 \r
 }\r
index 77da44a..02b5a73 100644 (file)
@@ -166,10 +166,10 @@ void SiteInserter::GeneratePages(const long localidentityid, std::string &uskkey
                uskkey=key;\r
 \r
                filename=name+"-template.htm";\r
-               FILE *infile=fopen(filename.c_str(),"r+b");\r
+               FILE *infile=fopen(filename.c_str(),"rb");\r
                if(!infile)\r
                {\r
-                       infile=fopen("site-template.htm","r+b");\r
+                       infile=fopen("site-template.htm","rb");\r
                }\r
                if(infile)\r
                {\r
@@ -205,7 +205,7 @@ void SiteInserter::GeneratePages(const long localidentityid, std::string &uskkey
 \r
                // get extra files that the user wants to add to the Freesite\r
                filename=name+"-files.txt";\r
-               infile=fopen(filename.c_str(),"r+b");\r
+               infile=fopen(filename.c_str(),"rb");\r
                if(infile)\r
                {\r
                        std::vector<std::string> files;\r
index 668cdb9..d7dc27b 100644 (file)
@@ -30,6 +30,8 @@ const bool TrustListRequester::HandleAllData(FCPMessage &message)
        TrustListXML xml;\r
        long identityid;\r
        long index;\r
+       int insertcount=0;\r
+       int dayinsertcount=0;\r
 \r
        StringFunctions::Split(message["Identifier"],"|",idparts);\r
        StringFunctions::Convert(message["DataLength"],datalength);\r
@@ -52,6 +54,22 @@ const bool TrustListRequester::HandleAllData(FCPMessage &message)
        data.resize(datalength);\r
        m_fcp->ReceiveRaw(&data[0],datalength);\r
 \r
+       // get count of identities added in last 24 hours\r
+       st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity WHERE DateAdded>=?;");\r
+       st.Bind(0,Poco::DateTimeFormatter::format(now,"%Y-%m-%d %H:%M:%S"));\r
+       st.Step();\r
+       if(st.RowReturned())\r
+       {\r
+               if(st.ResultNull(0)==false)\r
+               {\r
+                       st.ResultInt(0,dayinsertcount);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               m_log->error("TrustListRequester::HandleAllData couldn't get count of identities added in last 24 hours");\r
+       }\r
+\r
        // parse file into xml and update the database\r
        if(xml.ParseXML(std::string(data.begin(),data.end()))==true)\r
        {\r
@@ -98,13 +116,17 @@ const bool TrustListRequester::HandleAllData(FCPMessage &message)
                        st.Step();\r
                        if(st.RowReturned()==false)\r
                        {\r
-                               idinsert.Bind(0,identity);\r
-                               idinsert.Bind(1,Poco::DateTimeFormatter::format(now,"%Y-%m-%d %H:%M:%S"));\r
-                               idinsert.Bind(2,"trust list of "+publisherid);\r
-                               idinsert.Step(true);\r
-                               id=idinsert.GetLastInsertRowID();\r
-                               idinsert.Reset();\r
-                       //      m_db->ExecuteInsert("INSERT INTO tblIdentity(PublicKey,DateAdded,AddedMethod) VALUES('"+identity+"','"+now.Format("%Y-%m-%d %H:%M:%S")+"');",(long &)id);\r
+                               if(insertcount<50 && dayinsertcount<100)\r
+                               {\r
+                                       idinsert.Bind(0,identity);\r
+                                       idinsert.Bind(1,Poco::DateTimeFormatter::format(now,"%Y-%m-%d %H:%M:%S"));\r
+                                       idinsert.Bind(2,"trust list of "+publisherid);\r
+                                       idinsert.Step(true);\r
+                                       id=idinsert.GetLastInsertRowID();\r
+                                       idinsert.Reset();\r
+                               }\r
+                               insertcount++;\r
+                               dayinsertcount++;\r
                        }\r
                        else\r
                        {\r
@@ -151,6 +173,15 @@ const bool TrustListRequester::HandleAllData(FCPMessage &message)
                trustst.Finalize();\r
                st.Finalize();\r
 \r
+               if(insertcount>=50)\r
+               {\r
+                       m_log->warning("TrustListRequester::HandleAllData TrustList contained more than 50 new identities : "+message["Identifier"]);\r
+               }\r
+               if(dayinsertcount>=100)\r
+               {\r
+                       m_log->warning("TrustListRequester::HandleAllData TrustList would have inserted more than 100 new identities in the last 24 hours : "+message["Identifier"]);\r
+               }\r
+\r
                st=m_db->Prepare("INSERT INTO tblTrustListRequests(IdentityID,Day,RequestIndex,Found) VALUES(?,?,?,'true');");\r
                st.Bind(0,identityid);\r
                st.Bind(1,idparts[4]);\r
index 53211b1..9048d98 100644 (file)
@@ -102,7 +102,10 @@ void IPageHandler::handleRequest(Poco::Net::HTTPServerRequest &request, Poco::Ne
 \r
        CreateQueryVarMap(request,vars);\r
 \r
-       response.setChunkedTransferEncoding(true);\r
+       if(request.getVersion()==Poco::Net::HTTPRequest::HTTP_1_1)\r
+       {\r
+               response.setChunkedTransferEncoding(true);\r
+       }\r
        response.setContentType("text/html");\r
 \r
        std::ostream &ostr = response.send();\r
index 2f41fac..fc60f78 100644 (file)
@@ -59,7 +59,7 @@ const std::string HomePage::GeneratePage(const std::string &method, const std::m
 \r
        if(showgenericupdate)\r
        {\r
-               content+="Check for new versions at the <a href=\"http://"+fcphost+":"+fproxyport+"/USK@0npnMrqZNKRCRoGojZV93UNHCMN-6UU3rRSAmP6jNLE,~BG-edFtdCC1cSH4O3BWdeIYa8Sw5DfyrSV-TKdO5ec,AQACAAE/fms/66/\">FMS Freesite</a><br>";\r
+               content+="Check for new versions at the <a href=\"http://"+fcphost+":"+fproxyport+"/USK@0npnMrqZNKRCRoGojZV93UNHCMN-6UU3rRSAmP6jNLE,~BG-edFtdCC1cSH4O3BWdeIYa8Sw5DfyrSV-TKdO5ec,AQACAAE/fms/69/\">FMS Freesite</a><br>";\r
        }\r
 \r
        content+="Use these pages to administer your FMS installation.";\r
index 4f7cc83..5a1d8e1 100644 (file)
@@ -119,7 +119,7 @@ const std::string OptionsPage::GeneratePage(const std::string &method, const std
                st.Step();\r
                count++;\r
        }\r
-content+="<input type=\"hidden\" name=\"param[0]\" value=\"\">";\r
+       content+="<input type=\"hidden\" name=\"param[0]\" value=\"\">";\r
        content+="<tr><td colspan=\"3\"><center><input type=\"submit\" value=\"Save\"></form></td></tr>";\r
        content+="</table>";\r
        \r