| | |
| | | +-----------------------------------------------------------------------+ |
| | | | Author: Thomas Bruederli <roundcube@gmail.com> | |
| | | +-----------------------------------------------------------------------+ |
| | | |
| | | $Id$ |
| | | |
| | | */ |
| | | |
| | | |
| | |
| | | /** |
| | | * Instace of database class. |
| | | * |
| | | * @var rcube_mdb2 |
| | | * @var rcube_pdo |
| | | */ |
| | | public $db; |
| | | |
| | | /** |
| | | * Instace of Memcache class. |
| | | * |
| | | * @var rcube_mdb2 |
| | | * @var Memcache |
| | | */ |
| | | public $memcache; |
| | | |
| | |
| | | /** |
| | | * This implements the 'singleton' design pattern |
| | | * |
| | | * @param integer Options to initialize with this instance. See rcube::INIT_WITH_* constants |
| | | * @return rcube The one and only instance |
| | | */ |
| | | static function get_instance() |
| | | static function get_instance($mode = 0) |
| | | { |
| | | if (!self::$instance) { |
| | | self::$instance = new rcube(); |
| | | self::$instance->init($mode); |
| | | } |
| | | |
| | | return self::$instance; |
| | |
| | | /** |
| | | * Get the current database connection |
| | | * |
| | | * @return rcube_mdb2 Database connection object |
| | | * @return rcube_pdo Database connection object |
| | | */ |
| | | public function get_dbh() |
| | | { |
| | | if (!$this->db) { |
| | | $config_all = $this->config->all(); |
| | | |
| | | $this->db = new rcube_mdb2($config_all['db_dsnw'], $config_all['db_dsnr'], $config_all['db_persistent']); |
| | | $this->db->sqlite_initials = INSTALL_PATH . 'SQL/sqlite.initial.sql'; |
| | | $this->db = rcube_db::factory($config_all['db_dsnw'], $config_all['db_dsnr'], $config_all['db_persistent']); |
| | | $this->db->set_debug((bool)$config_all['sql_debug']); |
| | | } |
| | | |
| | |
| | | $this->memcache = new Memcache; |
| | | $this->mc_available = 0; |
| | | |
| | | // add alll configured hosts to pool |
| | | // add all configured hosts to pool |
| | | $pconnect = $this->config->get('memcache_pconnect', true); |
| | | foreach ($this->config->get('memcache_hosts', array()) as $host) { |
| | | list($host, $port) = explode(':', $host); |
| | | if (!$port) $port = 11211; |
| | | if (substr($host, 0, 7) != 'unix://') { |
| | | list($host, $port) = explode(':', $host); |
| | | if (!$port) $port = 11211; |
| | | } |
| | | else { |
| | | $port = 0; |
| | | } |
| | | |
| | | $this->mc_available += intval($this->memcache->addServer($host, $port, $pconnect, 1, 1, 15, false, array($this, 'memcache_failure'))); |
| | | } |
| | | |
| | |
| | | */ |
| | | public function get_cache($name, $type='db', $ttl=0, $packed=true) |
| | | { |
| | | if (!isset($this->caches[$name])) { |
| | | $userid = $this->get_user_id(); |
| | | if (!isset($this->caches[$name]) && ($userid = $this->get_user_id())) { |
| | | $this->caches[$name] = new rcube_cache($type, $userid, $name, $ttl, $packed); |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | /** |
| | | * Connect to the mail storage server with stored session data |
| | | * |
| | | * @return bool True on success, False on error |
| | | */ |
| | | public function storage_connect() |
| | | { |
| | | $storage = $this->get_storage(); |
| | | |
| | | if ($_SESSION['storage_host'] && !$storage->is_connected()) { |
| | | $host = $_SESSION['storage_host']; |
| | | $user = $_SESSION['username']; |
| | | $port = $_SESSION['storage_port']; |
| | | $ssl = $_SESSION['storage_ssl']; |
| | | $pass = $this->decrypt($_SESSION['password']); |
| | | |
| | | if (!$storage->connect($host, $user, $pass, $port, $ssl)) { |
| | | if (is_object($this->output)) |
| | | $this->output->show_message($storage->get_error_code() == -1 ? 'storageerror' : 'sessionerror', 'error'); |
| | | } |
| | | else { |
| | | $this->set_storage_prop(); |
| | | return $storage->is_connected(); |
| | | } |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * Set storage parameters. |
| | | * This must be done AFTER connecting to the server! |
| | | */ |
| | |
| | | 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); |
| | |
| | | */ |
| | | public static function raise_error($arg = array(), $log = false, $terminate = false) |
| | | { |
| | | // handle PHP exceptions |
| | | if (is_object($arg) && is_a($arg, 'Exception')) { |
| | | $err = array( |
| | | 'type' => 'php', |
| | | 'code' => $arg->getCode(), |
| | | 'line' => $arg->getLine(), |
| | | 'file' => $arg->getFile(), |
| | | 'message' => $arg->getMessage(), |
| | | ); |
| | | $arg = $err; |
| | | } |
| | | |
| | | // installer |
| | | if (class_exists('rcube_install', false)) { |
| | | $rci = rcube_install::get_instance(); |
| | |
| | | return; |
| | | } |
| | | |
| | | if ($log && $arg['type'] && $arg['message']) { |
| | | if (($log || $terminate) && $arg['type'] && $arg['message']) { |
| | | $arg['fatal'] = $terminate; |
| | | self::log_bug($arg); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | // write error to local log file |
| | | if ($level & 1) { |
| | | if (($level & 1) || !empty($arg_arr['fatal'])) { |
| | | if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
| | | $post_query = '?_task='.urlencode($_POST['_task']).'&_action='.urlencode($_POST['_action']); |
| | | } |