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