| | |
| | | var $bool_config_props = array(); |
| | | |
| | | var $local_config = array('db_dsnw', 'default_host', 'support_url', 'des_key', 'plugins'); |
| | | var $obsolete_config = array('db_backend', 'double_auth'); |
| | | var $obsolete_config = array('db_backend', 'db_max_length', 'double_auth'); |
| | | var $replaced_config = array( |
| | | 'skin_path' => 'skin', |
| | | 'locale_string' => 'language', |
| | |
| | | 'pagesize' => 'mail_pagesize', |
| | | 'default_imap_folders' => 'default_folders', |
| | | 'top_posting' => 'reply_mode', |
| | | 'keep_alive' => 'refresh_interval', |
| | | 'min_keep_alive' => 'min_refresh_interval', |
| | | ); |
| | | |
| | | // list of supported database drivers |
| | |
| | | $is_default = !isset($_POST["_$prop"]); |
| | | $value = !$is_default || $this->bool_config_props[$prop] ? $_POST["_$prop"] : $default; |
| | | |
| | | // always disable installer |
| | | if ($prop == 'enable_installer') |
| | | $value = false; |
| | | |
| | | // reset useragent to default (keeps version up-to-date) |
| | | if ($prop == 'useragent' && stripos($value, 'Roundcube Webmail/') !== false) |
| | | $value = $this->defaults[$prop]; |
| | | |
| | | // generate new encryption key, never use the default value |
| | | if ($prop == 'des_key' && $value == $this->defaults[$prop]) |
| | | $value = $this->random_key(24); |
| | | |
| | | // convert some form data |
| | | if ($prop == 'debug_level' && !$is_default) { |
| | |
| | | } |
| | | |
| | | // skip this property |
| | | if ((!array_key_exists($prop, $this->defaults) || ($value == $this->defaults[$prop])) && !in_array($prop, $this->local_config)) { |
| | | if (($value == $this->defaults[$prop]) && !in_array($prop, $this->local_config) |
| | | || in_array($prop, array_merge($this->obsolete_config, array_keys($this->replaced_config))) |
| | | || preg_match('/^db_(table|sequence)_/', $prop)) { |
| | | continue; |
| | | } |
| | | |
| | |
| | | return $out; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * save generated config file in RCUBE_CONFIG_DIR |
| | | * |
| | | * @return boolean True if the file was saved successfully, false if not |
| | | */ |
| | | function save_configfile($config) |
| | | { |
| | | if (is_writable(RCUBE_CONFIG_DIR)) { |
| | | return file_put_contents(RCUBE_CONFIG_DIR . 'config.inc.php', $config); |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * Check the current configuration for missing properties |
| | |
| | | * |
| | | * @param rcube_db Database object |
| | | * |
| | | * @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) |
| | | { |
| | |
| | | return $schema; |
| | | } |
| | | |
| | | /** |
| | | * Try to detect some file's mimetypes to test the correct behavior of fileinfo |
| | | */ |
| | | function check_mime_detection() |
| | | { |
| | | $files = array( |
| | | 'installer/images/roundcube_logo.png' => 'image/png', |
| | | 'program/resources/blank.tif' => 'image/tiff', |
| | | 'skins/larry/images/buttons.gif' => 'image/gif', |
| | | 'skins/larry/README' => 'text/plain', |
| | | ); |
| | | |
| | | $errors = array(); |
| | | foreach ($files as $path => $expected) { |
| | | $mimetype = rcube_mime::file_content_type(INSTALL_PATH . $path, basename($path)); |
| | | if ($mimetype != $expected) { |
| | | $errors[] = array($path, $mimetype, $expected); |
| | | } |
| | | } |
| | | |
| | | return $errors; |
| | | } |
| | | |
| | | /** |
| | | * Check the correct configuration of the 'mime_types' mapping option |
| | | */ |
| | | function check_mime_extensions() |
| | | { |
| | | $types = array( |
| | | 'application/zip' => 'zip', |
| | | 'application/x-tar' => 'tar', |
| | | 'application/pdf' => 'pdf', |
| | | 'image/gif' => 'gif', |
| | | 'image/svg+xml' => 'svg', |
| | | ); |
| | | |
| | | $errors = array(); |
| | | foreach ($types as $mimetype => $expected) { |
| | | $ext = rcube_mime::get_mime_extensions($mimetype); |
| | | if (!in_array($expected, (array) $ext)) { |
| | | $errors[] = array($mimetype, $ext, $expected); |
| | | } |
| | | } |
| | | |
| | | return $errors; |
| | | } |
| | | |
| | | /** |
| | | * Getter for the last error message |
| | |
| | | * @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); |
| | |
| | | // read schema file from /SQL/* |
| | | $fname = INSTALL_PATH . "SQL/$engine.initial.sql"; |
| | | if ($sql = @file_get_contents($fname)) { |
| | | $this->exec_sql($sql, $DB); |
| | | $DB->set_option('table_prefix', $this->config['db_prefix']); |
| | | $DB->exec_script($sql); |
| | | } |
| | | else { |
| | | $this->fail('DB Schema', "Cannot read the schema file: $fname"); |
| | |
| | | . " 2>&1", $result); |
| | | |
| | | return !$result; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Execute the given SQL queries on the database connection |
| | | * |
| | | * @param string SQL queries to execute |
| | | * @param object rcube_db Database connection |
| | | * @return boolen True on success, False on error |
| | | */ |
| | | function exec_sql($sql, $DB) |
| | | { |
| | | $sql = $this->fix_table_names($sql, $DB); |
| | | $buff = ''; |
| | | foreach (explode("\n", $sql) as $line) { |
| | | if (preg_match('/^--/', $line) || trim($line) == '') |
| | | continue; |
| | | |
| | | $buff .= $line . "\n"; |
| | | if (preg_match('/(;|^GO)$/', trim($line))) { |
| | | $DB->query($buff); |
| | | $buff = ''; |
| | | if ($DB->is_error()) |
| | | break; |
| | | } |
| | | } |
| | | |
| | | return !$DB->is_error(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Parse SQL file and fix table names according to db_prefix |
| | | * Note: This need to be a complete database initial file |
| | | */ |
| | | private function fix_table_names($sql, $DB) |
| | | { |
| | | if (empty($this->config['db_prefix'])) { |
| | | return $sql; |
| | | } |
| | | |
| | | // replace table names |
| | | if (preg_match_all('/CREATE TABLE (\[dbo\]\.|IF NOT EXISTS )?[`"\[\]]*([^`"\[\] \r\n]+)/i', $sql, $matches)) { |
| | | foreach ($matches[2] as $table) { |
| | | $real_table = $this->config['db_prefix'] . $table; |
| | | $sql = preg_replace("/([^a-zA-Z0-9_])$table([^a-zA-Z0-9_])/", "\\1$real_table\\2", $sql); |
| | | } |
| | | } |
| | | // replace sequence names |
| | | if ($DB->db_provider == 'postgres' && preg_match_all('/CREATE SEQUENCE (IF NOT EXISTS )?"?([^" \n\r]+)/i', $sql, $matches)) { |
| | | foreach ($matches[2] as $sequence) { |
| | | $real_sequence = $this->config['db_prefix'] . $sequence; |
| | | $sql = preg_replace("/([^a-zA-Z0-9_])$sequence([^a-zA-Z0-9_])/", "\\1$real_sequence\\2", $sql); |
| | | } |
| | | } |
| | | |
| | | return $sql; |
| | | } |
| | | |
| | | |