From 461a30d771edd8bc6606f2c92dfde363514b93b1 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Fri, 14 Jun 2013 12:09:08 +0200 Subject: Merge config files (#1487311). Now we have defaults.inc.php and config.inc.php. Renamed $rcmail_config to $config. Old naming and old files are supported for backward compatibility. --- installer/rcube_install.php | 129 +++++++++++++++++++++++--------------------- 1 file changed, 68 insertions(+), 61 deletions(-) (limited to 'installer/rcube_install.php') diff --git a/installer/rcube_install.php b/installer/rcube_install.php index c95d936d2..8165401a3 100644 --- a/installer/rcube_install.php +++ b/installer/rcube_install.php @@ -44,11 +44,6 @@ class rcube_install 'top_posting' => 'reply_mode', ); - // these config options are required for a working system - var $required_config = array( - 'db_dsnw', 'des_key', 'session_lifetime', - ); - // list of supported database drivers var $supported_dbs = array( 'MySQL' => 'pdo_mysql', @@ -82,44 +77,52 @@ class rcube_install return $inst; } - /** - * Read the default config files and store properties - */ - function load_defaults() - { - $this->_load_config('.php.dist'); - } - - /** * Read the local config files and store properties */ function load_config() { - $this->config = array(); - $this->_load_config('.php'); - $this->configured = !empty($this->config); + // defaults + if ($config = $this->load_config_file(RCUBE_CONFIG_DIR . 'defaults.inc.php')) { + $this->config = (array) $config; + $this->defaults = $this->config; + } + + $config = null; + + // config + if ($config = $this->load_config_file(RCUBE_CONFIG_DIR . 'config.inc.php')) { + $this->config = array_merge($this->config, $config); + } + else { + if ($config = $this->load_config_file(RCUBE_CONFIG_DIR . 'main.inc.php')) { + $this->config = array_merge($this->config, $config); + } + if ($config = $this->load_config_file(RCUBE_CONFIG_DIR . 'db.inc.php')) { + $this->config = array_merge($this->config, $config); + } + } + + $this->configured = !empty($config); } /** * Read the default config file and store properties - * @access private */ - function _load_config($suffix) + public function load_config_file($file) { - 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 = RCUBE_CONFIG_DIR . 'db.inc'. $suffix)) { - include($db_inc); - if (is_array($rcmail_config)) - $this->config += $rcmail_config; + if (is_readable($file)) { + include $file; + + // deprecated name of config variable + if (is_array($rcmail_config)) { + return $rcmail_config; + } + + return $config; } } - /** * Getter for a certain config property * @@ -139,21 +142,16 @@ class rcube_install /** - * Take the default config file and replace the parameters - * with the submitted form data + * Create configuration file that contains parameters + * that differ from default values. * - * @param string Which config file (either 'main' or 'db') * @return string The complete config file content */ - function create_config($which, $force = false) + function create_config() { - $out = @file_get_contents(RCUBE_CONFIG_DIR . $which . '.inc.php.dist'); - - if (!$out) - return '[Warning: could not read the config template file]'; + $config = array(); foreach ($this->config as $prop => $default) { - $is_default = !isset($_POST["_$prop"]); $value = !$is_default || $this->bool_config_props[$prop] ? $_POST["_$prop"] : $default; @@ -211,20 +209,26 @@ class rcube_install } // skip this property - if (!$force && !$this->configured && ($value == $default)) + if (!array_key_exists($prop, $this->defaults) || ($value == $this->defaults[$prop])) { continue; + } // save change $this->config[$prop] = $value; + $config[$prop] = $value; + } + + // sort by option name + ksort($config); - // 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) . ';'", - $out); + $out = " $value) { + // @TODO: copy option descriptions from defaults.inc.php file? + $out .= "\$config['$prop'] = " . rcube_install::_dump_var($value, $prop) . ";\n"; } + $out .= "\n?>"; - return trim($out); + return $out; } @@ -236,16 +240,13 @@ class rcube_install */ function check_config() { - $this->config = array(); - $this->load_defaults(); - $defaults = $this->config; - $this->load_config(); - if (!$this->configured) + + if (!$this->configured) { return null; + } $out = $seen = array(); - $required = array_flip($this->required_config); // iterate over the current configuration foreach ($this->config as $prop => $value) { @@ -264,12 +265,6 @@ class rcube_install $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]))) - $out['missing'][] = array('prop' => $prop); - } - // check config dependencies and contradictions if ($this->config['enable_spellcheck'] && $this->config['spellcheck_engine'] == 'pspell') { if (!extension_loaded('pspell')) { @@ -317,7 +312,6 @@ class rcube_install { $current = $this->config; $this->config = array(); - $this->load_defaults(); foreach ($this->replaced_config as $prop => $replacement) { if (isset($current[$prop])) { @@ -345,7 +339,7 @@ class rcube_install } } - $this->config = array_merge($this->config, $current); + $this->config = array_merge($this->config, $current); foreach (array_keys((array)$current['ldap_public']) as $key) { $this->config['ldap_public'][$key] = $current['ldap_public'][$key]; @@ -563,7 +557,8 @@ class rcube_install } - static function _dump_var($var, $name=null) { + static function _dump_var($var, $name=null) + { // special values switch ($name) { case 'syslog_facility': @@ -576,8 +571,20 @@ class rcube_install if ($val = $list[$var]) return $val; break; - } + case 'mail_header_delimiter': + $var = str_replace(array("\r", "\n"), array('\r', '\n'), $var); + return '"' . $var. '"'; + break; +/* + // RCMAIL_VERSION is undefined here + case 'useragent': + if (preg_match('|^(.*)/('.preg_quote(RCMAIL_VERSION, '|').')$|i', $var, $m)) { + return '"' . addcslashes($var, '"') . '/" . RCMAIL_VERSION'; + } + break; +*/ + } if (is_array($var)) { if (empty($var)) { -- cgit v1.2.3 From d6707475ccf0462849309ac1ab902d37b72c4ff9 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Fri, 28 Jun 2013 21:08:53 +0200 Subject: Flag config as 'legacy'; remove config file switch --- installer/rcube_install.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'installer/rcube_install.php') diff --git a/installer/rcube_install.php b/installer/rcube_install.php index 8165401a3..5d766f4d0 100644 --- a/installer/rcube_install.php +++ b/installer/rcube_install.php @@ -97,9 +97,11 @@ class rcube_install else { if ($config = $this->load_config_file(RCUBE_CONFIG_DIR . 'main.inc.php')) { $this->config = array_merge($this->config, $config); + $this->legacy_config = true; } if ($config = $this->load_config_file(RCUBE_CONFIG_DIR . 'db.inc.php')) { $this->config = array_merge($this->config, $config); + $this->legacy_config = true; } } @@ -164,7 +166,7 @@ class rcube_install $value = $val; } } - else if ($which == 'db' && $prop == 'db_dsnw' && !empty($_POST['_dbtype'])) { + else if ($prop == 'db_dsnw' && !empty($_POST['_dbtype'])) { if ($_POST['_dbtype'] == 'sqlite') $value = sprintf('%s://%s?mode=0646', $_POST['_dbtype'], $_POST['_dbname']{0} == '/' ? '/' . $_POST['_dbname'] : $_POST['_dbname']); else if ($_POST['_dbtype']) -- cgit v1.2.3 From 9bacb2cd3f7e8f96a29f651460954965c400aac6 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Fri, 28 Jun 2013 22:27:59 +0200 Subject: Prepare config migration: - Show warning in installer and hints how to migrate - Let update.sh create the new config file if legacy config is detected - Provide a sample config file for manual configuration - Define a list of options which always should be written to local config --- INSTALL | 11 +++--- bin/update.sh | 30 +++++++++++----- config/config.inc.php.sample | 85 ++++++++++++++++++++++++++++++++++++++++++++ config/defaults.inc.php | 12 +++---- installer/config.php | 13 ++++--- installer/index.php | 12 +++++-- installer/rcube_install.php | 7 +++- 7 files changed, 144 insertions(+), 26 deletions(-) create mode 100644 config/config.inc.php.sample (limited to 'installer/rcube_install.php') diff --git a/INSTALL b/INSTALL index 4573c55af..b80d3323b 100644 --- a/INSTALL +++ b/INSTALL @@ -141,10 +141,13 @@ Best solution is to install a cronjob running this script daily. MANUAL CONFIGURATION ==================== -First of all, rename the files config/*.inc.php.dist to config/*.inc.php. -You can then change these files according to your environment and your needs. -Details about the config parameters can be found in the config files. -See http://trac.roundcube.net/wiki/Howto_Install for even more guidance. +First of all, copy the sample configuration file config/config.inc.php.sample +to config/config.inc.php and make the necessary adjustments according to your +environment and your needs. More configuration options can be copied from the +config/defaults.inc.php file into your local config.inc.php file as needed. +Read the comments above the individual configuration options to find out what +they do or read http://trac.roundcube.net/wiki/Howto_Install for even more +guidance. You can also modify the default .htaccess file. This is necessary to increase the allowed size of file attachments, for example: diff --git a/bin/update.sh b/bin/update.sh index 1a6fbd32d..b5000bbe5 100755 --- a/bin/update.sh +++ b/bin/update.sh @@ -36,17 +36,17 @@ if (!$opts['version']) { $opts['version'] = RCMAIL_VERSION; } -if ($opts['version'] && version_compare(version_parse($opts['version']), version_parse(RCMAIL_VERSION), '>=')) - die("Nothing to be done here. Bye!\n"); - - $RCI = rcube_install::get_instance(); $RCI->load_config(); +if ($opts['version'] && version_compare(version_parse($opts['version']), version_parse(RCMAIL_VERSION), '>=') && !$RCI->legacy_config) + die("Nothing to be done here. Bye!\n"); + + if ($RCI->configured) { $success = true; - if ($messages = $RCI->check_config()) { + if (($messages = $RCI->check_config()) || $RCI->legacy_config) { $success = false; $err = 0; @@ -74,6 +74,12 @@ if ($RCI->configured) { echo "\n"; } + if (!$err && $RCI->legacy_config) { + echo "WARNING: Your configuration needs to be migrated!\n"; + echo "We changed the configuration files structure and your two config files main.inc.php and db.inc.php have to be merged into one single file.\n"; + $err++; + } + // ask user to update config files if ($err) { echo "Do you want me to fix your local configuration? (y/N)\n"; @@ -81,13 +87,13 @@ if ($RCI->configured) { // positive: let's merge the local config with the defaults if (strtolower($input) == 'y') { - $error = $writed = false; + $error = $written = false; // backup current config echo ". backing up the current config file(s)...\n"; foreach (array('config', 'main', 'db') as $file) { - if (file_exists(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php')) + if (file_exists(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php')) { if (!copy(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php', RCMAIL_CONFIG_DIR . '/' . $file . '.old.php')) { $error = true; } @@ -97,11 +103,11 @@ if ($RCI->configured) { if (!$error) { $RCI->merge_config(); echo ". writing " . RCMAIL_CONFIG_DIR . "/config.inc.php...\n"; - $writed = file_put_contents(RCMAIL_CONFIG_DIR . '/config.inc.php', $RCI->create_config()); + $written = file_put_contents(RCMAIL_CONFIG_DIR . '/config.inc.php', $RCI->create_config()); } // Success! - if ($writed) { + if ($written) { echo "Done.\n"; echo "Your configuration files are now up-to-date!\n"; @@ -110,6 +116,12 @@ if ($RCI->configured) { foreach ($messages['missing'] as $msg) echo "- '" . $msg['prop'] . ($msg['name'] ? "': " . $msg['name'] : "'") . "\n"; } + + if ($RCI->legacy_config) { + foreach (array('main', 'db') as $file) { + @unlink(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php'); + } + } } else { echo "Failed to write config file(s)!\n"; diff --git a/config/config.inc.php.sample b/config/config.inc.php.sample new file mode 100644 index 000000000..22a269460 --- /dev/null +++ b/config/config.inc.php.sample @@ -0,0 +1,85 @@ +bool_config_props = array( $_SESSION['allowinstaller'] = true; if (!empty($_POST['submit'])) { - echo '

Copy or download the following configuration and save'; - echo ' as config.inc.php within the '.RCMAIL_CONFIG_DIR.' directory of your Roundcube installation.
'; + echo '

Copy or download the following configuration and save it'; + echo ' as config.inc.php within the '.RCUBE_CONFIG_DIR.' directory of your Roundcube installation.
'; echo ' Make sure that there are no characters outside the <?php ?> brackets when saving the file.'; - echo ' 

'; + echo ' '; + if ($RCI->legacy_config) { + echo '

Afterwards, please remove the old configuration files main.inc.php and db.inc.php'; + echo ' from the config directory.'; + } + echo '

'; $textbox = new html_textarea(array('rows' => 16, 'cols' => 60, 'class' => "configfile")); echo $textbox->show(($_SESSION['config'] = $RCI->create_config())); @@ -640,7 +645,7 @@ $select_param_folding->add('Full RFC 2231 (Roundcube, Thunderbird)', '0'); $select_param_folding->add('RFC 2047/2231 (MS Outlook, OE)', '1'); $select_param_folding->add('Full RFC 2047 (deprecated)', '2'); -echo $select_param_folding->show(intval($RCI->getprop('mime_param_folding'))); +echo $select_param_folding->show(strval($RCI->getprop('mime_param_folding'))); ?>
How to encode attachment long/non-ascii names
diff --git a/installer/index.php b/installer/index.php index 4e4a04326..dc4c0a43f 100644 --- a/installer/index.php +++ b/installer/index.php @@ -121,8 +121,16 @@ if ($RCI->configured && empty($_REQUEST['_step'])) { // exit if installation is complete if ($RCI->configured && !$RCI->getprop('enable_installer') && !$_SESSION['allowinstaller']) { // header("HTTP/1.0 404 Not Found"); - echo '

The installer is disabled!

'; - echo '

To enable it again, set $rcmail_config[\'enable_installer\'] = true; in RCUBE_CONFIG_DIR/config.inc.php

'; + if ($RCI->configured && $RCI->legacy_config) { + echo '

Your configuration needs to be migrated!

'; + echo '

We changed the configuration files structure and your installation needs to be updated accordingly.

'; + echo '

Please run the bin/update.sh script from the command line or set

  $rcmail_config[\'enable_installer\'] = true;

'; + echo ' in your RCUBE_CONFIG_DIR/main.inc.php to let the installer help you migrating it.

'; + } + else { + echo '

The installer is disabled!

'; + echo '

To enable it again, set $rcmail_config[\'enable_installer\'] = true; in RCUBE_CONFIG_DIR/config.inc.php

'; + } echo ''; exit; } diff --git a/installer/rcube_install.php b/installer/rcube_install.php index 5d766f4d0..06622de4d 100644 --- a/installer/rcube_install.php +++ b/installer/rcube_install.php @@ -28,10 +28,12 @@ class rcube_install var $failures = 0; var $config = array(); var $configured = false; + var $legacy_config = false; var $last_error = null; var $email_pattern = '([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9]([a-z0-9\-][.]?)*[a-z0-9])'; 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 $replaced_config = array( 'skin_path' => 'skin', @@ -157,6 +159,9 @@ class rcube_install $is_default = !isset($_POST["_$prop"]); $value = !$is_default || $this->bool_config_props[$prop] ? $_POST["_$prop"] : $default; + if ($prop == 'enable_installer') + $value = false; + // convert some form data if ($prop == 'debug_level' && !$is_default) { if (is_array($value)) { @@ -211,7 +216,7 @@ class rcube_install } // skip this property - if (!array_key_exists($prop, $this->defaults) || ($value == $this->defaults[$prop])) { + if ((!array_key_exists($prop, $this->defaults) || ($value == $this->defaults[$prop])) && !in_array($prop, $this->local_config)) { continue; } -- cgit v1.2.3 From 47278835f5173a65b797643e2a90edfcb55a1c5f Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Fri, 28 Jun 2013 22:54:29 +0200 Subject: Preserve comments and order from existing or default config files --- installer/rcube_install.php | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'installer/rcube_install.php') diff --git a/installer/rcube_install.php b/installer/rcube_install.php index 06622de4d..da636555b 100644 --- a/installer/rcube_install.php +++ b/installer/rcube_install.php @@ -118,6 +118,28 @@ class rcube_install if (is_readable($file)) { include $file; + // read comments from config file + if (function_exists('token_get_all')) { + $tokens = token_get_all(file_get_contents($file)); + $in_config = false; + $buffer = ''; + for ($i=0; $i < count($tokens); $i++) { + $token = $tokens[$i]; + if ($token[0] == T_VARIABLE && $token[1] == '$config' || $token[1] == '$rcmail_config') { + $in_config = true; + if ($buffer && $tokens[$i+1] == '[' && $tokens[$i+2][0] == T_CONSTANT_ENCAPSED_STRING) { + $propname = trim($tokens[$i+2][1], "'\""); + $this->comments[$propname] = $buffer; + $buffer = ''; + $i += 3; + } + } + else if ($in_config && $token[0] == T_COMMENT) { + $buffer .= strtr($token[1], array('\n' => "\n")); + } + } + } + // deprecated name of config variable if (is_array($rcmail_config)) { return $rcmail_config; @@ -225,15 +247,13 @@ class rcube_install $config[$prop] = $value; } - // sort by option name - ksort($config); - $out = " $value) { - // @TODO: copy option descriptions from defaults.inc.php file? - $out .= "\$config['$prop'] = " . rcube_install::_dump_var($value, $prop) . ";\n"; + // copy option descriptions from existing config or defaults.inc.php + $out .= $this->comments[$prop]; + $out .= "\$config['$prop'] = " . rcube_install::_dump_var($value, $prop) . ";\n\n"; } - $out .= "\n?>"; return $out; } -- cgit v1.2.3