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