Aleksander Machniak
2015-05-23 3994b3a26c252cba4070337b036e3a1c12c81369
program/lib/Roundcube/rcube.php
@@ -37,6 +37,8 @@
    const REQUEST_ERROR_URL   = 1;
    const REQUEST_ERROR_TOKEN = 2;
    const DEBUG_LINE_LENGTH = 4096;
    /**
     * Singleton instace of rcube
     *
@@ -521,48 +523,15 @@
        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);
        // register default gc handler
        // get session driver instance
        $this->session = rcube_session::factory($this->config);
        $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'));
        }
        // 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
@@ -1030,8 +999,7 @@
            if (empty($_SESSION['secure_token']) && $generate) {
                // generate x characters long token
                $length = $len > 1 ? $len : 16;
                $token  = openssl_random_pseudo_bytes($length / 2);
                $token  = bin2hex($token);
                $token  = rcube_utils::random_bytes($length);
                $plugin = $this->plugins->exec_hook('secure_token',
                    array('value' => $token, 'length' => $length));
@@ -1486,6 +1454,32 @@
    /**
     * Write debug info to the log
     *
     * @param string Engine type - file name (memcache, apc)
     * @param string Data string to log
     * @param bool   Operation result
     */
    public static function debug($engine, $data, $result = null)
    {
        static $debug_counter;
        $line = '[' . (++$debug_counter[$engine]) . '] ' . $data;
        if (($len = strlen($line)) > self::DEBUG_LINE_LENGTH) {
            $diff = $len - self::DEBUG_LINE_LENGTH;
            $line = substr($line, 0, self::DEBUG_LINE_LENGTH) . "... [truncated $diff bytes]";
        }
        if ($result !== null) {
            $line .= ' [' . ($result ? 'TRUE' : 'FALSE') . ']';
        }
        self::write_log($engine, $line);
    }
    /**
     * Returns current time (with microseconds).
     *
     * @return float Current time in seconds since the Unix
@@ -1706,15 +1700,18 @@
            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 {
@@ -1757,11 +1754,11 @@
            $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();