resubmitting last Monday updates and adding php 5.1.0 timezone support
[squirrelmail.git] / src / configtest.php
1 <?php
2
3 /**
4 * SquirrelMail configtest script
5 *
6 * @copyright &copy; 2003-2006 The SquirrelMail Project Team
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
8 * @version $Id$
9 * @package squirrelmail
10 * @subpackage config
11 */
12
13 /************************************************************
14 * NOTE: you do not need to change this script! *
15 * If it throws errors you need to adjust your config. *
16 ************************************************************/
17
18 // This script could really use some restructuring as it has grown quite rapidly
19 // but is not very 'clean'. Feel free to get some structure into this thing.
20 $warnings = 0;
21
22 function do_err($str, $fatal = TRUE) {
23 global $IND, $warnings;
24 $level = $fatal ? 'FATAL ERROR:' : 'WARNING:';
25 echo '<p>'.$IND.'<font color="red"><b>' . $level . '</b></font> ' .$str. "</p>\n";
26 if($fatal) {
27 echo '</body></html>';
28 exit;
29 } else {
30 $warnings++;
31 }
32 }
33
34 $IND = str_repeat('&nbsp;',4);
35
36 ob_implicit_flush();
37 /** @ignore */
38 define('SM_PATH', '../');
39
40 /* set default value in order to block remote access to script */
41 $allow_remote_configtest=false;
42
43 /*
44 * Load config before output begins. functions/strings.php depends on
45 * functions/globals.php. functions/global.php needs to be run before
46 * any html output starts. If config.php is missing, error will be displayed
47 * later.
48 */
49 if (file_exists(SM_PATH . 'config/config.php')) {
50 require(SM_PATH . 'config/config.php');
51 }
52 require(SM_PATH . 'functions/global.php');
53 require(SM_PATH . 'functions/strings.php');
54
55 /**
56 * get_location starts session and must be run before output is started.
57 */
58 $test_location = get_location();
59
60 ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
61 "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
62 <html>
63 <head>
64 <meta name="robots" content="noindex,nofollow">
65 <title>SquirrelMail configtest</title>
66 </head>
67 <body>
68 <h1>SquirrelMail configtest</h1>
69
70 <p>This script will try to check some aspects of your SquirrelMail configuration
71 and point you to errors whereever it can find them. You need to go run <tt>conf.pl</tt>
72 in the <tt>config/</tt> directory first before you run this script.</p>
73
74 <?php
75
76 $included = array_map('basename', get_included_files() );
77 if(!in_array('config.php', $included)) {
78 if(!file_exists(SM_PATH . 'config/config.php')) {
79 do_err('Config file '.SM_PATH . 'config/config.php does not exist!<br />'.
80 'You need to run <tt>conf.pl</tt> first.');
81 }
82 do_err('Could not read '.SM_PATH.'config/config.php! Check file permissions.');
83 }
84 if(!in_array('strings.php', $included)) {
85 do_err('Could not include '.SM_PATH.'functions/strings.php!<br />'.
86 'Check permissions on that file.');
87 }
88
89 /* Block remote use of script */
90 if (! $allow_remote_configtest) {
91 sqGetGlobalVar('REMOTE_ADDR',$client_ip,SQ_SERVER);
92 sqGetGlobalVar('SERVER_ADDR',$server_ip,SQ_SERVER);
93
94 if ((! isset($client_ip) || $client_ip!='127.0.0.1') &&
95 (! isset($client_ip) || ! isset($server_ip) || $client_ip!=$server_ip)) {
96 do_err('Enable "Allow remote configtest" option in squirrelmail configuration in order to use this script.');
97 }
98 }
99 /* checking PHP specs */
100
101 echo "<p><table>\n<tr><td>SquirrelMail version:</td><td><b>" . $version . "</b></td></tr>\n" .
102 '<tr><td>Config file version:</td><td><b>' . $config_version . "</b></td></tr>\n" .
103 '<tr><td>Config file last modified:</td><td><b>' .
104 date ('d F Y H:i:s', filemtime(SM_PATH . 'config/config.php')) .
105 "</b></td></tr>\n</table>\n</p>\n\n";
106
107 /* check $config_version */
108 if ($config_version!='1.4.0') {
109 do_err('Configuration file version does not match required version. Please update your configuration file.');
110 }
111
112 echo "Checking PHP configuration...<br />\n";
113
114 if(!check_php_version(4,1,0)) {
115 do_err('Insufficient PHP version: '. PHP_VERSION . '! Minimum required: 4.1.0');
116 }
117
118 echo $IND . 'PHP version ' . PHP_VERSION . ' OK. (You have: ' . phpversion() . ". Minimum: 4.1.0)<br />\n";
119 /* test for boolean false and any string that is not equal to 'off' */
120 if ((bool) ini_get('register_globals') &&
121 strtolower(ini_get('register_globals'))!='off') {
122 do_err('You have register_globals turned on. This is not an error, but it CAN be a security hazard. Consider turning register_globals off.', false);
123 }
124 $php_exts = array('session','pcre');
125 $diff = array_diff($php_exts, get_loaded_extensions());
126 if(count($diff)) {
127 do_err('Required PHP extensions missing: '.implode(', ',$diff) );
128 }
129
130 echo $IND . "PHP extensions OK.<br />\n";
131
132 /* dangerous php settings */
133 /**
134 * mbstring.func_overload allows to replace original string and regexp functions
135 * with their equivalents from php mbstring extension. It causes problems when
136 * scripts analyze 8bit strings byte after byte or use 8bit strings in regexp tests.
137 * Setting can be controlled in php.ini (php 4.2.0), webserver config (php 4.2.0)
138 * and .htaccess files (php 4.3.5).
139 */
140 if (function_exists('mb_internal_encoding') &&
141 check_php_version(4,2,0) &&
142 (int)ini_get('mbstring.func_overload')!=0) {
143 $mb_error='You have enabled mbstring overloading.'
144 .' It can cause problems with SquirrelMail scripts that rely on single byte string functions.';
145 do_err($mb_error);
146 }
147
148 /* checking paths */
149
150 echo "Checking paths...<br />\n";
151
152 if(!file_exists($data_dir)) {
153 // data_dir is not that important in db_setups.
154 if (isset($prefs_dsn) && ! empty($prefs_dsn)) {
155 $data_dir_error = "Data dir ($data_dir) does not exist!\n";
156 echo $IND .'<font color="red"><b>ERROR:</b></font> ' . $data_dir_error;
157 } else {
158 do_err("Data dir ($data_dir) does not exist!");
159 }
160 }
161 // don't check if errors
162 if(!isset($data_dir_error) && !is_dir($data_dir)) {
163 if (isset($prefs_dsn) && ! empty($prefs_dsn)) {
164 $data_dir_error = "Data dir ($data_dir) is not a directory!\n";
165 echo $IND . '<font color="red"><b>ERROR:</b></font> ' . $data_dir_error;
166 } else {
167 do_err("Data dir ($data_dir) is not a directory!");
168 }
169 }
170 // datadir should be executable - but no clean way to test on that
171 if(!isset($data_dir_error) && !is_writable($data_dir)) {
172 if (isset($prefs_dsn) && ! empty($prefs_dsn)) {
173 $data_dir_error = "Data dir ($data_dir) is not writable!\n";
174 echo $IND . '<font color="red"><b>ERROR:</b></font> ' . $data_dir_error;
175 } else {
176 do_err("Data dir ($data_dir) is not writable!");
177 }
178 }
179
180 if (isset($data_dir_error)) {
181 echo " Some plugins might need access to data directory.<br />\n";
182 } else {
183 // todo_ornot: actually write something and read it back.
184 echo $IND . "Data dir OK.<br />\n";
185 }
186
187 if($data_dir == $attachment_dir) {
188 echo $IND . "Attachment dir is the same as data dir.<br />\n";
189 if (isset($data_dir_error)) {
190 do_err($data_dir_error);
191 }
192 } else {
193 if(!file_exists($attachment_dir)) {
194 do_err("Attachment dir ($attachment_dir) does not exist!");
195 }
196 if (!is_dir($attachment_dir)) {
197 do_err("Attachment dir ($attachment_dir) is not a directory!");
198 }
199 if (!is_writable($attachment_dir)) {
200 do_err("I cannot write to attachment dir ($attachment_dir)!");
201 }
202 echo $IND . "Attachment dir OK.<br />\n";
203 }
204
205
206 /* check plugins and themes */
207 $bad_plugins = array(
208 'attachment_common', // Integrated into SquirrelMail 1.2 core
209 'auto_prune_sent', // Obsolete: See Proon Automatic Folder Pruning plugin
210 'compose_new_window', // Integrated into SquirrelMail 1.4 core
211 'delete_move_next', // Integrated into SquirrelMail 1.5 core
212 'disk_quota', // Obsolete: See Check Quota plugin
213 'email_priority', // Integrated into SquirrelMail 1.2 core
214 'emoticons', // Obsolete: See HTML Mail plugin
215 'focus_change', // Integrated into SquirrelMail 1.2 core
216 'folder_settings', // Integrated into SquirrelMail 1.5.1 core
217 'global_sql_addressbook', // Integrated into SquirrelMail 1.4 core
218 'hancock', // Not Working: See Random Signature Taglines plugin
219 'msg_flags', // Integrated into SquirrelMail 1.5.1 core
220 'message_source', // Added to SquirrelMail 1.4 Core Plugins (message_details)
221 'motd', // Integrated into SquirrelMail 1.2 core
222 'paginator', // Integrated into SquirrelMail 1.2 core
223 'printer_friendly', // Integrated into SquirrelMail 1.2 core
224 'procfilter', // Obsolete: See Server Side Filter plugin
225 'redhat_php_cgi_fix', // Integrated into SquirrelMail 1.1.1 core
226 'send_to_semicolon', // Integrated into SquirrelMail 1.4.1 core
227 'spamassassin', // Not working beyond SquirrelMail 1.2.7: See Spamassassin SpamFilter (Frontend) v2 plugin
228 'sqcalendar', // Added to SquirrelMail 1.2 Core Plugins (calendar)
229 'sqclock', // Integrated into SquirrelMail 1.2 core
230 'sql_squirrel_logger', // Obsolete: See Squirrel Logger plugin
231 'tmda', // Obsolete: See TMDA Tools plugin
232 'vacation', // Obsolete: See Vacation Local plugin
233 'view_as_html', // Integrated into SquirrelMail 1.5.1 core
234 'xmailer' // Integrated into SquirrelMail 1.2 core
235 );
236
237 if (isset($plugins[0])) {
238 foreach($plugins as $plugin) {
239 if(!file_exists(SM_PATH .'plugins/'.$plugin)) {
240 do_err('You have enabled the <i>'.$plugin.'</i> plugin, but I cannot find it.', FALSE);
241 } elseif (!is_readable(SM_PATH .'plugins/'.$plugin.'/setup.php')) {
242 do_err('You have enabled the <i>'.$plugin.'</i> plugin, but I cannot read its setup.php file.', FALSE);
243 } elseif (in_array($plugin, $bad_plugins)) {
244 do_err('You have enabled the <i>'.$plugin.'</i> plugin, which causes problems with this version of SquirrelMail. Please check the ReleaseNotes or other documentation for more information.', false);
245 }
246 }
247 // load plugin functions
248 include_once(SM_PATH . 'functions/plugin.php');
249 // turn on output buffering in order to prevent output of new lines
250 ob_start();
251 foreach ($plugins as $name) {
252 use_plugin($name);
253 }
254 // get output and remove whitespace
255 $output = trim(ob_get_contents());
256 ob_end_clean();
257 // if plugins output more than newlines and spacing, stop script execution.
258 if (!empty($output)) {
259 $plugin_load_error = 'Some output is produced when plugins are loaded.'
260 .' Usually it means error. Output said: '.htmlspecialchars($output);
261 do_err($plugin_load_error);
262 }
263 /**
264 * Hook is added in 1.5.2. Plugins should print error message and return true
265 * if there is an error in plugin.
266 */
267 $plugin_err = boolean_hook_function('configtest');
268 if($plugin_err) {
269 do_err('Some plugin tests failed.');
270 } else {
271 echo $IND . "Plugins OK.<br />\n";
272 }
273 } else {
274 echo $IND . "Plugins are not enabled in config.<br />\n";
275 }
276 foreach($theme as $thm) {
277 if(!file_exists($thm['PATH'])) {
278 do_err('You have enabled the <i>'.$thm['NAME'].'</i> theme but I cannot find it ('.$thm['PATH'].').', FALSE);
279 } elseif(!is_readable($thm['PATH'])) {
280 do_err('You have enabled the <i>'.$thm['NAME'].'</i> theme but I cannot read it ('.$thm['PATH'].').', FALSE);
281 }
282 }
283
284 echo $IND . "Themes OK.<br />\n";
285
286 if ( $squirrelmail_default_language != 'en_US' ) {
287 $loc_path = SM_PATH .'locale/'.$squirrelmail_default_language.'/LC_MESSAGES/squirrelmail.mo';
288 if( ! file_exists( $loc_path ) ) {
289 do_err('You have set <i>' . $squirrelmail_default_language .
290 '</i> as your default language, but I cannot find this translation (should be '.
291 'in <tt>' . $loc_path . '</tt>). Please note that you have to download translations '.
292 'separately from the main SquirrelMail package.', FALSE);
293 } elseif ( ! is_readable( $loc_path ) ) {
294 do_err('You have set <i>' . $squirrelmail_default_language .
295 '</i> as your default language, but I cannot read this translation (file '.
296 'in <tt>' . $loc_path . '</tt> unreadable).', FALSE);
297 } else {
298 echo $IND . "Default language OK.<br />\n";
299 }
300 } else {
301 echo $IND . "Default language OK.<br />\n";
302 }
303
304 echo $IND . "Base URL detected as: <tt>" . htmlspecialchars($test_location) . "</tt><br />\n";
305
306 /* check minimal requirements for other security options */
307
308 /* imaps or ssmtp */
309 if($use_smtp_tls == 1 || $use_imap_tls == 1) {
310 if(!check_php_version(4,3,0)) {
311 do_err('You need at least PHP 4.3.0 for SMTP/IMAP TLS!');
312 }
313 if(!extension_loaded('openssl')) {
314 do_err('You need the openssl PHP extension to use SMTP/IMAP TLS!');
315 }
316 }
317 /* starttls extensions */
318 if($use_smtp_tls === 2 || $use_imap_tls === 2) {
319 if (! function_exists('stream_socket_enable_crypto')) {
320 do_err('If you want to use STARTTLS extension, you need stream_socket_enable_crypto() function from PHP 5.1.0 and newer.');
321 }
322 }
323 /* digest-md5 */
324 if ($smtp_auth_mech=='digest-md5' || $imap_auth_mech =='digest-md5') {
325 if (!extension_loaded('xml')) {
326 do_err('You need the PHP XML extension to use Digest-MD5 authentication!');
327 }
328 }
329
330 /* check outgoing mail */
331
332 echo "Checking outgoing mail service....<br />\n";
333
334 if($useSendmail) {
335 // is_executable also checks for existance, but we want to be as precise as possible with the errors
336 if(!file_exists($sendmail_path)) {
337 do_err("Location of sendmail program incorrect ($sendmail_path)!");
338 }
339 if(!is_executable($sendmail_path)) {
340 do_err("I cannot execute the sendmail program ($sendmail_path)!");
341 }
342
343 echo $IND . "sendmail OK<br />\n";
344 } else {
345 $stream = fsockopen( ($use_smtp_tls==1?'tls://':'').$smtpServerAddress, $smtpPort,
346 $errorNumber, $errorString);
347 if(!$stream) {
348 do_err("Error connecting to SMTP server \"$smtpServerAddress:$smtpPort\".".
349 "Server error: ($errorNumber) ".htmlspecialchars($errorString));
350 }
351
352 // check for SMTP code; should be 2xx to allow us access
353 $smtpline = fgets($stream, 1024);
354 if(((int) $smtpline{0}) > 3) {
355 do_err("Error connecting to SMTP server. Server error: ".
356 htmlspecialchars($smtpline));
357 }
358
359 /* smtp starttls checks */
360 if ($use_smtp_tls===2) {
361 // if something breaks, script should close smtp connection on exit.
362
363 // say helo
364 fwrite($stream,"EHLO $client_ip\r\n");
365
366 $ehlo=array();
367 $ehlo_error = false;
368 while ($line=fgets($stream, 1024)){
369 if (preg_match("/^250(-|\s)(\S*)\s+(\S.*)/",$line,$match)||
370 preg_match("/^250(-|\s)(\S*)\s+/",$line,$match)) {
371 if (!isset($match[3])) {
372 // simple one word extension
373 $ehlo[strtoupper($match[2])]='';
374 } else {
375 // ehlo-keyword + ehlo-param
376 $ehlo[strtoupper($match[2])]=trim($match[3]);
377 }
378 if ($match[1]==' ') {
379 $ret = $line;
380 break;
381 }
382 } else {
383 //
384 $ehlo_error = true;
385 $ehlo[]=$line;
386 break;
387 }
388 }
389 if ($ehlo_error) {
390 do_err('SMTP EHLO failed. You need ESMTP support for SMTP STARTTLS');
391 } elseif (!array_key_exists('STARTTLS',$ehlo)) {
392 do_err('STARTTLS support is not declared by SMTP server.');
393 }
394
395 fwrite($stream,"STARTTLS\r\n");
396 $starttls_response=fgets($stream, 1024);
397 if ($starttls_response[0]!=2) {
398 $starttls_cmd_err = 'SMTP STARTTLS failed. Server replied: '
399 .htmlspecialchars($starttls_response);
400 do_err($starttls_cmd_err);
401 } elseif(! stream_socket_enable_crypto($stream,true,STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
402 do_err('Failed to enable encryption on SMTP STARTTLS connection.');
403 } else {
404 echo $IND . "SMTP STARTTLS extension looks OK.<br />\n";
405 }
406 // According to RFC we should second ehlo call here.
407 }
408
409 fputs($stream, 'QUIT');
410 fclose($stream);
411 echo $IND . 'SMTP server OK (<tt><small>'.
412 trim(htmlspecialchars($smtpline))."</small></tt>)<br />\n";
413
414 /* POP before SMTP */
415 if($pop_before_smtp) {
416 $stream = fsockopen($smtpServerAddress, 110, $err_no, $err_str);
417 if (!$stream) {
418 do_err("Error connecting to POP Server ($smtpServerAddress:110) "
419 . $err_no . ' : ' . htmlspecialchars($err_str));
420 }
421
422 $tmp = fgets($stream, 1024);
423 if (substr($tmp, 0, 3) != '+OK') {
424 do_err("Error connecting to POP Server ($smtpServerAddress:110)"
425 . ' '.htmlspecialchars($tmp));
426 }
427 fputs($stream, 'QUIT');
428 fclose($stream);
429 echo $IND . "POP-before-SMTP OK.<br />\n";
430 }
431 }
432
433 /**
434 * Check the IMAP server
435 */
436 echo "Checking IMAP service....<br />\n";
437
438 /** Can we open a connection? */
439 $stream = fsockopen( ($use_imap_tls==1?'tls://':'').$imapServerAddress, $imapPort,
440 $errorNumber, $errorString);
441 if(!$stream) {
442 do_err("Error connecting to IMAP server \"$imapServerAddress:$imapPort\".".
443 "Server error: ($errorNumber) ".
444 htmlspecialchars($errorString));
445 }
446
447 /** Is the first response 'OK'? */
448 $imapline = fgets($stream, 1024);
449 if(substr($imapline, 0,4) != '* OK') {
450 do_err('Error connecting to IMAP server. Server error: '.
451 htmlspecialchars($imapline));
452 }
453
454 echo $IND . 'IMAP server ready (<tt><small>'.
455 htmlspecialchars(trim($imapline))."</small></tt>)<br />\n";
456
457 /** Check capabilities */
458 fputs($stream, "A001 CAPABILITY\r\n");
459 $capline = '';
460 while ($line=fgets($stream, 1024)){
461 if (preg_match("/A001.*/",$line)) {
462 break;
463 } else {
464 $capline.=$line;
465 }
466 }
467
468 /* don't display capabilities before STARTTLS */
469 if ($use_imap_tls===2 && stristr($capline, 'STARTTLS') === false) {
470 do_err('Your server doesn\'t support STARTTLS.');
471 } elseif($use_imap_tls===2) {
472 /* try starting starttls */
473 fwrite($stream,"A002 STARTTLS\r\n");
474 $starttls_line=fgets($stream, 1024);
475 if (! preg_match("/^A002 OK.*/i",$starttls_line)) {
476 $imap_starttls_err = 'IMAP STARTTLS failed. Server replied: '
477 .htmlspecialchars($starttls_line);
478 do_err($imap_starttls_err);
479 } elseif (! stream_socket_enable_crypto($stream,true,STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
480 do_err('Failed to enable encryption on IMAP connection.');
481 } else {
482 echo $IND . "IMAP STARTTLS extension looks OK.<br />\n";
483 }
484
485 // get new capability line
486 fwrite($stream,"A003 CAPABILITY\r\n");
487 $capline='';
488 while ($line=fgets($stream, 1024)){
489 if (preg_match("/A003.*/",$line)) {
490 break;
491 } else {
492 $capline.=$line;
493 }
494 }
495 }
496
497 echo $IND . 'Capabilities: <tt>'.htmlspecialchars($capline)."</tt><br />\n";
498
499 if($imap_auth_mech == 'login' && stristr($capline, 'LOGINDISABLED') !== FALSE) {
500 do_err('Your server doesn\'t allow plaintext logins. '.
501 'Try enabling another authentication mechanism like CRAM-MD5, DIGEST-MD5 or TLS-encryption '.
502 'in the SquirrelMail configuration.', FALSE);
503 }
504
505 /** OK, close connection */
506 fputs($stream, "A004 LOGOUT\r\n");
507 fclose($stream);
508
509 echo "Checking internationalization (i18n) settings...<br />\n";
510 echo "$IND gettext - ";
511 if (function_exists('gettext')) {
512 echo 'Gettext functions are available.'
513 .' On some systems you must have appropriate system locales compiled.'
514 ."<br />\n";
515
516 /* optional setlocale() tests. Should work only on glibc systems. */
517 if (sqgetGlobalVar('testlocales',$testlocales,SQ_GET)) {
518 include_once(SM_PATH . 'include/languages.php');
519 echo $IND . $IND . 'Testing translations:<br>';
520 foreach ($languages as $lang_code => $lang_data) {
521 /* don't test aliases */
522 if (isset($lang_data['NAME'])) {
523 /* locale can be $lang_code or $lang_data['LOCALE'] */
524 if (isset($lang_data['LOCALE'])) {
525 $setlocale = $lang_data['LOCALE'];
526 } else {
527 $setlocale = $lang_code;
528 }
529 /* prepare information about tested locales */
530 if (is_array($setlocale)) {
531 $display_locale = implode(', ',$setlocale);
532 $locale_count = count($setlocale);
533 } else {
534 $display_locale = $setlocale;
535 $locale_count = 1;
536 }
537 $tested_locales_msg = 'Tested '.htmlspecialchars($display_locale).' '
538 .($locale_count>1 ? 'locales':'locale'). '.';
539
540 echo $IND . $IND .$IND . $lang_data['NAME'].' (' .$lang_code. ') - ';
541 $retlocale = sq_setlocale(LC_ALL,$setlocale);
542 if (is_bool($retlocale)) {
543 echo '<font color="red">unsupported</font>. ';
544 echo $tested_locales_msg;
545 } else {
546 echo 'supported. '
547 .$tested_locales_msg
548 .' setlocale() returned "'.htmlspecialchars($retlocale).'"';
549 }
550 echo "<br />\n";
551 }
552 }
553 echo $IND . $IND . '<a href="configtest.php">Don\'t test translations</a>';
554 } else {
555 echo $IND . $IND . '<a href="configtest.php?testlocales=1">Test translations</a>. '
556 .'This test is not accurate and might work only on some systems.'
557 ."\n";
558 }
559 echo "<br />\n";
560 /* end of translation tests */
561 } else {
562 echo 'Gettext functions are unavailable.'
563 .' SquirrelMail will use slower internal gettext functions.'
564 ."<br />\n";
565 }
566 echo "$IND mbstring - ";
567 if (function_exists('mb_detect_encoding')) {
568 echo "Mbstring functions are available.<br />\n";
569 } else {
570 echo 'Mbstring functions are unavailable.'
571 ." Japanese translation won't work.<br />\n";
572 }
573 echo "$IND recode - ";
574 if (function_exists('recode')) {
575 echo "Recode functions are available.<br />\n";
576 } elseif (isset($use_php_recode) && $use_php_recode) {
577 echo "Recode functions are unavailable.<br />\n";
578 do_err('Your configuration requires recode support, but recode support is missing.');
579 } else {
580 echo "Recode functions are unavailable.<br />\n";
581 }
582 echo "$IND iconv - ";
583 if (function_exists('iconv')) {
584 echo "Iconv functions are available.<br />\n";
585 } elseif (isset($use_php_iconv) && $use_php_iconv) {
586 echo "Iconv functions are unavailable.<br />\n";
587 do_err('Your configuration requires iconv support, but iconv support is missing.');
588 } else {
589 echo "Iconv functions are unavailable.<br />\n";
590 }
591 // same test as in include/init.php + date_default_timezone_set check
592 echo "$IND timezone - ";
593 if ( (!ini_get('safe_mode')) || function_exists('date_default_timezone_set') ||
594 !strcmp(ini_get('safe_mode_allowed_env_vars'),'') ||
595 preg_match('/^([\w_]+,)*TZ/', ini_get('safe_mode_allowed_env_vars')) ) {
596 echo "Webmail users can change their time zone settings. \n";
597 } else {
598 echo "Webmail users can't change their time zone settings. \n";
599 }
600 if (isset($_ENV['TZ'])) {
601 echo 'Default time zone is '.htmlspecialchars($_ENV['TZ']);
602 } else {
603 echo 'Current time zone is '.date('T');
604 }
605 echo ".<br />\n";
606
607 // Pear DB tests
608 echo "Checking database functions...<br />\n";
609 if($addrbook_dsn || $prefs_dsn || $addrbook_global_dsn) {
610 @include_once('DB.php');
611 if (class_exists('DB')) {
612 echo "$IND PHP Pear DB support is present.<br />\n";
613 $db_functions=array(
614 'dbase' => 'dbase_open',
615 'fbsql' => 'fbsql_connect',
616 'interbase' => 'ibase_connect',
617 'informix' => 'ifx_connect',
618 'msql' => 'msql_connect',
619 'mssql' => 'mssql_connect',
620 'mysql' => 'mysql_connect',
621 'mysqli' => 'mysqli_connect',
622 'oci8' => 'ocilogon',
623 'odbc' => 'odbc_connect',
624 'pgsql' => 'pg_connect',
625 'sqlite' => 'sqlite_open',
626 'sybase' => 'sybase_connect'
627 );
628
629 $dsns = array();
630 if($prefs_dsn) {
631 $dsns['preferences'] = $prefs_dsn;
632 }
633 if($addrbook_dsn) {
634 $dsns['addressbook'] = $addrbook_dsn;
635 }
636 if($addrbook_global_dsn) {
637 $dsns['global addressbook'] = $addrbook_global_dsn;
638 }
639
640 foreach($dsns as $type => $dsn) {
641 $aDsn = explode(':', $dsn);
642 $dbtype = array_shift($aDsn);
643 if(isset($db_functions[$dbtype]) && function_exists($db_functions[$dbtype])) {
644 echo "$IND$dbtype database support present.<br />\n";
645
646 // now, test this interface:
647
648 $dbh = DB::connect($dsn, true);
649 if (DB::isError($dbh)) {
650 do_err('Database error: '. htmlspecialchars(DB::errorMessage($dbh)) .
651 ' in ' .$type .' DSN.');
652 }
653 $dbh->disconnect();
654 echo "$IND$type database connect successful.<br />\n";
655
656 } else {
657 do_err($dbtype.' database support not present!');
658 }
659 }
660 } else {
661 $db_error='Required PHP PEAR DB support is not available.'
662 .' Is PEAR installed and is the include path set correctly to find <tt>DB.php</tt>?'
663 .' The include path is now:<tt>' . ini_get('include_path') . '</tt>.';
664 do_err($db_error);
665 }
666 } else {
667 echo $IND."not using database functionality.<br />\n";
668 }
669
670 // LDAP DB tests
671 echo "Checking LDAP functions...<br />\n";
672 if( empty($ldap_server) ) {
673 echo $IND."not using LDAP functionality.<br />\n";
674 } else {
675 if ( !function_exists('ldap_connect') ) {
676 do_err('Required LDAP support is not available.');
677 } else {
678 echo "$IND LDAP support present.<br />\n";
679 foreach ( $ldap_server as $param ) {
680
681 $linkid = @ldap_connect($param['host'], (empty($param['port']) ? 389 : $param['port']) );
682
683 if ( $linkid ) {
684 echo "$IND LDAP connect to ".$param['host']." successful: ".$linkid."<br />\n";
685
686 if ( !empty($param['protocol']) &&
687 !ldap_set_option($linkid, LDAP_OPT_PROTOCOL_VERSION, $param['protocol']) ) {
688 do_err('Unable to set LDAP protocol');
689 }
690
691 if ( empty($param['binddn']) ) {
692 $bind = @ldap_bind($linkid);
693 } else {
694 $bind = @ldap_bind($param['binddn'], $param['bindpw']);
695 }
696
697 if ( $bind ) {
698 echo "$IND LDAP Bind Successful <br />";
699 } else {
700 do_err('Unable to Bind to LDAP Server');
701 }
702
703 @ldap_close($linkid);
704 } else {
705 do_err('Connection to LDAP failed');
706 }
707 }
708 }
709 }
710
711 echo '<hr width="75%" align="center">';
712 echo '<h2 align="center">Summary</h2>';
713 $footer = '<hr width="75%" align="center">';
714 if ($warnings) {
715 echo '<p>No fatal errors were found, but there was at least 1 warning. Please check the flagged issue(s) carefully, as correcting them may prevent erratic, undefined, or incorrect behavior (or flat out breakage).</p>';
716 echo $footer;
717 } else {
718 print <<< EOF
719 <p>Congratulations, your SquirrelMail setup looks fine to me!</p>
720
721 <p><a href="login.php">Login now</a></p>
722
723 </body>
724 </html>
725 EOF;
726 echo $footer;
727 }
728 ?>