don't tag subfolders of Drafts,Trash and Sent as special in folder management
[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) .
305 "</tt> (location base " . (empty($config_location_base) ? 'autodetected' : 'set to <tt>' .
306 htmlspecialchars($config_location_base)."</tt>") . ")<br />\n";
307
308 /* check minimal requirements for other security options */
309
310 /* imaps or ssmtp */
311 if($use_smtp_tls == 1 || $use_imap_tls == 1) {
312 if(!check_php_version(4,3,0)) {
313 do_err('You need at least PHP 4.3.0 for SMTP/IMAP TLS!');
314 }
315 if(!extension_loaded('openssl')) {
316 do_err('You need the openssl PHP extension to use SMTP/IMAP TLS!');
317 }
318 }
319 /* starttls extensions */
320 if($use_smtp_tls === 2 || $use_imap_tls === 2) {
321 if (! function_exists('stream_socket_enable_crypto')) {
322 do_err('If you want to use STARTTLS extension, you need stream_socket_enable_crypto() function from PHP 5.1.0 and newer.');
323 }
324 }
325 /* digest-md5 */
326 if ($smtp_auth_mech=='digest-md5' || $imap_auth_mech =='digest-md5') {
327 if (!extension_loaded('xml')) {
328 do_err('You need the PHP XML extension to use Digest-MD5 authentication!');
329 }
330 }
331
332 /* check outgoing mail */
333
334 echo "Checking outgoing mail service....<br />\n";
335
336 if($useSendmail) {
337 // is_executable also checks for existance, but we want to be as precise as possible with the errors
338 if(!file_exists($sendmail_path)) {
339 do_err("Location of sendmail program incorrect ($sendmail_path)!");
340 }
341 if(!is_executable($sendmail_path)) {
342 do_err("I cannot execute the sendmail program ($sendmail_path)!");
343 }
344
345 echo $IND . "sendmail OK<br />\n";
346 } else {
347 $stream = fsockopen( ($use_smtp_tls==1?'tls://':'').$smtpServerAddress, $smtpPort,
348 $errorNumber, $errorString);
349 if(!$stream) {
350 do_err("Error connecting to SMTP server \"$smtpServerAddress:$smtpPort\".".
351 "Server error: ($errorNumber) ".htmlspecialchars($errorString));
352 }
353
354 // check for SMTP code; should be 2xx to allow us access
355 $smtpline = fgets($stream, 1024);
356 if(((int) $smtpline{0}) > 3) {
357 do_err("Error connecting to SMTP server. Server error: ".
358 htmlspecialchars($smtpline));
359 }
360
361 /* smtp starttls checks */
362 if ($use_smtp_tls===2) {
363 // if something breaks, script should close smtp connection on exit.
364
365 // say helo
366 fwrite($stream,"EHLO $client_ip\r\n");
367
368 $ehlo=array();
369 $ehlo_error = false;
370 while ($line=fgets($stream, 1024)){
371 if (preg_match("/^250(-|\s)(\S*)\s+(\S.*)/",$line,$match)||
372 preg_match("/^250(-|\s)(\S*)\s+/",$line,$match)) {
373 if (!isset($match[3])) {
374 // simple one word extension
375 $ehlo[strtoupper($match[2])]='';
376 } else {
377 // ehlo-keyword + ehlo-param
378 $ehlo[strtoupper($match[2])]=trim($match[3]);
379 }
380 if ($match[1]==' ') {
381 $ret = $line;
382 break;
383 }
384 } else {
385 //
386 $ehlo_error = true;
387 $ehlo[]=$line;
388 break;
389 }
390 }
391 if ($ehlo_error) {
392 do_err('SMTP EHLO failed. You need ESMTP support for SMTP STARTTLS');
393 } elseif (!array_key_exists('STARTTLS',$ehlo)) {
394 do_err('STARTTLS support is not declared by SMTP server.');
395 }
396
397 fwrite($stream,"STARTTLS\r\n");
398 $starttls_response=fgets($stream, 1024);
399 if ($starttls_response[0]!=2) {
400 $starttls_cmd_err = 'SMTP STARTTLS failed. Server replied: '
401 .htmlspecialchars($starttls_response);
402 do_err($starttls_cmd_err);
403 } elseif(! stream_socket_enable_crypto($stream,true,STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
404 do_err('Failed to enable encryption on SMTP STARTTLS connection.');
405 } else {
406 echo $IND . "SMTP STARTTLS extension looks OK.<br />\n";
407 }
408 // According to RFC we should second ehlo call here.
409 }
410
411 fputs($stream, 'QUIT');
412 fclose($stream);
413 echo $IND . 'SMTP server OK (<tt><small>'.
414 trim(htmlspecialchars($smtpline))."</small></tt>)<br />\n";
415
416 /* POP before SMTP */
417 if($pop_before_smtp) {
418 $stream = fsockopen($smtpServerAddress, 110, $err_no, $err_str);
419 if (!$stream) {
420 do_err("Error connecting to POP Server ($smtpServerAddress:110) "
421 . $err_no . ' : ' . htmlspecialchars($err_str));
422 }
423
424 $tmp = fgets($stream, 1024);
425 if (substr($tmp, 0, 3) != '+OK') {
426 do_err("Error connecting to POP Server ($smtpServerAddress:110)"
427 . ' '.htmlspecialchars($tmp));
428 }
429 fputs($stream, 'QUIT');
430 fclose($stream);
431 echo $IND . "POP-before-SMTP OK.<br />\n";
432 }
433 }
434
435 /**
436 * Check the IMAP server
437 */
438 echo "Checking IMAP service....<br />\n";
439
440 /** Can we open a connection? */
441 $stream = fsockopen( ($use_imap_tls==1?'tls://':'').$imapServerAddress, $imapPort,
442 $errorNumber, $errorString);
443 if(!$stream) {
444 do_err("Error connecting to IMAP server \"$imapServerAddress:$imapPort\".".
445 "Server error: ($errorNumber) ".
446 htmlspecialchars($errorString));
447 }
448
449 /** Is the first response 'OK'? */
450 $imapline = fgets($stream, 1024);
451 if(substr($imapline, 0,4) != '* OK') {
452 do_err('Error connecting to IMAP server. Server error: '.
453 htmlspecialchars($imapline));
454 }
455
456 echo $IND . 'IMAP server ready (<tt><small>'.
457 htmlspecialchars(trim($imapline))."</small></tt>)<br />\n";
458
459 /** Check capabilities */
460 fputs($stream, "A001 CAPABILITY\r\n");
461 $capline = '';
462 while ($line=fgets($stream, 1024)){
463 if (preg_match("/A001.*/",$line)) {
464 break;
465 } else {
466 $capline.=$line;
467 }
468 }
469
470 /* don't display capabilities before STARTTLS */
471 if ($use_imap_tls===2 && stristr($capline, 'STARTTLS') === false) {
472 do_err('Your server doesn\'t support STARTTLS.');
473 } elseif($use_imap_tls===2) {
474 /* try starting starttls */
475 fwrite($stream,"A002 STARTTLS\r\n");
476 $starttls_line=fgets($stream, 1024);
477 if (! preg_match("/^A002 OK.*/i",$starttls_line)) {
478 $imap_starttls_err = 'IMAP STARTTLS failed. Server replied: '
479 .htmlspecialchars($starttls_line);
480 do_err($imap_starttls_err);
481 } elseif (! stream_socket_enable_crypto($stream,true,STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
482 do_err('Failed to enable encryption on IMAP connection.');
483 } else {
484 echo $IND . "IMAP STARTTLS extension looks OK.<br />\n";
485 }
486
487 // get new capability line
488 fwrite($stream,"A003 CAPABILITY\r\n");
489 $capline='';
490 while ($line=fgets($stream, 1024)){
491 if (preg_match("/A003.*/",$line)) {
492 break;
493 } else {
494 $capline.=$line;
495 }
496 }
497 }
498
499 echo $IND . 'Capabilities: <tt>'.htmlspecialchars($capline)."</tt><br />\n";
500
501 if($imap_auth_mech == 'login' && stristr($capline, 'LOGINDISABLED') !== FALSE) {
502 do_err('Your server doesn\'t allow plaintext logins. '.
503 'Try enabling another authentication mechanism like CRAM-MD5, DIGEST-MD5 or TLS-encryption '.
504 'in the SquirrelMail configuration.', FALSE);
505 }
506
507 if (stristr($capline, 'XMAGICTRASH') !== false) {
508 $magic_trash = 'It looks like IMAP_MOVE_EXPUNGE_TO_TRASH option is turned on '
509 .'in your Courier IMAP configuration. Courier does not provide tools that '
510 .'allow to detect folder used for Trash or commands are not documented. '
511 .'SquirrelMail can\'t detect special trash folder. SquirrelMail manages '
512 .'all message deletion or move operations internally and '
513 .'IMAP_MOVE_EXPUNGE_TO_TRASH option can cause errors in message and '
514 .'folder management operations. Please turn off IMAP_MOVE_EXPUNGE_TO_TRASH '
515 .'option in Courier imapd configuration.';
516 do_err($magic_trash,false);
517 }
518
519 /** OK, close connection */
520 fputs($stream, "A004 LOGOUT\r\n");
521 fclose($stream);
522
523 echo "Checking internationalization (i18n) settings...<br />\n";
524 echo "$IND gettext - ";
525 if (function_exists('gettext')) {
526 echo 'Gettext functions are available.'
527 .' On some systems you must have appropriate system locales compiled.'
528 ."<br />\n";
529
530 /* optional setlocale() tests. Should work only on glibc systems. */
531 if (sqgetGlobalVar('testlocales',$testlocales,SQ_GET)) {
532 include_once(SM_PATH . 'include/languages.php');
533 echo $IND . $IND . 'Testing translations:<br>';
534 foreach ($languages as $lang_code => $lang_data) {
535 /* don't test aliases */
536 if (isset($lang_data['NAME'])) {
537 /* locale can be $lang_code or $lang_data['LOCALE'] */
538 if (isset($lang_data['LOCALE'])) {
539 $setlocale = $lang_data['LOCALE'];
540 } else {
541 $setlocale = $lang_code;
542 }
543 /* prepare information about tested locales */
544 if (is_array($setlocale)) {
545 $display_locale = implode(', ',$setlocale);
546 $locale_count = count($setlocale);
547 } else {
548 $display_locale = $setlocale;
549 $locale_count = 1;
550 }
551 $tested_locales_msg = 'Tested '.htmlspecialchars($display_locale).' '
552 .($locale_count>1 ? 'locales':'locale'). '.';
553
554 echo $IND . $IND .$IND . $lang_data['NAME'].' (' .$lang_code. ') - ';
555 $retlocale = sq_setlocale(LC_ALL,$setlocale);
556 if (is_bool($retlocale)) {
557 echo '<font color="red">unsupported</font>. ';
558 echo $tested_locales_msg;
559 } else {
560 echo 'supported. '
561 .$tested_locales_msg
562 .' setlocale() returned "'.htmlspecialchars($retlocale).'"';
563 }
564 echo "<br />\n";
565 }
566 }
567 echo $IND . $IND . '<a href="configtest.php">Don\'t test translations</a>';
568 } else {
569 echo $IND . $IND . '<a href="configtest.php?testlocales=1">Test translations</a>. '
570 .'This test is not accurate and might work only on some systems.'
571 ."\n";
572 }
573 echo "<br />\n";
574 /* end of translation tests */
575 } else {
576 echo 'Gettext functions are unavailable.'
577 .' SquirrelMail will use slower internal gettext functions.'
578 ."<br />\n";
579 }
580 echo "$IND mbstring - ";
581 if (function_exists('mb_detect_encoding')) {
582 echo "Mbstring functions are available.<br />\n";
583 } else {
584 echo 'Mbstring functions are unavailable.'
585 ." Japanese translation won't work.<br />\n";
586 }
587 echo "$IND recode - ";
588 if (function_exists('recode')) {
589 echo "Recode functions are available.<br />\n";
590 } elseif (isset($use_php_recode) && $use_php_recode) {
591 echo "Recode functions are unavailable.<br />\n";
592 do_err('Your configuration requires recode support, but recode support is missing.');
593 } else {
594 echo "Recode functions are unavailable.<br />\n";
595 }
596 echo "$IND iconv - ";
597 if (function_exists('iconv')) {
598 echo "Iconv functions are available.<br />\n";
599 } elseif (isset($use_php_iconv) && $use_php_iconv) {
600 echo "Iconv functions are unavailable.<br />\n";
601 do_err('Your configuration requires iconv support, but iconv support is missing.');
602 } else {
603 echo "Iconv functions are unavailable.<br />\n";
604 }
605 // same test as in include/init.php + date_default_timezone_set check
606 echo "$IND timezone - ";
607 if ( (!ini_get('safe_mode')) || function_exists('date_default_timezone_set') ||
608 !strcmp(ini_get('safe_mode_allowed_env_vars'),'') ||
609 preg_match('/^([\w_]+,)*TZ/', ini_get('safe_mode_allowed_env_vars')) ) {
610 echo "Webmail users can change their time zone settings. \n";
611 } else {
612 echo "Webmail users can't change their time zone settings. \n";
613 }
614 if (isset($_ENV['TZ'])) {
615 echo 'Default time zone is '.htmlspecialchars($_ENV['TZ']);
616 } else {
617 echo 'Current time zone is '.date('T');
618 }
619 echo ".<br />\n";
620
621 // Pear DB tests
622 echo "Checking database functions...<br />\n";
623 if($addrbook_dsn || $prefs_dsn || $addrbook_global_dsn) {
624 @include_once('DB.php');
625 if (class_exists('DB')) {
626 echo "$IND PHP Pear DB support is present.<br />\n";
627 $db_functions=array(
628 'dbase' => 'dbase_open',
629 'fbsql' => 'fbsql_connect',
630 'interbase' => 'ibase_connect',
631 'informix' => 'ifx_connect',
632 'msql' => 'msql_connect',
633 'mssql' => 'mssql_connect',
634 'mysql' => 'mysql_connect',
635 'mysqli' => 'mysqli_connect',
636 'oci8' => 'ocilogon',
637 'odbc' => 'odbc_connect',
638 'pgsql' => 'pg_connect',
639 'sqlite' => 'sqlite_open',
640 'sybase' => 'sybase_connect'
641 );
642
643 $dsns = array();
644 if($prefs_dsn) {
645 $dsns['preferences'] = $prefs_dsn;
646 }
647 if($addrbook_dsn) {
648 $dsns['addressbook'] = $addrbook_dsn;
649 }
650 if($addrbook_global_dsn) {
651 $dsns['global addressbook'] = $addrbook_global_dsn;
652 }
653
654 foreach($dsns as $type => $dsn) {
655 $aDsn = explode(':', $dsn);
656 $dbtype = array_shift($aDsn);
657 if(isset($db_functions[$dbtype]) && function_exists($db_functions[$dbtype])) {
658 echo "$IND$dbtype database support present.<br />\n";
659
660 // now, test this interface:
661
662 $dbh = DB::connect($dsn, true);
663 if (DB::isError($dbh)) {
664 do_err('Database error: '. htmlspecialchars(DB::errorMessage($dbh)) .
665 ' in ' .$type .' DSN.');
666 }
667 $dbh->disconnect();
668 echo "$IND$type database connect successful.<br />\n";
669
670 } else {
671 do_err($dbtype.' database support not present!');
672 }
673 }
674 } else {
675 $db_error='Required PHP PEAR DB support is not available.'
676 .' Is PEAR installed and is the include path set correctly to find <tt>DB.php</tt>?'
677 .' The include path is now:<tt>' . ini_get('include_path') . '</tt>.';
678 do_err($db_error);
679 }
680 } else {
681 echo $IND."not using database functionality.<br />\n";
682 }
683
684 // LDAP DB tests
685 echo "Checking LDAP functions...<br />\n";
686 if( empty($ldap_server) ) {
687 echo $IND."not using LDAP functionality.<br />\n";
688 } else {
689 if ( !function_exists('ldap_connect') ) {
690 do_err('Required LDAP support is not available.');
691 } else {
692 echo "$IND LDAP support present.<br />\n";
693 foreach ( $ldap_server as $param ) {
694
695 $linkid = @ldap_connect($param['host'], (empty($param['port']) ? 389 : $param['port']) );
696
697 if ( $linkid ) {
698 echo "$IND LDAP connect to ".$param['host']." successful: ".$linkid."<br />\n";
699
700 if ( !empty($param['protocol']) &&
701 !ldap_set_option($linkid, LDAP_OPT_PROTOCOL_VERSION, $param['protocol']) ) {
702 do_err('Unable to set LDAP protocol');
703 }
704
705 if ( empty($param['binddn']) ) {
706 $bind = @ldap_bind($linkid);
707 } else {
708 $bind = @ldap_bind($param['binddn'], $param['bindpw']);
709 }
710
711 if ( $bind ) {
712 echo "$IND LDAP Bind Successful <br />";
713 } else {
714 do_err('Unable to Bind to LDAP Server');
715 }
716
717 @ldap_close($linkid);
718 } else {
719 do_err('Connection to LDAP failed');
720 }
721 }
722 }
723 }
724
725 echo '<hr width="75%" align="center">';
726 echo '<h2 align="center">Summary</h2>';
727 $footer = '<hr width="75%" align="center">';
728 if ($warnings) {
729 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>';
730 echo $footer;
731 } else {
732 print <<< EOF
733 <p>Congratulations, your SquirrelMail setup looks fine to me!</p>
734
735 <p><a href="login.php">Login now</a></p>
736
737 </body>
738 </html>
739 EOF;
740 echo $footer;
741 }
742 ?>