X-Git-Url: https://git.pterodactylus.net/?p=fms.git;a=blobdiff_plain;f=src%2Ffreenet%2Fsiteinserter.cpp;h=e54a28ea080854512bcbd7708b04f4e0c896ca56;hp=76bfb958ee5aefb863241836d7ce384df0c595fa;hb=853f67b0b7b8121d572cff34d40f7b28cac8f65e;hpb=b4f4686250878cdf4fcb2986a2ea6546cba867d1 diff --git a/src/freenet/siteinserter.cpp b/src/freenet/siteinserter.cpp index 76bfb95..e54a28e 100644 --- a/src/freenet/siteinserter.cpp +++ b/src/freenet/siteinserter.cpp @@ -22,6 +22,10 @@ void SiteInserter::CheckForNeededInsert() { DateTime date; date.SetToGMTime(); + date.SetHour(0); + date.SetMinute(0); + date.SetSecond(0); + date.Normalize(); 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;"); @@ -84,6 +86,9 @@ std::string SiteInserter::GenerateIndex(const std::string &htmltemplate, const l content+=""; content+="
"; content+=SanitizeOutput(post); + //post=SanitizeOutput(post); + //StringFunctions::Replace(post,"\r\n","
"); + //content+=post; content+="
"; content+=""; @@ -113,7 +118,7 @@ std::string SiteInserter::GenerateLinks(const bool publishtrustlist, const bool 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=?;"); + SQLite3DB::Statement st=m_db->Prepare("SELECT Name, PrivateKey, PublishTrustList, PublishBoardList, FreesiteEdition FROM tblLocalIdentity WHERE LocalIdentityID=?;"); st.Bind(0,localidentityid); st.Step(); @@ -127,14 +132,29 @@ void SiteInserter::GeneratePages(const long localidentityid, std::string &uskkey std::string publishboardliststr=""; bool publishtrustlist=false; bool publishboardlist=false; + std::string editionstr=""; st.ResultText(0,name); st.ResultText(1,key); st.ResultText(2,publishtrustliststr); st.ResultText(3,publishboardliststr); + st.ResultText(4,editionstr); publishtrustliststr=="true" ? publishtrustlist=true : publishtrustlist=false; publishboardliststr=="true" ? publishboardlist=true : publishboardlist=false; + // no edition exists - start at 0 + if(editionstr=="") + { + editionstr="0"; + } + // previous edition exists - add 1 + else + { + int edition=0; + StringFunctions::Convert(editionstr,edition); + edition++; + StringFunctions::Convert(edition,editionstr); + } filename=name+"-template.htm"; FILE *infile=fopen(filename.c_str(),"r+b"); @@ -156,6 +176,7 @@ void SiteInserter::GeneratePages(const long localidentityid, std::string &uskkey htmltemplate.append(data.begin(),data.end()); htmltemplate=StringFunctions::Replace(htmltemplate,"[LINKS]",GenerateLinks(publishtrustlist,publishboardlist)); + htmltemplate=StringFunctions::Replace(htmltemplate,"[IDENTITYNAME]",SanitizeOutput(name)); pages["index.htm"]=GenerateIndex(htmltemplate,localidentityid,name); if(publishtrustlist) @@ -173,7 +194,7 @@ void SiteInserter::GeneratePages(const long localidentityid, std::string &uskkey key.erase(0,3); key="USK"+key; } - key+=m_messagebase+"/0/"; + key+=m_messagebase+"/"+editionstr+"/"; uskkey=key; } @@ -182,6 +203,66 @@ void SiteInserter::GeneratePages(const long localidentityid, std::string &uskkey LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_ERROR,"SiteInserter::GeneratePages unable to open "+filename+" or site-template.htm."); } + // get extra files that the user wants to add to the Freesite + filename=name+"-files.txt"; + infile=fopen(filename.c_str(),"r+b"); + if(infile) + { + std::vector files; + + 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); + + // split on \r and \n - on systems with \r\n line endings there will be blank entries, but we'll just skip those + std::string filecontent(data.begin(),data.end()); + StringFunctions::SplitMultiple(filecontent,"\r\n",files); + + for(std::vector::iterator i=files.begin(); i!=files.end(); i++) + { + if((*i)!="" && (*i).find("index.htm")==std::string::npos && (*i).find("trustlist.htm")==std::string::npos && (*i).find("files.htm")==std::string::npos) + { + filename=(*i); + infile=fopen(filename.c_str(),"r+b"); + if(infile) + { + fseek(infile,0,SEEK_END); + len=ftell(infile); + fseek(infile,0,SEEK_SET); + + data.resize(len); + fread(&data[0],1,data.size(),infile); + fclose(infile); + + filecontent=""; + filecontent.append(data.begin(),data.end()); + + // strip off path from filename + while(filename.find_first_of("/")!=std::string::npos) + { + filename.erase(0,filename.find_first_of("/")+1); + } + + if(filecontent.size()>0) + { + pages[filename]=filecontent; + } + + } + else + { + m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"SiteInserter::GeneratePages could not include user file "+(*i)); + } + } + } + + } + } } @@ -192,7 +273,7 @@ std::string SiteInserter::GenerateTrustList(const std::string &htmltemplate, con date.SetToGMTime(); date.Add(0,0,0,-20); - SQLite3DB::Statement st=m_db->Prepare("SELECT Name,PublicKey,tblIdentityTrust.LocalMessageTrust,tblIdentityTrust.LocalTrustListTrust,tblIdentity.IdentityID,tblIdentityTrust.MessageTrustComment,tblIdentityTrust.TrustListTrustComment FROM tblIdentity LEFT JOIN (SELECT IdentityID,LocalMessageTrust,LocalTrustListTrust,MessageTrustComment,TrustListTrustComment FROM tblIdentityTrust WHERE LocalIdentityID=?) AS 'tblIdentityTrust' ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID WHERE PublicKey IS NOT NULL AND LastSeen IS NOT NULL AND LastSeen>=? ORDER BY Name COLLATE NOCASE;"); + SQLite3DB::Statement st=m_db->Prepare("SELECT Name,PublicKey,tblIdentityTrust.LocalMessageTrust,tblIdentityTrust.LocalTrustListTrust,tblIdentity.IdentityID,tblIdentityTrust.MessageTrustComment,tblIdentityTrust.TrustListTrustComment,tblIdentity.FreesiteEdition FROM tblIdentity LEFT JOIN (SELECT IdentityID,LocalMessageTrust,LocalTrustListTrust,MessageTrustComment,TrustListTrustComment FROM tblIdentityTrust WHERE LocalIdentityID=?) AS 'tblIdentityTrust' ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID WHERE PublicKey IS NOT NULL AND LastSeen IS NOT NULL AND LastSeen>=? ORDER BY Name COLLATE NOCASE;"); st.Bind(0,localidentityid); st.Bind(1,date.Format("%Y-%m-%d %H:%M:%S")); st.Step(); @@ -212,6 +293,7 @@ std::string SiteInserter::GenerateTrustList(const std::string &htmltemplate, con std::string trustlisttrust=""; std::string publickey=""; std::string uskkey=""; + std::string freesiteedition=""; st.ResultText(0,idname); st.ResultText(1,publickey); @@ -220,17 +302,28 @@ std::string SiteInserter::GenerateTrustList(const std::string &htmltemplate, con st.ResultText(4,thisid); st.ResultText(5,messagetrustcomment); st.ResultText(6,trustlisttrustcomment); + st.ResultText(7,freesiteedition); - if(publickey.find("SSK@")==0) + if(freesiteedition!="") { - uskkey=publickey; - uskkey.erase(0,3); - uskkey="USK"+uskkey; - uskkey+=m_messagebase+"/0/"; + if(publickey.find("SSK@")==0) + { + uskkey=publickey; + uskkey.erase(0,3); + uskkey="USK"+uskkey; + uskkey+=m_messagebase+"/"+freesiteedition+"/"; + } } content+=""; - content+=""+SanitizeOutput(CreateShortIdentityName(idname,publickey))+""; + if(freesiteedition!="") + { + content+=""+SanitizeOutput(CreateShortIdentityName(idname,publickey))+""; + } + else + { + content+=""+SanitizeOutput(CreateShortIdentityName(idname,publickey))+""; + } content+=""+messagetrust+""; content+=""+SanitizeOutput(messagetrustcomment)+""; content+=""+trustlisttrust+""; @@ -273,13 +366,17 @@ const bool SiteInserter::HandlePutFailed(FCPMessage &message) RemoveFromInsertList(localidentityid); + m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"SiteInserter::HandlePutFailed failed to insert Freesite, Freenet error code : "+message["Code"]); + return true; } const bool SiteInserter::HandlePutSuccessful(FCPMessage &message) { std::vector idparts; + std::vector uriparts; long localidentityid; + int edition=-1; DateTime now; now.SetToGMTime(); @@ -287,9 +384,17 @@ const bool SiteInserter::HandlePutSuccessful(FCPMessage &message) StringFunctions::Split(message["Identifier"],"|",idparts); StringFunctions::Convert(idparts[1],localidentityid); - SQLite3DB::Statement st=m_db->Prepare("UPDATE tblLocalIdentity SET LastInsertedFreesite=? WHERE LocalIdentityID=?;"); + // edition is very last part of uri + StringFunctions::Split(message["URI"],"/",uriparts); + if(uriparts.size()>0) + { + StringFunctions::Convert(uriparts[uriparts.size()-1],edition); + } + + SQLite3DB::Statement st=m_db->Prepare("UPDATE tblLocalIdentity SET LastInsertedFreesite=?, FreesiteEdition=? WHERE LocalIdentityID=?;"); st.Bind(0,now.Format("%Y-%m-%d %H:%M:%S")); - st.Bind(1,localidentityid); + st.Bind(1,edition); + st.Bind(2,localidentityid); st.Step(); m_log->WriteLog(LogFile::LOGLEVEL_INFO,"SiteInserter::HandlePutSuccessful successfully inserted Freesite."); @@ -315,7 +420,7 @@ const std::string SiteInserter::SanitizeOutput(const std::string &input) return output; } -void SiteInserter::StartInsert(const long &localidentityid) +const bool SiteInserter::StartInsert(const long &localidentityid) { FCPMessage message; std::string localidentityidstr=""; @@ -359,4 +464,6 @@ void SiteInserter::StartInsert(const long &localidentityid) m_inserting.push_back(localidentityid); + return true; + }