alecpl
2012-04-15 831c830124c5cafeb36e952acacc01e36de50d78
installer/rcube_install.php
@@ -5,11 +5,14 @@
 | rcube_install.php                                                     |
 |                                                                       |
 | This file is part of the Roundcube Webmail package                    |
 | Copyright (C) 2008-2009, The Roundcube Dev Team                       |
 | Licensed under the GNU Public License                                 |
 | Copyright (C) 2008-2011, 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$
*/
@@ -40,14 +43,16 @@
    'multiple_identities' => 'identities_level',
    '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',
  );
  /**
   * Constructor
   */
@@ -95,14 +100,15 @@
   */
  function _load_config($suffix)
  {
    @include RCMAIL_CONFIG_DIR . '/main.inc' . $suffix;
    if (is_array($rcmail_config)) {
      $this->config += $rcmail_config;
    if (is_readable($main_inc = RCMAIL_CONFIG_DIR . '/main.inc' . $suffix)) {
      include($main_inc);
      if (is_array($rcmail_config))
        $this->config += $rcmail_config;
    }
    @include RCMAIL_CONFIG_DIR . '/db.inc'. $suffix;
    if (is_array($rcmail_config)) {
      $this->config += $rcmail_config;
    if (is_readable($db_inc = RCMAIL_CONFIG_DIR . '/db.inc'. $suffix)) {
      include($db_inc);
      if (is_array($rcmail_config))
        $this->config += $rcmail_config;
    }
  }
  
@@ -123,8 +129,8 @@
    
    return $value !== null && $value !== '' ? $value : $default;
  }
  /**
   * Take the default config file and replace the parameters
   * with the submitted form data
@@ -135,25 +141,28 @@
  function create_config($which, $force = false)
  {
    $out = @file_get_contents(RCMAIL_CONFIG_DIR . "/{$which}.inc.php.dist");
    if (!$out)
      return '[Warning: could not read the config template file]';
    foreach ($this->config as $prop => $default) {
      $value = (isset($_POST["_$prop"]) || $this->bool_config_props[$prop]) ? $_POST["_$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') {
        $val = 0;
        if (is_array($value))
      if ($prop == 'debug_level' && !$is_default) {
        if (is_array($value)) {
          $val = 0;
          foreach ($value as $dbgval)
            $val += intval($dbgval);
        $value = $val;
          $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
        else if ($_POST['_dbtype'])
          $value = sprintf('%s://%s:%s@%s/%s', $_POST['_dbtype'], 
            rawurlencode($_POST['_dbuser']), rawurlencode($_POST['_dbpass']), $_POST['_dbhost'], $_POST['_dbname']);
      }
@@ -165,7 +174,7 @@
        if (count($value) <= 1)
          $value = $value[0];
      }
      else if ($prop == 'pagesize') {
      else if ($prop == 'mail_pagesize' || $prop == 'addressbook_pagesize') {
        $value = max(2, intval($value));
      }
      else if ($prop == 'smtp_user' && !empty($_POST['_smtp_user_u'])) {
@@ -174,10 +183,10 @@
      else if ($prop == 'smtp_pass' && !empty($_POST['_smtp_user_u'])) {
        $value = '%p';
      }
      else if ($prop == 'default_imap_folders') {
       $value = Array();
       foreach ($this->config['default_imap_folders'] as $_folder) {
         switch($_folder) {
      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;
@@ -193,9 +202,9 @@
      else if (is_numeric($value)) {
        $value = intval($value);
      }
      // skip this property
      if (!$force && ($value == $default))
      if (!$force && !$this->configured && ($value == $default))
        continue;
      // save change
@@ -204,7 +213,7 @@
      // replace the matching line in config file
      $out = preg_replace(
        '/(\$rcmail_config\[\''.preg_quote($prop).'\'\])\s+=\s+(.+);/Uie',
        "'\\1 = ' . rcube_install::_dump_var(\$value) . ';'",
        "'\\1 = ' . rcube_install::_dump_var(\$value, \$prop) . ';'",
        $out);
    }
@@ -245,7 +254,7 @@
    
    // 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);
    }
@@ -297,7 +306,7 @@
    $current = $this->config;
    $this->config = array();
    $this->load_defaults();
    foreach ($this->replaced_config as $prop => $replacement) {
      if (isset($current[$prop])) {
        if ($prop == 'skin_path')
@@ -326,9 +335,9 @@
    
    if ($current['keep_alive'] && $current['session_lifetime'] < $current['keep_alive'])
      $current['session_lifetime'] = max(10, ceil($current['keep_alive'] / 60) * 2);
    $this->config  = array_merge($this->config, $current);
    foreach ((array)$current['ldap_public'] as $key => $values) {
      $this->config['ldap_public'][$key] = $current['ldap_public'][$key];
    }
@@ -500,17 +509,40 @@
    
    return $out;
  }
  /**
   * Create a HTML dropdown to select a previous version of Roundcube
   */
  function versions_select($attrib = array())
  {
    $select = new html_select($attrib);
    $select->add(array('0.1-stable', '0.1.1', '0.2-alpha', '0.2-beta', '0.2-stable', '0.3-stable', '0.3.1', '0.4-beta', '0.4.2', '0.5-beta', '0.5', '0.5.1'));
    $select->add(array(
        '0.1-stable', '0.1.1',
        '0.2-alpha', '0.2-beta', '0.2-stable',
        '0.3-stable', '0.3.1',
        '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.1', '0.7.2',
        '0.8-beta',
    ));
    return $select;
  }
  /**
   * Return a list with available subfolders of the skin directory
   */
  function list_skins()
  {
    $skins = array();
    $skindir = INSTALL_PATH . 'skins/';
    foreach (glob($skindir . '*') as $path) {
      if (is_dir($path) && is_readable($path)) {
        $skins[] = substr($path, strlen($skindir));
      }
    }
    return $skins;
  }
  
  /**
   * Display OK status
@@ -598,7 +630,22 @@
  }
  
  
  static function _dump_var($var) {
  static function _dump_var($var, $name=null) {
    // special values
    switch ($name) {
    case 'syslog_facility':
      $list = array(32 => 'LOG_AUTH', 80 => 'LOG_AUTHPRIV', 72 => ' LOG_CRON',
                    24 => 'LOG_DAEMON', 0 => 'LOG_KERN', 128 => 'LOG_LOCAL0',
                    136 => 'LOG_LOCAL1', 144 => 'LOG_LOCAL2', 152 => 'LOG_LOCAL3',
                    160 => 'LOG_LOCAL4', 168 => 'LOG_LOCAL5', 176 => 'LOG_LOCAL6',
                    184 => 'LOG_LOCAL7', 48 => 'LOG_LPR', 16 => 'LOG_MAIL',
                    56 => 'LOG_NEWS', 40 => 'LOG_SYSLOG', 8 => 'LOG_USER', 64 => 'LOG_UUCP');
      if ($val = $list[$var])
        return $val;
      break;
    }
    if (is_array($var)) {
      if (empty($var)) {
        return 'array()';