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 From b59b72cc3028cc0514e951f135d8bfe7efcaaa6f Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Thu, 26 Feb 2015 18:04:03 +0100 Subject: Fix "Non-static method PEAR::isError() should not be called statically" errors (#1490281) --- CHANGELOG | 1 + plugins/managesieve/lib/Roundcube/rcube_sieve.php | 93 +++++++++++++++------- .../lib/Roundcube/rcube_sieve_engine.php | 5 +- plugins/password/drivers/ldap.php | 6 +- plugins/password/drivers/poppassd.php | 2 +- plugins/password/drivers/vpopmaild.php | 9 ++- program/lib/Roundcube/rcube.php | 15 ++-- program/lib/Roundcube/rcube_smtp.php | 14 ++-- program/steps/mail/sendmail.inc | 7 +- 9 files changed, 99 insertions(+), 53 deletions(-) (limited to 'program/lib/Roundcube/rcube.php') diff --git a/CHANGELOG b/CHANGELOG index 72ccf7043..4855f2c31 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -17,6 +17,7 @@ CHANGELOG Roundcube Webmail - Fix cursor position on reply below the quote in HTML mode (#1490263) - Fix so "over quota" errors are displayed also in message compose page - Fix duplicate entries supression in autocomplete result (#1490290) +- Fix "Non-static method PEAR::isError() should not be called statically" errors (#1490281) RELEASE 1.1.0 ------------- diff --git a/plugins/managesieve/lib/Roundcube/rcube_sieve.php b/plugins/managesieve/lib/Roundcube/rcube_sieve.php index 389c85012..59a7bc134 100644 --- a/plugins/managesieve/lib/Roundcube/rcube_sieve.php +++ b/plugins/managesieve/lib/Roundcube/rcube_sieve.php @@ -68,7 +68,9 @@ class rcube_sieve $this->sieve->setDebug(true, array($this, 'debug_handler')); } - if (PEAR::isError($this->sieve->connect($host, $port, $options, $usetls))) { + $result = $this->sieve->connect($host, $port, $options, $usetls); + + if (is_a($result, 'PEAR_Error')) { return $this->_set_error(self::ERROR_CONNECTION); } @@ -78,9 +80,9 @@ class rcube_sieve $password = $auth_pw; } - if (PEAR::isError($this->sieve->login($username, $password, - $auth_type ? strtoupper($auth_type) : null, $authz)) - ) { + $result = $this->sieve->login($username, $password, $auth_type ? strtoupper($auth_type) : null, $authz); + + if (is_a($result, 'PEAR_Error')) { return $this->_set_error(self::ERROR_LOGIN); } @@ -115,22 +117,28 @@ class rcube_sieve */ public function save($name = null) { - if (!$this->sieve) + if (!$this->sieve) { return $this->_set_error(self::ERROR_INTERNAL); + } - if (!$this->script) + if (!$this->script) { return $this->_set_error(self::ERROR_INTERNAL); + } - if (!$name) + if (!$name) { $name = $this->current; + } $script = $this->script->as_text(); - if (!$script) + if (!$script) { $script = '/* empty script */'; + } - if (PEAR::isError($this->sieve->installScript($name, $script))) + $result = $this->sieve->installScript($name, $script); + if (is_a($result, 'PEAR_Error')) { return $this->_set_error(self::ERROR_INSTALL); + } return true; } @@ -140,14 +148,19 @@ class rcube_sieve */ public function save_script($name, $content = null) { - if (!$this->sieve) + if (!$this->sieve) { return $this->_set_error(self::ERROR_INTERNAL); + } - if (!$content) + if (!$content) { $content = '/* empty script */'; + } + + $result = $this->sieve->installScript($name, $content); - if (PEAR::isError($this->sieve->installScript($name, $content))) + if (is_a($result, 'PEAR_Error')) { return $this->_set_error(self::ERROR_INSTALL); + } return true; } @@ -157,14 +170,19 @@ class rcube_sieve */ public function activate($name = null) { - if (!$this->sieve) + if (!$this->sieve) { return $this->_set_error(self::ERROR_INTERNAL); + } - if (!$name) + if (!$name) { $name = $this->current; + } - if (PEAR::isError($this->sieve->setActive($name))) + $result = $this->sieve->setActive($name); + + if (is_a($result, 'PEAR_Error')) { return $this->_set_error(self::ERROR_ACTIVATE); + } return true; } @@ -174,11 +192,15 @@ class rcube_sieve */ public function deactivate() { - if (!$this->sieve) + if (!$this->sieve) { return $this->_set_error(self::ERROR_INTERNAL); + } + + $result = $this->sieve->setActive(''); - if (PEAR::isError($this->sieve->setActive(''))) + if (is_a($result, 'PEAR_Error')) { return $this->_set_error(self::ERROR_DEACTIVATE); + } return true; } @@ -188,22 +210,32 @@ class rcube_sieve */ public function remove($name = null) { - if (!$this->sieve) + if (!$this->sieve) { return $this->_set_error(self::ERROR_INTERNAL); + } - if (!$name) + if (!$name) { $name = $this->current; + } // script must be deactivated first - if ($name == $this->sieve->getActive()) - if (PEAR::isError($this->sieve->setActive(''))) + if ($name == $this->sieve->getActive()) { + $result = $this->sieve->setActive(''); + + if (is_a($result, 'PEAR_Error')) { return $this->_set_error(self::ERROR_DELETE); + } + } + + $result = $this->sieve->removeScript($name); - if (PEAR::isError($this->sieve->removeScript($name))) + if (is_a($result, 'PEAR_Error')) { return $this->_set_error(self::ERROR_DELETE); + } - if ($name == $this->current) + if ($name == $this->current) { $this->current = null; + } return true; } @@ -221,7 +253,7 @@ class rcube_sieve $ext = $this->sieve->getExtensions(); - if (PEAR::isError($ext)) { + if (is_a($ext, 'PEAR_Error')) { return array(); } @@ -250,8 +282,9 @@ class rcube_sieve $list = $this->sieve->listScripts(); - if (PEAR::isError($list)) + if (is_a($list, 'PEAR_Error')) { return $this->_set_error(self::ERROR_OTHER); + } $this->list = $list; } @@ -283,8 +316,9 @@ class rcube_sieve $script = $this->sieve->getScript($name); - if (PEAR::isError($script)) + if (is_a($script, 'PEAR_Error')) { return $this->_set_error(self::ERROR_OTHER); + } // try to parse from Roundcube format $this->script = $this->_parse($script); @@ -349,8 +383,9 @@ class rcube_sieve $content = $this->sieve->getScript($name); - if (PEAR::isError($content)) + if (is_a($content, 'PEAR_Error')) { return $this->_set_error(self::ERROR_OTHER); + } return $content; } @@ -366,10 +401,12 @@ class rcube_sieve if ($copy) { $content = $this->sieve->getScript($copy); - if (PEAR::isError($content)) + if (is_a($content, 'PEAR_Error')) { return $this->_set_error(self::ERROR_OTHER); + } } + return $this->save_script($name, $content); } diff --git a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php index 69ae4b8a6..98c4c952c 100644 --- a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php +++ b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php @@ -390,10 +390,11 @@ class rcube_sieve_engine } else if ($action == 'setget') { $script_name = rcube_utils::get_input_value('_set', rcube_utils::INPUT_GPC, true); - $script = $this->sieve->get_script($script_name); + $script = $this->sieve->get_script($script_name); - if (PEAR::isError($script)) + if (is_a($script, 'PEAR_Error')) { exit; + } $browser = new rcube_browser; diff --git a/plugins/password/drivers/ldap.php b/plugins/password/drivers/ldap.php index c18ff0f06..a11c38d17 100644 --- a/plugins/password/drivers/ldap.php +++ b/plugins/password/drivers/ldap.php @@ -75,7 +75,7 @@ class rcube_ldap_password $ldap = Net_LDAP2::connect($ldapConfig); // Checking for connection error - if (PEAR::isError($ldap)) { + if (is_a($ldap, 'PEAR_Error')) { return PASSWORD_CONNECT_ERROR; } @@ -176,7 +176,7 @@ class rcube_ldap_password $ldap = Net_LDAP2::connect($ldapConfig); - if (PEAR::isError($ldap)) { + if (is_a($ldap, 'PEAR_Error')) { return ''; } @@ -189,7 +189,7 @@ class rcube_ldap_password $result = $ldap->search($base, $filter, $options); $ldap->done(); - if (PEAR::isError($result) || ($result->count() != 1)) { + if (is_a($result, 'PEAR_Error') || ($result->count() != 1)) { return ''; } diff --git a/plugins/password/drivers/poppassd.php b/plugins/password/drivers/poppassd.php index 8ddbef5d3..7a2821083 100644 --- a/plugins/password/drivers/poppassd.php +++ b/plugins/password/drivers/poppassd.php @@ -42,7 +42,7 @@ class rcube_poppassd_password $poppassd = new Net_Socket(); $result = $poppassd->connect($rcmail->config->get('password_pop_host'), $rcmail->config->get('password_pop_port'), null); - if (PEAR::isError($result)) { + if (is_a($result, 'PEAR_Error')) { return $this->format_error_result(PASSWORD_CONNECT_ERROR, $result->getMessage()); } else { diff --git a/plugins/password/drivers/vpopmaild.php b/plugins/password/drivers/vpopmaild.php index a7644fc21..90fce02c5 100644 --- a/plugins/password/drivers/vpopmaild.php +++ b/plugins/password/drivers/vpopmaild.php @@ -28,12 +28,13 @@ class rcube_vpopmaild_password { function save($curpass, $passwd) { - $rcmail = rcmail::get_instance(); - // include('Net/Socket.php'); + $rcmail = rcmail::get_instance(); $vpopmaild = new Net_Socket(); + $host = $rcmail->config->get('password_vpopmaild_host'); + $port = $rcmail->config->get('password_vpopmaild_port'); - if (PEAR::isError($vpopmaild->connect($rcmail->config->get('password_vpopmaild_host'), - $rcmail->config->get('password_vpopmaild_port'), null))) { + $result = $vpopmaild->connect($hostname, $port, null); + if (is_a($result, 'PEAR_Error')) { return PASSWORD_CONNECT_ERROR; } diff --git a/program/lib/Roundcube/rcube.php b/program/lib/Roundcube/rcube.php index 3aca88843..20f509e3d 100644 --- a/program/lib/Roundcube/rcube.php +++ b/program/lib/Roundcube/rcube.php @@ -1681,15 +1681,18 @@ class rcube if ($message->getParam('delay_file_io')) { // use common temp dir - $temp_dir = $this->config->get('temp_dir'); - $body_file = tempnam($temp_dir, 'rcmMsg'); - if (PEAR::isError($mime_result = $message->saveMessageBody($body_file))) { + $temp_dir = $this->config->get('temp_dir'); + $body_file = tempnam($temp_dir, 'rcmMsg'); + $mime_result = $message->saveMessageBody($body_file); + + if (is_a($mime_result, 'PEAR_Error')) { self::raise_error(array('code' => 650, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Could not create message: ".$mime_result->getMessage()), - TRUE, FALSE); + true, false); return false; } + $msg_body = fopen($body_file, 'r'); } else { @@ -1732,11 +1735,11 @@ class rcube $msg_body = $message->get(); - if (PEAR::isError($msg_body)) { + if (is_a($msg_body, 'PEAR_Error')) { self::raise_error(array('code' => 650, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Could not create message: ".$msg_body->getMessage()), - TRUE, FALSE); + true, false); } else { $delim = $this->config->header_delimiter(); diff --git a/program/lib/Roundcube/rcube_smtp.php b/program/lib/Roundcube/rcube_smtp.php index b37b44426..0322a0d46 100644 --- a/program/lib/Roundcube/rcube_smtp.php +++ b/program/lib/Roundcube/rcube_smtp.php @@ -126,7 +126,7 @@ class rcube_smtp // try to connect to server and exit on failure $result = $this->conn->connect($CONFIG['smtp_timeout']); - if (PEAR::isError($result)) { + if (is_a($result, 'PEAR_Error')) { $this->response[] = "Connection failed: ".$result->getMessage(); $this->error = array('label' => 'smtpconnerror', 'vars' => array('code' => $this->conn->_code)); $this->conn = null; @@ -159,7 +159,7 @@ class rcube_smtp $result = $this->conn->auth($smtp_user, $smtp_pass, $smtp_auth_type, $use_tls, $smtp_authz); - if (PEAR::isError($result)) { + if (is_a($result, 'PEAR_Error')) { $this->error = array('label' => 'smtpautherror', 'vars' => array('code' => $this->conn->_code)); $this->response[] .= 'Authentication failure: ' . $result->getMessage() . ' (Code: ' . $result->getCode() . ')'; $this->reset(); @@ -240,7 +240,8 @@ class rcube_smtp } // set From: address - if (PEAR::isError($this->conn->mailFrom($from, $from_params))) { + $result = $this->conn->mailFrom($from, $from_params); + if (is_a($result, 'PEAR_Error')) { $err = $this->conn->getResponse(); $this->error = array('label' => 'smtpfromerror', 'vars' => array( 'from' => $from, 'code' => $err[0], 'msg' => $err[1])); @@ -252,7 +253,7 @@ class rcube_smtp // prepare list of recipients $recipients = $this->_parse_rfc822($recipients); - if (PEAR::isError($recipients)) { + if (is_a($recipients, 'PEAR_Error')) { $this->error = array('label' => 'smtprecipientserror'); $this->reset(); return false; @@ -260,7 +261,8 @@ class rcube_smtp // set mail recipients foreach ($recipients as $recipient) { - if (PEAR::isError($this->conn->rcptTo($recipient, $recipient_params))) { + $result = $this->conn->rcptTo($recipient, $recipient_params); + if (is_a($result, 'PEAR_Error')) { $err = $this->conn->getResponse(); $this->error = array('label' => 'smtptoerror', 'vars' => array( 'to' => $recipient, 'code' => $err[0], 'msg' => $err[1])); @@ -289,7 +291,7 @@ class rcube_smtp // Send the message's headers and the body as SMTP data. $result = $this->conn->data($data, $text_headers); - if (PEAR::isError($result)) { + if (is_a($result, 'PEAR_Error')) { $err = $this->conn->getResponse(); if (!in_array($err[0], array(354, 250, 221))) { $msg = sprintf('[%d] %s', $err[0], $err[1]); diff --git a/program/steps/mail/sendmail.inc b/program/steps/mail/sendmail.inc index 08b085c88..9e674f773 100644 --- a/program/steps/mail/sendmail.inc +++ b/program/steps/mail/sendmail.inc @@ -601,8 +601,9 @@ if ($store_target) { else { $temp_dir = $RCMAIL->config->get('temp_dir'); $mailbody_file = tempnam($temp_dir, 'rcmMsg'); + $msg = $MAIL_MIME->saveMessageBody($mailbody_file); - if (!PEAR::isError($msg = $MAIL_MIME->saveMessageBody($mailbody_file))) { + if (!is_a($msg, 'PEAR_Error')) { $msg = $mailbody_file; } } @@ -612,7 +613,7 @@ if ($store_target) { $headers = ''; } - if (PEAR::isError($msg)) { + if (is_a($msg, 'PEAR_Error')) { rcube::raise_error(array('code' => 650, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Could not create message: ".$msg->getMessage()), @@ -800,7 +801,7 @@ function rcmail_fix_emoticon_paths($mime_message) if (!in_array($image_name, $included_images)) { // add the image to the MIME message $res = $mime_message->addHTMLImage($img_file, 'image/gif', '', true, $image_name); - if (PEAR::isError($res)) { + if (is_a($res, 'PEAR_Error')) { $RCMAIL->output->show_message("emoticonerror", 'error'); continue; } -- cgit v1.2.3 From b4be89bdac46af2b1370ea25268159c2cf2cc632 Mon Sep 17 00:00:00 2001 From: corbosman Date: Fri, 27 Feb 2015 15:03:58 +0100 Subject: use factory --- program/lib/Roundcube/rcube.php | 41 ++------------- program/lib/Roundcube/rcube_session.php | 67 ++++++++++++++++++++---- program/lib/Roundcube/rcube_session_db.php | 7 ++- program/lib/Roundcube/rcube_session_memcache.php | 12 +++-- program/lib/Roundcube/rcube_session_php.php | 12 +++-- program/lib/Roundcube/rcube_session_redis.php | 20 +++---- 6 files changed, 95 insertions(+), 64 deletions(-) (limited to 'program/lib/Roundcube/rcube.php') diff --git a/program/lib/Roundcube/rcube.php b/program/lib/Roundcube/rcube.php index 42d880763..f15ae840a 100644 --- a/program/lib/Roundcube/rcube.php +++ b/program/lib/Roundcube/rcube.php @@ -521,49 +521,18 @@ class rcube ini_set('session.use_only_cookies', 1); ini_set('session.cookie_httponly', 1); - // use database for storing session data - $storage = $this->config->get('session_storage', 'db'); - $this->session = $this->get_session($storage); + // get storage driver from config + // $storage = $this->config->get('session_storage', 'db'); - // 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')); - - if ($this->config->get('session_auth_name')) { - $this->session->set_cookiename($this->config->get('session_auth_name')); - } + // get session driver instance + $this->session = rcube_session::factory($this->config); // start PHP session (if not in CLI mode) if ($_SERVER['REMOTE_ADDR']) { - $this->session->start($this->config); + $this->session->start(); } } - /** - * 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); - } - - /** * Garbage collector - cache/temp cleaner */ diff --git a/program/lib/Roundcube/rcube_session.php b/program/lib/Roundcube/rcube_session.php index 08a9dc302..fc1d87150 100644 --- a/program/lib/Roundcube/rcube_session.php +++ b/program/lib/Roundcube/rcube_session.php @@ -15,6 +15,7 @@ +-----------------------------------------------------------------------+ | Author: Thomas Bruederli | | Author: Aleksander Machniak | + | Author: Cor Bosman | +-----------------------------------------------------------------------+ */ @@ -43,6 +44,7 @@ abstract class rcube_session protected $secret = ''; protected $ip_check = false; protected $logging = false; + protected $config; /** * Blocks session data from being written to database. @@ -50,7 +52,55 @@ abstract class rcube_session * @var boolean */ public $nowrite = false; - + + /** + * Factory, returns driver-specific instance of the class + * + * @param object $config + * @return Object rcube_session + */ + public static function factory($config) + { + // get session storage driver + $storage = $config->get('session_storage', 'db'); + + // class name for this storage + $class = "rcube_session_" . $storage; + + // try to instantiate class + if (class_exists($class)) { + return new $class($config); + } + + // 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); + } + + /** + * @param Object $config + */ + public function __construct($config) + { + $this->config = $config; + + // register default gc handler + $this->register_gc_handler(array($this, 'gc')); + + // set secret + $this->set_secret($this->config->get('des_key') . dirname($_SERVER['SCRIPT_NAME'])); + + // set ip check + $this->set_ip_check($this->config->get('ip_check')); + + // set cookie name + if ($this->config->get('session_auth_name')) { + $this->set_cookiename($this->config->get('session_auth_name')); + } + } + /** * register session handler */ @@ -73,13 +123,13 @@ abstract class rcube_session /** * Wrapper for session_start() */ - public function start($config) + public function start() { $this->start = microtime(true); $this->ip = rcube_utils::remote_addr(); - $this->logging = $config->get('log_session', false); + $this->logging = $this->config->get('log_session', false); - $lifetime = $config->get('session_lifetime', 1) * 60; + $lifetime = $this->config->get('session_lifetime', 1) * 60; $this->set_lifetime($lifetime); session_start(); @@ -105,8 +155,9 @@ abstract class rcube_session */ public function sess_write($key, $vars) { - if ($this->nowrite) + if ($this->nowrite) { return true; + } // check cache $oldvars = $this->get_cache($key); @@ -201,12 +252,6 @@ abstract class rcube_session protected function gc_shutdown() { if ($this->gc_enabled) { - // just delete all expired sessions - if ($this->storage == 'db') { - $this->db->query("DELETE FROM {$this->table_name}" - . " WHERE `changed` < " . $this->db->now(-$this->gc_enabled)); - } - foreach ($this->gc_handlers as $fct) { call_user_func($fct); } diff --git a/program/lib/Roundcube/rcube_session_db.php b/program/lib/Roundcube/rcube_session_db.php index 93d5c2b66..feba2e083 100644 --- a/program/lib/Roundcube/rcube_session_db.php +++ b/program/lib/Roundcube/rcube_session_db.php @@ -33,8 +33,13 @@ class rcube_session_db extends rcube_session private $db; private $table_name; - public function __construct() + /** + * @param Object $config + */ + public function __construct($config) { + parent::__construct($config); + // get db instance $this->db = rcube::get_instance()->get_dbh(); diff --git a/program/lib/Roundcube/rcube_session_memcache.php b/program/lib/Roundcube/rcube_session_memcache.php index 85a4aa617..732d5fb7a 100644 --- a/program/lib/Roundcube/rcube_session_memcache.php +++ b/program/lib/Roundcube/rcube_session_memcache.php @@ -15,7 +15,7 @@ +-----------------------------------------------------------------------+ | Author: Thomas Bruederli | | Author: Aleksander Machniak | - | Author: Cor Bosman | + | Author: Cor Bosman | +-----------------------------------------------------------------------+ */ @@ -32,11 +32,16 @@ class rcube_session_memcache extends rcube_session { private $memcache; - public function __construct() + /** + * @param Object $config + */ + public function __construct($config) { + parent::__construct($config); + $this->memcache = rcube::get_instance()->get_memcache(); - if(! $this->memcache) { + if (!$this->memcache) { rcube::raise_error(array('code' => 604, 'type' => 'db', 'line' => __LINE__, 'file' => __FILE__, 'message' => "Failed to connect to memcached. Please check configuration"), @@ -45,7 +50,6 @@ class rcube_session_memcache extends rcube_session // register sessions handler $this->register_session_handler(); - } /** diff --git a/program/lib/Roundcube/rcube_session_php.php b/program/lib/Roundcube/rcube_session_php.php index 73a889259..2f7085fc7 100644 --- a/program/lib/Roundcube/rcube_session_php.php +++ b/program/lib/Roundcube/rcube_session_php.php @@ -30,7 +30,6 @@ */ class rcube_session_php extends rcube_session { - /** * native php sessions don't need a save handler * we do need to define abstract function implementations but they are not used. @@ -43,6 +42,13 @@ class rcube_session_php extends rcube_session { public function write($key, $vars) {} public function update($key, $newvars, $oldvars) {} + /** + * @param Object $config + */ + public function __construct($config) + { + parent::__construct($config); + } /** * Wrapper for session_write_close() @@ -58,9 +64,9 @@ class rcube_session_php extends rcube_session { /** * Wrapper for session_start() */ - public function start($config) + public function start() { - parent::start($config); + parent::start(); $this->key = session_id(); $this->ip = $_SESSION['__IP']; diff --git a/program/lib/Roundcube/rcube_session_redis.php b/program/lib/Roundcube/rcube_session_redis.php index 07a91cc45..bc545ca95 100644 --- a/program/lib/Roundcube/rcube_session_redis.php +++ b/program/lib/Roundcube/rcube_session_redis.php @@ -13,8 +13,6 @@ | PURPOSE: | | Provide database supported session management | +-----------------------------------------------------------------------+ - | Author: Thomas Bruederli | - | Author: Aleksander Machniak | | Author: Cor Bosman | +-----------------------------------------------------------------------+ */ @@ -30,12 +28,17 @@ class rcube_session_redis extends rcube_session { private $redis; - public function __construct() + /** + * @param Object $config + */ + public function __construct($config) { + parent::__construct($config); + // instantiate Redis object $this->redis = new Redis(); - if (! $this->redis) { + if (!$this->redis) { rcube::raise_error(array('code' => 604, 'type' => 'session', 'line' => __LINE__, 'file' => __FILE__, 'message' => "Failed to find Redis. Make sure php-redis is included"), @@ -43,10 +46,10 @@ class rcube_session_redis extends rcube_session { } // get config instance - $hosts = rcube::get_instance()->config->get('redis_hosts', array()); + $hosts = $this->config->get('redis_hosts', array('localhost')); // host config is wrong - if (!is_array($hosts) || empty($hosts) ) { + if (!is_array($hosts) || empty($hosts)) { rcube::raise_error(array('code' => 604, 'type' => 'session', 'line' => __LINE__, 'file' => __FILE__, 'message' => "Redis host not configured"), @@ -61,9 +64,9 @@ class rcube_session_redis extends rcube_session { true, true); } - foreach($hosts as $config) { + foreach ($hosts as $host) { // explode individual fields - list($host, $port, $database, $password) = array_pad(explode(':', $config, 4), 4, null); + list($host, $port, $database, $password) = array_pad(explode(':', $host, 4), 4, null); // set default values if not set $host = ($host !== null) ? $host : '127.0.0.1'; @@ -115,7 +118,6 @@ class rcube_session_redis extends rcube_session { // register sessions handler $this->register_session_handler(); - } /** -- cgit v1.2.3 From 6e3d249655f7d93a5b48cabedd229304bb69df90 Mon Sep 17 00:00:00 2001 From: corbosman Date: Fri, 27 Feb 2015 16:36:26 +0100 Subject: remove commented out code --- program/lib/Roundcube/rcube.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'program/lib/Roundcube/rcube.php') diff --git a/program/lib/Roundcube/rcube.php b/program/lib/Roundcube/rcube.php index f15ae840a..3aa461e36 100644 --- a/program/lib/Roundcube/rcube.php +++ b/program/lib/Roundcube/rcube.php @@ -520,10 +520,7 @@ class rcube ini_set('session.use_cookies', 1); ini_set('session.use_only_cookies', 1); ini_set('session.cookie_httponly', 1); - - // get storage driver from config - // $storage = $this->config->get('session_storage', 'db'); - + // get session driver instance $this->session = rcube_session::factory($this->config); -- cgit v1.2.3 From 82058d7af26ff04fd95442815b93f944cea46f10 Mon Sep 17 00:00:00 2001 From: corbosman Date: Wed, 4 Mar 2015 13:56:37 +0100 Subject: minor fixes --- program/lib/Roundcube/rcube.php | 2 +- program/lib/Roundcube/rcube_session_db.php | 2 +- program/lib/Roundcube/rcube_session_redis.php | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) (limited to 'program/lib/Roundcube/rcube.php') diff --git a/program/lib/Roundcube/rcube.php b/program/lib/Roundcube/rcube.php index 3aa461e36..a7c6b9317 100644 --- a/program/lib/Roundcube/rcube.php +++ b/program/lib/Roundcube/rcube.php @@ -520,7 +520,7 @@ class rcube ini_set('session.use_cookies', 1); ini_set('session.use_only_cookies', 1); ini_set('session.cookie_httponly', 1); - + // get session driver instance $this->session = rcube_session::factory($this->config); diff --git a/program/lib/Roundcube/rcube_session_db.php b/program/lib/Roundcube/rcube_session_db.php index feba2e083..78138d1eb 100644 --- a/program/lib/Roundcube/rcube_session_db.php +++ b/program/lib/Roundcube/rcube_session_db.php @@ -41,7 +41,7 @@ class rcube_session_db extends rcube_session parent::__construct($config); // get db instance - $this->db = rcube::get_instance()->get_dbh(); + $this->db = rcube::get_instance()->get_dbh(); // session table name $this->table_name = $this->db->table_name('session', true); diff --git a/program/lib/Roundcube/rcube_session_redis.php b/program/lib/Roundcube/rcube_session_redis.php index bc545ca95..4822db7f9 100644 --- a/program/lib/Roundcube/rcube_session_redis.php +++ b/program/lib/Roundcube/rcube_session_redis.php @@ -4,14 +4,13 @@ +-----------------------------------------------------------------------+ | This file is part of the Roundcube Webmail client | | Copyright (C) 2005-2014, The Roundcube Dev Team | - | Copyright (C) 2011, Kolab Systems AG | | | | Licensed under the GNU General Public License version 3 or | | any later version with exceptions for skins & plugins. | | See the README file for a full license statement. | | | | PURPOSE: | - | Provide database supported session management | + | Provide redis supported session management | +-----------------------------------------------------------------------+ | Author: Cor Bosman | +-----------------------------------------------------------------------+ -- cgit v1.2.3 From 87ff88d55003a7af755d290ae06173c4d73cc133 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Mon, 9 Mar 2015 17:16:39 +0100 Subject: Fix session garbage collector handler registration after refactoring --- program/lib/Roundcube/rcube.php | 1 + program/lib/Roundcube/rcube_session.php | 3 --- program/lib/Roundcube/rcube_session_db.php | 1 + 3 files changed, 2 insertions(+), 3 deletions(-) (limited to 'program/lib/Roundcube/rcube.php') diff --git a/program/lib/Roundcube/rcube.php b/program/lib/Roundcube/rcube.php index 3d081539f..cf6ebf993 100644 --- a/program/lib/Roundcube/rcube.php +++ b/program/lib/Roundcube/rcube.php @@ -523,6 +523,7 @@ class rcube // get session driver instance $this->session = rcube_session::factory($this->config); + $this->session->register_gc_handler(array($this, 'gc')); // start PHP session (if not in CLI mode) if ($_SERVER['REMOTE_ADDR']) { diff --git a/program/lib/Roundcube/rcube_session.php b/program/lib/Roundcube/rcube_session.php index fc1d87150..ab5c24c1e 100644 --- a/program/lib/Roundcube/rcube_session.php +++ b/program/lib/Roundcube/rcube_session.php @@ -86,9 +86,6 @@ abstract class rcube_session { $this->config = $config; - // register default gc handler - $this->register_gc_handler(array($this, 'gc')); - // set secret $this->set_secret($this->config->get('des_key') . dirname($_SERVER['SCRIPT_NAME'])); diff --git a/program/lib/Roundcube/rcube_session_db.php b/program/lib/Roundcube/rcube_session_db.php index 78138d1eb..4d94f43ff 100644 --- a/program/lib/Roundcube/rcube_session_db.php +++ b/program/lib/Roundcube/rcube_session_db.php @@ -168,6 +168,7 @@ class rcube_session_db extends rcube_session // just clean all old sessions when this GC is called $this->db->query("DELETE FROM " . $this->db->table_name('session') . " WHERE changed < " . $this->db->now(-$this->gc_enabled)); + $this->log("Session GC (DB): remove records < " . date('Y-m-d H:i:s', time() - $this->gc_enabled) . '; rows = ' . intval($this->db->affected_rows())); } } \ No newline at end of file -- cgit v1.2.3