#include "../../include/freenet/siteinserter.h"\r
+#include "../../include/global.h"\r
\r
#ifdef XMEM\r
#include <xmem.h>\r
\r
void SiteInserter::GeneratePages(const long localidentityid, std::string &uskkey, std::map<std::string,std::string> &pages)\r
{\r
- SQLite3DB::Statement st=m_db->Prepare("SELECT Name, PrivateKey, PublishTrustList, PublishBoardList FROM tblLocalIdentity WHERE LocalIdentityID=?;");\r
+ SQLite3DB::Statement st=m_db->Prepare("SELECT Name, PrivateKey, PublishTrustList, PublishBoardList, FreesiteEdition FROM tblLocalIdentity WHERE LocalIdentityID=?;");\r
st.Bind(0,localidentityid);\r
st.Step();\r
\r
LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_ERROR,"SiteInserter::GeneratePages unable to open "+filename+" or site-template.htm.");\r
}\r
\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
+ if(infile)\r
+ {\r
+ std::vector<std::string> files;\r
+\r
+ fseek(infile,0,SEEK_END);\r
+ long len=ftell(infile);\r
+ fseek(infile,0,SEEK_SET);\r
+\r
+ std::vector<unsigned char> data;\r
+ data.resize(len);\r
+ fread(&data[0],1,data.size(),infile);\r
+ fclose(infile);\r
+\r
+ // split on \r and \n - on systems with \r\n line endings there will be blank entries, but we'll just skip those\r
+ std::string filecontent(data.begin(),data.end());\r
+ StringFunctions::SplitMultiple(filecontent,"\r\n",files);\r
+\r
+ for(std::vector<std::string>::iterator i=files.begin(); i!=files.end(); i++)\r
+ {\r
+ if((*i)!="" && (*i).find("index.htm")==std::string::npos && (*i).find("trustlist.htm")==std::string::npos && (*i).find("files.htm")==std::string::npos)\r
+ {\r
+ filename=(*i);\r
+ infile=fopen(filename.c_str(),"r+b");\r
+ if(infile)\r
+ {\r
+ fseek(infile,0,SEEK_END);\r
+ len=ftell(infile);\r
+ fseek(infile,0,SEEK_SET);\r
+\r
+ data.resize(len);\r
+ fread(&data[0],1,data.size(),infile);\r
+ fclose(infile);\r
+\r
+ filecontent="";\r
+ filecontent.append(data.begin(),data.end());\r
+\r
+ // strip off path from filename\r
+ while(filename.find_first_of("/")!=std::string::npos)\r
+ {\r
+ filename.erase(0,filename.find_first_of("/")+1);\r
+ }\r
+\r
+ if(filecontent.size()>0)\r
+ {\r
+ pages[filename]=filecontent;\r
+ }\r
+\r
+ }\r
+ else\r
+ {\r
+ m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"SiteInserter::GeneratePages could not include user file "+(*i));\r
+ }\r
+ }\r
+ }\r
+\r
+ }\r
+\r
}\r
}\r
\r
\r
date.SetToGMTime();\r
date.Add(0,0,0,-20);\r
- 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;");\r
- st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S"));\r
+ 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;");\r
+ st.Bind(0,localidentityid);\r
+ st.Bind(1,date.Format("%Y-%m-%d %H:%M:%S"));\r
st.Step();\r
\r
content+="<table>";\r
std::string messagetrust="";\r
std::string trustlisttrust="";\r
std::string publickey="";\r
- std::string keypart="";\r
std::string uskkey="";\r
+ std::string freesiteedition="";\r
\r
st.ResultText(0,idname);\r
st.ResultText(1,publickey);\r
st.ResultText(4,thisid);\r
st.ResultText(5,messagetrustcomment);\r
st.ResultText(6,trustlisttrustcomment);\r
+ st.ResultText(7,freesiteedition);\r
\r
- if(publickey.size()>8)\r
+ if(freesiteedition!="")\r
{\r
- keypart=publickey.substr(3,5);\r
+ if(publickey.find("SSK@")==0)\r
+ {\r
+ uskkey=publickey;\r
+ uskkey.erase(0,3);\r
+ uskkey="USK"+uskkey;\r
+ uskkey+=m_messagebase+"/"+freesiteedition+"/";\r
+ }\r
}\r
\r
- if(publickey.find("SSK@")==0)\r
+ content+="<tr>";\r
+ if(freesiteedition!="")\r
{\r
- uskkey=publickey;\r
- uskkey.erase(0,3);\r
- uskkey="USK"+uskkey;\r
- uskkey+=m_messagebase+"/0/";\r
+ content+="<td><a href=\""+uskkey+"\">"+SanitizeOutput(CreateShortIdentityName(idname,publickey))+"</a></td>";\r
+ }\r
+ else\r
+ {\r
+ content+="<td>"+SanitizeOutput(CreateShortIdentityName(idname,publickey))+"</td>";\r
}\r
-\r
- content+="<tr>";\r
- content+="<td><a href=\""+uskkey+"\">"+SanitizeOutput(idname+keypart)+"...</a></td>";\r
content+="<td "+GetClassString(messagetrust)+">"+messagetrust+"</td>";\r
content+="<td>"+SanitizeOutput(messagetrustcomment)+"</td>";\r
content+="<td "+GetClassString(trustlisttrust)+">"+trustlisttrust+"</td>";\r
\r
RemoveFromInsertList(localidentityid);\r
\r
+ m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"SiteInserter::HandlePutFailed failed to insert Freesite, Freenet error code : "+message["Code"]);\r
+\r
return true;\r
}\r
\r
const bool SiteInserter::HandlePutSuccessful(FCPMessage &message)\r
{\r
std::vector<std::string> idparts;\r
+ std::vector<std::string> uriparts;\r
long localidentityid;\r
+ int edition=-1;\r
DateTime now;\r
\r
now.SetToGMTime();\r
StringFunctions::Split(message["Identifier"],"|",idparts);\r
StringFunctions::Convert(idparts[1],localidentityid);\r
\r
- SQLite3DB::Statement st=m_db->Prepare("UPDATE tblLocalIdentity SET LastInsertedFreesite=? WHERE LocalIdentityID=?;");\r
+ // edition is very last part of uri\r
+ StringFunctions::Split(message["URI"],"/",uriparts);\r
+ if(uriparts.size()>0)\r
+ {\r
+ StringFunctions::Convert(uriparts[uriparts.size()-1],edition);\r
+ }\r
+\r
+ SQLite3DB::Statement st=m_db->Prepare("UPDATE tblLocalIdentity SET LastInsertedFreesite=?, FreesiteEdition=? WHERE LocalIdentityID=?;");\r
st.Bind(0,now.Format("%Y-%m-%d %H:%M:%S"));\r
- st.Bind(1,localidentityid);\r
+ st.Bind(1,edition);\r
+ st.Bind(2,localidentityid);\r
st.Step();\r
\r
m_log->WriteLog(LogFile::LOGLEVEL_INFO,"SiteInserter::HandlePutSuccessful successfully inserted Freesite.");\r