4 +-----------------------------------------------------------------------+
5 | program/include/rcube_config.php |
7 | This file is part of the RoundCube Webmail client |
8 | Copyright (C) 2008, RoundCube Dev. - Switzerland |
9 | Licensed under the GNU GPL |
12 | Class to read configuration settings |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
23 * Configuration class for RoundCube
29 private $prop = array();
35 public function __construct()
42 * Load config from local config file
44 * @todo Remove global $CONFIG
46 private function load()
48 // start output buffering, we don't need any output yet,
49 // it'll be cleared after reading of config files, etc.
52 // load main config file
53 include_once(INSTALL_PATH . 'config/main.inc.php');
54 $this->prop = (array)$rcmail_config;
56 // load database config
57 include_once(INSTALL_PATH . 'config/db.inc.php');
58 $this->prop += (array)$rcmail_config;
60 // load host-specific configuration
61 $this->load_host_config();
64 $this->prop['skin_path'] = $this->prop['skin_path'] ? unslashify($this->prop['skin_path']) : 'skins/default';
65 $this->prop['log_dir'] = $this->prop['log_dir'] ? unslashify($this->prop['log_dir']) : INSTALL_PATH . 'logs';
68 if (isset($this->prop['locale_string']) && empty($this->prop['language']))
69 $this->prop['language'] = $this->prop['locale_string'];
71 // set PHP error logging according to config
72 if ($this->prop['debug_level'] & 1) {
73 ini_set('log_errors', 1);
74 ini_set('error_log', $this->prop['log_dir'] . '/errors');
76 if ($this->prop['debug_level'] & 4) {
77 ini_set('display_errors', 1);
80 ini_set('display_errors', 0);
83 // clear output buffer
87 $GLOBALS['CONFIG'] = &$this->prop;
92 * Load a host-specific config file if configured
93 * This will merge the host specific configuration with the given one
95 private function load_host_config()
99 if (is_array($this->prop['include_host_config'])) {
100 $fname = $this->prop['include_host_config'][$_SERVER['HTTP_HOST']];
102 else if (!empty($this->prop['include_host_config'])) {
103 $fname = preg_replace('/[^a-z0-9\.\-_]/i', '', $_SERVER['HTTP_HOST']) . '.inc.php';
106 if ($fname && is_file(INSTALL_PATH . 'config/' . $fname)) {
107 include(INSTALL_PATH . 'config/' . $fname);
108 $this->prop = array_merge($this->prop, (array)$rcmail_config);
114 * Getter for a specific config parameter
116 * @param string Parameter name
117 * @param mixed Default value if not set
118 * @return mixed The requested config value
120 public function get($name, $def = null)
122 return isset($this->prop[$name]) ? $this->prop[$name] : $def;
127 * Setter for a config parameter
129 * @param string Parameter name
130 * @param mixed Parameter value
132 public function set($name, $value)
134 $this->prop[$name] = $value;
139 * Override config options with the given values (eg. user prefs)
141 * @param array Hash array with config props to merge over
143 public function merge($prefs)
145 $this->prop = array_merge($this->prop, $prefs);
150 * Getter for all config options
152 * @return array Hash array containg all config properties
154 public function all()
161 * Return a 24 byte key for the DES encryption
163 * @return string DES encryption key
165 public function get_des_key()
167 $key = !empty($this->prop['des_key']) ? $this->prop['des_key'] : 'rcmail?24BitPwDkeyF**ECB';
170 // make sure the key is exactly 24 chars long
172 $key .= str_repeat('_', 24-$len);