commit | author | age
|
197601
|
1 |
<?php |
T |
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 |
033478
|
43 |
* |
T |
44 |
* @todo Remove global $CONFIG |
197601
|
45 |
*/ |
T |
46 |
private function load() |
|
47 |
{ |
|
48 |
// start output buffering, we don't need any output yet, |
|
49 |
// it'll be cleared after reading of config files, etc. |
|
50 |
ob_start(); |
|
51 |
|
|
52 |
// load main config file |
|
53 |
include_once(INSTALL_PATH . 'config/main.inc.php'); |
|
54 |
$this->prop = (array)$rcmail_config; |
|
55 |
|
|
56 |
// load database config |
|
57 |
include_once(INSTALL_PATH . 'config/db.inc.php'); |
|
58 |
$this->prop += (array)$rcmail_config; |
2ca388
|
59 |
|
T |
60 |
// load host-specific configuration |
|
61 |
$this->load_host_config(); |
197601
|
62 |
|
T |
63 |
// fix paths |
67effe
|
64 |
$this->prop['skin'] = $this->prop['skin'] ? unslashify($this->prop['skin']) : 'default'; |
197601
|
65 |
$this->prop['log_dir'] = $this->prop['log_dir'] ? unslashify($this->prop['log_dir']) : INSTALL_PATH . 'logs'; |
T |
66 |
|
|
67 |
// handle aliases |
|
68 |
if (isset($this->prop['locale_string']) && empty($this->prop['language'])) |
|
69 |
$this->prop['language'] = $this->prop['locale_string']; |
|
70 |
|
|
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'); |
|
75 |
} |
|
76 |
if ($this->prop['debug_level'] & 4) { |
|
77 |
ini_set('display_errors', 1); |
|
78 |
} |
|
79 |
else { |
|
80 |
ini_set('display_errors', 0); |
|
81 |
} |
|
82 |
|
|
83 |
// clear output buffer |
|
84 |
ob_end_clean(); |
033478
|
85 |
|
T |
86 |
// export config data |
|
87 |
$GLOBALS['CONFIG'] = &$this->prop; |
197601
|
88 |
} |
T |
89 |
|
|
90 |
|
|
91 |
/** |
|
92 |
* Load a host-specific config file if configured |
|
93 |
* This will merge the host specific configuration with the given one |
|
94 |
*/ |
|
95 |
private function load_host_config() |
|
96 |
{ |
|
97 |
$fname = null; |
|
98 |
|
|
99 |
if (is_array($this->prop['include_host_config'])) { |
|
100 |
$fname = $this->prop['include_host_config'][$_SERVER['HTTP_HOST']]; |
|
101 |
} |
|
102 |
else if (!empty($this->prop['include_host_config'])) { |
|
103 |
$fname = preg_replace('/[^a-z0-9\.\-_]/i', '', $_SERVER['HTTP_HOST']) . '.inc.php'; |
|
104 |
} |
|
105 |
|
|
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); |
|
109 |
} |
|
110 |
} |
|
111 |
|
|
112 |
|
|
113 |
/** |
|
114 |
* Getter for a specific config parameter |
|
115 |
* |
|
116 |
* @param string Parameter name |
|
117 |
* @param mixed Default value if not set |
|
118 |
* @return mixed The requested config value |
|
119 |
*/ |
|
120 |
public function get($name, $def = null) |
|
121 |
{ |
|
122 |
return isset($this->prop[$name]) ? $this->prop[$name] : $def; |
|
123 |
} |
|
124 |
|
|
125 |
|
|
126 |
/** |
|
127 |
* Setter for a config parameter |
|
128 |
* |
|
129 |
* @param string Parameter name |
|
130 |
* @param mixed Parameter value |
|
131 |
*/ |
|
132 |
public function set($name, $value) |
|
133 |
{ |
|
134 |
$this->prop[$name] = $value; |
|
135 |
} |
|
136 |
|
|
137 |
|
|
138 |
/** |
|
139 |
* Override config options with the given values (eg. user prefs) |
|
140 |
* |
|
141 |
* @param array Hash array with config props to merge over |
|
142 |
*/ |
|
143 |
public function merge($prefs) |
|
144 |
{ |
|
145 |
$this->prop = array_merge($this->prop, $prefs); |
|
146 |
} |
|
147 |
|
|
148 |
|
|
149 |
/** |
|
150 |
* Getter for all config options |
|
151 |
* |
|
152 |
* @return array Hash array containg all config properties |
|
153 |
*/ |
|
154 |
public function all() |
|
155 |
{ |
|
156 |
return $this->prop; |
|
157 |
} |
|
158 |
|
1854c4
|
159 |
|
T |
160 |
/** |
|
161 |
* Return a 24 byte key for the DES encryption |
|
162 |
* |
|
163 |
* @return string DES encryption key |
|
164 |
*/ |
|
165 |
public function get_des_key() |
|
166 |
{ |
|
167 |
$key = !empty($this->prop['des_key']) ? $this->prop['des_key'] : 'rcmail?24BitPwDkeyF**ECB'; |
|
168 |
$len = strlen($key); |
|
169 |
|
|
170 |
// make sure the key is exactly 24 chars long |
|
171 |
if ($len<24) |
|
172 |
$key .= str_repeat('_', 24-$len); |
|
173 |
else if ($len>24) |
|
174 |
substr($key, 0, 24); |
|
175 |
|
|
176 |
return $key; |
|
177 |
} |
|
178 |
|
|
179 |
|
83a763
|
180 |
/** |
T |
181 |
* Try to autodetect operating system and find the correct line endings |
|
182 |
* |
|
183 |
* @return string The appropriate mail header delimiter |
|
184 |
*/ |
|
185 |
public function header_delimiter() |
|
186 |
{ |
|
187 |
// use the configured delimiter for headers |
|
188 |
if (!empty($this->prop['mail_header_delimiter'])) |
|
189 |
return $this->prop['mail_header_delimiter']; |
|
190 |
else if (strtolower(substr(PHP_OS, 0, 3) == 'win')) |
|
191 |
return "\r\n"; |
|
192 |
else if (strtolower(substr(PHP_OS, 0, 3) == 'mac')) |
|
193 |
return "\r\n"; |
|
194 |
else |
|
195 |
return "\n"; |
|
196 |
} |
|
197 |
|
|
198 |
|
|
199 |
|
|
200 |
/** |
|
201 |
* Return the mail domain configured for the given host |
|
202 |
* |
|
203 |
* @param string IMAP host |
|
204 |
* @return string Resolved SMTP host |
|
205 |
*/ |
|
206 |
public function mail_domain($host) |
|
207 |
{ |
|
208 |
$domain = $host; |
|
209 |
|
|
210 |
if (is_array($this->prop['mail_domain'])) { |
|
211 |
if (isset($this->prop['mail_domain'][$host])) |
|
212 |
$domain = $this->prop['mail_domain'][$host]; |
|
213 |
} |
|
214 |
else if (!empty($this->prop['mail_domain'])) |
|
215 |
$domain = $this->prop['mail_domain']; |
|
216 |
|
|
217 |
return $domain; |
|
218 |
} |
|
219 |
|
|
220 |
|
197601
|
221 |
} |
T |
222 |
|