| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /* |
|---|
| 4 | +-----------------------------------------------------------------------+ |
|---|
| 5 | | program/include/rcube_config.php | |
|---|
| 6 | | | |
|---|
| 7 | | This file is part of the RoundCube Webmail client | |
|---|
| 8 | | Copyright (C) 2008, RoundCube Dev. - Switzerland | |
|---|
| 9 | | Licensed under the GNU GPL | |
|---|
| 10 | | | |
|---|
| 11 | | PURPOSE: | |
|---|
| 12 | | Class to read configuration settings | |
|---|
| 13 | | | |
|---|
| 14 | +-----------------------------------------------------------------------+ |
|---|
| 15 | | Author: Thomas Bruederli <roundcube@gmail.com> | |
|---|
| 16 | +-----------------------------------------------------------------------+ |
|---|
| 17 | |
|---|
| 18 | $Id: $ |
|---|
| 19 | |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | /** |
|---|
| 23 | * Configuration class for RoundCube |
|---|
| 24 | * |
|---|
| 25 | * @package Core |
|---|
| 26 | */ |
|---|
| 27 | class rcube_config |
|---|
| 28 | { |
|---|
| 29 | private $prop = array(); |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | /** |
|---|
| 33 | * Object constructor |
|---|
| 34 | */ |
|---|
| 35 | public function __construct() |
|---|
| 36 | { |
|---|
| 37 | $this->load(); |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | /** |
|---|
| 42 | * Load config from local config file |
|---|
| 43 | */ |
|---|
| 44 | private function load() |
|---|
| 45 | { |
|---|
| 46 | // start output buffering, we don't need any output yet, |
|---|
| 47 | // it'll be cleared after reading of config files, etc. |
|---|
| 48 | ob_start(); |
|---|
| 49 | |
|---|
| 50 | // load main config file |
|---|
| 51 | include_once(INSTALL_PATH . 'config/main.inc.php'); |
|---|
| 52 | $this->prop = (array)$rcmail_config; |
|---|
| 53 | |
|---|
| 54 | // load database config |
|---|
| 55 | include_once(INSTALL_PATH . 'config/db.inc.php'); |
|---|
| 56 | $this->prop += (array)$rcmail_config; |
|---|
| 57 | |
|---|
| 58 | // fix paths |
|---|
| 59 | $this->prop['skin_path'] = $this->prop['skin_path'] ? unslashify($this->prop['skin_path']) : 'skins/default'; |
|---|
| 60 | $this->prop['log_dir'] = $this->prop['log_dir'] ? unslashify($this->prop['log_dir']) : INSTALL_PATH . 'logs'; |
|---|
| 61 | |
|---|
| 62 | // handle aliases |
|---|
| 63 | if (isset($this->prop['locale_string']) && empty($this->prop['language'])) |
|---|
| 64 | $this->prop['language'] = $this->prop['locale_string']; |
|---|
| 65 | |
|---|
| 66 | // set PHP error logging according to config |
|---|
| 67 | if ($this->prop['debug_level'] & 1) { |
|---|
| 68 | ini_set('log_errors', 1); |
|---|
| 69 | ini_set('error_log', $this->prop['log_dir'] . '/errors'); |
|---|
| 70 | } |
|---|
| 71 | if ($this->prop['debug_level'] & 4) { |
|---|
| 72 | ini_set('display_errors', 1); |
|---|
| 73 | } |
|---|
| 74 | else { |
|---|
| 75 | ini_set('display_errors', 0); |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | // clear output buffer |
|---|
| 79 | ob_end_clean(); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | /** |
|---|
| 84 | * Load a host-specific config file if configured |
|---|
| 85 | * This will merge the host specific configuration with the given one |
|---|
| 86 | */ |
|---|
| 87 | private function load_host_config() |
|---|
| 88 | { |
|---|
| 89 | $fname = null; |
|---|
| 90 | |
|---|
| 91 | if (is_array($this->prop['include_host_config'])) { |
|---|
| 92 | $fname = $this->prop['include_host_config'][$_SERVER['HTTP_HOST']]; |
|---|
| 93 | } |
|---|
| 94 | else if (!empty($this->prop['include_host_config'])) { |
|---|
| 95 | $fname = preg_replace('/[^a-z0-9\.\-_]/i', '', $_SERVER['HTTP_HOST']) . '.inc.php'; |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | if ($fname && is_file(INSTALL_PATH . 'config/' . $fname)) { |
|---|
| 99 | include(INSTALL_PATH . 'config/' . $fname); |
|---|
| 100 | $this->prop = array_merge($this->prop, (array)$rcmail_config); |
|---|
| 101 | } |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | /** |
|---|
| 106 | * Getter for a specific config parameter |
|---|
| 107 | * |
|---|
| 108 | * @param string Parameter name |
|---|
| 109 | * @param mixed Default value if not set |
|---|
| 110 | * @return mixed The requested config value |
|---|
| 111 | */ |
|---|
| 112 | public function get($name, $def = null) |
|---|
| 113 | { |
|---|
| 114 | return isset($this->prop[$name]) ? $this->prop[$name] : $def; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | /** |
|---|
| 119 | * Setter for a config parameter |
|---|
| 120 | * |
|---|
| 121 | * @param string Parameter name |
|---|
| 122 | * @param mixed Parameter value |
|---|
| 123 | */ |
|---|
| 124 | public function set($name, $value) |
|---|
| 125 | { |
|---|
| 126 | $this->prop[$name] = $value; |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | /** |
|---|
| 131 | * Override config options with the given values (eg. user prefs) |
|---|
| 132 | * |
|---|
| 133 | * @param array Hash array with config props to merge over |
|---|
| 134 | */ |
|---|
| 135 | public function merge($prefs) |
|---|
| 136 | { |
|---|
| 137 | $this->prop = array_merge($this->prop, $prefs); |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | /** |
|---|
| 142 | * Getter for all config options |
|---|
| 143 | * |
|---|
| 144 | * @return array Hash array containg all config properties |
|---|
| 145 | */ |
|---|
| 146 | public function all() |
|---|
| 147 | { |
|---|
| 148 | return $this->prop; |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | |
|---|
| 152 | /** |
|---|
| 153 | * Return a 24 byte key for the DES encryption |
|---|
| 154 | * |
|---|
| 155 | * @return string DES encryption key |
|---|
| 156 | */ |
|---|
| 157 | public function get_des_key() |
|---|
| 158 | { |
|---|
| 159 | $key = !empty($this->prop['des_key']) ? $this->prop['des_key'] : 'rcmail?24BitPwDkeyF**ECB'; |
|---|
| 160 | $len = strlen($key); |
|---|
| 161 | |
|---|
| 162 | // make sure the key is exactly 24 chars long |
|---|
| 163 | if ($len<24) |
|---|
| 164 | $key .= str_repeat('_', 24-$len); |
|---|
| 165 | else if ($len>24) |
|---|
| 166 | substr($key, 0, 24); |
|---|
| 167 | |
|---|
| 168 | return $key; |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | } |
|---|
| 173 | |
|---|