Thomas Bruederli
2013-03-27 217694ebe579759a575aa42bb755bf5f3670b597
installer/rcube_install.php
@@ -5,11 +5,14 @@
 | rcube_install.php                                                     |
 |                                                                       |
 | This file is part of the Roundcube Webmail package                    |
 | Copyright (C) 2008-2011, The Roundcube Dev Team                       |
 | Licensed under the GNU Public License                                 |
 | Copyright (C) 2008-2012, The Roundcube Dev Team                       |
 |                                                                       |
 | Licensed under the GNU General Public License version 3 or            |
 | any later version with exceptions for skins & plugins.                |
 | See the README file for a full license statement.                     |
 +-----------------------------------------------------------------------+
 $Id:  $
 $Id$
*/
@@ -41,12 +44,13 @@
    'addrbook_show_images' => 'show_images',
    'imap_root' => 'imap_ns_personal',
    'pagesize' => 'mail_pagesize',
    'default_imap_folders' => 'default_folders',
  );
  // these config options are required for a working system
  var $required_config = array(
    'db_dsnw', 'db_table_contactgroups', 'db_table_contactgroupmembers',
    'des_key', 'session_lifetime',
    'des_key', 'session_lifetime', 'support_url',
  );
  /**
@@ -179,9 +183,9 @@
      else if ($prop == 'smtp_pass' && !empty($_POST['_smtp_user_u'])) {
        $value = '%p';
      }
      else if ($prop == 'default_imap_folders') {
      else if ($prop == 'default_folders') {
       $value = array();
       foreach ($this->config['default_imap_folders'] as $_folder) {
       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;
@@ -247,10 +251,15 @@
        $seen[$prop] = true;
      }
    }
    // the old default mime_magic reference is obsolete
    if ($this->config['mime_magic'] == '/usr/share/misc/magic') {
        $out['obsolete'][] = array('prop' => 'mime_magic', 'explain' => "Set value to null in order to use system default");
    }
    // iterate over default config
    foreach ($defaults as $prop => $value) {
      if (!isset($seen[$prop]) && !isset($this->config[$prop]) && isset($required[$prop]))
      if (!isset($seen[$prop]) && isset($required[$prop]) && !(is_bool($this->config[$prop]) || strlen($this->config[$prop])))
        $out['missing'][] = array('prop' => $prop);
    }
@@ -262,7 +271,7 @@
      }
      else if (!empty($this->config['spellcheck_languages'])) {
        foreach ($this->config['spellcheck_languages'] as $lang => $descr)
          if (!pspell_new($lang))
          if (!@pspell_new($lang))
            $out['dependencies'][] = array('prop' => 'spellcheck_languages',
              'explain' => "You are missing pspell support for language $lang ($descr)");
      }
@@ -409,7 +418,7 @@
  {
    if (!$this->configured)
      return false;
    $options = array(
      'use_transactions' => false,
      'log_line_break' => "\n",
@@ -419,11 +428,11 @@
      'force_defaults' => false,
      'portability' => true
    );
    $dsnw = $this->config['db_dsnw'];
    $schema = MDB2_Schema::factory($dsnw, $options);
    $schema->db->supported['transactions'] = false;
    if (PEAR::isError($schema)) {
      $this->raise_error(array('code' => $schema->getCode(), 'message' => $schema->getMessage() . ' ' . $schema->getUserInfo()));
      return false;
@@ -431,33 +440,33 @@
    else {
      $definition = $schema->getDefinitionFromDatabase();
      $definition['charset'] = 'utf8';
      if (PEAR::isError($definition)) {
        $this->raise_error(array('code' => $definition->getCode(), 'message' => $definition->getMessage() . ' ' . $definition->getUserInfo()));
        return false;
      }
      // load reference schema
      $dsn_arr = MDB2::parseDSN($this->config['db_dsnw']);
      $ref_schema = INSTALL_PATH . 'SQL/' . $dsn_arr['phptype'] . '.schema.xml';
      if (is_readable($ref_schema)) {
        $reference = $schema->parseDatabaseDefinition($ref_schema, false, array(), $schema->options['fail_on_invalid_names']);
        if (PEAR::isError($reference)) {
          $this->raise_error(array('code' => $reference->getCode(), 'message' => $reference->getMessage() . ' ' . $reference->getUserInfo()));
        }
        else {
          $diff = $schema->compareDefinitions($reference, $definition);
          if (empty($diff)) {
            return true;
          }
          else if ($update) {
            // update database schema with the diff from the above check
            $success = $schema->alterDatabase($reference, $definition, $diff);
            if (PEAR::isError($success)) {
              $this->raise_error(array('code' => $success->getCode(), 'message' => $success->getMessage() . ' ' . $success->getUserInfo()));
            }
@@ -472,11 +481,11 @@
        $this->raise_error(array('message' => "Could not find reference schema file ($ref_schema)"));
        return false;
    }
    return false;
  }
  /**
   * Getter for the last error message
   *
@@ -486,8 +495,8 @@
  {
      return $this->last_error['message'];
  }
  /**
   * Return a list with all imap hosts configured
   *
@@ -497,12 +506,12 @@
  {
    $default_hosts = (array)$this->getprop('default_host');
    $out = array();
    foreach ($default_hosts as $key => $name) {
      if (!empty($name))
        $out[] = rcube_parse_host(is_numeric($key) ? $name : $key);
    }
    return $out;
  }
@@ -519,7 +528,8 @@
        '0.4-beta', '0.4.2',
        '0.5-beta', '0.5', '0.5.1',
        '0.6-beta', '0.6',
        '0.7-beta', '0.7',
        '0.7-beta', '0.7', '0.7.1', '0.7.2', '0.7.3', '0.7.4',
        '0.8-beta', '0.8-rc', '0.8.0', '0.8.1', '0.8.2', '0.8.3', '0.8.4', '0.8.5',
    ));
    return $select;
  }
@@ -538,7 +548,7 @@
    }
    return $skins;
  }
  /**
   * Display OK status
   *
@@ -550,8 +560,8 @@
    echo Q($name) . ':&nbsp; <span class="success">OK</span>';
    $this->_showhint($message);
  }
  /**
   * Display an error status and increase failure count
   *
@@ -562,7 +572,7 @@
  function fail($name, $message = '', $url = '')
  {
    $this->failures++;
    echo Q($name) . ':&nbsp; <span class="fail">NOT OK</span>';
    $this->_showhint($message, $url);
  }
@@ -580,8 +590,8 @@
    echo Q($name) . ':&nbsp; <span class="na">NOT OK</span>';
    $this->_showhint($message, $url);
  }
  /**
   * Display warning status
   *
@@ -594,24 +604,24 @@
    echo Q($name) . ':&nbsp; <span class="na">NOT AVAILABLE</span>';
    $this->_showhint($message, $url);
  }
  function _showhint($message, $url = '')
  {
    $hint = Q($message);
    if ($url)
      $hint .= ($hint ? '; ' : '') . 'See <a href="' . Q($url) . '" target="_blank">' . Q($url) . '</a>';
    if ($hint)
      echo '<span class="indent">(' . $hint . ')</span>';
  }
  static function _clean_array($arr)
  {
    $out = array();
    foreach (array_unique($arr) as $k => $val) {
      if (!empty($val)) {
        if (is_numeric($k))
@@ -620,11 +630,11 @@
          $out[$k] = $val;
      }
    }
    return $out;
  }
  static function _dump_var($var, $name=null) {
    // special values
    switch ($name) {
@@ -653,16 +663,16 @@
            break;
          }
        }
        if ($isnum)
          return 'array(' . join(', ', array_map(array('rcube_install', '_dump_var'), $var)) . ')';
      }
    }
    return var_export($var, true);
  }
  /**
   * Initialize the database with the according schema
   *
@@ -672,7 +682,7 @@
  function init_db($DB)
  {
    $engine = isset($this->db_map[$DB->db_provider]) ? $this->db_map[$DB->db_provider] : $DB->db_provider;
    // read schema file from /SQL/*
    $fname = INSTALL_PATH . "SQL/$engine.initial.sql";
    if ($sql = @file_get_contents($fname)) {
@@ -682,7 +692,7 @@
      $this->fail('DB Schema', "Cannot read the schema file: $fname");
      return false;
    }
    if ($err = $this->get_error()) {
      $this->fail('DB Schema', "Error creating database schema: $err");
      return false;
@@ -690,8 +700,8 @@
    return true;
  }
  /**
   * Update database with SQL statements from SQL/*.update.sql
   *
@@ -703,7 +713,7 @@
  {
    $version = strtolower($version);
    $engine = isset($this->db_map[$DB->db_provider]) ? $this->db_map[$DB->db_provider] : $DB->db_provider;
    // read schema file from /SQL/*
    $fname = INSTALL_PATH . "SQL/$engine.update.sql";
    if ($lines = @file($fname, FILE_SKIP_EMPTY_LINES)) {
@@ -718,7 +728,7 @@
        if ($from && !$is_comment)
          $sql .= $line. "\n";
      }
      if ($sql)
        $this->exec_sql($sql, $DB);
    }
@@ -726,7 +736,7 @@
      $this->fail('DB Schema', "Cannot read the update file: $fname");
      return false;
    }
    if ($err = $this->get_error()) {
      $this->fail('DB Schema', "Error updating database: $err");
      return false;
@@ -734,8 +744,8 @@
    return true;
  }
  /**
   * Execute the given SQL queries on the database connection
   *
@@ -749,7 +759,7 @@
    foreach (explode("\n", $sql) as $line) {
      if (preg_match('/^--/', $line) || trim($line) == '')
        continue;
      $buff .= $line . "\n";
      if (preg_match('/(;|^GO)$/', trim($line))) {
        $DB->query($buff);
@@ -758,11 +768,11 @@
          break;
      }
    }
    return !$DB->is_error();
  }
  /**
   * Handler for Roundcube errors
   */
@@ -770,8 +780,8 @@
  {
      $this->last_error = $p;
  }
  /**
   * Generarte a ramdom string to be used as encryption key
   *
@@ -783,12 +793,12 @@
  {
    $alpha = 'ABCDEFGHIJKLMNOPQERSTUVXYZabcdefghijklmnopqrtsuvwxyz0123456789+*%&?!$-_=';
    $out = '';
    for ($i=0; $i < $length; $i++)
      $out .= $alpha{rand(0, strlen($alpha)-1)};
    return $out;
  }
}