Aleksander Machniak
2014-04-01 dc0b500e78aae13349b848303302a213ed3a1e65
installer/rcube_install.php
@@ -34,7 +34,7 @@
  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 $obsolete_config = array('db_backend', 'db_max_length', 'double_auth');
  var $replaced_config = array(
    'skin_path'            => 'skin',
    'locale_string'        => 'language',
@@ -42,8 +42,9 @@
    'addrbook_show_images' => 'show_images',
    'imap_root'            => 'imap_ns_personal',
    'pagesize'             => 'mail_pagesize',
    'default_imap_folders' => 'default_folders',
    'top_posting'          => 'reply_mode',
    'keep_alive'           => 'refresh_interval',
    'min_keep_alive'       => 'min_refresh_interval',
  );
  // list of supported database drivers
@@ -181,8 +182,17 @@
      $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) {
@@ -217,19 +227,6 @@
      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;
      }
@@ -238,7 +235,9 @@
      }
      // skip this property
      if ((!array_key_exists($prop, $this->defaults) || ($value == $this->defaults[$prop])) && !in_array($prop, $this->local_config)) {
      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;
      }
@@ -258,6 +257,20 @@
    return $out;
  }
  /**
   * save generated config file in RCUBE_CONFIG_DIR
   *
   * @return boolean True if the file was saved successfully, false if not
   */
  function save_configfile($config)
  {
    if (is_writable(RCUBE_CONFIG_DIR)) {
      return file_put_contents(RCUBE_CONFIG_DIR . 'config.inc.php', $config);
    }
    return false;
  }
  /**
   * Check the current configuration for missing properties
@@ -379,7 +392,7 @@
   *
   * @param rcube_db Database object
   *
   * @return boolean True if the schema is up-to-date, false if not or an error occured
   * @return boolean True if the schema is up-to-date, false if not or an error occurred
   */
  function db_schema_check($DB)
  {
@@ -432,6 +445,52 @@
    return $schema;
  }
  /**
   * Try to detect some file's mimetypes to test the correct behavior of fileinfo
   */
  function check_mime_detection()
  {
    $files = array(
      'installer/images/roundcube_logo.png' => 'image/png',
      'program/resources/blank.tif' => 'image/tiff',
      'skins/larry/images/buttons.gif' => 'image/gif',
      'skins/larry/README' => 'text/plain',
    );
    $errors = array();
    foreach ($files as $path => $expected) {
      $mimetype = rcube_mime::file_content_type(INSTALL_PATH . $path, basename($path));
      if ($mimetype != $expected) {
        $errors[] = array($path, $mimetype, $expected);
      }
    }
    return $errors;
  }
  /**
   * Check the correct configuration of the 'mime_types' mapping option
   */
  function check_mime_extensions()
  {
    $types = array(
      'application/zip'   => 'zip',
      'application/x-tar' => 'tar',
      'application/java-archive' => 'jar',
      'image/gif'     => 'gif',
      'image/svg+xml' => 'svg',
    );
    $errors = array();
    foreach ($types as $mimetype => $expected) {
      $ext = rcube_mime::get_mime_extensions($mimetype);
      if ($ext[0] != $expected) {
        $errors[] = array($mimetype, $ext, $expected);
      }
    }
    return $errors;
  }
  /**
   * Getter for the last error message
@@ -517,10 +576,13 @@
   * @param string Test name
   * @param string Error message
   * @param string URL for details
   * @param bool   Do not count this failure
   */
  function fail($name, $message = '', $url = '')
  function fail($name, $message = '', $url = '', $optional=false)
  {
    $this->failures++;
    if (!$optional) {
      $this->failures++;
    }
    echo Q($name) . ':&nbsp; <span class="fail">NOT OK</span>';
    $this->_showhint($message, $url);