From e107123780c12b4d43d0264cb9c6180fb02d9ab8 Mon Sep 17 00:00:00 2001 From: thomascube Date: Fri, 3 Oct 2008 20:58:23 +0000 Subject: [PATCH] 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 diff --git a/installer/images/error.png b/installer/images/error.png new file mode 100755 index 0000000000000000000000000000000000000000..628cf2dae3d419ae220c8928ac71393b480745a3 GIT binary patch literal 666 zcmV;L0%iS)P)eOSYYtbpBV}~vsBnU!_?2tr-P=|^T zED%wc9ezHgW@NMb!^uT_|SvCpFLJylbx zY%bpaTGI8IYXMN$9w<3j9VkA~NYOKEQXsj?6a9_hcwfU$acAhJhB)zb_w@MVUEy@S zX&I>K-R!bhu3?(6bHWIg$HEl7{9g>>&l_qdd+UYb(1~BCo9LptNq&8>!yoJ3Ui(i5 zRJ|XnYBklL!{@$-7=3mJ>P@1c=7Oc79e-V7yf+%lD2!I;Y&nXBZ>=B!5?CB>LvEx6 znI%n)qqi$#X#wKB(U7XP2P=+4{b@j#r%9-K(8UqtSDk>0UKzf*HM9yqMZ1D!$2MdZ zR=`U>0zhOH1XqN?nY@AQqB7)Fp4{v&dKXvb43hZKvnN8;Po;+jY*}~*Z|W9Q0W%{D z^T}Cc<|r(Su=1K=P5>Z4 zg`et&Va}tdzBS-G-ZcO)zCWpJvGQwrHZ`@wpM420ac@bI5~KkTFfGEM3sPWO8co4^fI6lPnA)Y{ef%@{+SnoUk0+dW+*{8WvF8}}l07*qoM6N<$g7cXs A&j0`b literal 0 HcmV?d00001 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 '
    '; + foreach ($messages['missing'] as $msg) { + echo html::tag('li', null, html::span('propname', $msg['prop']) . ($msg['name'] ? ': ' . $msg['name'] : '')); + } + 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 '
    '; + foreach ($messages['replaced'] as $msg) { + echo html::tag('li', null, html::span('propname', $msg['prop']) . + ' was replaced by ' . html::span('propname', $msg['replacement'])); + } + 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 '
    '; + foreach ($messages['obsolete'] as $msg) { + echo html::tag('li', null, html::span('propname', $msg['prop']) . ($msg['name'] ? ': ' . $msg['name'] : '')); + } + 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