From e107123780c12b4d43d0264cb9c6180fb02d9ab8 Mon Sep 17 00:00:00 2001 From: thomascube Date: Fri, 3 Oct 2008 20:58:23 +0000 Subject: Add methods to check and update local config files + show HTML output in installer test step --- installer/images/error.png | Bin 0 -> 666 bytes installer/index.php | 17 +++++++++ installer/rcube_install.php | 85 ++++++++++++++++++++++++++++++++++++++++++-- installer/styles.css | 17 +++++++-- installer/test.php | 44 +++++++++++++++++++++++ 5 files changed, 159 insertions(+), 4 deletions(-) create mode 100755 installer/images/error.png (limited to 'installer') diff --git a/installer/images/error.png b/installer/images/error.png new file mode 100755 index 000000000..628cf2dae Binary files /dev/null and b/installer/images/error.png differ diff --git a/installer/index.php b/installer/index.php index d14e6ff37..6ece82385 100644 --- a/installer/index.php +++ b/installer/index.php @@ -45,6 +45,23 @@ if (isset($_GET['_getfile']) && in_array($_GET['_getfile'], array('main', 'db')) } } +if (isset($_GET['_mergeconfig']) && in_array($_GET['_mergeconfig'], array('main', 'db'))) { + $filename = $_GET['_mergeconfig'] . '.inc.php'; + + header('Content-type: text/plain'); + header('Content-Disposition: attachment; filename="'.$filename.'"'); + + $RCI->merge_config(); + echo $RCI->create_config($_GET['_mergeconfig'], true); + exit; +} + +// go to 'test' step if we have a local configuration +if ($RCI->configured && empty($_REQUEST['_step'])) { + header("Location: ./?_step=3"); + exit; +} + ?> diff --git a/installer/rcube_install.php b/installer/rcube_install.php index 37645adbc..21e353c9c 100644 --- a/installer/rcube_install.php +++ b/installer/rcube_install.php @@ -31,6 +31,18 @@ class rcube_install var $last_error = null; var $email_pattern = '([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9]([a-z0-9\-][.]?)*[a-z0-9])'; var $config_props = array(); + + var $obsolete_config = array('db_backend'); + var $replaced_config = array('skin_path' => 'skin', 'locale_string' => 'language'); + + // these config options are optional or can be set to null + var $optional_config = array( + 'log_driver', 'syslog_id', 'syslog_facility', 'imap_auth_type', + 'smtp_helo_host', 'sendmail_delay', 'double_auth', 'language', + 'mail_header_delimiter', 'create_default_folders', + 'quota_zero_as_unlimited', 'spellcheck_uri', 'spellcheck_languages', + 'http_received_header', 'session_domain', 'mime_magic', 'log_logins', + 'enable_installer', 'skin_include_php'); /** * Constructor @@ -116,7 +128,7 @@ class rcube_install * @param string Which config file (either 'main' or 'db') * @return string The complete config file content */ - function create_config($which) + function create_config($which, $force = false) { $out = file_get_contents("../config/{$which}.inc.php.dist"); @@ -166,7 +178,7 @@ class rcube_install } // skip this property - if ($value == $default) + if (!$force && ($value == $default)) continue; // save change @@ -181,6 +193,75 @@ class rcube_install return trim($out); } + + + /** + * Check the current configuration for missing properties + * and deprecated or obsolete settings + * + * @return array List with problems detected + */ + function check_config() + { + $this->config = array(); + $this->load_defaults(); + $defaults = $this->config; + + $this->load_config(); + if (!$this->configured) + return null; + + $out = $seen = array(); + $optional = array_flip($this->optional_config); + + // ireate over the current configuration + foreach ($this->config as $prop => $value) { + if ($replacement = $this->replaced_config[$prop]) { + $out['replaced'][] = array('prop' => $prop, 'replacement' => $replacement); + $seen[$replacement] = true; + } + else if (!$seen[$prop] && in_array($prop, $this->obsolete_config)) { + $out['obsolete'][] = array('prop' => $prop); + $seen[$prop] = true; + } + } + + // iterate over default config + foreach ($defaults as $prop => $value) { + if (!$seen[$prop] && !isset($this->config[$prop]) && !isset($optional[$prop])) + $out['missing'][] = array('prop' => $prop); + } + + return $out; + } + + + /** + * Merge the current configuration with the defaults + * and copy replaced values to the new options. + */ + function merge_config() + { + $current = $this->config; + $this->config = array(); + $this->load_defaults(); + + foreach ($this->replaced_config as $prop => $replacement) + if (isset($current[$prop])) { + if ($prop == 'skin_path') + $this->config[$replacement] = preg_replace('#skins/(\w+)/?$#', '\\1', $current[$prop]); + else + $this->config[$replacement] = $current[$prop]; + + unset($current[$prop]); + } + + foreach ($this->obsolete_config as $prop) { + unset($current[$prop]); + } + + $this->config = array_merge($current, $this->config); + } /** diff --git a/installer/styles.css b/installer/styles.css index ed64ff001..1acdc9cd0 100644 --- a/installer/styles.css +++ b/installer/styles.css @@ -131,7 +131,7 @@ textarea.configfile { height: 30em; } -dt.propname { +.propname { font-family: monospace; font-size: 9pt; margin-top: 1em; @@ -219,12 +219,25 @@ a.removelink { border: 2px solid #c2d071; } -.warning { +.suggestion { + padding: 0.6em; + background-color: #ebebeb; + border: 1px solid #999; +} + +p.warning, +div.warning { padding: 1em; background-color: #ef9398; border: 2px solid #dc5757; } +h3.warning { + color: #c00; + background: url('images/error.png') top left no-repeat; + padding-left: 24px; +} + .userconf { color: #00c; font-family: "Lucida Grande", Verdana, Arial, Helvetica, sans-serif; diff --git a/installer/test.php b/installer/test.php index ca7c7add4..8af6a6aef 100644 --- a/installer/test.php +++ b/installer/test.php @@ -27,6 +27,50 @@ else if (!$read_db) { $RCI->fail('db.inc.php', 'Unable to read file. Did you create the config files?'); } +if ($RCI->configured && ($messages = $RCI->check_config())) { + + if (is_array($messages['missing'])) { + echo '

Missing config options

'; + echo '

The following config options are not present in the current configuration.
'; + echo 'Please check the default config files and add the missing properties to your local config files.

'; + + echo ''; + } + + if (is_array($messages['replaced'])) { + echo '

Replaced config options

'; + echo '

The following config options have been replaced or renamed. '; + echo 'Please update them accordingly in your config files.

'; + + echo ''; + } + + if (is_array($messages['obsolete'])) { + echo '

Obsolete config options

'; + echo '

You still have some obsolete or inexistent properties set. This isn\'t a problem but should be noticed.

'; + + echo ''; + } + + echo '

OK, lazy people can download the updated config files here: '; + echo html::a(array('href' => './?_mergeconfig=main'), 'main.inc.php') . '  '; + echo html::a(array('href' => './?_mergeconfig=db'), 'db.inc.php'); + echo "

"; +} + ?>

Check if directories are writable

-- cgit v1.2.3