From 42b90599be768ef1fec056cb4ccee838f9ed55fe Mon Sep 17 00:00:00 2001 From: moodler Date: Thu, 30 Sep 2004 06:02:39 +0000 Subject: [PATCH] SESSIONS-IN-DATABASE SUPPORT Support for a new configuration variable called $CFG->dbsessions which enables sessions via database. Based on code from Jason Cole's team - thanks! --- lib/db/mysql.php | 11 +++++++++++ lib/db/mysql.sql | 14 ++++++++++++++ lib/db/postgres7.php | 11 +++++++++++ lib/db/postgres7.sql | 8 ++++++++ lib/defaults.php | 21 +++++++++++---------- lib/setup.php | 31 ++++++++++++++++++++++--------- version.php | 2 +- 7 files changed, 78 insertions(+), 20 deletions(-) diff --git a/lib/db/mysql.php b/lib/db/mysql.php index 71dc80c3a1..aa0f63aea7 100644 --- a/lib/db/mysql.php +++ b/lib/db/mysql.php @@ -863,6 +863,17 @@ function main_upgrade($oldversion=0) { execute_sql("ALTER TABLE {$CFG->prefix}user ADD INDEX auth (auth)"); } + if ($oldversion < 2004093001) { // add new table for sessions storage + execute_sql(" CREATE TABLE `{$CFG->prefix}sessions` ( + `sesskey` char(32) NOT null, + `expiry` int(11) unsigned NOT null, + `expireref` varchar(64), + `data` text NOT null, + PRIMARY KEY (`sesskey`), + KEY (`expiry`) + ) TYPE=MyISAM COMMENT='Optional database session storage, not used by default';"); + } + return $result; } diff --git a/lib/db/mysql.sql b/lib/db/mysql.sql index 832a7fc7b6..d70b7d72ab 100644 --- a/lib/db/mysql.sql +++ b/lib/db/mysql.sql @@ -301,6 +301,20 @@ CREATE TABLE `prefix_scale` ( # -------------------------------------------------------- +# +# Table structure for table `sessions` +# + +CREATE TABLE `prefix_sessions` ( + `sesskey` char(32) NOT null, + `expiry` int(11) unsigned NOT null, + `expireref` varchar(64), + `data` text NOT null, + PRIMARY KEY (`sesskey`), + KEY (`expiry`) +) TYPE=MyISAM COMMENT='Optional database session storage, not used by default'; +# -------------------------------------------------------- + # # Table structure for table `user` # diff --git a/lib/db/postgres7.php b/lib/db/postgres7.php index 6c2fa3a7d1..4a7afde154 100644 --- a/lib/db/postgres7.php +++ b/lib/db/postgres7.php @@ -601,6 +601,17 @@ function main_upgrade($oldversion=0) { if ($oldversion < 2004092000) { //redoing this just to be sure that column type is text (postgres type changes didnt work when this was done first time) table_column("config", "value", "value", "text", "", "", ""); } + + if ($oldversion < 2004093001) { // add new table for sessions storage + execute_sql(" CREATE TABLE {$CFG->prefix}sessions ( + sesskey char(32) PRIMARY KEY, + expiry integer NOT null, + expireref varchar(64), + data text NOT null + );"); + + execute_sql(" CREATE INDEX {$CFG->prefix}sessions_expiry_idx ON {$CFG->prefix}sessions (expiry)"); + } return $result; diff --git a/lib/db/postgres7.sql b/lib/db/postgres7.sql index a7d532553e..5094e477e9 100644 --- a/lib/db/postgres7.sql +++ b/lib/db/postgres7.sql @@ -172,6 +172,14 @@ CREATE TABLE prefix_scale ( timemodified integer NOT NULL default '0' ); +CREATE TABLE prefix_sessions ( + sesskey char(32) PRIMARY KEY, + expiry integer NOT null, + expireref varchar(64), + data text NOT null +); + +CREATE INDEX prefix_sessions_expiry_idx ON prefix_sessions (expiry); CREATE TABLE prefix_cache_filters ( id SERIAL PRIMARY KEY, diff --git a/lib/defaults.php b/lib/defaults.php index 93703ae390..228e3562a9 100644 --- a/lib/defaults.php +++ b/lib/defaults.php @@ -8,22 +8,23 @@ 'allusersaresitestudents' => true, 'auth' => 'email', 'auth_pop3mailbox' => 'INBOX', - 'autologinguests' => 0, + 'autologinguests' => 0, 'cachetext' => 60, 'changepassword' => true, 'country' => '', + 'dbsessions' => false, 'debug' => 7, - 'deleteunconfirmed' => 168, - 'digestmailtime' => 17, + 'deleteunconfirmed' => 168, + 'digestmailtime' => 17, 'displayloginfailures' => '', - 'enablerssfeeds' => 0, + 'enablerssfeeds' => 0, 'enrol' => 'internal', - 'extendedusernamechars' => false, + 'extendedusernamechars' => false, 'editorbackgroundcolor' => '#ffffff', 'editorfontfamily' => 'Trebuchet MS,Verdana,Arial,Helvetica,sans-serif', 'editorfontsize' => '', - 'editorkillword' => 1, - 'editorspelling' => 0, + 'editorkillword' => 1, + 'editorspelling' => 0, 'editorfontlist' => 'Trebuchet:Trebuchet MS,Verdana,Arial,Helvetica,sans-serif;Arial:arial,helvetica,sans-serif;Courier New:courier new,courier,monospace;Georgia:georgia,times new roman,times,serif;Tahoma:tahoma,arial,helvetica,sans-serif;Times New Roman:times new roman,times,serif;Verdana:verdana,arial,helvetica,sans-serif;Impact:impact;Wingdings:wingdings', 'filteruploadedfiles' => true, 'forcelogin' => false, @@ -53,16 +54,16 @@ 'secureforms' => false, 'sessioncookie' => '', 'sessiontimeout' => 7200, - 'showsiteparticipantslist' => 0, + 'showsiteparticipantslist' => 0, 'slasharguments' => 1, 'smtphosts' => '', 'smtppass' => '', 'smtpuser' => '', 'style' => 'default', - 'teacherassignteachers' => true, + 'teacherassignteachers' => true, 'template' => 'default', 'textfilters' => 'mod/glossary/dynalink.php', - 'timezone' => 99, + 'timezone' => 99, 'theme' => 'standard', 'unzip' => '', 'zip' => '' diff --git a/lib/setup.php b/lib/setup.php index de355ff1cb..4415958239 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -169,16 +169,29 @@ global $THEME; } $smarty->compile_dir = $CFG->dataroot .'/cache'; -/// Set session timeouts - if (!empty($CFG->sessiontimeout)) { - ini_set('session.gc_maxlifetime', $CFG->sessiontimeout); - } - -/// Set custom session path - if (!file_exists($CFG->dataroot .'/sessions')) { - make_upload_directory('sessions'); +/// Set up session handling + if (empty($CFG->dbsessions)) { /// File-based sessions + if (!empty($CFG->sessiontimeout)) { + ini_set('session.gc_maxlifetime', $CFG->sessiontimeout); + } + + if (!file_exists($CFG->dataroot .'/sessions')) { + make_upload_directory('sessions'); + } + ini_set('session.save_path', $CFG->dataroot .'/sessions'); + + } else { /// Database sessions + ini_set('session.save_handler', 'user'); + + $ADODB_SESSION_DRIVER = $CFG->dbtype; + $ADODB_SESSION_CONNECT = $CFG->dbhost; + $ADODB_SESSION_USER = $CFG->dbuser; + $ADODB_SESSION_PWD = $CFG->dbpass; + $ADODB_SESSION_DB = $CFG->dbname; + $ADODB_SESSION_TBL = $CFG->prefix.'sessions'; + + require_once($CFG->libdir. '/adodb/session/adodb-session.php'); } - ini_set('session.save_path', $CFG->dataroot .'/sessions'); /// Set sessioncookie variable if it isn't already if (!isset($CFG->sessioncookie)) { diff --git a/version.php b/version.php index e7d655859f..bc5f9f308f 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2004092700; // YYYYMMDD = date of first major branch release 1.4 + $version = 2004093001; // YYYYMMDD = date of first major branch release 1.4 // XY = increments within a single day $release = '1.5 UNSTABLE DEVELOPMENT'; // Human-friendly version name -- 2.39.5