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