From 4df4ab500788f0792b75baf1fa98e4647d713ed1 Mon Sep 17 00:00:00 2001 From: corbosman Date: Thu, 19 Feb 2015 14:55:09 +0100 Subject: session refactor and add redis driver --- program/lib/Roundcube/rcube.php | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'program/lib/Roundcube/rcube.php') diff --git a/program/lib/Roundcube/rcube.php b/program/lib/Roundcube/rcube.php index 3aca88843..42d880763 100644 --- a/program/lib/Roundcube/rcube.php +++ b/program/lib/Roundcube/rcube.php @@ -522,9 +522,12 @@ class rcube ini_set('session.cookie_httponly', 1); // use database for storing session data - $this->session = new rcube_session($this->get_dbh(), $this->config); + $storage = $this->config->get('session_storage', 'db'); + $this->session = $this->get_session($storage); + // register default gc handler $this->session->register_gc_handler(array($this, 'gc')); + $this->session->set_secret($this->config->get('des_key') . dirname($_SERVER['SCRIPT_NAME'])); $this->session->set_ip_check($this->config->get('ip_check')); @@ -534,8 +537,30 @@ class rcube // start PHP session (if not in CLI mode) if ($_SERVER['REMOTE_ADDR']) { - $this->session->start(); + $this->session->start($this->config); + } + } + + /** + * get an rcube_session instance + * + * @return rcube_session + */ + private function get_session($storage) + { + // class name for this storage + $class = "rcube_session_" . $storage; + + // try to instantiate class + if(class_exists($class)) { + return new $class(); } + + // no storage found, raise error + rcube::raise_error(array('code' => 604, 'type' => 'session', + 'line' => __LINE__, 'file' => __FILE__, + 'message' => "Failed to find session driver. Check session_storage config option"), + true, true); } -- cgit v1.2.3