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();
30 private $errors = array();
36 public function __construct()
43 * Load config from local config file
45 * @todo Remove global $CONFIG
47 private function load()
49 // start output buffering, we don't need any output yet,
50 // it'll be cleared after reading of config files, etc.
53 // load main config file
54 if (include(RCMAIL_CONFIG_DIR . '/main.inc.php'))
55 $this->prop = (array)$rcmail_config;
57 $this->errors[] = 'main.inc.php was not found.';
59 // load database config
60 if (include(RCMAIL_CONFIG_DIR . '/db.inc.php'))
61 $this->prop += (array)$rcmail_config;
63 $this->errors[] = 'db.inc.php was not found.';
65 // load host-specific configuration
66 $this->load_host_config();
68 // set skin (with fallback to old 'skin_path' property)
69 if (empty($this->prop['skin']) && !empty($this->prop['skin_path']))
70 $this->prop['skin'] = str_replace('skins/', '', unslashify($this->prop['skin_path']));
71 else if (empty($this->prop['skin']))
72 $this->prop['skin'] = 'default';
75 $this->prop['log_dir'] = $this->prop['log_dir'] ? unslashify($this->prop['log_dir']) : INSTALL_PATH . 'logs';
76 $this->prop['temp_dir'] = $this->prop['temp_dir'] ? unslashify($this->prop['temp_dir']) : INSTALL_PATH . 'temp';
78 // fix default imap folders encoding
79 foreach (array('drafts_mbox', 'junk_mbox', 'sent_mbox', 'trash_mbox') as $folder)
80 $this->prop[$folder] = rcube_charset_convert($this->prop[$folder], RCMAIL_CHARSET, 'UTF-7');
82 if (!empty($this->prop['default_imap_folders']))
83 foreach ($this->prop['default_imap_folders'] as $n => $folder)
84 $this->prop['default_imap_folders'][$n] = rcube_charset_convert($folder, RCMAIL_CHARSET, 'UTF-7');
86 // set PHP error logging according to config
87 if ($this->prop['debug_level'] & 1) {
88 ini_set('log_errors', 1);
90 if ($this->prop['log_driver'] == 'syslog') {
91 ini_set('error_log', 'syslog');
93 ini_set('error_log', $this->prop['log_dir'].'/errors');
96 if ($this->prop['debug_level'] & 4) {
97 ini_set('display_errors', 1);
100 ini_set('display_errors', 0);
103 // clear output buffer
106 // export config data
107 $GLOBALS['CONFIG'] = &$this->prop;
112 * Load a host-specific config file if configured
113 * This will merge the host specific configuration with the given one
115 private function load_host_config()
119 if (is_array($this->prop['include_host_config'])) {
120 $fname = $this->prop['include_host_config'][$_SERVER['HTTP_HOST']];
122 else if (!empty($this->prop['include_host_config'])) {
123 $fname = preg_replace('/[^a-z0-9\.\-_]/i', '', $_SERVER['HTTP_HOST']) . '.inc.php';
126 if ($fname && is_file(RCMAIL_CONFIG_DIR . '/' . $fname)) {
127 include(RCMAIL_CONFIG_DIR . '/' . $fname);
128 $this->prop = array_merge($this->prop, (array)$rcmail_config);
134 * Getter for a specific config parameter
136 * @param string Parameter name
137 * @param mixed Default value if not set
138 * @return mixed The requested config value
140 public function get($name, $def = null)
142 return isset($this->prop[$name]) ? $this->prop[$name] : $def;
147 * Setter for a config parameter
149 * @param string Parameter name
150 * @param mixed Parameter value
152 public function set($name, $value)
154 $this->prop[$name] = $value;
159 * Override config options with the given values (eg. user prefs)
161 * @param array Hash array with config props to merge over
163 public function merge($prefs)
165 $this->prop = array_merge($this->prop, $prefs);
170 * Getter for all config options
172 * @return array Hash array containg all config properties
174 public function all()
181 * Return a 24 byte key for the DES encryption
183 * @return string DES encryption key
185 public function get_des_key()
187 $key = !empty($this->prop['des_key']) ? $this->prop['des_key'] : 'rcmail?24BitPwDkeyF**ECB';
190 // make sure the key is exactly 24 chars long
192 $key .= str_repeat('_', 24-$len);
201 * Try to autodetect operating system and find the correct line endings
203 * @return string The appropriate mail header delimiter
205 public function header_delimiter()
207 // use the configured delimiter for headers
208 if (!empty($this->prop['mail_header_delimiter']))
209 return $this->prop['mail_header_delimiter'];
210 else if (strtolower(substr(PHP_OS, 0, 3) == 'win'))
212 else if (strtolower(substr(PHP_OS, 0, 3) == 'mac'))
221 * Return the mail domain configured for the given host
223 * @param string IMAP host
224 * @return string Resolved SMTP host
226 public function mail_domain($host)
230 if (is_array($this->prop['mail_domain'])) {
231 if (isset($this->prop['mail_domain'][$host]))
232 $domain = $this->prop['mail_domain'][$host];
234 else if (!empty($this->prop['mail_domain']))
235 $domain = $this->prop['mail_domain'];
242 * Getter for error state
244 * @return mixed Error message on error, False if no errors
246 public function get_error()
248 return empty($this->errors) ? false : join("\n", $this->errors);