Thomas Bruederli
2013-06-28 47278835f5173a65b797643e2a90edfcb55a1c5f
installer/rcube_install.php
@@ -28,10 +28,12 @@
  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',
@@ -116,6 +118,28 @@
    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;
@@ -156,6 +180,9 @@
    foreach ($this->config as $prop => $default) {
      $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) {
@@ -211,7 +238,7 @@
      }
      // 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;
      }
@@ -220,15 +247,13 @@
      $config[$prop] = $value;
    }
    // sort by option name
    ksort($config);
    $out = "<?php\n\n";
    $out .= "/* Local configuration for Roundcube Webmail */\n\n";
    foreach ($config as $prop => $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;
  }