d1ae9d4c |
1 | <?php |
134e4174 |
2 | |
30967a1e |
3 | /** |
d1ae9d4c |
4 | * SquirrelMail configtest script |
5 | * |
6c84ba1e |
6 | * Copyright (c) 2003-2005 The SquirrelMail Project Team |
d1ae9d4c |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
30967a1e |
9 | * @version $Id$ |
10 | * @package squirrelmail |
11 | * @subpackage config |
d1ae9d4c |
12 | */ |
13 | |
14 | /************************************************************ |
15 | * NOTE: you do not need to change this script! * |
16 | * If it throws errors you need to adjust your config. * |
17 | ************************************************************/ |
18 | |
df758744 |
19 | // This script could really use some restructuring as it has grown quite rapidly |
20 | // but is not very 'clean'. Feel free to get some structure into this thing. |
21 | |
5b53b7e0 |
22 | function do_err($str, $exit = TRUE) { |
d18703d3 |
23 | global $IND; |
24 | echo '<p>'.$IND.'<font color="red"><b>ERROR:</b></font> ' .$str. "</p>\n"; |
5b53b7e0 |
25 | if($exit) { |
26 | echo '</body></html>'; |
27 | exit; |
28 | } |
29 | } |
30 | |
31 | $IND = str_repeat(' ',4); |
32 | |
33 | ob_implicit_flush(); |
30967a1e |
34 | /** @ignore */ |
5b53b7e0 |
35 | define('SM_PATH', '../'); |
36 | |
37 | /* |
91e0dccc |
38 | * Load config before output begins. functions/strings.php depends on |
5b53b7e0 |
39 | * functions/globals.php. functions/global.php needs to be run before |
91e0dccc |
40 | * any html output starts. If config.php is missing, error will be displayed |
5b53b7e0 |
41 | * later. |
42 | */ |
43 | if (file_exists(SM_PATH . 'config/config.php')) { |
44 | include(SM_PATH . 'config/config.php'); |
45 | include(SM_PATH . 'functions/strings.php'); |
46 | } |
d1ae9d4c |
47 | ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
48 | <html> |
49 | <head> |
50 | <title>SquirrelMail configtest</title> |
51 | </head> |
52 | <body> |
53 | <h1>SquirrelMail configtest</h1> |
54 | |
55 | <p>This script will try to check some aspects of your SquirrelMail configuration |
56 | and point you to errors whereever it can find them. You need to go run <tt>conf.pl</tt> |
d18703d3 |
57 | in the <tt>config/</tt> directory first before you run this script.</p> |
d1ae9d4c |
58 | |
59 | <?php |
60 | |
d1ae9d4c |
61 | |
62 | $included = array_map('basename', get_included_files() ); |
63 | if(!in_array('config.php', $included)) { |
64 | if(!file_exists(SM_PATH . 'config/config.php')) { |
65 | do_err('Config file '.SM_PATH . 'config/config.php does not exist!<br />'. |
66 | 'You need to run <tt>conf.pl</tt> first.'); |
67 | } |
68 | do_err('Could not read '.SM_PATH.'config/config.php! Check file permissions.'); |
69 | } |
70 | if(!in_array('strings.php', $included)) { |
71 | do_err('Could not include '.SM_PATH.'functions/strings.php!<br />'. |
72 | 'Check permissions on that file.'); |
73 | } |
74 | |
75 | /* checking PHP specs */ |
76 | |
17fca61d |
77 | echo "<p><table>\n<tr><td>SquirrelMail version:</td><td><b>" . $version . "</b></td></tr>\n" . |
78 | '<tr><td>Config file version:</td><td><b>' . $config_version . "</b></td></tr>\n" . |
91e0dccc |
79 | '<tr><td>Config file last modified:</td><td><b>' . |
17fca61d |
80 | date ('d F Y H:i:s', filemtime(SM_PATH . 'config/config.php')) . |
81 | "</b></td></tr>\n</table>\n</p>\n\n"; |
d1ae9d4c |
82 | |
83 | echo "Checking PHP configuration...<br />\n"; |
84 | |
abd74f7d |
85 | if(!check_php_version(4,1,0)) { |
86 | do_err('Insufficient PHP version: '. PHP_VERSION . '! Minimum required: 4.1.0'); |
d1ae9d4c |
87 | } |
88 | |
17fca61d |
89 | echo $IND . 'PHP version ' . PHP_VERSION . " OK.<br />\n"; |
d1ae9d4c |
90 | |
91 | $php_exts = array('session','pcre'); |
92 | $diff = array_diff($php_exts, get_loaded_extensions()); |
93 | if(count($diff)) { |
94 | do_err('Required PHP extensions missing: '.implode(', ',$diff) ); |
95 | } |
96 | |
17fca61d |
97 | echo $IND . "PHP extensions OK.<br />\n"; |
d1ae9d4c |
98 | |
99 | |
100 | /* checking paths */ |
101 | |
102 | echo "Checking paths...<br />\n"; |
103 | |
104 | if(!file_exists($data_dir)) { |
105 | do_err("Data dir ($data_dir) does not exist!"); |
91e0dccc |
106 | } |
d1ae9d4c |
107 | if(!is_dir($data_dir)) { |
108 | do_err("Data dir ($data_dir) is not a directory!"); |
91e0dccc |
109 | } |
d1ae9d4c |
110 | if(!is_readable($data_dir)) { |
111 | do_err("I cannot read from data dir ($data_dir)!"); |
91e0dccc |
112 | } |
d1ae9d4c |
113 | if(!is_writable($data_dir)) { |
114 | do_err("I cannot write to data dir ($data_dir)!"); |
115 | } |
116 | |
117 | // todo_ornot: actually write something and read it back. |
118 | echo $IND . "Data dir OK.<br />\n"; |
119 | |
120 | |
121 | if($data_dir == $attachment_dir) { |
122 | echo $IND . "Attachment dir is the same as data dir.<br />\n"; |
123 | } else { |
124 | if(!file_exists($attachment_dir)) { |
125 | do_err("Attachment dir ($attachment_dir) does not exist!"); |
91e0dccc |
126 | } |
d1ae9d4c |
127 | if (!is_dir($attachment_dir)) { |
128 | do_err("Attachment dir ($attachment_dir) is not a directory!"); |
91e0dccc |
129 | } |
d1ae9d4c |
130 | if (!is_writable($attachment_dir)) { |
131 | do_err("I cannot write to attachment dir ($attachment_dir)!"); |
132 | } |
133 | echo $IND . "Attachment dir OK.<br />\n"; |
134 | } |
135 | |
136 | |
137 | /* check plugins and themes */ |
5b53b7e0 |
138 | if (isset($plugins[0])) { |
139 | foreach($plugins as $plugin) { |
140 | if(!file_exists(SM_PATH .'plugins/'.$plugin)) { |
141 | do_err('You have enabled the <i>'.$plugin.'</i> plugin but I cannot find it.', FALSE); |
142 | } elseif (!is_readable(SM_PATH .'plugins/'.$plugin.'/setup.php')) { |
143 | do_err('You have enabled the <i>'.$plugin.'</i> plugin but I cannot read its setup.php file.', FALSE); |
144 | } |
d1ae9d4c |
145 | } |
5b53b7e0 |
146 | echo $IND . "Plugins OK.<br />\n"; |
147 | } else { |
148 | echo $IND . "Plugins are not enabled in config.<br />\n"; |
d1ae9d4c |
149 | } |
d1ae9d4c |
150 | foreach($theme as $thm) { |
151 | if(!file_exists($thm['PATH'])) { |
152 | do_err('You have enabled the <i>'.$thm['NAME'].'</i> theme but I cannot find it ('.$thm['PATH'].').', FALSE); |
153 | } elseif(!is_readable($thm['PATH'])) { |
154 | do_err('You have enabled the <i>'.$thm['NAME'].'</i> theme but I cannot read it ('.$thm['PATH'].').', FALSE); |
155 | } |
156 | } |
157 | |
158 | echo $IND . "Themes OK.<br />\n"; |
159 | |
160 | |
161 | /* check outgoing mail */ |
162 | |
163 | if($use_smtp_tls || $use_imap_tls) { |
164 | if(!check_php_version(4,3,0)) { |
165 | do_err('You need at least PHP 4.3.0 for SMTP/IMAP TLS!'); |
166 | } |
167 | if(!extension_loaded('openssl')) { |
168 | do_err('You need the openssl PHP extension to use SMTP/IMAP TLS!'); |
169 | } |
170 | } |
171 | |
172 | echo "Checking outgoing mail service....<br />\n"; |
173 | |
174 | if($useSendmail) { |
175 | // is_executable also checks for existance, but we want to be as precise as possible with the errors |
176 | if(!file_exists($sendmail_path)) { |
177 | do_err("Location of sendmail program incorrect ($sendmail_path)!"); |
91e0dccc |
178 | } |
d1ae9d4c |
179 | if(!is_executable($sendmail_path)) { |
180 | do_err("I cannot execute the sendmail program ($sendmail_path)!"); |
181 | } |
182 | |
183 | echo $IND . "sendmail OK<br />\n"; |
184 | } else { |
185 | $stream = fsockopen( ($use_smtp_tls?'tls://':'').$smtpServerAddress, $smtpPort, |
186 | $errorNumber, $errorString); |
187 | if(!$stream) { |
188 | do_err("Error connecting to SMTP server \"$smtpServerAddress:$smtpPort\".". |
9c941728 |
189 | "Server error: ($errorNumber) ".htmlspecialchars($errorString)); |
d1ae9d4c |
190 | } |
191 | |
192 | // check for SMTP code; should be 2xx to allow us access |
193 | $smtpline = fgets($stream, 1024); |
194 | if(((int) $smtpline{0}) > 3) { |
9c941728 |
195 | do_err("Error connecting to SMTP server. Server error: ". |
134e4174 |
196 | htmlspecialchars($smtpline)); |
d1ae9d4c |
197 | } |
198 | |
199 | fputs($stream, 'QUIT'); |
200 | fclose($stream); |
9c941728 |
201 | echo $IND . 'SMTP server OK (<tt><small>'. |
202 | trim(htmlspecialchars($smtpline))."</small></tt>)<br />\n"; |
d1ae9d4c |
203 | |
204 | /* POP before SMTP */ |
205 | if($pop_before_smtp) { |
206 | $stream = fsockopen($smtpServerAddress, 110, $err_no, $err_str); |
207 | if (!$stream) { |
9c941728 |
208 | do_err("Error connecting to POP Server ($smtpServerAddress:110) " |
209 | . $err_no . ' : ' . htmlspecialchars($err_str)); |
d1ae9d4c |
210 | } |
211 | |
212 | $tmp = fgets($stream, 1024); |
213 | if (substr($tmp, 0, 3) != '+OK') { |
214 | do_err("Error connecting to POP Server ($smtpServerAddress:110)" |
9c941728 |
215 | . ' '.htmlspecialchars($tmp)); |
d1ae9d4c |
216 | } |
217 | fputs($stream, 'QUIT'); |
218 | fclose($stream); |
219 | echo $IND . "POP-before-SMTP OK.<br />\n"; |
220 | } |
221 | } |
222 | |
df758744 |
223 | /** |
224 | * Check the IMAP server |
225 | */ |
d1ae9d4c |
226 | echo "Checking IMAP service....<br />\n"; |
227 | |
df758744 |
228 | /** Can we open a connection? */ |
d1ae9d4c |
229 | $stream = fsockopen( ($use_imap_tls?'tls://':'').$imapServerAddress, $imapPort, |
230 | $errorNumber, $errorString); |
231 | if(!$stream) { |
70b71161 |
232 | do_err("Error connecting to IMAP server \"$imapServerAddress:$imapPort\".". |
9c941728 |
233 | "Server error: ($errorNumber) ". |
134e4174 |
234 | htmlspecialchars($errorString)); |
d1ae9d4c |
235 | } |
236 | |
df758744 |
237 | /** Is the first response 'OK'? */ |
d1ae9d4c |
238 | $imapline = fgets($stream, 1024); |
239 | if(substr($imapline, 0,4) != '* OK') { |
9c941728 |
240 | do_err('Error connecting to IMAP server. Server error: '. |
241 | htmlspecialchars($imapline)); |
d1ae9d4c |
242 | } |
243 | |
df758744 |
244 | echo $IND . 'IMAP server ready (<tt><small>'. |
9c941728 |
245 | htmlspecialchars(trim($imapline))."</small></tt>)<br />\n"; |
d1ae9d4c |
246 | |
df758744 |
247 | /** Check capabilities */ |
248 | fputs($stream, "A001 CAPABILITY\r\n"); |
249 | $capline = fgets($stream, 1024); |
250 | |
251 | echo $IND . 'Capabilities: <tt>'.htmlspecialchars($capline)."</tt><br />\n"; |
252 | |
253 | if($imap_auth_mech == 'login' && stristr($capline, 'LOGINDISABLED') !== FALSE) { |
254 | do_err('Your server doesn\'t allow plaintext logins. '. |
255 | 'Try enabling another authentication mechanism like CRAM-MD5, DIGEST-MD5 or TLS-encryption '. |
256 | 'in the SquirrelMail configuration.', FALSE); |
257 | } |
258 | if($use_imap_tls && stristr($capline, 'STARTTLS') === FALSE) { |
259 | do_err('You have enabled TLS encryption in the config, but the server does not '. |
260 | 'report STARTTLS capability. TLS is probably not supported.', FALSE); |
261 | } |
262 | |
263 | /** OK, close connection */ |
264 | fputs($stream, "A002 LOGOUT\r\n"); |
265 | fclose($stream); |
266 | |
17fca61d |
267 | echo "Checking internationalization (i18n) settings...<br />\n"; |
0ed3bdc3 |
268 | echo "$IND gettext - "; |
269 | if (function_exists('gettext')) { |
270 | echo "Gettext functions are available. You must have appropriate system locales compiled.<br />\n"; |
271 | } else { |
272 | echo "Gettext functions are unavailable. SquirrelMail will use slower internal gettext functions.<br />\n"; |
273 | } |
274 | echo "$IND mbstring - "; |
275 | if (function_exists('mb_detect_encoding')) { |
276 | echo "Mbstring functions are available.<br />\n"; |
277 | } else { |
278 | echo "Mbstring functions are unavailable. Japanese translation won't work.<br />\n"; |
279 | } |
280 | echo "$IND recode - "; |
281 | if (function_exists('recode')) { |
282 | echo "Recode functions are available.<br />\n"; |
283 | } elseif ($use_php_recode) { |
284 | echo "Recode functions are unavailable.<br />\n"; |
285 | do_err('Your configuration requires recode support, but recode support is missing.'); |
286 | } else { |
287 | echo "Recode functions are unavailable.<br />\n"; |
288 | } |
289 | echo "$IND iconv - "; |
290 | if (function_exists('iconv')) { |
291 | echo "Iconv functions are available.<br />\n"; |
292 | } elseif ($use_php_iconv) { |
293 | echo "Iconv functions are unavailable.<br />\n"; |
294 | do_err('Your configuration requires iconv support, but iconv support is missing.'); |
295 | } else { |
296 | echo "Iconv functions are unavailable.<br />\n"; |
297 | } |
298 | // same test as in include/validate.php |
299 | echo "$IND timezone - "; |
300 | if ( (!ini_get('safe_mode')) || |
301 | !strcmp(ini_get('safe_mode_allowed_env_vars'),'') || |
302 | preg_match('/^([\w_]+,)*TZ/', ini_get('safe_mode_allowed_env_vars')) ) { |
134e4174 |
303 | echo "Webmail users can change their time zone settings.<br />\n"; |
0ed3bdc3 |
304 | } else { |
4764a7ff |
305 | echo "Webmail users can't change their time zone settings.<br />\n"; |
306 | } |
307 | |
d18703d3 |
308 | |
4764a7ff |
309 | // Pear DB tests |
d18703d3 |
310 | echo "Checking database functions...<br />\n"; |
311 | if($addrbook_dsn || $prefs_dsn || $addrbook_global_dsn) { |
134e4174 |
312 | @include_once('DB.php'); |
313 | if (class_exists('DB')) { |
314 | echo "$IND PHP Pear DB support is present.<br />\n"; |
315 | $db_functions=array( |
91e0dccc |
316 | 'dbase' => 'dbase_open', |
317 | 'fbsql' => 'fbsql_connect', |
318 | 'interbase' => 'ibase_connect', |
134e4174 |
319 | 'informix' => 'ifx_connect', |
320 | 'msql' => 'msql_connect', |
321 | 'mssql' => 'mssql_connect', |
322 | 'mysql' => 'mysql_connect', |
323 | 'mysqli' => 'mysqli_connect', |
324 | 'oci8' => 'ocilogon', |
325 | 'odbc' => 'odbc_connect', |
326 | 'pgsql' => 'pgsql_connect', |
327 | 'sqlite' => 'sqlite_open', |
328 | 'sybase' => 'sybase_connect' |
329 | ); |
330 | |
331 | $dsns = array(); |
332 | if($prefs_dsn) { |
333 | $dsns['preferences'] = $prefs_dsn; |
334 | } |
335 | if($addrbook_dsn) { |
336 | $dsns['addressbook'] = $addrbook_dsn; |
337 | } |
338 | if($addrbook_global_dsn) { |
339 | $dsns['global addressbook'] = $addrbook_global_dsn; |
340 | } |
341 | |
342 | foreach($dsns as $type => $dsn) { |
343 | $dbtype = array_shift(explode(':', $dsn)); |
344 | if(isset($db_functions[$dbtype]) && function_exists($db_functions[$dbtype])) { |
345 | echo "$IND$dbtype database support present.<br />\n"; |
346 | |
347 | // now, test this interface: |
348 | |
349 | $dbh = DB::connect($dsn, true); |
350 | if (DB::isError($dbh)) { |
351 | do_err('Database error: '. htmlspecialchars(DB::errorMessage($dbh)) . |
352 | ' in ' .$type .' DSN.'); |
353 | } |
354 | $dbh->disconnect(); |
355 | echo "$IND$type database connect successful.<br />\n"; |
356 | |
357 | } else { |
358 | do_err($db.' database support not present!'); |
d18703d3 |
359 | } |
134e4174 |
360 | } |
361 | } else { |
362 | do_err('Required PHP PEAR DB support is not available. Is PEAR installed and is the |
363 | include path set correctly to find <tt>DB.php</tt>? The include path is now: |
364 | "<tt>' . ini_get('include_path') . '</tt>".'); |
365 | } |
4764a7ff |
366 | } else { |
d18703d3 |
367 | echo $IND."not using database functionality.<br />\n"; |
0ed3bdc3 |
368 | } |
7562c55b |
369 | |
370 | // LDAP DB tests |
371 | echo "Checking LDAP functions...<br />\n"; |
372 | if( empty($ldap_server) ) { |
134e4174 |
373 | echo $IND."not using LDAP functionality.<br />\n"; |
7562c55b |
374 | } else { |
375 | if ( !function_exists(ldap_connect) ) { |
376 | do_err('Required LDAP support is not available.'); |
377 | } else { |
134e4174 |
378 | echo "$IND LDAP support present.<br />\n"; |
7562c55b |
379 | foreach ( $ldap_server as $param ) { |
380 | |
381 | $linkid = ldap_connect($param['host'], (empty($param['port']) ? 389 : $param['port']) ); |
382 | |
383 | if ( $linkid ) { |
134e4174 |
384 | echo "$IND LDAP connect to ".$param['host']." successful: ".$linkid."<br />\n"; |
91e0dccc |
385 | |
7562c55b |
386 | if ( !empty($param['protocol']) && |
387 | !ldap_set_option($linkid, LDAP_OPT_PROTOCOL_VERSION, $param['protocol']) ) { |
388 | do_err('Unable to set LDAP protocol'); |
91e0dccc |
389 | } |
7562c55b |
390 | |
391 | if ( empty($param['binddn']) ) { |
91e0dccc |
392 | $bind = ldap_bind($linkid); |
7562c55b |
393 | } else { |
394 | $bind = ldap_bind($param['binddn'], $param['bindpw']); |
395 | } |
396 | |
397 | if ( $bind ) { |
398 | echo "$IND LDAP Bind Successful <br />"; |
399 | } else { |
400 | do_err('Unable to Bind to LDAP Server'); |
401 | } |
91e0dccc |
402 | |
7562c55b |
403 | ldap_close($linkid); |
404 | } else { |
405 | do_err('Connection to LDAP failed'); |
406 | } |
407 | } |
408 | } |
409 | } |
d1ae9d4c |
410 | ?> |
411 | |
412 | <p>Congratulations, your SquirrelMail setup looks fine to me!</p> |
413 | |
13721b47 |
414 | <p><a href="login.php">Login now</a></p> |
d1ae9d4c |
415 | |
416 | </body> |
417 | </html> |
17fca61d |
418 | <?php |
419 | // vim: et ts=4 |
91e0dccc |
420 | ?> |