Add methods to check and update local config files + show HTML output in installer test step

release-0.6
thomascube 16 years ago
parent 2b58528f6a
commit e107123780

Binary file not shown.

After

Width:  |  Height:  |  Size: 666 B

@ -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;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

@ -32,6 +32,18 @@ class rcube_install
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
@ -183,6 +195,75 @@ class rcube_install
}
/**
* 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);
}
/**
* Getter for the last error message
*

@ -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;

@ -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 '<h3 class="warning">Missing config options</h3>';
echo '<p class="hint">The following config options are not present in the current configuration.<br/>';
echo 'Please check the default config files and add the missing properties to your local config files.</p>';
echo '<ul class="configwarings">';
foreach ($messages['missing'] as $msg) {
echo html::tag('li', null, html::span('propname', $msg['prop']) . ($msg['name'] ? ':&nbsp;' . $msg['name'] : ''));
}
echo '</ul>';
}
if (is_array($messages['replaced'])) {
echo '<h3 class="warning">Replaced config options</h3>';
echo '<p class="hint">The following config options have been replaced or renamed. ';
echo 'Please update them accordingly in your config files.</p>';
echo '<ul class="configwarings">';
foreach ($messages['replaced'] as $msg) {
echo html::tag('li', null, html::span('propname', $msg['prop']) .
' was replaced by ' . html::span('propname', $msg['replacement']));
}
echo '</ul>';
}
if (is_array($messages['obsolete'])) {
echo '<h3>Obsolete config options</h3>';
echo '<p class="hint">You still have some obsolete or inexistent properties set. This isn\'t a problem but should be noticed.</p>';
echo '<ul class="configwarings">';
foreach ($messages['obsolete'] as $msg) {
echo html::tag('li', null, html::span('propname', $msg['prop']) . ($msg['name'] ? ':&nbsp;' . $msg['name'] : ''));
}
echo '</ul>';
}
echo '<p class="suggestion">OK, lazy people can download the updated config files here: ';
echo html::a(array('href' => './?_mergeconfig=main'), 'main.inc.php') . ' &nbsp;';
echo html::a(array('href' => './?_mergeconfig=db'), 'db.inc.php');
echo "</p>";
}
?>
<h3>Check if directories are writable</h3>

Loading…
Cancel
Save