X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Fsiteinserter.cpp;h=9ee3019a352892125abe2de401df1af309d4a331;hb=63376b2a82c3f6cdf2df56b1f134bd7df0aaab3a;hp=f943f5618a144e17ea150bf0a2810760e4b10ef3;hpb=8a0a83a78390f22f99d4487cda2569909dfbc28e;p=fms.git diff --git a/src/freenet/siteinserter.cpp b/src/freenet/siteinserter.cpp index f943f56..9ee3019 100644 --- a/src/freenet/siteinserter.cpp +++ b/src/freenet/siteinserter.cpp @@ -1,4 +1,5 @@ #include "../../include/freenet/siteinserter.h" +#include "../../include/global.h" #ifdef XMEM #include @@ -112,7 +113,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(); @@ -181,6 +182,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)); + } + } + } + + } + } } @@ -191,8 +252,9 @@ 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,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")); + 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(); content+=""; @@ -209,8 +271,8 @@ std::string SiteInserter::GenerateTrustList(const std::string &htmltemplate, con std::string messagetrust=""; std::string trustlisttrust=""; std::string publickey=""; - std::string keypart=""; std::string uskkey=""; + std::string freesiteedition=""; st.ResultText(0,idname); st.ResultText(1,publickey); @@ -219,22 +281,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.size()>8) + if(freesiteedition!="") { - keypart=publickey.substr(3,5); + if(publickey.find("SSK@")==0) + { + uskkey=publickey; + uskkey.erase(0,3); + uskkey="USK"+uskkey; + uskkey+=m_messagebase+"/"+freesiteedition+"/"; + } } - if(publickey.find("SSK@")==0) + content+=""; + if(freesiteedition!="") { - uskkey=publickey; - uskkey.erase(0,3); - uskkey="USK"+uskkey; - uskkey+=m_messagebase+"/0/"; + content+=""; + } + else + { + content+=""; } - - content+=""; - content+=""; content+=""; content+=""; content+=""; @@ -277,13 +345,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(); @@ -291,9 +363,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.");
"+SanitizeOutput(CreateShortIdentityName(idname,publickey))+""+SanitizeOutput(CreateShortIdentityName(idname,publickey))+"
"+SanitizeOutput(idname+keypart)+"..."+messagetrust+""+SanitizeOutput(messagetrustcomment)+""+trustlisttrust+"