| | |
| | | var $config = array(); |
| | | var $configured = false; |
| | | var $last_error = null; |
| | | var $db_map = array('pgsql' => 'postgres', 'mysqli' => 'mysql', 'sqlsrv' => 'mssql'); |
| | | var $email_pattern = '([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9]([a-z0-9\-][.]?)*[a-z0-9])'; |
| | | var $bool_config_props = array(); |
| | | |
| | |
| | | |
| | | // these config options are required for a working system |
| | | var $required_config = array( |
| | | 'db_dsnw', 'db_table_contactgroups', 'db_table_contactgroupmembers', |
| | | 'des_key', 'session_lifetime', 'support_url', |
| | | 'db_dsnw', 'des_key', 'session_lifetime', |
| | | ); |
| | | |
| | | // list of supported database drivers |
| | |
| | | /** |
| | | * Constructor |
| | | */ |
| | | function rcube_install() |
| | | function __construct() |
| | | { |
| | | $this->step = intval($_REQUEST['_step']); |
| | | $this->is_post = $_SERVER['REQUEST_METHOD'] == 'POST'; |
| | |
| | | /** |
| | | * Singleton getter |
| | | */ |
| | | function get_instance() |
| | | static function get_instance() |
| | | { |
| | | static $inst; |
| | | |
| | |
| | | */ |
| | | function _load_config($suffix) |
| | | { |
| | | if (is_readable($main_inc = RCMAIL_CONFIG_DIR . '/main.inc' . $suffix)) { |
| | | if (is_readable($main_inc = RCUBE_CONFIG_DIR . 'main.inc' . $suffix)) { |
| | | include($main_inc); |
| | | if (is_array($rcmail_config)) |
| | | $this->config += $rcmail_config; |
| | | } |
| | | if (is_readable($db_inc = RCMAIL_CONFIG_DIR . '/db.inc'. $suffix)) { |
| | | if (is_readable($db_inc = RCUBE_CONFIG_DIR . 'db.inc'. $suffix)) { |
| | | include($db_inc); |
| | | if (is_array($rcmail_config)) |
| | | $this->config += $rcmail_config; |
| | |
| | | */ |
| | | function create_config($which, $force = false) |
| | | { |
| | | $out = @file_get_contents(RCMAIL_CONFIG_DIR . "/{$which}.inc.php.dist"); |
| | | $out = @file_get_contents(RCUBE_CONFIG_DIR . $which . '.inc.php.dist'); |
| | | |
| | | if (!$out) |
| | | return '[Warning: could not read the config template file]'; |
| | |
| | | // save change |
| | | $this->config[$prop] = $value; |
| | | |
| | | $dump = self::_dump_var($value, $prop); |
| | | |
| | | // replace the matching line in config file |
| | | $out = preg_replace( |
| | | '/(\$rcmail_config\[\''.preg_quote($prop).'\'\])\s+=\s+(.+);/Uie', |
| | | "'\\1 = ' . rcube_install::_dump_var(\$value, \$prop) . ';'", |
| | | '/(\$rcmail_config\[\''.preg_quote($prop).'\'\])\s+=\s+(.+);/Ui', |
| | | "\\1 = $dump;", |
| | | $out); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | // the old default mime_magic reference is obsolete |
| | | if ($this->config['mime_magic'] == '/usr/share/misc/magic') { |
| | | $out['obsolete'][] = array('prop' => 'mime_magic', 'explain' => "Set value to null in order to use system default"); |
| | | } |
| | | |
| | | // iterate over default config |
| | | foreach ($defaults as $prop => $value) { |
| | | if (!isset($seen[$prop]) && isset($required[$prop]) && !(is_bool($this->config[$prop]) || strlen($this->config[$prop]))) |
| | |
| | | if ($this->config['log_driver'] == 'syslog') { |
| | | if (!function_exists('openlog')) { |
| | | $out['dependencies'][] = array('prop' => 'log_driver', |
| | | 'explain' => 'This requires the <tt>sylog</tt> extension which could not be loaded.'); |
| | | 'explain' => 'This requires the <tt>syslog</tt> extension which could not be loaded.'); |
| | | } |
| | | if (empty($this->config['syslog_id'])) { |
| | | $out['dependencies'][] = array('prop' => 'syslog_id', |
| | |
| | | } |
| | | } |
| | | |
| | | if ($current['keep_alive'] && $current['session_lifetime'] < $current['keep_alive']) |
| | | $current['session_lifetime'] = max(10, ceil($current['keep_alive'] / 60) * 2); |
| | | |
| | | $this->config = array_merge($this->config, $current); |
| | | |
| | | foreach ((array)$current['ldap_public'] as $key => $values) { |
| | |
| | | * required for this version of Roundcube |
| | | * |
| | | * @param boolean True if the schema schould be updated |
| | | * @return boolean True if the schema is up-to-date, false if not or an error occured |
| | | * @return boolean True if the schema is up-to-date, false if not or an error occurred |
| | | */ |
| | | function db_schema_check($DB, $update = false) |
| | | { |
| | |
| | | '0.2-alpha', '0.2-beta', '0.2-stable', |
| | | '0.3-stable', '0.3.1', |
| | | '0.4-beta', '0.4.2', |
| | | '0.5-beta', '0.5', '0.5.1', |
| | | '0.5-beta', '0.5', '0.5.1', '0.5.2', '0.5.3', '0.5.4', |
| | | '0.6-beta', '0.6', |
| | | '0.7-beta', '0.7', '0.7.1', '0.7.2', '0.7.3', |
| | | '0.8-beta', '0.8-rc', '0.8.0', '0.8.1', '0.8.2', '0.8.3', |
| | | '0.7-beta', '0.7', '0.7.1', '0.7.2', '0.7.3', '0.7.4', |
| | | '0.8-beta', '0.8-rc', '0.8.0', '0.8.1', '0.8.2', '0.8.3', '0.8.4', '0.8.5', '0.8.6', |
| | | '0.9-beta', '0.9-rc', '0.9-rc2', |
| | | // Note: Do not add newer versions here |
| | | )); |
| | | return $select; |
| | | } |
| | |
| | | * @param string Test name |
| | | * @param string Error message |
| | | * @param string URL for details |
| | | * @param bool Do not count this failure |
| | | */ |
| | | function fail($name, $message = '', $url = '') |
| | | function fail($name, $message = '', $url = '', $optional=false) |
| | | { |
| | | $this->failures++; |
| | | if (!$optional) { |
| | | $this->failures++; |
| | | } |
| | | |
| | | echo Q($name) . ': <span class="fail">NOT OK</span>'; |
| | | $this->_showhint($message, $url); |
| | |
| | | */ |
| | | function init_db($DB) |
| | | { |
| | | $engine = isset($this->db_map[$DB->db_provider]) ? $this->db_map[$DB->db_provider] : $DB->db_provider; |
| | | $engine = $DB->db_provider; |
| | | |
| | | // read schema file from /SQL/* |
| | | $fname = INSTALL_PATH . "SQL/$engine.initial.sql"; |
| | |
| | | |
| | | |
| | | /** |
| | | * Update database with SQL statements from SQL/*.update.sql |
| | | * Update database schema |
| | | * |
| | | * @param object rcube_db Database connection |
| | | * @param string Version to update from |
| | | * |
| | | * @return boolen True on success, False on error |
| | | */ |
| | | function update_db($DB, $version) |
| | | function update_db($version) |
| | | { |
| | | $version = strtolower($version); |
| | | $engine = isset($this->db_map[$DB->db_provider]) ? $this->db_map[$DB->db_provider] : $DB->db_provider; |
| | | system(INSTALL_PATH . "bin/updatedb.sh --package=roundcube" |
| | | . " --version=" . escapeshellarg($version) |
| | | . " --dir=" . INSTALL_PATH . "SQL" |
| | | . " 2>&1", $result); |
| | | |
| | | // read schema file from /SQL/* |
| | | $fname = INSTALL_PATH . "SQL/$engine.update.sql"; |
| | | if ($lines = @file($fname, FILE_SKIP_EMPTY_LINES)) { |
| | | $from = false; $sql = ''; |
| | | foreach ($lines as $line) { |
| | | $is_comment = preg_match('/^--/', $line); |
| | | if (!$from && $is_comment && preg_match('/from version\s([0-9.]+[a-z-]*)/', $line, $m)) { |
| | | $v = strtolower($m[1]); |
| | | if ($v == $version || version_compare($version, $v, '<=')) |
| | | $from = true; |
| | | } |
| | | if ($from && !$is_comment) |
| | | $sql .= $line. "\n"; |
| | | } |
| | | |
| | | if ($sql) |
| | | $this->exec_sql($sql, $DB); |
| | | } |
| | | else { |
| | | $this->fail('DB Schema', "Cannot read the update file: $fname"); |
| | | return false; |
| | | } |
| | | |
| | | if ($err = $this->get_error()) { |
| | | $this->fail('DB Schema', "Error updating database: $err"); |
| | | return false; |
| | | } |
| | | |
| | | return true; |
| | | return !$result; |
| | | } |
| | | |
| | | |