/** * Create configuration file that contains parameters * that differ from default values. * * @return string The complete config file content */ function create_config() { $config = array(); foreach ($this->config as $prop => $default) { $is_default = !isset($_POST["_{$prop}"]); $value = !$is_default || $this->bool_config_props[$prop] ? $_POST["_{$prop}"] : $default; // always disable installer if ($prop == 'enable_installer') { $value = false; } // reset useragent to default (keeps version up-to-date) if ($prop == 'useragent' && stripos($value, 'Roundcube Webmail/') !== false) { $value = $this->defaults[$prop]; } // generate new encryption key, never use the default value if ($prop == 'des_key' && $value == $this->defaults[$prop]) { $value = $this->random_key(24); } // convert some form data if ($prop == 'debug_level' && !$is_default) { if (is_array($value)) { $val = 0; foreach ($value as $dbgval) { $val += intval($dbgval); } $value = $val; } } 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']) { $value = sprintf('%s://%s:%s@%s/%s', $_POST['_dbtype'], rawurlencode($_POST['_dbuser']), rawurlencode($_POST['_dbpass']), $_POST['_dbhost'], $_POST['_dbname']); } } } else { if ($prop == 'smtp_auth_type' && $value == '0') { $value = ''; } else { if ($prop == 'default_host' && is_array($value)) { $value = rcube_install::_clean_array($value); if (count($value) <= 1) { $value = $value[0]; } } else { if ($prop == 'mail_pagesize' || $prop == 'addressbook_pagesize') { $value = max(2, intval($value)); } else { if ($prop == 'smtp_user' && !empty($_POST['_smtp_user_u'])) { $value = '%u'; } else { if ($prop == 'smtp_pass' && !empty($_POST['_smtp_user_u'])) { $value = '%p'; } else { if ($prop == 'default_folders') { $value = array(); foreach ($this->config['default_folders'] as $_folder) { switch ($_folder) { case 'Drafts': $_folder = $this->config['drafts_mbox']; break; case 'Sent': $_folder = $this->config['sent_mbox']; break; case 'Junk': $_folder = $this->config['junk_mbox']; break; case 'Trash': $_folder = $this->config['trash_mbox']; break; } if (!in_array($_folder, $value)) { $value[] = $_folder; } } } else { if (is_bool($default)) { $value = (bool) $value; } else { if (is_numeric($value)) { $value = intval($value); } } } } } } } } } } // skip this property if ($value == $this->defaults[$prop] && !in_array($prop, $this->local_config) || in_array($prop, array_merge($this->obsolete_config, array_keys($this->replaced_config))) || preg_match('/^db_(table|sequence)_/', $prop)) { continue; } // save change $this->config[$prop] = $value; $config[$prop] = $value; } $out = "<?php\n\n"; $out .= "/* Local configuration for Roundcube Webmail */\n\n"; foreach ($config as $prop => $value) { // 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"; } return $out; }
/** * Take the default config file and replace the parameters * with the submitted form data * * @param string Which config file (either 'main' or 'db') * @return string The complete config file content */ function create_config($which, $force = false) { $out = @file_get_contents(RCUBE_CONFIG_DIR . $which . '.inc.php.dist'); if (!$out) { return '[Warning: could not read the config template file]'; } foreach ($this->config as $prop => $default) { $is_default = !isset($_POST["_{$prop}"]); $value = !$is_default || $this->bool_config_props[$prop] ? $_POST["_{$prop}"] : $default; // convert some form data if ($prop == 'debug_level' && !$is_default) { if (is_array($value)) { $val = 0; foreach ($value as $dbgval) { $val += intval($dbgval); } $value = $val; } } else { if ($which == 'db' && $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']) { $value = sprintf('%s://%s:%s@%s/%s', $_POST['_dbtype'], rawurlencode($_POST['_dbuser']), rawurlencode($_POST['_dbpass']), $_POST['_dbhost'], $_POST['_dbname']); } } } else { if ($prop == 'smtp_auth_type' && $value == '0') { $value = ''; } else { if ($prop == 'default_host' && is_array($value)) { $value = rcube_install::_clean_array($value); if (count($value) <= 1) { $value = $value[0]; } } else { if ($prop == 'mail_pagesize' || $prop == 'addressbook_pagesize') { $value = max(2, intval($value)); } else { if ($prop == 'smtp_user' && !empty($_POST['_smtp_user_u'])) { $value = '%u'; } else { if ($prop == 'smtp_pass' && !empty($_POST['_smtp_user_u'])) { $value = '%p'; } else { if ($prop == 'default_folders') { $value = array(); foreach ($this->config['default_folders'] as $_folder) { switch ($_folder) { case 'Drafts': $_folder = $this->config['drafts_mbox']; break; case 'Sent': $_folder = $this->config['sent_mbox']; break; case 'Junk': $_folder = $this->config['junk_mbox']; break; case 'Trash': $_folder = $this->config['trash_mbox']; break; } if (!in_array($_folder, $value)) { $value[] = $_folder; } } } else { if (is_bool($default)) { $value = (bool) $value; } else { if (is_numeric($value)) { $value = intval($value); } } } } } } } } } } // skip this property if (!$force && !$this->configured && $value == $default) { continue; } // save change $this->config[$prop] = $value; $dump = self::_dump_var($value, $prop); // replace the matching line in config file $out = preg_replace('/(\\$rcmail_config\\[\'' . preg_quote($prop) . '\'\\])\\s+=\\s+(.+);/Ui', "\\1 = {$dump};", $out); } return trim($out); }