/**
  * 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;
 }
Beispiel #2
0
*/
ini_set('error_reporting', E_ALL & ~(E_NOTICE | E_STRICT));
ini_set('display_errors', 1);
define('INSTALL_PATH', realpath(dirname(__FILE__) . '/../') . '/');
define('RCUBE_INSTALL_PATH', INSTALL_PATH);
define('RCUBE_CONFIG_DIR', INSTALL_PATH . 'config/');
$include_path = INSTALL_PATH . 'program/lib' . PATH_SEPARATOR;
$include_path .= INSTALL_PATH . 'program/include' . PATH_SEPARATOR;
$include_path .= ini_get('include_path');
set_include_path($include_path);
require_once 'Roundcube/bootstrap.php';
require_once 'rcube_install.php';
// deprecated aliases (to be removed)
require_once 'bc.php';
session_start();
$RCI = rcube_install::get_instance();
$RCI->load_config();
if (isset($_GET['_getfile']) && in_array($_GET['_getfile'], array('main', 'db'))) {
    $filename = $_GET['_getfile'] . '.inc.php';
    if (!empty($_SESSION[$filename])) {
        header('Content-type: text/plain');
        header('Content-Disposition: attachment; filename="' . $filename . '"');
        echo $_SESSION[$filename];
        exit;
    } else {
        header('HTTP/1.0 404 Not found');
        die("The requested configuration was not found. Please run the installer from the beginning.");
    }
}
if ($RCI->configured && ($RCI->getprop('enable_installer') || $_SESSION['allowinstaller']) && isset($_GET['_mergeconfig']) && in_array($_GET['_mergeconfig'], array('main', 'db'))) {
    $filename = $_GET['_mergeconfig'] . '.inc.php';
Beispiel #3
0
 /**
  * Throw system error (and show error page).
  *
  * @param array Named parameters
  *      - code:    Error code (required)
  *      - type:    Error type [php|db|imap|javascript] (required)
  *      - message: Error message
  *      - file:    File where error occured
  *      - line:    Line where error occured
  * @param boolean True to log the error
  * @param boolean Terminate script execution
  */
 public static function raise_error($arg = array(), $log = false, $terminate = false)
 {
     // handle PHP exceptions
     if (is_object($arg) && is_a($arg, 'Exception')) {
         $err = array('type' => 'php', 'code' => $arg->getCode(), 'line' => $arg->getLine(), 'file' => $arg->getFile(), 'message' => $arg->getMessage());
         $arg = $err;
     }
     // installer
     if (class_exists('rcube_install', false)) {
         $rci = rcube_install::get_instance();
         $rci->raise_error($arg);
         return;
     }
     if (($log || $terminate) && $arg['type'] && $arg['message']) {
         $arg['fatal'] = $terminate;
         self::log_bug($arg);
     }
     // display error page and terminate script
     if ($terminate && is_object(self::$instance->output)) {
         self::$instance->output->raise_error($arg['code'], $arg['message']);
     }
 }
Beispiel #4
0
 /**
  * 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);
 }
Beispiel #5
0
 /**
  * Throw system error (and show error page).
  *
  * @param array Named parameters
  *      - code:    Error code (required)
  *      - type:    Error type [php|db|imap|javascript] (required)
  *      - message: Error message
  *      - file:    File where error occurred
  *      - line:    Line where error occurred
  * @param boolean True to log the error
  * @param boolean Terminate script execution
  */
 public static function raise_error($arg = array(), $log = false, $terminate = false)
 {
     // handle PHP exceptions
     if (is_object($arg) && is_a($arg, 'Exception')) {
         $arg = array('code' => $arg->getCode(), 'line' => $arg->getLine(), 'file' => $arg->getFile(), 'message' => $arg->getMessage());
     } else {
         if (is_string($arg)) {
             $arg = array('message' => $arg);
         }
     }
     if (empty($arg['code'])) {
         $arg['code'] = 500;
     }
     // installer
     if (class_exists('rcube_install', false)) {
         $rci = rcube_install::get_instance();
         $rci->raise_error($arg);
         return;
     }
     $cli = php_sapi_name() == 'cli';
     if (($log || $terminate) && !$cli && $arg['message']) {
         $arg['fatal'] = $terminate;
         self::log_bug($arg);
     }
     // terminate script
     if ($terminate) {
         // display error page
         if (is_object(self::$instance->output)) {
             self::$instance->output->raise_error($arg['code'], $arg['message']);
         } else {
             if ($cli) {
                 fwrite(STDERR, 'ERROR: ' . $arg['message']);
             }
         }
         exit(1);
     }
 }
Beispiel #6
0
/**
 * Fake internal error handler to catch errors
 */
function raise_error($p)
{
    $rci = rcube_install::get_instance();
    $rci->raise_error($p);
}