Beispiel #1
0
 /**
  * Function to be executed in script shutdown
  * Registered with register_shutdown_function()
  */
 public function shutdown()
 {
     foreach ($this->shutdown_functions as $function) {
         call_user_func($function);
     }
     // write session data as soon as possible and before
     // closing database connection, don't do this before
     // registered shutdown functions, they may need the session
     // Note: this will run registered gc handlers (ie. cache gc)
     if ($_SERVER['REMOTE_ADDR'] && is_object($this->session)) {
         $this->session->write_close();
     }
     if (is_object($this->smtp)) {
         $this->smtp->disconnect();
     }
     foreach ($this->caches as $cache) {
         if (is_object($cache)) {
             $cache->close();
         }
     }
     if (is_object($this->storage)) {
         $this->storage->close();
     }
     if ($this->config->get('log_driver') == 'syslog') {
         closelog();
     }
 }
 /**
  * Wrapper for session_start()
  */
 public function start()
 {
     parent::start();
     $this->key = session_id();
     $this->ip = $_SESSION['__IP'];
     $this->changed = $_SESSION['__MTIME'];
 }
Beispiel #3
0
 /**
  * Destroy session data and remove cookie
  */
 public function kill_session()
 {
     $this->plugins->exec_hook('session_destroy');
     $this->session->remove();
     $_SESSION = array('language' => $this->user->language, 'auth_time' => time(), 'temp' => true);
     rcmail::setcookie('sessauth', '-del-', time() - 60);
     $this->user->reset();
 }
 /**
  * @param Object $config
  */
 public function __construct($config)
 {
     parent::__construct($config);
     $this->memcache = rcube::get_instance()->get_memcache();
     $this->debug = $config->get('memcache_debug');
     if (!$this->memcache) {
         rcube::raise_error(array('code' => 604, 'type' => 'db', 'line' => __LINE__, 'file' => __FILE__, 'message' => "Failed to connect to memcached. Please check configuration"), true, true);
     }
     // register sessions handler
     $this->register_session_handler();
 }
 /**
  * @param Object $config
  */
 public function __construct($config)
 {
     parent::__construct($config);
     // get db instance
     $this->db = rcube::get_instance()->get_dbh();
     // session table name
     $this->table_name = $this->db->table_name('session', true);
     // register sessions handler
     $this->register_session_handler();
     // register db gc handler
     $this->register_gc_handler(array($this, 'gc_db'));
 }
Beispiel #6
0
 /**
  * Configure session object internals
  */
 public function session_configure()
 {
     if (!$this->session) {
         return;
     }
     $lifetime = $this->config->get('session_lifetime', 0) * 60;
     $keep_alive = $this->config->get('keep_alive');
     // set keep-alive/check-recent interval
     if ($keep_alive) {
         // be sure that it's less than session lifetime
         if ($lifetime) {
             $keep_alive = min($keep_alive, $lifetime - 30);
         }
         $keep_alive = max(60, $keep_alive);
         $this->session->set_keep_alive($keep_alive);
     }
     $this->session->set_secret($this->config->get('des_key') . dirname($_SERVER['SCRIPT_NAME']));
     $this->session->set_ip_check($this->config->get('ip_check'));
 }
Beispiel #7
0
 /**
  * Create session object and start the session.
  */
 public function session_init()
 {
     // session started (Installer?)
     if (session_id()) {
         return;
     }
     $sess_name = $this->config->get('session_name');
     $sess_domain = $this->config->get('session_domain');
     $sess_path = $this->config->get('session_path');
     $lifetime = $this->config->get('session_lifetime', 0) * 60;
     $is_secure = $this->config->get('use_https') || rcube_utils::https_check();
     // set session domain
     if ($sess_domain) {
         ini_set('session.cookie_domain', $sess_domain);
     }
     // set session path
     if ($sess_path) {
         ini_set('session.cookie_path', $sess_path);
     }
     // set session garbage collecting time according to session_lifetime
     if ($lifetime) {
         ini_set('session.gc_maxlifetime', $lifetime * 2);
     }
     ini_set('session.cookie_secure', $is_secure);
     ini_set('session.name', $sess_name ? $sess_name : 'roundcube_sessid');
     ini_set('session.use_cookies', 1);
     ini_set('session.use_only_cookies', 1);
     ini_set('session.serialize_handler', 'php');
     ini_set('session.cookie_httponly', 1);
     // use database for storing session data
     $this->session = new rcube_session($this->get_dbh(), $this->config);
     $this->session->register_gc_handler(array($this, 'temp_gc'));
     $this->session->register_gc_handler(array($this, 'cache_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'));
     }
     // start PHP session (if not in CLI mode)
     if ($_SERVER['REMOTE_ADDR']) {
         session_start();
     }
 }
Beispiel #8
0
 /**
  * Do server side actions on logout
  */
 public function logout_actions()
 {
     $config = $this->config->all();
     // on logout action we're not connected to imap server
     if ($config['logout_purge'] && !empty($config['trash_mbox']) || $config['logout_expunge']) {
         if (!$this->session->check_auth()) {
             return;
         }
         $this->imap_connect();
     }
     if ($config['logout_purge'] && !empty($config['trash_mbox'])) {
         $this->imap->clear_mailbox($config['trash_mbox']);
     }
     if ($config['logout_expunge']) {
         $this->imap->expunge('INBOX');
     }
     // Try to save unsaved user preferences
     if (!empty($_SESSION['preferences'])) {
         $this->user->save_prefs(unserialize($_SESSION['preferences']));
     }
 }
 /**
  * @param Object $config
  */
 public function __construct($config)
 {
     parent::__construct($config);
     // instantiate Redis object
     $this->redis = new 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"), true, true);
     }
     // get config instance
     $hosts = $this->config->get('redis_hosts', array('localhost'));
     // host config is wrong
     if (!is_array($hosts) || empty($hosts)) {
         rcube::raise_error(array('code' => 604, 'type' => 'session', 'line' => __LINE__, 'file' => __FILE__, 'message' => "Redis host not configured"), true, true);
     }
     // only allow 1 host for now until we support clustering
     if (count($hosts) > 1) {
         rcube::raise_error(array('code' => 604, 'type' => 'session', 'line' => __LINE__, 'file' => __FILE__, 'message' => "Redis cluster not yet supported"), true, true);
     }
     foreach ($hosts as $host) {
         // explode individual fields
         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';
         $port = $port !== null ? $port : 6379;
         $database = $database !== null ? $database : 0;
         if ($this->redis->connect($host, $port) === false) {
             rcube::raise_error(array('code' => 604, 'type' => 'session', 'line' => __LINE__, 'file' => __FILE__, 'message' => "Could not connect to Redis server. Please check host and port"), true, true);
         }
         if ($password != null && $this->redis->auth($password) === false) {
             rcube::raise_error(array('code' => 604, 'type' => 'session', 'line' => __LINE__, 'file' => __FILE__, 'message' => "Could not authenticate with Redis server. Please check password."), true, true);
         }
         if ($database != 0 && $this->redis->select($database) === false) {
             rcube::raise_error(array('code' => 604, 'type' => 'session', 'line' => __LINE__, 'file' => __FILE__, 'message' => "Could not select Redis database. Please check database setting."), true, true);
         }
     }
     // register sessions handler
     $this->register_session_handler();
 }