cyrus capability and permanent flags
[squirrelmail.git] / src / configtest.php
CommitLineData
d1ae9d4c 1<?php
134e4174 2
30967a1e 3/**
d1ae9d4c 4 * SquirrelMail configtest script
5 *
4b4abf93 6 * @copyright &copy; 2003-2005 The SquirrelMail Project Team
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.
20
5b53b7e0 21function do_err($str, $exit = TRUE) {
d18703d3 22 global $IND;
23 echo '<p>'.$IND.'<font color="red"><b>ERROR:</b></font> ' .$str. "</p>\n";
5b53b7e0 24 if($exit) {
25 echo '</body></html>';
26 exit;
27 }
28}
29
30$IND = str_repeat('&nbsp;',4);
31
32ob_implicit_flush();
30967a1e 33/** @ignore */
5b53b7e0 34define('SM_PATH', '../');
35
d0184454 36/* set default value in order to block remote access to script */
37$allow_remote_configtest=false;
38
5b53b7e0 39/*
91e0dccc 40 * Load config before output begins. functions/strings.php depends on
5b53b7e0 41 * functions/globals.php. functions/global.php needs to be run before
91e0dccc 42 * any html output starts. If config.php is missing, error will be displayed
5b53b7e0 43 * later.
44 */
45if (file_exists(SM_PATH . 'config/config.php')) {
46 include(SM_PATH . 'config/config.php');
47 include(SM_PATH . 'functions/strings.php');
48}
d1ae9d4c 49?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
50<html>
51<head>
f9f738dc 52 <meta name="robots" content="noindex,nofollow">
d1ae9d4c 53 <title>SquirrelMail configtest</title>
54</head>
55<body>
56<h1>SquirrelMail configtest</h1>
57
58<p>This script will try to check some aspects of your SquirrelMail configuration
59and point you to errors whereever it can find them. You need to go run <tt>conf.pl</tt>
d18703d3 60in the <tt>config/</tt> directory first before you run this script.</p>
d1ae9d4c 61
62<?php
63
d1ae9d4c 64$included = array_map('basename', get_included_files() );
65if(!in_array('config.php', $included)) {
66 if(!file_exists(SM_PATH . 'config/config.php')) {
67 do_err('Config file '.SM_PATH . 'config/config.php does not exist!<br />'.
68 'You need to run <tt>conf.pl</tt> first.');
69 }
70 do_err('Could not read '.SM_PATH.'config/config.php! Check file permissions.');
71}
72if(!in_array('strings.php', $included)) {
73 do_err('Could not include '.SM_PATH.'functions/strings.php!<br />'.
74 'Check permissions on that file.');
75}
76
d0184454 77/* Block remote use of script */
78if (! $allow_remote_configtest) {
79 sqGetGlobalVar('REMOTE_ADDR',$client_ip,SQ_SERVER);
80 if (! isset($client_ip) || $client_ip!='127.0.0.1') {
f8a1ed5a 81 do_err('Enable "Allow remote configtest" option in squirrelmail configuration in order to use this script.');
d0184454 82 }
83}
d1ae9d4c 84/* checking PHP specs */
85
17fca61d 86echo "<p><table>\n<tr><td>SquirrelMail version:</td><td><b>" . $version . "</b></td></tr>\n" .
87 '<tr><td>Config file version:</td><td><b>' . $config_version . "</b></td></tr>\n" .
91e0dccc 88 '<tr><td>Config file last modified:</td><td><b>' .
17fca61d 89 date ('d F Y H:i:s', filemtime(SM_PATH . 'config/config.php')) .
90 "</b></td></tr>\n</table>\n</p>\n\n";
d1ae9d4c 91
92echo "Checking PHP configuration...<br />\n";
93
abd74f7d 94if(!check_php_version(4,1,0)) {
95 do_err('Insufficient PHP version: '. PHP_VERSION . '! Minimum required: 4.1.0');
d1ae9d4c 96}
97
17fca61d 98echo $IND . 'PHP version ' . PHP_VERSION . " OK.<br />\n";
d1ae9d4c 99
100$php_exts = array('session','pcre');
101$diff = array_diff($php_exts, get_loaded_extensions());
102if(count($diff)) {
103 do_err('Required PHP extensions missing: '.implode(', ',$diff) );
104}
105
17fca61d 106echo $IND . "PHP extensions OK.<br />\n";
d1ae9d4c 107
8f186a2a 108/* dangerous php settings */
109/**
110 * mbstring.func_overload allows to replace original string and regexp functions
111 * with their equivalents from php mbstring extension. It causes problems when
d0184454 112 * scripts analyze 8bit strings byte after byte or use 8bit strings in regexp tests.
9211bcef 113 * Setting can be controlled in php.ini (php 4.2.0), webserver config (php 4.2.0)
8f186a2a 114 * and .htaccess files (php 4.3.5).
115 */
116if (function_exists('mb_internal_encoding') &&
9211bcef 117 check_php_version(4,2,0) &&
8f186a2a 118 (int)ini_get('mbstring.func_overload')!=0) {
119 $mb_error='You have enabled mbstring overloading.'
120 .' It can cause problems with SquirrelMail scripts that rely on single byte string functions.';
121 do_err($mb_error);
122}
d1ae9d4c 123
5096de48 124/**
125 * We code with register_globals = off. SquirrelMail should work in such setup
126 * since 1.2.9 and 1.3.0. Running SquirrelMail with register_globals = on can
127 * cause variable corruption and security issues. Globals can be turned off in
128 * php.ini, webserver config and .htaccess files. Scripts can turn off globals only
129 * in php 4.2.3 or older.
130 */
131if ((bool) ini_get('register_globals')) {
132 $rg_error='You have enabled php register_globals.'
133 .' Running PHP installation with register_globals=on can cause problems.'
134 .' See <a href="http://www.php.net/manual/en/security.registerglobals.php">'
135 .'security information about register_globals</a>.';
136 do_err($rg_error);
137}
138
d1ae9d4c 139/* checking paths */
140
141echo "Checking paths...<br />\n";
142
143if(!file_exists($data_dir)) {
d0184454 144 // data_dir is not that important in db_setups.
145 if (isset($prefs_dsn) && ! empty($prefs_dsn)) {
146 $data_dir_error = "Data dir ($data_dir) does not exist!\n";
147 echo $IND .'<font color="red"><b>ERROR:</b></font> ' . $data_dir_error;
148 } else {
149 do_err("Data dir ($data_dir) does not exist!");
150 }
91e0dccc 151}
d0184454 152// don't check if errors
153if(!isset($data_dir_error) && !is_dir($data_dir)) {
154 if (isset($prefs_dsn) && ! empty($prefs_dsn)) {
155 $data_dir_error = "Data dir ($data_dir) is not a directory!\n";
156 echo $IND . '<font color="red"><b>ERROR:</b></font> ' . $data_dir_error;
157 } else {
158 do_err("Data dir ($data_dir) is not a directory!");
159 }
91e0dccc 160}
d4eaadbe 161// datadir should be executable - but no clean way to test on that
d0184454 162if(!isset($data_dir_error) && !is_writable($data_dir)) {
163 if (isset($prefs_dsn) && ! empty($prefs_dsn)) {
164 $data_dir_error = "Data dir ($data_dir) is not writable!\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 writable!");
168 }
d1ae9d4c 169}
170
d0184454 171if (isset($data_dir_error)) {
172 echo " Some plugins might need access to data directory.<br />\n";
173} else {
174 // todo_ornot: actually write something and read it back.
175 echo $IND . "Data dir OK.<br />\n";
176}
d1ae9d4c 177
178if($data_dir == $attachment_dir) {
179 echo $IND . "Attachment dir is the same as data dir.<br />\n";
d0184454 180 if (isset($data_dir_error)) {
181 do_err($data_dir_error);
182 }
d1ae9d4c 183} else {
184 if(!file_exists($attachment_dir)) {
185 do_err("Attachment dir ($attachment_dir) does not exist!");
91e0dccc 186 }
d1ae9d4c 187 if (!is_dir($attachment_dir)) {
188 do_err("Attachment dir ($attachment_dir) is not a directory!");
91e0dccc 189 }
d1ae9d4c 190 if (!is_writable($attachment_dir)) {
191 do_err("I cannot write to attachment dir ($attachment_dir)!");
192 }
193 echo $IND . "Attachment dir OK.<br />\n";
194}
195
196
197/* check plugins and themes */
5b53b7e0 198if (isset($plugins[0])) {
199 foreach($plugins as $plugin) {
200 if(!file_exists(SM_PATH .'plugins/'.$plugin)) {
201 do_err('You have enabled the <i>'.$plugin.'</i> plugin but I cannot find it.', FALSE);
202 } elseif (!is_readable(SM_PATH .'plugins/'.$plugin.'/setup.php')) {
203 do_err('You have enabled the <i>'.$plugin.'</i> plugin but I cannot read its setup.php file.', FALSE);
204 }
d1ae9d4c 205 }
5b53b7e0 206 echo $IND . "Plugins OK.<br />\n";
207} else {
208 echo $IND . "Plugins are not enabled in config.<br />\n";
d1ae9d4c 209}
d1ae9d4c 210foreach($theme as $thm) {
211 if(!file_exists($thm['PATH'])) {
212 do_err('You have enabled the <i>'.$thm['NAME'].'</i> theme but I cannot find it ('.$thm['PATH'].').', FALSE);
213 } elseif(!is_readable($thm['PATH'])) {
214 do_err('You have enabled the <i>'.$thm['NAME'].'</i> theme but I cannot read it ('.$thm['PATH'].').', FALSE);
215 }
216}
217
218echo $IND . "Themes OK.<br />\n";
219
07337c9b 220if ( $squirrelmail_default_language != 'en_US' ) {
221 $loc_path = SM_PATH .'locale/'.$squirrelmail_default_language.'/LC_MESSAGES/squirrelmail.mo';
222 if( ! file_exists( $loc_path ) ) {
f8a1ed5a 223 do_err('You have set <i>' . $squirrelmail_default_language .
07337c9b 224 '</i> as your default language, but I cannot find this translation (should be '.
225 'in <tt>' . $loc_path . '</tt>). Please note that you have to download translations '.
226 'separately from the main SquirrelMail package.', FALSE);
227 } elseif ( ! is_readable( $loc_path ) ) {
f8a1ed5a 228 do_err('You have set <i>' . $squirrelmail_default_language .
07337c9b 229 '</i> as your default language, but I cannot read this translation (file '.
230 'in <tt>' . $loc_path . '</tt> unreadable).', FALSE);
231 } else {
232 echo $IND . "Default language OK.<br />\n";
233 }
234} else {
235 echo $IND . "Default language OK.<br />\n";
236}
237
23649466 238echo $IND . "Base URL detected as: <tt>" . htmlspecialchars(get_location()) . "</tt><br />\n";
239
d1ae9d4c 240
241/* check outgoing mail */
242
243if($use_smtp_tls || $use_imap_tls) {
244 if(!check_php_version(4,3,0)) {
245 do_err('You need at least PHP 4.3.0 for SMTP/IMAP TLS!');
246 }
247 if(!extension_loaded('openssl')) {
248 do_err('You need the openssl PHP extension to use SMTP/IMAP TLS!');
249 }
250}
251
252echo "Checking outgoing mail service....<br />\n";
253
254if($useSendmail) {
255 // is_executable also checks for existance, but we want to be as precise as possible with the errors
256 if(!file_exists($sendmail_path)) {
257 do_err("Location of sendmail program incorrect ($sendmail_path)!");
91e0dccc 258 }
d1ae9d4c 259 if(!is_executable($sendmail_path)) {
260 do_err("I cannot execute the sendmail program ($sendmail_path)!");
261 }
262
263 echo $IND . "sendmail OK<br />\n";
264} else {
265 $stream = fsockopen( ($use_smtp_tls?'tls://':'').$smtpServerAddress, $smtpPort,
266 $errorNumber, $errorString);
267 if(!$stream) {
268 do_err("Error connecting to SMTP server \"$smtpServerAddress:$smtpPort\".".
9c941728 269 "Server error: ($errorNumber) ".htmlspecialchars($errorString));
d1ae9d4c 270 }
271
272 // check for SMTP code; should be 2xx to allow us access
273 $smtpline = fgets($stream, 1024);
274 if(((int) $smtpline{0}) > 3) {
9c941728 275 do_err("Error connecting to SMTP server. Server error: ".
134e4174 276 htmlspecialchars($smtpline));
d1ae9d4c 277 }
278
279 fputs($stream, 'QUIT');
280 fclose($stream);
9c941728 281 echo $IND . 'SMTP server OK (<tt><small>'.
282 trim(htmlspecialchars($smtpline))."</small></tt>)<br />\n";
d1ae9d4c 283
284 /* POP before SMTP */
285 if($pop_before_smtp) {
286 $stream = fsockopen($smtpServerAddress, 110, $err_no, $err_str);
287 if (!$stream) {
9c941728 288 do_err("Error connecting to POP Server ($smtpServerAddress:110) "
289 . $err_no . ' : ' . htmlspecialchars($err_str));
d1ae9d4c 290 }
291
292 $tmp = fgets($stream, 1024);
293 if (substr($tmp, 0, 3) != '+OK') {
294 do_err("Error connecting to POP Server ($smtpServerAddress:110)"
9c941728 295 . ' '.htmlspecialchars($tmp));
d1ae9d4c 296 }
297 fputs($stream, 'QUIT');
298 fclose($stream);
299 echo $IND . "POP-before-SMTP OK.<br />\n";
300 }
301}
302
df758744 303/**
304 * Check the IMAP server
305 */
d1ae9d4c 306echo "Checking IMAP service....<br />\n";
307
df758744 308/** Can we open a connection? */
d1ae9d4c 309$stream = fsockopen( ($use_imap_tls?'tls://':'').$imapServerAddress, $imapPort,
310 $errorNumber, $errorString);
311if(!$stream) {
70b71161 312 do_err("Error connecting to IMAP server \"$imapServerAddress:$imapPort\".".
9c941728 313 "Server error: ($errorNumber) ".
134e4174 314 htmlspecialchars($errorString));
d1ae9d4c 315}
316
df758744 317/** Is the first response 'OK'? */
d1ae9d4c 318$imapline = fgets($stream, 1024);
319if(substr($imapline, 0,4) != '* OK') {
9c941728 320 do_err('Error connecting to IMAP server. Server error: '.
321 htmlspecialchars($imapline));
d1ae9d4c 322}
323
df758744 324echo $IND . 'IMAP server ready (<tt><small>'.
9c941728 325 htmlspecialchars(trim($imapline))."</small></tt>)<br />\n";
d1ae9d4c 326
df758744 327/** Check capabilities */
328fputs($stream, "A001 CAPABILITY\r\n");
329$capline = fgets($stream, 1024);
330
331echo $IND . 'Capabilities: <tt>'.htmlspecialchars($capline)."</tt><br />\n";
332
333if($imap_auth_mech == 'login' && stristr($capline, 'LOGINDISABLED') !== FALSE) {
334 do_err('Your server doesn\'t allow plaintext logins. '.
335 'Try enabling another authentication mechanism like CRAM-MD5, DIGEST-MD5 or TLS-encryption '.
336 'in the SquirrelMail configuration.', FALSE);
337}
338if($use_imap_tls && stristr($capline, 'STARTTLS') === FALSE) {
339 do_err('You have enabled TLS encryption in the config, but the server does not '.
340 'report STARTTLS capability. TLS is probably not supported.', FALSE);
341}
342
343/** OK, close connection */
344fputs($stream, "A002 LOGOUT\r\n");
345fclose($stream);
346
17fca61d 347echo "Checking internationalization (i18n) settings...<br />\n";
0ed3bdc3 348echo "$IND gettext - ";
349if (function_exists('gettext')) {
8f186a2a 350 echo 'Gettext functions are available.'
351 .' On some systems you must have appropriate system locales compiled.'
352 ."<br />\n";
0ed3bdc3 353} else {
8f186a2a 354 echo 'Gettext functions are unavailable.'
355 .' SquirrelMail will use slower internal gettext functions.'
356 ."<br />\n";
0ed3bdc3 357}
358echo "$IND mbstring - ";
359if (function_exists('mb_detect_encoding')) {
360 echo "Mbstring functions are available.<br />\n";
361} else {
8f186a2a 362 echo 'Mbstring functions are unavailable.'
363 ." Japanese translation won't work.<br />\n";
0ed3bdc3 364}
365echo "$IND recode - ";
366if (function_exists('recode')) {
367 echo "Recode functions are available.<br />\n";
ba17b6c7 368} elseif (isset($use_php_recode) && $use_php_recode) {
0ed3bdc3 369 echo "Recode functions are unavailable.<br />\n";
370 do_err('Your configuration requires recode support, but recode support is missing.');
371} else {
372 echo "Recode functions are unavailable.<br />\n";
373}
374echo "$IND iconv - ";
375if (function_exists('iconv')) {
376 echo "Iconv functions are available.<br />\n";
ba17b6c7 377} elseif (isset($use_php_iconv) && $use_php_iconv) {
0ed3bdc3 378 echo "Iconv functions are unavailable.<br />\n";
379 do_err('Your configuration requires iconv support, but iconv support is missing.');
380} else {
381 echo "Iconv functions are unavailable.<br />\n";
382}
383// same test as in include/validate.php
384echo "$IND timezone - ";
385if ( (!ini_get('safe_mode')) ||
386 !strcmp(ini_get('safe_mode_allowed_env_vars'),'') ||
387 preg_match('/^([\w_]+,)*TZ/', ini_get('safe_mode_allowed_env_vars')) ) {
134e4174 388 echo "Webmail users can change their time zone settings.<br />\n";
0ed3bdc3 389} else {
4764a7ff 390 echo "Webmail users can't change their time zone settings.<br />\n";
391}
392
d18703d3 393
4764a7ff 394// Pear DB tests
d18703d3 395echo "Checking database functions...<br />\n";
396if($addrbook_dsn || $prefs_dsn || $addrbook_global_dsn) {
134e4174 397 @include_once('DB.php');
398 if (class_exists('DB')) {
399 echo "$IND PHP Pear DB support is present.<br />\n";
400 $db_functions=array(
91e0dccc 401 'dbase' => 'dbase_open',
402 'fbsql' => 'fbsql_connect',
403 'interbase' => 'ibase_connect',
134e4174 404 'informix' => 'ifx_connect',
405 'msql' => 'msql_connect',
406 'mssql' => 'mssql_connect',
407 'mysql' => 'mysql_connect',
408 'mysqli' => 'mysqli_connect',
409 'oci8' => 'ocilogon',
410 'odbc' => 'odbc_connect',
7ed4c524 411 'pgsql' => 'pg_connect',
134e4174 412 'sqlite' => 'sqlite_open',
413 'sybase' => 'sybase_connect'
414 );
415
416 $dsns = array();
417 if($prefs_dsn) {
418 $dsns['preferences'] = $prefs_dsn;
419 }
420 if($addrbook_dsn) {
421 $dsns['addressbook'] = $addrbook_dsn;
422 }
423 if($addrbook_global_dsn) {
424 $dsns['global addressbook'] = $addrbook_global_dsn;
425 }
426
427 foreach($dsns as $type => $dsn) {
ba17b6c7 428 $aDsn = explode(':', $dsn);
429 $dbtype = array_shift($aDsn);
134e4174 430 if(isset($db_functions[$dbtype]) && function_exists($db_functions[$dbtype])) {
431 echo "$IND$dbtype database support present.<br />\n";
432
433 // now, test this interface:
434
435 $dbh = DB::connect($dsn, true);
436 if (DB::isError($dbh)) {
437 do_err('Database error: '. htmlspecialchars(DB::errorMessage($dbh)) .
438 ' in ' .$type .' DSN.');
439 }
440 $dbh->disconnect();
441 echo "$IND$type database connect successful.<br />\n";
442
443 } else {
ba17b6c7 444 do_err($dbtype.' database support not present!');
d18703d3 445 }
134e4174 446 }
447 } else {
8f186a2a 448 $db_error='Required PHP PEAR DB support is not available.'
449 .' Is PEAR installed and is the include path set correctly to find <tt>DB.php</tt>?'
450 .' The include path is now:<tt>' . ini_get('include_path') . '</tt>.';
451 do_err($db_error);
134e4174 452 }
4764a7ff 453} else {
d18703d3 454 echo $IND."not using database functionality.<br />\n";
0ed3bdc3 455}
7562c55b 456
457// LDAP DB tests
458echo "Checking LDAP functions...<br />\n";
459if( empty($ldap_server) ) {
134e4174 460 echo $IND."not using LDAP functionality.<br />\n";
7562c55b 461} else {
d0184454 462 if ( !function_exists('ldap_connect') ) {
7562c55b 463 do_err('Required LDAP support is not available.');
464 } else {
134e4174 465 echo "$IND LDAP support present.<br />\n";
7562c55b 466 foreach ( $ldap_server as $param ) {
467
d0184454 468 $linkid = @ldap_connect($param['host'], (empty($param['port']) ? 389 : $param['port']) );
7562c55b 469
470 if ( $linkid ) {
134e4174 471 echo "$IND LDAP connect to ".$param['host']." successful: ".$linkid."<br />\n";
91e0dccc 472
7562c55b 473 if ( !empty($param['protocol']) &&
474 !ldap_set_option($linkid, LDAP_OPT_PROTOCOL_VERSION, $param['protocol']) ) {
475 do_err('Unable to set LDAP protocol');
91e0dccc 476 }
7562c55b 477
478 if ( empty($param['binddn']) ) {
d0184454 479 $bind = @ldap_bind($linkid);
7562c55b 480 } else {
d0184454 481 $bind = @ldap_bind($param['binddn'], $param['bindpw']);
7562c55b 482 }
483
484 if ( $bind ) {
485 echo "$IND LDAP Bind Successful <br />";
486 } else {
487 do_err('Unable to Bind to LDAP Server');
488 }
91e0dccc 489
d0184454 490 @ldap_close($linkid);
7562c55b 491 } else {
492 do_err('Connection to LDAP failed');
493 }
494 }
495 }
496}
a2b193bc 497
d1ae9d4c 498?>
499
500<p>Congratulations, your SquirrelMail setup looks fine to me!</p>
501
13721b47 502<p><a href="login.php">Login now</a></p>
d1ae9d4c 503
504</body>
f8a1ed5a 505</html>