From: SomeDude Date: Wed, 2 Apr 2008 14:49:00 +0000 (+0200) Subject: version 0.2.7 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=b4f4686250878cdf4fcb2986a2ea6546cba867d1;p=fms.git version 0.2.7 --- diff --git a/include/global.h b/include/global.h index 8b781f9..834f605 100644 --- a/include/global.h +++ b/include/global.h @@ -4,7 +4,7 @@ #include #include "pthreadwrapper/thread.h" -#define FMS_VERSION "0.2.6" +#define FMS_VERSION "0.2.7" // opens database and creates tables and initial inserts if necessary void SetupDB(); @@ -19,6 +19,8 @@ void SetupDefaultOptions(); // opens logfile and sets it up void SetupLogFile(); +std::string CreateShortIdentityName(const std::string &name, const std::string &publickey); + // TODO remove sometime after 0.1.17 void FixCapitalBoardNames(); diff --git a/include/http/pages/peertrustpage.h b/include/http/pages/peertrustpage.h index 8f91446..851296f 100644 --- a/include/http/pages/peertrustpage.h +++ b/include/http/pages/peertrustpage.h @@ -14,8 +14,9 @@ private: const std::string GeneratePage(const std::string &method, const std::map &queryvars); const std::string GetClassString(const std::string &trustlevel); - const std::string BuildQueryString(const long startrow, const std::string &namesearch, const std::string &sortby, const std::string &sortorder); + const std::string BuildQueryString(const long startrow, const std::string &namesearch, const std::string &sortby, const std::string &sortorder, const int localidentityid); const std::string ReverseSort(const std::string &sortname, const std::string ¤tsortby, const std::string ¤tsortorder); + const std::string CreateLocalIdentityDropDown(const std::string &name, const int selectedlocalidentityid); }; diff --git a/include/message.h b/include/message.h index 3033229..eda6752 100644 --- a/include/message.h +++ b/include/message.h @@ -55,6 +55,7 @@ private: const bool CheckForAdministrationBoard(const std::vector &boards); void HandleChangeTrust(); void StripAdministrationBoards(); // removes administration boards from boards vector + const int FindLocalIdentityID(const std::string &name); long m_messageid; bool m_addnewpostfromidentities; diff --git a/readme.txt b/readme.txt index 593a99f..db879dc 100644 --- a/readme.txt +++ b/readme.txt @@ -83,6 +83,13 @@ trust to arbitrary identities. Pick whom you trust wisely. The settings for minimum trust before downloading messages and trust lists can be changed on the web interface. +You must have a local identity created before you can set trust levels. Even +if you don't want to post messages, you must still create an identity, but you +do not have to announce it. This way, no-one will know about that identity and +you will be able to set trust. If you have multiple identities, each with +different trust levels for peers, the highest trust level set for a peer will +determine if messages/trust lists are downloaded from them. + A note on NULL trust: If you neither trust or distrust an identity, they will have NULL trust (no trust at all). You will download messages and trust lists from identities with NULL peer trust as long as the local trust level is at or diff --git a/src/freenet/freenetmasterthread.cpp b/src/freenet/freenetmasterthread.cpp index 4e7b570..db72906 100644 --- a/src/freenet/freenetmasterthread.cpp +++ b/src/freenet/freenetmasterthread.cpp @@ -245,7 +245,7 @@ void FreenetMasterThread::Run() if(m_fcp.Connected()==false) { - m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"FreenetMasterThread::Run Disconnected from Freenet node."); + m_log->WriteLog(LogFile::LOGLEVEL_INFO,"FreenetMasterThread::Run Disconnected from Freenet node."); } } diff --git a/src/freenet/messagerequester.cpp b/src/freenet/messagerequester.cpp index 5b6d271..c9b78bb 100644 --- a/src/freenet/messagerequester.cpp +++ b/src/freenet/messagerequester.cpp @@ -376,6 +376,7 @@ void MessageRequester::PopulateIDList() sql+="WHERE (tblIdentity.LocalMessageTrust IS NULL OR tblIdentity.LocalMessageTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalMessageTrust')) "; sql+="AND FromMessageList='true' AND Found='false' AND Day>='"+date.Format("%Y-%m-%d")+"' "; sql+="AND (tblIdentity.PeerMessageTrust IS NULL OR tblIdentity.PeerMessageTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinPeerMessageTrust')) "; + sql+="AND tblIdentity.Name <> '' "; sql+=";"; SQLite3DB::Statement st=m_db->Prepare(sql); diff --git a/src/freenet/siteinserter.cpp b/src/freenet/siteinserter.cpp index f943f56..76bfb95 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 @@ -191,8 +192,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 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,7 +211,6 @@ std::string SiteInserter::GenerateTrustList(const std::string &htmltemplate, con std::string messagetrust=""; std::string trustlisttrust=""; std::string publickey=""; - std::string keypart=""; std::string uskkey=""; st.ResultText(0,idname); @@ -220,11 +221,6 @@ std::string SiteInserter::GenerateTrustList(const std::string &htmltemplate, con st.ResultText(5,messagetrustcomment); st.ResultText(6,trustlisttrustcomment); - if(publickey.size()>8) - { - keypart=publickey.substr(3,5); - } - if(publickey.find("SSK@")==0) { uskkey=publickey; @@ -234,7 +230,7 @@ std::string SiteInserter::GenerateTrustList(const std::string &htmltemplate, con } content+=""; - content+=""; + content+=""; content+=""; content+=""; content+=""; diff --git a/src/freenet/trustlistinserter.cpp b/src/freenet/trustlistinserter.cpp index 79745ee..8962d5e 100644 --- a/src/freenet/trustlistinserter.cpp +++ b/src/freenet/trustlistinserter.cpp @@ -142,10 +142,16 @@ void TrustListInserter::StartInsert(const long localidentityid, const std::strin now.SetToGMTime(); date.SetToGMTime(); + // insert all identities not in trust list already + m_db->Execute("INSERT INTO tblIdentityTrust(LocalIdentityID,IdentityID) SELECT LocalIdentityID,IdentityID FROM tblLocalIdentity,tblIdentity WHERE LocalIdentityID || '_' || IdentityID NOT IN (SELECT LocalIdentityID || '_' || IdentityID FROM tblIdentityTrust);"); + // build the xml file - we only want to add identities that we recently saw, otherwise we could be inserting a ton of identities date.Add(0,0,0,-20); // identities seen in last 20 days - SQLite3DB::Statement st=m_db->Prepare("SELECT PublicKey, LocalMessageTrust, LocalTrustListTrust, MessageTrustComment, TrustListTrustComment FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey<>'' AND LastSeen>=?;"); + //SQLite3DB::Statement st=m_db->Prepare("SELECT PublicKey, LocalMessageTrust, LocalTrustListTrust, MessageTrustComment, TrustListTrustComment FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey<>'' AND LastSeen>=?;"); + // we want to order by public key so we can't do identity correllation based on the sequence of identities in the list. + SQLite3DB::Statement st=m_db->Prepare("SELECT PublicKey, tblIdentityTrust.LocalMessageTrust, tblIdentityTrust.LocalTrustListTrust, tblIdentityTrust.MessageTrustComment, tblIdentityTrust.TrustListTrustComment FROM tblIdentity INNER JOIN tblIdentityTrust ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID WHERE PublicKey IS NOT NULL AND PublicKey<>'' AND LastSeen>=? AND tblIdentityTrust.LocalIdentityID=? ORDER BY PublicKey;"); st.Bind(0,date.Format("%Y-%m-%d")); + st.Bind(1,localidentityid); st.Step(); while(st.RowReturned()) { diff --git a/src/global.cpp b/src/global.cpp index aa87b99..7889810 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -19,6 +19,22 @@ bool wantshutdown=false; +std::string CreateShortIdentityName(const std::string &name, const std::string &publickey) +{ + std::string result=""; + std::vector keyparts; + + StringFunctions::SplitMultiple(publickey,"@,",keyparts); + + result+=name; + if(keyparts.size()>1 && keyparts[1].size()>8) + { + result+="@"+keyparts[1].substr(0,4)+"..."; + } + + return result; +} + void SetupDB() { @@ -27,7 +43,7 @@ void SetupDB() db->Open("fms.db3"); db->SetBusyTimeout(10000); // set timeout to 10 seconds - db->Execute("VACUUM;"); + //db->Execute("VACUUM;"); // not needed every startup db->Execute("CREATE TABLE IF NOT EXISTS tblDBVersion(\ Major INTEGER,\ @@ -192,6 +208,35 @@ void SetupDB() Inserted BOOL CHECK(Inserted IN('true','false')) DEFAULT 'false'\ );"); + db->Execute("CREATE TABLE IF NOT EXISTS tblIdentityTrust(\ + LocalIdentityID INTEGER,\ + IdentityID INTEGER,\ + LocalMessageTrust INTEGER CHECK(LocalMessageTrust BETWEEN 0 AND 100) DEFAULT NULL,\ + MessageTrustComment TEXT,\ + LocalTrustListTrust INTEGER CHECK(LocalTrustListTrust BETWEEN 0 AND 100) DEFAULT NULL,\ + TrustListTrustComment TEXT\ + );"); + + db->Execute("CREATE UNIQUE INDEX IF NOT EXISTS idxIdentityTrust_IDs ON tblIdentityTrust(LocalIdentityID,IdentityID);"); + + db->Execute("CREATE TRIGGER IF NOT EXISTS trgInsertOnIdentityTrust AFTER INSERT ON tblIdentityTrust \ + FOR EACH ROW \ + BEGIN \ + UPDATE tblIdentity SET LocalMessageTrust=(SELECT MAX(LocalMessageTrust) FROM tblIdentityTrust WHERE tblIdentityTrust.IdentityID=new.IdentityID GROUP BY tblIdentityTrust.IdentityID), LocalTrustListTrust=(SELECT MAX(LocalTrustListTrust) FROM tblIdentityTrust WHERE tblIdentityTrust.IdentityID=new.IdentityID GROUP BY tblIdentityTrust.IdentityID) WHERE tblIdentity.IdentityID=new.IdentityID; \ + END;"); + + db->Execute("CREATE TRIGGER IF NOT EXISTS trgUpdateOnIdentityTrust AFTER UPDATE OF LocalMessageTrust,LocalTrustListTrust ON tblIdentityTrust \ + FOR EACH ROW \ + BEGIN \ + UPDATE tblIdentity SET LocalMessageTrust=(SELECT MAX(LocalMessageTrust) FROM tblIdentityTrust WHERE tblIdentityTrust.IdentityID=new.IdentityID GROUP BY tblIdentityTrust.IdentityID), LocalTrustListTrust=(SELECT MAX(LocalTrustListTrust) FROM tblIdentityTrust WHERE tblIdentityTrust.IdentityID=new.IdentityID GROUP BY tblIdentityTrust.IdentityID) WHERE tblIdentity.IdentityID=new.IdentityID; \ + END;"); + + db->Execute("CREATE TRIGGER IF NOT EXISTS trgDeleteOnIdentityTrust AFTER DELETE ON tblIdentityTrust \ + FOR EACH ROW \ + BEGIN \ + UPDATE tblIdentity SET LocalMessageTrust=(SELECT MAX(LocalMessageTrust) FROM tblIdentityTrust WHERE tblIdentityTrust.IdentityID=old.IdentityID GROUP BY tblIdentityTrust.IdentityID), LocalTrustListTrust=(SELECT MAX(LocalTrustListTrust) FROM tblIdentityTrust WHERE tblIdentityTrust.IdentityID=old.IdentityID GROUP BY tblIdentityTrust.IdentityID) WHERE tblIdentity.IdentityID=old.IdentityID; \ + END;"); + db->Execute("CREATE TABLE IF NOT EXISTS tblPeerTrust(\ IdentityID INTEGER,\ TargetIdentityID INTEGER,\ @@ -386,6 +431,7 @@ void SetupDB() DELETE FROM tblTrustListRequests WHERE IdentityID=old.IdentityID;\ END;"); + db->Execute("DROP TRIGGER IF EXISTS trgDeleteLocalIdentity;"); db->Execute("CREATE TRIGGER IF NOT EXISTS trgDeleteLocalIdentity AFTER DELETE ON tblLocalIdentity \ FOR EACH ROW \ BEGIN \ @@ -395,6 +441,7 @@ void SetupDB() DELETE FROM tblMessageInserts WHERE LocalIdentityID=old.LocalIdentityID;\ DELETE FROM tblMessageListInserts WHERE LocalIdentityID=old.LocalIdentityID;\ DELETE FROM tblTrustListInserts WHERE LocalIdentityID=old.LocalIdentityID;\ + DELETE FROM tblIdentityTrust WHERE LocalIdentityID=old.LocalIdentityID;\ END;"); db->Execute("CREATE TRIGGER IF NOT EXISTS trgDeleteBoard AFTER DELETE ON tblBoard \ diff --git a/src/http/pages/announceidentitypage.cpp b/src/http/pages/announceidentitypage.cpp index 32a13cc..83ce674 100644 --- a/src/http/pages/announceidentitypage.cpp +++ b/src/http/pages/announceidentitypage.cpp @@ -1,6 +1,7 @@ #include "../../../include/http/pages/announceidentitypage.h" #include "../../../include/stringfunctions.h" #include "../../../include/datetime.h" +#include "../../../include/global.h" #ifdef XMEM #include @@ -18,18 +19,12 @@ const std::string AnnounceIdentityPage::CreateLocalIdentityDropDown(const std::s std::string id; std::string name; std::string pubkey; - std::string keypart=""; st.ResultText(0,id); st.ResultText(1,name); st.ResultText(2,pubkey); - if(pubkey.size()>8) - { - keypart=pubkey.substr(3,5); - } - - rval+=""; + rval+=""; st.Step(); } rval+=""; diff --git a/src/http/pages/localidentitiespage.cpp b/src/http/pages/localidentitiespage.cpp index c0b6105..8b26238 100644 --- a/src/http/pages/localidentitiespage.cpp +++ b/src/http/pages/localidentitiespage.cpp @@ -1,6 +1,7 @@ #include "../../../include/http/pages/localidentitiespage.h" #include "../../../include/stringfunctions.h" #include "../../../include/http/identityexportxml.h" +#include "../../../include/global.h" #ifdef XMEM #include @@ -221,7 +222,6 @@ const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, c std::string publickey=""; std::string publishtrustlist=""; std::string singleuse=""; - std::string keypart=""; std::string publishboardlist=""; std::string publishfreesite=""; @@ -233,14 +233,9 @@ const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, c st.ResultText(5,publishboardlist); st.ResultText(7,publishfreesite); - if(publickey.size()>8) - { - keypart=publickey.substr(3,5); - } - content+=""; // content+=""; - content+=""; + content+=""; content+=""; content+=""; content+=""; diff --git a/src/http/pages/peerdetailspage.cpp b/src/http/pages/peerdetailspage.cpp index 6d05231..78ea02c 100644 --- a/src/http/pages/peerdetailspage.cpp +++ b/src/http/pages/peerdetailspage.cpp @@ -1,6 +1,7 @@ #include "../../../include/http/pages/peerdetailspage.h" #include "../../../include/stringfunctions.h" #include "../../../include/option.h" +#include "../../../include/global.h" #ifdef XMEM #include @@ -15,7 +16,6 @@ const std::string PeerDetailsPage::GeneratePage(const std::string &method, const std::string publickey; std::string messagetrust; std::string trustlisttrust; - std::string keypart=""; std::string lastseen=""; std::string dateadded=""; std::string addedmethod=""; @@ -144,13 +144,8 @@ const std::string PeerDetailsPage::GeneratePage(const std::string &method, const st.ResultText(5,messagetrustcomment); st.ResultText(6,trustlisttrustcomment); - if(publickey.size()>8) - { - keypart=publickey.substr(3,5); - } - content+=""; - content+=""; + content+=""; content+=""; content+=""; content+=""; @@ -182,14 +177,9 @@ const std::string PeerDetailsPage::GeneratePage(const std::string &method, const st.ResultText(4,thisid); st.ResultText(5,messagetrustcomment); st.ResultText(6,trustlisttrustcomment); - - if(publickey.size()>8) - { - keypart=publickey.substr(3,5); - } content+=""; - content+=""; + content+=""; content+=""; content+=""; content+=""; diff --git a/src/http/pages/peertrustpage.cpp b/src/http/pages/peertrustpage.cpp index 9429ede..21b0730 100644 --- a/src/http/pages/peertrustpage.cpp +++ b/src/http/pages/peertrustpage.cpp @@ -1,11 +1,12 @@ #include "../../../include/http/pages/peertrustpage.h" #include "../../../include/stringfunctions.h" +#include "../../../include/global.h" #ifdef XMEM #include #endif -const std::string PeerTrustPage::BuildQueryString(const long startrow, const std::string &namesearch, const std::string &sortby, const std::string &sortorder) +const std::string PeerTrustPage::BuildQueryString(const long startrow, const std::string &namesearch, const std::string &sortby, const std::string &sortorder, const int localidentityid) { std::string returnval=""; std::string tempval=""; @@ -43,10 +44,57 @@ const std::string PeerTrustPage::BuildQueryString(const long startrow, const std returnval+="sortorder="+sortorder; } + if(localidentityid>=0) + { + std::string localidentityidstr=""; + StringFunctions::Convert(localidentityid,localidentityidstr); + if(returnval!="") + { + returnval+="&"; + } + returnval+="localidentityid="+localidentityidstr; + } + return returnval; } +const std::string PeerTrustPage::CreateLocalIdentityDropDown(const std::string &name, const int selectedlocalidentityid) +{ + std::string result=""; + + result+=""; + + return result; +} + const std::string PeerTrustPage::GeneratePage(const std::string &method, const std::map &queryvars) { int count=0; @@ -61,9 +109,28 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s std::string sql; std::string sortby=""; std::string sortorder=""; + std::string localidentityidstr=""; + int localidentityid=-1; StringFunctions::Convert(rowsperpage,rowsperpagestr); + // get localidentityid from querystring or load one from the database + if(queryvars.find("localidentityid")!=queryvars.end()) + { + localidentityidstr=(*queryvars.find("localidentityid")).second; + StringFunctions::Convert(localidentityidstr,localidentityid); + } + else + { + SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID FROM tblLocalIdentity;"); + st.Step(); + if(st.RowReturned()) + { + st.ResultInt(0,localidentityid); + StringFunctions::Convert(localidentityid,localidentityidstr); + } + } + if(queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="update") { std::vector identityids; @@ -77,7 +144,7 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s std::vector tltc; int localmessagetrust=0; int localtrustlisttrust=0; - int identityid; + int identityid=-1; CreateArgArray(queryvars,"identityid",identityids); CreateArgArray(queryvars,"oldlocalmessagetrust",oldlmt); @@ -88,8 +155,9 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s CreateArgArray(queryvars,"messagetrustcomment",mtc); CreateArgArray(queryvars,"oldtrustlisttrustcomment",oldtltc); CreateArgArray(queryvars,"trustlisttrustcomment",tltc); - - SQLite3DB::Statement update=m_db->Prepare("UPDATE tblIdentity SET LocalMessageTrust=?, LocalTrustListTrust=?, MessageTrustComment=?, TrustListTrustComment=? WHERE IdentityID=?;"); + + SQLite3DB::Statement ins=m_db->Prepare("INSERT INTO tblIdentityTrust(LocalIdentityID,IdentityID) VALUES(?,?);"); + SQLite3DB::Statement update=m_db->Prepare("UPDATE tblIdentityTrust SET LocalMessageTrust=?, LocalTrustListTrust=?, MessageTrustComment=?, TrustListTrustComment=? WHERE LocalIdentityID=? AND IdentityID=?;"); for(int i=0; i"; - content+=""; + content+="Message Trust is how much you trust the identity to post good messages. Trust List Trust is how much weight you want the trust list of that identity to have when calculating the total. The local trust levels are set by you, and the peer trust levels are calculated by a weighted average using other identities' trust lists. Trust is recalculated once an hour from received trust lists. You must have at least 1 identity created and have received the SSK keypair for it from Freenet before setting trust."; + + // search drop down + content+="
"; + content+=""; content+=""; content+=""; content+=""; content+="
"; + + content+="
"; + content+="
"; + content+="Load Trust List of "; + content+=CreateLocalIdentityDropDown("localidentityid",localidentityid); + content+=""; + content+=""; + content+="
"; + content+="
"; content+=""; + content+=""; content+=""; if(namesearch!="") { content+=""; } content+="
"+SanitizeOutput(idname+keypart)+"..."+SanitizeOutput(CreateShortIdentityName(idname,publickey))+""+messagetrust+""+SanitizeOutput(messagetrustcomment)+""+trustlisttrust+"
"+SanitizeOutput(name+keypart)+"...
"+SanitizeOutput(CreateShortIdentityName(name,publickey))+""+CreateTrueFalseDropDown("singleuse["+countstr+"]",singleuse)+""+CreateTrueFalseDropDown("publishtrustlist["+countstr+"]",publishtrustlist)+""+CreateTrueFalseDropDown("publishboardlist["+countstr+"]",publishboardlist)+"
"+SanitizeOutput(name+keypart)+"..."+SanitizeOutput(CreateShortIdentityName(name,publickey))+""+messagetrust+""+SanitizeOutput(messagetrustcomment)+""+trustlisttrust+"
"+SanitizeOutput(name+keypart)+"..."+SanitizeOutput(CreateShortIdentityName(name,publickey))+""+messagetrust+""+SanitizeOutput(messagetrustcomment)+""+trustlisttrust+"
"; - content+=""; - content+=""; + content+=""; + content+=""; content+=""; - content+=""; - content+=""; + content+=""; + content+=""; content+=""; - content+=""; - content+=""; + content+=""; + content+=""; content+="\r\n"; +//TODO - modify this query // get count of identities we are showing - sql="SELECT COUNT(*) FROM tblIdentity"; + sql="SELECT COUNT(*) FROM tblIdentity LEFT JOIN (SELECT IdentityID FROM tblIdentityTrust WHERE LocalIdentityID=?) AS 'tblIdentityTrust' ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID "; + sql+="WHERE tblIdentity.Hidden='false'"; if(namesearch!="") { - sql+=" WHERE Name LIKE '%' || ? || '%' AND tblIdentity.Hidden='false'"; - } - else - { - sql+=" WHERE tblIdentity.Hidden='false'"; + sql+=" AND (Name LIKE '%' || ? || '%' OR PublicKey LIKE '%' || ? || '%')"; } sql+=";"; SQLite3DB::Statement st=m_db->Prepare(sql); + st.Bind(0,localidentityid); if(namesearch!="") { - st.Bind(0,namesearch); + st.Bind(1,namesearch); + st.Bind(2,namesearch); } st.Step(); st.ResultInt(0,identitycount); st.Finalize(); - sql="SELECT tblIdentity.IdentityID,Name,LocalMessageTrust,PeerMessageTrust,LocalTrustListTrust,PeerTrustListTrust,PublicKey,MessageTrustComment,TrustListTrustComment,COUNT(MessageID) AS 'MessageCount' FROM tblIdentity LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID"; + sql="SELECT tblIdentity.IdentityID,Name,tblIdentityTrust.LocalMessageTrust,PeerMessageTrust,tblIdentityTrust.LocalTrustListTrust,PeerTrustListTrust,PublicKey,tblIdentityTrust.MessageTrustComment,tblIdentityTrust.TrustListTrustComment,COUNT(MessageID) AS 'MessageCount' "; + sql+="FROM tblIdentity LEFT JOIN (SELECT LocalIdentityID,IdentityID,LocalMessageTrust,LocalTrustListTrust,MessageTrustComment,TrustListTrustComment FROM tblIdentityTrust WHERE LocalIdentityID=?) AS tblIdentityTrust ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID "; + sql+="WHERE tblIdentity.Hidden='false'"; if(namesearch!="") { - sql+=" WHERE (Name LIKE '%' || ? || '%' OR PublicKey LIKE '%' || ? || '%') AND tblIdentity.Hidden='false'"; - } - else - { - sql+=" WHERE tblIdentity.Hidden='false'"; + sql+=" AND (Name LIKE '%' || ? || '%' OR PublicKey LIKE '%' || ? || '%')"; } sql+=" GROUP BY tblIdentity.IdentityID"; sql+=" ORDER BY"; @@ -235,10 +319,11 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s } sql+=" LIMIT "+startrowstr+","+rowsperpagestr+";"; st=m_db->Prepare(sql); + st.Bind(0,localidentityid); if(namesearch!="") { - st.Bind(0,namesearch); st.Bind(1,namesearch); + st.Bind(2,namesearch); } st.Step(); @@ -251,7 +336,6 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s std::string localtrustlisttrust; std::string peertrustlisttrust; std::string publickey; - std::string keypart=""; std::string messagetrustcomment=""; std::string trustlisttrustcomment=""; std::string messagecountstr=""; @@ -269,18 +353,13 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s st.ResultText(8,trustlisttrustcomment); st.ResultText(9,messagecountstr); - if(publickey.size()>8) - { - keypart=publickey.substr(3,5); - } - content+=""; content+=""; + content+=""; cols+=3; } if(startrow+rowsperpageNext Page -->"; + content+=""; } content+=""; } diff --git a/src/main.cpp b/src/main.cpp index 8b33355..4bbcb70 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,6 +6,9 @@ #include #include +//debug +#include "../include/freenet/fcpv2.h" + #ifdef _WIN32 #include "../include/fmsservice.h" #else diff --git a/src/message.cpp b/src/message.cpp index f95f541..eea0633 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -42,6 +42,35 @@ const bool Message::CheckForAdministrationBoard(const std::vector & return false; } +const int Message::FindLocalIdentityID(const std::string &name) +{ + SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID FROM tblLocalIdentity WHERE Name=?;"); + st.Bind(0,name); + st.Step(); + if(st.RowReturned()) + { + int result=-1; + st.ResultInt(0,result); + return result; + } + else + { + if(m_addnewpostfromidentities==true) + { + DateTime now; + now.SetToGMTime(); + st=m_db->Prepare("INSERT INTO tblLocalIdentity(Name) VALUES(?);"); + st.Bind(0,name); + st.Step(true); + return st.GetLastInsertRowID(); + } + else + { + return -1; + } + } +} + const std::string Message::GetNNTPArticleID() const { // old message - before 0.1.12 - doesn't have @domain so add @freenetproject.org @@ -112,6 +141,7 @@ void Message::HandleAdministrationMessage() // only continue if this message was actually a reply to another message if(m_inreplyto.size()>0) { + int localidentityid=-1; int boardid=0; std::string boardname=""; std::string identityname=""; @@ -123,7 +153,9 @@ void Message::HandleAdministrationMessage() SQLite3DB::Statement st=m_db->Prepare("SELECT tblBoard.BoardID,BoardName,ModifyLocalMessageTrust,ModifyLocalTrustListTrust FROM tblBoard INNER JOIN tblAdministrationBoard ON tblBoard.BoardID=tblAdministrationBoard.BoardID;"); st.Step(); - while(st.RowReturned()) + localidentityid=FindLocalIdentityID(m_fromname); + + while(st.RowReturned() && localidentityid!=-1) { st.ResultInt(0,boardid); st.ResultText(1,boardname); @@ -132,8 +164,9 @@ void Message::HandleAdministrationMessage() if(std::find(m_boards.begin(),m_boards.end(),boardname)!=m_boards.end()) { - SQLite3DB::Statement origmess=m_db->Prepare("SELECT tblIdentity.IdentityID,tblIdentity.Name,tblIdentity.LocalMessageTrust,tblIdentity.LocalTrustListTrust FROM tblIdentity INNER JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE tblMessage.MessageUUID=?;"); - origmess.Bind(0,m_inreplyto[0]); + SQLite3DB::Statement origmess=m_db->Prepare("SELECT tblIdentity.IdentityID,tblIdentity.Name,tblIdentityTrust.LocalMessageTrust,tblIdentityTrust.LocalTrustListTrust FROM tblIdentity INNER JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID LEFT JOIN (SELECT IdentityID,LocalMessageTrust,LocalTrustListTrust FROM tblIdentityTrust WHERE LocalIdentityID=?) AS 'tblIdentityTrust' ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID WHERE tblMessage.MessageUUID=?;"); + origmess.Bind(0,localidentityid); + origmess.Bind(1,m_inreplyto[0]); origmess.Step(); if(origmess.RowReturned()) @@ -165,11 +198,18 @@ void Message::HandleAdministrationMessage() origtrustlisttrust<0 ? origtrustlisttrust=0 : false; origtrustlisttrust>100 ? origtrustlisttrust=100 : false; + // make sure we have a record in tblIdentityTrust + SQLite3DB::Statement ins=m_db->Prepare("INSERT INTO tblIdentityTrust(LocalIdentityID,IdentityID) VALUES(?,?);"); + ins.Bind(0,localidentityid); + ins.Bind(1,identityid); + ins.Step(); + // update new trust levels - SQLite3DB::Statement update=m_db->Prepare("UPDATE tblIdentity SET LocalMessageTrust=?, LocalTrustListTrust=? WHERE IdentityID=?;"); + SQLite3DB::Statement update=m_db->Prepare("UPDATE tblIdentityTrust SET LocalMessageTrust=?, LocalTrustListTrust=? WHERE IdentityID=? AND LocalIdentityID=?;"); update.Bind(0,origmessagetrust); update.Bind(1,origtrustlisttrust); update.Bind(2,identityid); + update.Bind(3,localidentityid); update.Step(); // insert message to show what id was changed and what current levels are @@ -182,6 +222,7 @@ void Message::HandleAdministrationMessage() now.SetToGMTime(); StringFunctions::Convert(origmessagetrust,messagetruststr); StringFunctions::Convert(origtrustlisttrust,trustlisttruststr); + messagebody="Trust List of "+m_fromname+"\r\n"; messagebody="Trust Changed for "+identityname+"\r\n"; messagebody+="Local Message Trust : "+messagetruststr+"\r\n"; messagebody+="Local Trust List Trust : "+trustlisttruststr+"\r\n"; @@ -215,39 +256,52 @@ void Message::HandleChangeTrust() { if(m_changemessagetrustonreply!=0 && m_inreplyto.size()>0) { - SQLite3DB::Statement st=m_db->Prepare("SELECT tblIdentity.IdentityID,tblIdentity.LocalMessageTrust FROM tblIdentity INNER JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE tblMessage.MessageUUID=?;"); - st.Bind(0,m_inreplyto[0]); - st.Step(); - if(st.RowReturned()) + int localidentityid=FindLocalIdentityID(m_fromname); + if(localidentityid!=-1) { - int identityid=0; - int localmessagetrust=0; + // make sure we have a record in tblIdentityTrust + SQLite3DB::Statement ins=m_db->Prepare("INSERT INTO tblIdentityTrust(LocalIdentityID,IdentityID) VALUES(?,?);"); - st.ResultInt(0,identityid); - if(st.ResultNull(1)==false) - { - st.ResultInt(1,localmessagetrust); - } - else + SQLite3DB::Statement st=m_db->Prepare("SELECT tblIdentity.IdentityID,tblIdentityTrust.LocalMessageTrust FROM tblIdentity INNER JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID LEFT JOIN (SELECT IdentityID,LocalMessageTrust FROM tblIdentityTrust WHERE LocalIdentityID=?) AS 'tblIdentityTrust' ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID WHERE tblMessage.MessageUUID=?;"); + st.Bind(0,localidentityid); + st.Bind(1,m_inreplyto[0]); + st.Step(); + if(st.RowReturned()) { - localmessagetrust=m_minlocalmessagetrust; - } + int identityid=0; + int localmessagetrust=0; - localmessagetrust+=m_changemessagetrustonreply; - if(localmessagetrust<0) - { - localmessagetrust=0; - } - if(localmessagetrust>100) - { - localmessagetrust=100; - } + st.ResultInt(0,identityid); + if(st.ResultNull(1)==false) + { + st.ResultInt(1,localmessagetrust); + } + else + { + localmessagetrust=m_minlocalmessagetrust; + } + + localmessagetrust+=m_changemessagetrustonreply; + if(localmessagetrust<0) + { + localmessagetrust=0; + } + if(localmessagetrust>100) + { + localmessagetrust=100; + } - SQLite3DB::Statement st2=m_db->Prepare("UPDATE tblIdentity SET LocalMessageTrust=? WHERE IdentityID=?;"); - st2.Bind(0,localmessagetrust); - st2.Bind(1,identityid); - st2.Step(); + ins.Bind(0,localidentityid); + ins.Bind(1,identityid); + ins.Step(); + SQLite3DB::Statement st2=m_db->Prepare("UPDATE tblIdentityTrust SET LocalMessageTrust=? WHERE IdentityID=? AND LocalIdentityID=?;"); + st2.Bind(0,localmessagetrust); + st2.Bind(1,identityid); + st2.Bind(2,localidentityid); + st2.Step(); + + } } } } @@ -635,7 +689,9 @@ const bool Message::StartFreenetInsert() xml.AddInReplyTo((*j).first,(*j).second); } + // find identity to insert with + /* SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID FROM tblLocalIdentity WHERE Name=?;"); st.Bind(0,m_fromname); st.Step(); @@ -661,8 +717,14 @@ const bool Message::StartFreenetInsert() { st.ResultInt(0,localidentityid); } + */ + localidentityid=FindLocalIdentityID(m_fromname); + if(localidentityid==-1) + { + return false; + } - st=m_db->Prepare("INSERT INTO tblMessageInserts(LocalIdentityID,MessageUUID,MessageXML) VALUES(?,?,?);"); + SQLite3DB::Statement st=m_db->Prepare("INSERT INTO tblMessageInserts(LocalIdentityID,MessageUUID,MessageXML) VALUES(?,?,?);"); st.Bind(0,localidentityid); st.Bind(1,m_messageuuid); st.Bind(2,xml.GetXML());
NameLocal Message Trust
NameLocal Message TrustMessage CommentPeer Message TrustLocal Trust List TrustPeer Message TrustLocal Trust List TrustTrust CommentPeer Trust List TrustMessage CountPeer Trust List TrustMessage Count
"; content+=""; content+=""; if(name!="") { - content+=SanitizeOutput(name+keypart)+"..."; + content+=SanitizeOutput(CreateShortIdentityName(name,publickey)); } else { @@ -321,7 +400,7 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s if(startrow>0) { StringFunctions::Convert(startrow-rowsperpage,tempstr); - content+="<-- Previous Page<-- Previous PageNext Page -->