X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fglobal.cpp;h=251ea2abbb4e48a0887ad18f2245bcd99679d623;hb=a007770a843aa759763b98288c9432c3906ce5c6;hp=a9477679f30ffd2aec00de69a612452eace6a8fe;hpb=4430e7762844c66428b6f822288beb71b7f82b95;p=fms.git diff --git a/src/global.cpp b/src/global.cpp index a947767..251ea2a 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -28,9 +28,6 @@ void SetupDB() db->Open("fms.db3"); db->SetBusyTimeout(10000); // set timeout to 10 seconds db->Execute("VACUUM;"); - - // TODO remove this - temp fix for problem in 0.1.8 - db->Execute("DELETE FROM tblMessageBoard WHERE MessageID NOT IN (SELECT MessageID FROM tblMessage);"); db->Execute("CREATE TABLE IF NOT EXISTS tblDBVersion(\ Major INTEGER,\ @@ -64,10 +61,16 @@ void SetupDB() major=1; minor=4; } + if(major==1 && minor==4) + { + ConvertDB0104To0105(); + major=1; + minor=5; + } } else { - db->Execute("INSERT INTO tblDBVersion(Major,Minor) VALUES(1,4);"); + db->Execute("INSERT INTO tblDBVersion(Major,Minor) VALUES(1,5);"); } db->Execute("UPDATE tblDBVersion SET Major=1, Minor=4;"); @@ -131,18 +134,21 @@ void SetupDB() );"); db->Execute("CREATE TABLE IF NOT EXISTS tblIdentity(\ - IdentityID INTEGER PRIMARY KEY,\ - PublicKey TEXT UNIQUE,\ - Name TEXT,\ - SingleUse BOOL CHECK(SingleUse IN('true','false')) DEFAULT 'false',\ - PublishTrustList BOOL CHECK(PublishTrustList IN('true','false')) DEFAULT 'false',\ - PublishBoardList BOOL CHECK(PublishBoardList IN('true','false')) DEFAULT 'false',\ - DateAdded DATETIME,\ - LastSeen DATETIME,\ - LocalMessageTrust INTEGER CHECK(LocalMessageTrust BETWEEN 0 AND 100) DEFAULT NULL,\ - PeerMessageTrust INTEGER CHECK(PeerMessageTrust BETWEEN 0 AND 100) DEFAULT NULL,\ - LocalTrustListTrust INTEGER CHECK(LocalTrustListTrust BETWEEN 0 AND 100) DEFAULT NULL,\ - PeerTrustListTrust INTEGER CHECK(PeerTrustListTrust BETWEEN 0 AND 100) DEFAULT NULL\ + IdentityID INTEGER PRIMARY KEY,\ + PublicKey TEXT UNIQUE,\ + Name TEXT,\ + SingleUse BOOL CHECK(SingleUse IN('true','false')) DEFAULT 'false',\ + PublishTrustList BOOL CHECK(PublishTrustList IN('true','false')) DEFAULT 'false',\ + PublishBoardList BOOL CHECK(PublishBoardList IN('true','false')) DEFAULT 'false',\ + DateAdded DATETIME,\ + LastSeen DATETIME,\ + LocalMessageTrust INTEGER CHECK(LocalMessageTrust BETWEEN 0 AND 100) DEFAULT NULL,\ + PeerMessageTrust INTEGER CHECK(PeerMessageTrust BETWEEN 0 AND 100) DEFAULT NULL,\ + LocalTrustListTrust INTEGER CHECK(LocalTrustListTrust BETWEEN 0 AND 100) DEFAULT NULL,\ + PeerTrustListTrust INTEGER CHECK(PeerTrustListTrust BETWEEN 0 AND 100) DEFAULT NULL,\ + AddedMethod TEXT,\ + MessageTrustComment TEXT,\ + TrustListTrustComment TEXT\ );"); db->Execute("CREATE TABLE IF NOT EXISTS tblIdentityRequests(\ @@ -172,10 +178,12 @@ void SetupDB() );"); db->Execute("CREATE TABLE IF NOT EXISTS tblPeerTrust(\ - IdentityID INTEGER,\ - TargetIdentityID INTEGER,\ - MessageTrust INTEGER CHECK(MessageTrust BETWEEN 0 AND 100),\ - TrustListTrust INTEGER CHECK(TrustListTrust BETWEEN 0 AND 100)\ + IdentityID INTEGER,\ + TargetIdentityID INTEGER,\ + MessageTrust INTEGER CHECK(MessageTrust BETWEEN 0 AND 100),\ + TrustListTrust INTEGER CHECK(TrustListTrust BETWEEN 0 AND 100),\ + MessageTrustComment TEXT,\ + TrustListTrustComment TEXT\ );"); db->Execute("CREATE TABLE IF NOT EXISTS tblBoard(\ @@ -386,6 +394,9 @@ void SetupDB() // insert garfield's public key db->Execute("INSERT INTO tblIdentity(PublicKey,DateAdded) VALUES('SSK@T8l1IEGU4-PoASFzgc2GYhIgRzUvZsKdoQWeuLHuTmM,QLxAPfkGis8l5NafNpSCdbxzXhBlu9WL8svcqJw9Mpo,AQACAAE/','"+date.Format("%Y-%m-%d %H:%M:%S")+"');"); + // TODO remove sometime after 0.1.17 + FixCapitalBoardNames(); + } void ConvertDB0100To0101() @@ -460,6 +471,19 @@ void ConvertDB0103To0104() db->Execute("UPDATE tblDBVersion SET Major=1, Minor=4;"); } +void ConvertDB0104To0105() +{ + // add AddedMethod, MessageTrustComment, TrustListTrustComment to tblIdentity + // add MessageTrustComment,TrustListTrustComment to tblPeerTrust + SQLite3DB::DB *db=SQLite3DB::DB::Instance(); + db->Execute("ALTER TABLE tblIdentity ADD COLUMN AddedMethod TEXT;"); + db->Execute("ALTER TABLE tblIdentity ADD COLUMN MessageTrustComment TEXT;"); + db->Execute("ALTER TABLE tblIdentity ADD COLUMN TrustListTrustComment TEXT;"); + db->Execute("ALTER TABLE tblPeerTrust ADD COLUMN MessageTrustComment TEXT;"); + db->Execute("ALTER TABLE tblPeerTrust ADD COLUMN TrustListTrustComment TEXT;"); + db->Execute("UPDATE tblDBVersion SET Major=1, Minor=5;"); +} + void SetupDefaultOptions() { // OptionValue should always be inserted as a string, even if the option really isn't a string - just to keep the field data type consistent @@ -516,6 +540,12 @@ void SetupDefaultOptions() st.Step(); st.Reset(); + st.Bind(0,"HTTPAccessControl"); + st.Bind(1,"-0.0.0.0/0,+127.0.0.1"); + st.Bind(2,"Comma separated list of addresses and/or subnet masks that are allowed access to the administration pages. Default is localhost only. + allows a host, - denies as host."); + st.Step(); + st.Reset(); + // StartFreenetUpdater st.Bind(0,"StartFreenetUpdater"); st.Bind(1,"true"); @@ -645,6 +675,12 @@ void SetupDefaultOptions() st.Step(); st.Reset(); + st.Bind(0,"DeleteMessagesOlderThan"); + st.Bind(1,"180"); + st.Bind(2,"Automatically delete messages older than this many days."); + st.Step(); + st.Reset(); + } void SetupLogFile() @@ -705,68 +741,66 @@ void SigHandler(int signum) exit(0); } -/* -void ShutdownThreads(std::vector &threads) -{ - std::vector::iterator i; - for(i=threads.begin(); i!=threads.end(); i++) - { - (*i)->Cancel(); - } - - for(i=threads.begin(); i!=threads.end(); i++) - { - LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"ShutdownThreads waiting for thread to exit."); - //(*i)->wait(); - (*i)->Join(); - delete (*i); - } - - threads.clear(); - -} - -void StartThreads(std::vector &threads) +void FixCapitalBoardNames() { - std::string startfreenet; - std::string startnntp; - std::string starthttp; - - if(Option::Instance()->Get("StartFreenetUpdater",startfreenet)==false) - { - startfreenet="true"; - Option::Instance()->Set("StartFreenetUpdater","true"); - } - - if(Option::Instance()->Get("StartNNTP",startnntp)==false) - { - startnntp="true"; - Option::Instance()->Set("StartNNTP","true"); - } - - if(Option::Instance()->Get("StartHTTP",starthttp)==false) - { - starthttp="true"; - Option::Instance()->Set("StartHTTP","true"); - } - - if(startfreenet=="true") - { - PThread::Thread *t=new PThread::Thread(new FreenetMasterThread()); - threads.push_back(t); - } + SQLite3DB::DB *db=SQLite3DB::DB::Instance(); - if(startnntp=="true") - { - PThread::Thread *t=new PThread::Thread(new NNTPListener()); - threads.push_back(t); - } + SQLite3DB::Statement st=db->Prepare("SELECT BoardID,BoardName FROM tblBoard WHERE BoardID NOT IN (SELECT BoardID FROM tblAdministrationBoard);"); + SQLite3DB::Statement st2=db->Prepare("SELECT BoardID FROM tblBoard WHERE BoardName=?;"); + SQLite3DB::Statement del=db->Prepare("DELTE FROM tblBoard WHERE BoardID=?;"); + SQLite3DB::Statement upd=db->Prepare("UPDATE tblBoard SET BoardName=? WHERE BoardID=?;"); + SQLite3DB::Statement upd2=db->Prepare("UPDATE tblMessage SET ReplyBoardID=? WHERE ReplyBoardID=?;"); + SQLite3DB::Statement upd3=db->Prepare("UPDATE tblMessageBoard SET BoardID=? WHERE BoardID=?;"); - if(starthttp=="true") + st.Step(); + while(st.RowReturned()) { - PThread::Thread *t=new PThread::Thread(new HTTPThread()); - threads.push_back(t); + int boardid=0; + int newboardid=0; + std::string name=""; + std::string lowername=""; + + st.ResultInt(0,boardid); + st.ResultText(1,name); + + lowername=name; + StringFunctions::LowerCase(lowername,lowername); + + if(name!=lowername) + { + st2.Bind(0,lowername); + st2.Step(); + + if(st2.RowReturned()) + { + st2.ResultInt(0,newboardid); + + upd2.Bind(0,newboardid); + upd2.Bind(1,boardid); + upd2.Step(); + upd2.Reset(); + + upd3.Bind(0,newboardid); + upd3.Bind(1,boardid); + upd3.Step(); + upd3.Reset(); + + del.Bind(0,boardid); + del.Step(); + del.Reset(); + } + else + { + upd.Bind(0,lowername); + upd.Bind(1,boardid); + upd.Step(); + upd.Reset(); + } + + st2.Reset(); + } + + st.Step(); } } -*/