From: SomeDude Date: Thu, 15 May 2008 16:32:00 +0000 (+0200) Subject: version 0.2.16 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=7ddb1aeb0b3dc7384597e75f7b3557f2d8f6d14c;p=fms.git version 0.2.16 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index ebff758..986d1ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,6 +73,7 @@ src/http/pages/peerdetailspage.cpp src/http/pages/peermaintenancepage.cpp src/http/pages/peertrustpage.cpp src/http/pages/showcaptchapage.cpp +src/nntp/extensiontrust.cpp src/nntp/nntpconnection.cpp src/nntp/nntplistener.cpp src/nntp/uwildmat.cpp diff --git a/include/global.h b/include/global.h index 69952d1..29af655 100644 --- a/include/global.h +++ b/include/global.h @@ -5,7 +5,7 @@ #include #include "pthreadwrapper/thread.h" -#define FMS_VERSION "0.2.15" +#define FMS_VERSION "0.2.16" // opens database and creates tables and initial inserts if necessary void SetupDB(); diff --git a/include/nntp/extensiontrust.h b/include/nntp/extensiontrust.h new file mode 100644 index 0000000..b7a3bab --- /dev/null +++ b/include/nntp/extensiontrust.h @@ -0,0 +1,30 @@ +#ifndef _extension_trust_ +#define _extension_trust_ + +#include "../idatabase.h" + +class TrustExtension:public IDatabase +{ +public: + TrustExtension(); + TrustExtension(const int &localidentityid); + + void SetLocalIdentityID(const int id) { m_localidentityid=id; } + + const bool GetMessageTrust(const std::string &nntpname, int &trust); + const bool GetTrustListTrust(const std::string &nntpname, int &trust); + + const bool SetMessageTrust(const std::string &nntpname, const int trust); + const bool SetTrustListTrust(const std::string &nntpname, const int trust); + + const bool GetTrustList(std::map > &trustlist); + +private: + + const int GetIdentityID(const std::string &nntpname); // return -1 if not found + + int m_localidentityid; + +}; + +#endif // _extension_trust diff --git a/include/nntp/nntpconnection.h b/include/nntp/nntpconnection.h index e31fd1b..d116148 100644 --- a/include/nntp/nntpconnection.h +++ b/include/nntp/nntpconnection.h @@ -87,6 +87,9 @@ private: const bool HandlePostCommand(const NNTPCommand &command); const bool HandleOverCommand(const NNTPCommand &command); const bool HandleAuthInfoCommand(const NNTPCommand &command); + const bool HandleGetTrustCommand(const NNTPCommand &command); + const bool HandleSetTrustCommand(const NNTPCommand &command); + const bool HandleGetTrustListCommand(const NNTPCommand &command); SOCKET m_socket; ClientStatus m_status; diff --git a/readme.txt b/readme.txt index 133a0aa..1f5107f 100644 --- a/readme.txt +++ b/readme.txt @@ -107,3 +107,34 @@ 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. + +NNTP EXTENSIONS +--------------- +The following commands are available through the NNTP connection. The client +must have authenticated for the commands to work. + +XSETTRUST MESSAGE userid@keypart val +XSETTRUST TRUSTLIST userid@keypart val + +Responses: +2xx Trust Set +4xx Unknown ID or other error +5xx Syntax error + +XGETTRUST MESSAGE userid@keypart +XGETTRUST TRUSTLIST userid@keypart + +Responses: +2xx val +4xx Unknown ID or other error +5xx Syntax error + +XGETTRUSTLIST +messagetrust and trustlisttrust will be 0 to 100 or can be the string "null" +without quotes. + +Responses: +2xx Trust List Follows +userid@keypart TAB messagetrust TAB trustlisttrust +. +4xx other error diff --git a/site-template.htm b/site-template.htm index 57170f3..c7efff9 100644 --- a/site-template.htm +++ b/site-template.htm @@ -225,7 +225,7 @@ td { padding-left:5px; padding-right:5px; }
diff --git a/src/freenet/messagelistinserter.cpp b/src/freenet/messagelistinserter.cpp index e0d8957..f598b51 100644 --- a/src/freenet/messagelistinserter.cpp +++ b/src/freenet/messagelistinserter.cpp @@ -35,7 +35,7 @@ void MessageListInserter::CheckForNeededInsert() sql="SELECT tblLocalIdentity.LocalIdentityID "; sql+="FROM tblLocalIdentity INNER JOIN tblMessageInserts ON tblLocalIdentity.LocalIdentityID=tblMessageInserts.LocalIdentityID "; sql+="WHERE tblMessageInserts.Day>=? AND ((tblLocalIdentity.LastInsertedMessageList<=? OR tblLocalIdentity.LastInsertedMessageList IS NULL OR tblLocalIdentity.LastInsertedMessageList='') OR tblLocalIdentity.LocalIdentityID IN (SELECT LocalIdentityID FROM tmpMessageListInsert)) "; - sql+=";"; + sql+="GROUP BY tblLocalIdentity.LocalIdentityID;"; SQLite3DB::Statement st=m_db->Prepare(sql); st.Bind(0,previous.Format("%Y-%m-%d")); @@ -168,7 +168,7 @@ const bool MessageListInserter::StartInsert(const long &localidentityid) st.Finalize(); - st=m_db->Prepare("SELECT MessageDate, MessageIndex, PublicKey, MessageID FROM tblMessage INNER JOIN tblIdentity ON tblMessage.IdentityID=tblIdentity.IdentityID WHERE MessageIndex IS NOT NULL ORDER BY MessageDate DESC, MessageTime DESC LIMIT 100;"); + st=m_db->Prepare("SELECT MessageDate, MessageIndex, PublicKey, MessageID FROM tblMessage INNER JOIN tblIdentity ON tblMessage.IdentityID=tblIdentity.IdentityID WHERE MessageIndex IS NOT NULL ORDER BY MessageDate DESC, MessageTime DESC LIMIT 200;"); SQLite3DB::Statement st2=m_db->Prepare("SELECT BoardName FROM tblBoard INNER JOIN tblMessageBoard ON tblBoard.BoardID=tblMessageBoard.BoardID WHERE tblMessageBoard.MessageID=?;"); st.Step(); while(st.RowReturned()) @@ -214,12 +214,12 @@ const bool MessageListInserter::StartInsert(const long &localidentityid) } StringFunctions::Convert(index,indexstr); - // actually insert message xmlstr=mlxml.GetXML(); // only insert if the last message this identity inserted is different than this message if(m_lastinsertedxml[localidentityid]!=xmlstr) { + std::string targeturi=""; StringFunctions::Convert(xmlstr.size(),xmlsizestr); message.SetName("ClientPut"); @@ -230,9 +230,29 @@ const bool MessageListInserter::StartInsert(const long &localidentityid) m_fcp->SendMessage(message); m_fcp->SendRaw(xmlstr.c_str(),xmlstr.size()); - m_inserting.push_back(localidentityid); + /* + // insert a USK redirect to the file we just inserted + targeturi=message["URI"]; + message.Reset(); + message.SetName("ClientPut"); + message["URI"]="USK"+privatekey.substr(3)+m_messagebase+"|"+now.Format("%Y.%m.%d")+"|MessageList/0/MessageList.xml"; + message["Identifier"]=message["URI"]; + message["UploadFrom"]="redirect"; + message["TargetURI"]=targeturi; + m_fcp->SendMessage(message); + */ + message.Reset(); + message.SetName("ClientPut"); + message["URI"]="USK"+privatekey.substr(3)+m_messagebase+"|"+now.Format("%Y.%m.%d")+"|MessageList/0/MessageList.xml"; + message["Identifier"]=message["URI"]; + message["UploadFrom"]="direct"; + message["DataLength"]=xmlsizestr; + m_fcp->SendMessage(message); + m_fcp->SendRaw(xmlstr.c_str(),xmlstr.size()); + m_inserting.push_back(localidentityid); m_lastinsertedxml[localidentityid]=xmlstr; + return true; } else diff --git a/src/freenet/siteinserter.cpp b/src/freenet/siteinserter.cpp index c717d0d..f7d9ef2 100644 --- a/src/freenet/siteinserter.cpp +++ b/src/freenet/siteinserter.cpp @@ -40,8 +40,6 @@ std::string SiteInserter::GenerateIndex(const std::string &htmltemplate, const l { std::string content=""; - content="

FMS 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;"); @@ -93,7 +91,8 @@ std::string SiteInserter::GenerateIndex(const std::string &htmltemplate, const l st.Step(); } - return StringFunctions::Replace(htmltemplate,"[CONTENT]",content); + std::string output=StringFunctions::Replace(htmltemplate,"[CONTENT]",content); + return StringFunctions::Replace(output,"[IDENTITYNAME]",SanitizeOutput(name)); } diff --git a/src/nntp/extensiontrust.cpp b/src/nntp/extensiontrust.cpp new file mode 100644 index 0000000..6e49a93 --- /dev/null +++ b/src/nntp/extensiontrust.cpp @@ -0,0 +1,239 @@ +#include "../../include/nntp/extensiontrust.h" +#include "../../include/stringfunctions.h" + +#ifdef XMEM + #include +#endif + +TrustExtension::TrustExtension() +{ + m_localidentityid=-1; +} + +TrustExtension::TrustExtension(const int &localidentityid) +{ + m_localidentityid=localidentityid; +} + +const int TrustExtension::GetIdentityID(const std::string &nntpname) +{ + std::vector nameparts; + StringFunctions::Split(nntpname,"@",nameparts); + + SQLite3DB::Statement st=m_db->Prepare("SELECT IdentityID, PublicKey FROM tblIdentity WHERE Name=? AND PublicKey IS NOT NULL AND PublicKey <> '' ;"); + st.Bind(0,nameparts[0]); + st.Step(); + + while(st.RowReturned()) + { + int id=-1; + std::vector keyparts; + std::string publickey=""; + + st.ResultText(1,publickey); + StringFunctions::SplitMultiple(publickey,"@,",keyparts); + + if(keyparts.size()>1) + { + publickey=StringFunctions::Replace(StringFunctions::Replace(keyparts[1],"~",""),"-",""); + if(nameparts[0]+"@"+publickey==nntpname) + { + st.ResultInt(0,id); + return id; + } + } + + st.Step(); + } + + return -1; + +} + +const bool TrustExtension::GetMessageTrust(const std::string &nntpname, int &trust) +{ + if(m_localidentityid>=0) + { + int id=GetIdentityID(nntpname); + if(id>=0) + { + SQLite3DB::Statement st=m_db->Prepare("SELECT LocalMessageTrust FROM tblIdentityTrust WHERE LocalIdentityID=? AND IdentityID=?;"); + st.Bind(0,m_localidentityid); + st.Bind(1,id); + st.Step(); + + if(st.RowReturned()) + { + int tr=-1; + if(st.ResultNull(0)==false) + { + st.ResultInt(0,tr); + } + trust=tr; + } + else + { + trust=-1; + } + return true; + } + else + { + return false; + } + } + else + { + return false; + } +} + +const bool TrustExtension::GetTrustList(std::map > &trustlist) +{ + if(m_localidentityid>=0) + { + SQLite3DB::Statement st=m_db->Prepare("SELECT tblIdentityTrust.LocalMessageTrust,tblIdentityTrust.LocalTrustListTrust,tblIdentity.Name,tblIdentity.PublicKey FROM tblIdentityTrust INNER JOIN tblIdentity ON tblIdentityTrust.IdentityID=tblIdentity.IdentityID WHERE tblIdentityTrust.LocalIdentityID=? AND tblIdentity.Name IS NOT NULL AND tblIdentity.PublicKey IS NOT NULL AND tblIdentity.PublicKey <> '' ;"); + st.Bind(0,m_localidentityid); + st.Step(); + while(st.RowReturned()) + { + int messagetrust=-1; + int trustlisttrust=-1; + std::string name=""; + std::string publickey=""; + std::vector keyparts; + std::string nntpname=""; + + if(st.ResultNull(0)==false) + { + st.ResultInt(0,messagetrust); + } + if(st.ResultNull(1)==false) + { + st.ResultInt(1,trustlisttrust); + } + st.ResultText(2,name); + st.ResultText(3,publickey); + + StringFunctions::SplitMultiple(publickey,"@,",keyparts); + if(keyparts.size()>1) + { + publickey=StringFunctions::Replace(StringFunctions::Replace(keyparts[1],"~",""),"-",""); + nntpname=name+"@"+publickey; + } + + trustlist[nntpname]=std::pair(messagetrust,trustlisttrust); + + st.Step(); + } + return true; + } + else + { + return false; + } +} + +const bool TrustExtension::GetTrustListTrust(const std::string &nntpname, int &trust) +{ + if(m_localidentityid>=0) + { + int id=GetIdentityID(nntpname); + if(id>=0) + { + SQLite3DB::Statement st=m_db->Prepare("SELECT LocalTrustListTrust FROM tblIdentityTrust WHERE LocalIdentityID=? AND IdentityID=?;"); + st.Bind(0,m_localidentityid); + st.Bind(1,id); + st.Step(); + + if(st.RowReturned()) + { + int tr=-1; + if(st.ResultNull(0)==false) + { + st.ResultInt(0,tr); + } + trust=tr; + } + else + { + trust=-1; + } + return true; + } + else + { + return false; + } + } + else + { + return false; + } +} + +const bool TrustExtension::SetMessageTrust(const std::string &nntpname, const int trust) +{ + if(m_localidentityid>=0 && trust>=-1 && trust<=100) + { + int id=GetIdentityID(nntpname); + if(id>=0) + { + SQLite3DB::Statement st=m_db->Prepare("UPDATE tblIdentityTrust SET LocalMessageTrust=? WHERE LocalIdentityID=? AND IdentityID=?;"); + if(trust==-1) + { + st.Bind(0); + } + else + { + st.Bind(0,trust); + } + st.Bind(1,m_localidentityid); + st.Bind(2,id); + st.Step(); + + return true; + } + else + { + return false; + } + } + else + { + return false; + } +} + +const bool TrustExtension::SetTrustListTrust(const std::string &nntpname, const int trust) +{ + if(m_localidentityid>=0 && trust>=-1 && trust<=100) + { + int id=GetIdentityID(nntpname); + if(id>=0) + { + SQLite3DB::Statement st=m_db->Prepare("UPDATE tblIdentityTrust SET LocalTrustListTrust=? WHERE LocalIdentityID=? AND IdentityID=?;"); + if(trust==-1) + { + st.Bind(0); + } + else + { + st.Bind(0,trust); + } + st.Bind(1,m_localidentityid); + st.Bind(2,id); + st.Step(); + + return true; + } + else + { + return false; + } + } + else + { + return false; + } +} diff --git a/src/nntp/nntpconnection.cpp b/src/nntp/nntpconnection.cpp index b3eeecc..54d7c94 100644 --- a/src/nntp/nntpconnection.cpp +++ b/src/nntp/nntpconnection.cpp @@ -6,6 +6,7 @@ #include "../../include/message.h" #include "../../include/messagelist.h" #include "../../include/option.h" +#include "../../include/nntp/extensiontrust.h" #include @@ -148,6 +149,7 @@ const bool NNTPConnection::HandleCapabilitiesCommand(const NNTPCommand &command) { SendBufferedLine("AUTHINFO USER"); } + SendBufferedLine("XFMSTRUST"); SendBufferedLine("."); return true; @@ -227,6 +229,18 @@ const bool NNTPConnection::HandleCommand(const NNTPCommand &command) { return HandleAuthInfoCommand(command); } + if(command.m_command=="XGETTRUST") + { + return HandleGetTrustCommand(command); + } + if(command.m_command=="XSETTRUST") + { + return HandleSetTrustCommand(command); + } + if(command.m_command=="XGETTRUSTLIST") + { + return HandleGetTrustListCommand(command); + } return false; } @@ -239,6 +253,120 @@ const bool NNTPConnection::HandleDateCommand(const NNTPCommand &command) return true; } +const bool NNTPConnection::HandleGetTrustCommand(const NNTPCommand &command) +{ + if(command.m_arguments.size()>=2) + { + std::string type=command.m_arguments[0]; + StringFunctions::UpperCase(type,type); + if(type=="MESSAGE" || type=="TRUSTLIST") + { + if(m_status.m_authenticated) + { + bool found=false; + int trust=-1; + std::string nntpname=""; + for(int i=1; i=0 && found) + { + std::string truststr=""; + StringFunctions::Convert(trust,truststr); + SendBufferedLine("280 "+truststr); + } + else if(found) + { + SendBufferedLine("281 null"); + } + else + { + SendBufferedLine("480 Identity not found"); + } + + } + else + { + SendBufferedLine("480 User not authenticated"); + } + } + else + { + SendBufferedLine("501 Syntax error"); + } + } + else + { + SendBufferedLine("501 Syntax error"); + } + return true; +} + +const bool NNTPConnection::HandleGetTrustListCommand(const NNTPCommand &command) +{ + if(m_status.m_authenticated) + { + TrustExtension tr(m_status.m_authuser.GetID()); + std::map > trustlist; + if(tr.GetTrustList(trustlist)) + { + SendBufferedLine("280 Trust list follows"); + for(std::map >::iterator i=trustlist.begin(); i!=trustlist.end(); i++) + { + std::ostringstream tempstr; + tempstr << (*i).first << "\t"; + if((*i).second.first>-1) + { + tempstr << (*i).second.first; + } + else + { + tempstr << "null"; + } + tempstr << "\t"; + if((*i).second.second>-1) + { + tempstr << (*i).second.second; + } + else + { + tempstr << "null"; + } + SendBufferedLine(tempstr.str()); + } + SendBufferedLine("."); + } + else + { + SendBufferedLine("501 Syntax error"); + } + } + else + { + SendBufferedLine("480 User not authenticated"); + } + return true; +} + const bool NNTPConnection::HandleGroupCommand(const NNTPCommand &command) { if(command.m_arguments.size()==1) @@ -938,6 +1066,83 @@ void NNTPConnection::HandleReceivedData() } } +const bool NNTPConnection::HandleSetTrustCommand(const NNTPCommand &command) +{ + if(command.m_arguments.size()>=3) + { + std::string type=command.m_arguments[0]; + StringFunctions::UpperCase(type,type); + if(type=="MESSAGE" || type=="TRUSTLIST") + { + if(m_status.m_authenticated) + { + bool found=false; + bool valid=false; + int trust=-1; + std::string nntpname=""; + for(int i=1; i=-1 && trust<=100) + { + valid=true; + } + + TrustExtension tr(m_status.m_authuser.GetID()); + + if(type=="MESSAGE") + { + if(tr.SetMessageTrust(nntpname,trust)) + { + found=true; + } + } + if(type=="TRUSTLIST") + { + if(tr.SetTrustListTrust(nntpname,trust)) + { + found=true; + } + } + + if(found && valid) + { + SendBufferedLine("280 Trust Set"); + } + else if(found==false) + { + SendBufferedLine("480 Identity not found"); + } + else + { + SendBufferedLine("501 Syntax error"); + } + + } + else + { + SendBufferedLine("480 User not authenticated"); + } + } + else + { + SendBufferedLine("501 Syntax error"); + } + } + else + { + SendBufferedLine("501 Syntax error"); + } + return true; +} + const bool NNTPConnection::HandleStatCommand(const NNTPCommand &command) { SendArticleParts(command);