4 * SquirrelMail configtest script
6 * Copyright (c) 2003-2005 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
10 * @package squirrelmail
14 /************************************************************
15 * NOTE: you do not need to change this script! *
16 * If it throws errors you need to adjust your config. *
17 ************************************************************/
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.
22 function do_err($str, $exit = TRUE) {
24 echo '<p>'.$IND.'<font color="red"><b>ERROR:</b></font> ' .$str. "</p>\n";
26 echo '</body></html>';
31 $IND = str_repeat(' ',4);
35 define('SM_PATH', '../');
38 * Load config before output begins. functions/strings.php depends on
39 * functions/globals.php. functions/global.php needs to be run before
40 * any html output starts. If config.php is missing, error will be displayed
43 if (file_exists(SM_PATH
. 'config/config.php')) {
44 include(SM_PATH
. 'config/config.php');
45 include(SM_PATH
. 'functions/strings.php');
47 ?
><!DOCTYPE HTML
PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
50 <title
>SquirrelMail configtest
</title
>
53 <h1
>SquirrelMail configtest
</h1
>
55 <p
>This script will
try to check some aspects of your SquirrelMail configuration
56 and point you to errors whereever it can find them
. You need to go run
<tt
>conf
.pl
</tt
>
57 in the
<tt
>config
/</tt
> directory first before you run this script
.</p
>
62 $included = array_map('basename', get_included_files() );
63 if(!in_array('config.php', $included)) {
64 if(!file_exists(SM_PATH
. 'config/config.php')) {
65 do_err('Config file '.SM_PATH
. 'config/config.php does not exist!<br />'.
66 'You need to run <tt>conf.pl</tt> first.');
68 do_err('Could not read '.SM_PATH
.'config/config.php! Check file permissions.');
70 if(!in_array('strings.php', $included)) {
71 do_err('Could not include '.SM_PATH
.'functions/strings.php!<br />'.
72 'Check permissions on that file.');
75 /* checking PHP specs */
77 echo "<p><table>\n<tr><td>SquirrelMail version:</td><td><b>" . $version . "</b></td></tr>\n" .
78 '<tr><td>Config file version:</td><td><b>' . $config_version . "</b></td></tr>\n" .
79 '<tr><td>Config file last modified:</td><td><b>' .
80 date ('d F Y H:i:s', filemtime(SM_PATH
. 'config/config.php')) .
81 "</b></td></tr>\n</table>\n</p>\n\n";
83 echo "Checking PHP configuration...<br />\n";
85 if(!check_php_version(4,1,0)) {
86 do_err('Insufficient PHP version: '. PHP_VERSION
. '! Minimum required: 4.1.0');
89 echo $IND . 'PHP version ' . PHP_VERSION
. " OK.<br />\n";
91 $php_exts = array('session','pcre');
92 $diff = array_diff($php_exts, get_loaded_extensions());
94 do_err('Required PHP extensions missing: '.implode(', ',$diff) );
97 echo $IND . "PHP extensions OK.<br />\n";
99 /* dangerous php settings */
101 * mbstring.func_overload allows to replace original string and regexp functions
102 * with their equivalents from php mbstring extension. It causes problems when
103 * scripts analyse 8bit strings byte after byte or use 8bit strings in regexp tests.
104 * Setting can be controlled in php.ini (php 4.2.0), webserver config (php 4.2.0)
105 * and .htaccess files (php 4.3.5).
107 if (function_exists('mb_internal_encoding') &&
108 check_php_version(4,2,0) &&
109 (int)ini_get('mbstring.func_overload')!=0) {
110 $mb_error='You have enabled mbstring overloading.'
111 .' It can cause problems with SquirrelMail scripts that rely on single byte string functions.';
117 echo "Checking paths...<br />\n";
119 if(!file_exists($data_dir)) {
120 do_err("Data dir ($data_dir) does not exist!");
122 if(!is_dir($data_dir)) {
123 do_err("Data dir ($data_dir) is not a directory!");
125 if(!is_readable($data_dir)) {
126 do_err("I cannot read from data dir ($data_dir)!");
128 if(!is_writable($data_dir)) {
129 do_err("I cannot write to data dir ($data_dir)!");
132 // todo_ornot: actually write something and read it back.
133 echo $IND . "Data dir OK.<br />\n";
136 if($data_dir == $attachment_dir) {
137 echo $IND . "Attachment dir is the same as data dir.<br />\n";
139 if(!file_exists($attachment_dir)) {
140 do_err("Attachment dir ($attachment_dir) does not exist!");
142 if (!is_dir($attachment_dir)) {
143 do_err("Attachment dir ($attachment_dir) is not a directory!");
145 if (!is_writable($attachment_dir)) {
146 do_err("I cannot write to attachment dir ($attachment_dir)!");
148 echo $IND . "Attachment dir OK.<br />\n";
152 /* check plugins and themes */
153 if (isset($plugins[0])) {
154 foreach($plugins as $plugin) {
155 if(!file_exists(SM_PATH
.'plugins/'.$plugin)) {
156 do_err('You have enabled the <i>'.$plugin.'</i> plugin but I cannot find it.', FALSE);
157 } elseif (!is_readable(SM_PATH
.'plugins/'.$plugin.'/setup.php')) {
158 do_err('You have enabled the <i>'.$plugin.'</i> plugin but I cannot read its setup.php file.', FALSE);
161 echo $IND . "Plugins OK.<br />\n";
163 echo $IND . "Plugins are not enabled in config.<br />\n";
165 foreach($theme as $thm) {
166 if(!file_exists($thm['PATH'])) {
167 do_err('You have enabled the <i>'.$thm['NAME'].'</i> theme but I cannot find it ('.$thm['PATH'].').', FALSE);
168 } elseif(!is_readable($thm['PATH'])) {
169 do_err('You have enabled the <i>'.$thm['NAME'].'</i> theme but I cannot read it ('.$thm['PATH'].').', FALSE);
173 echo $IND . "Themes OK.<br />\n";
175 echo $IND . "Base URL detected as: <tt>" . htmlspecialchars(get_location()) . "</tt><br />\n";
178 /* check outgoing mail */
180 if($use_smtp_tls ||
$use_imap_tls) {
181 if(!check_php_version(4,3,0)) {
182 do_err('You need at least PHP 4.3.0 for SMTP/IMAP TLS!');
184 if(!extension_loaded('openssl')) {
185 do_err('You need the openssl PHP extension to use SMTP/IMAP TLS!');
189 echo "Checking outgoing mail service....<br />\n";
192 // is_executable also checks for existance, but we want to be as precise as possible with the errors
193 if(!file_exists($sendmail_path)) {
194 do_err("Location of sendmail program incorrect ($sendmail_path)!");
196 if(!is_executable($sendmail_path)) {
197 do_err("I cannot execute the sendmail program ($sendmail_path)!");
200 echo $IND . "sendmail OK<br />\n";
202 $stream = fsockopen( ($use_smtp_tls?
'tls://':'').$smtpServerAddress, $smtpPort,
203 $errorNumber, $errorString);
205 do_err("Error connecting to SMTP server \"$smtpServerAddress:$smtpPort\".".
206 "Server error: ($errorNumber) ".htmlspecialchars($errorString));
209 // check for SMTP code; should be 2xx to allow us access
210 $smtpline = fgets($stream, 1024);
211 if(((int) $smtpline{0}) > 3) {
212 do_err("Error connecting to SMTP server. Server error: ".
213 htmlspecialchars($smtpline));
216 fputs($stream, 'QUIT');
218 echo $IND . 'SMTP server OK (<tt><small>'.
219 trim(htmlspecialchars($smtpline))."</small></tt>)<br />\n";
221 /* POP before SMTP */
222 if($pop_before_smtp) {
223 $stream = fsockopen($smtpServerAddress, 110, $err_no, $err_str);
225 do_err("Error connecting to POP Server ($smtpServerAddress:110) "
226 . $err_no . ' : ' . htmlspecialchars($err_str));
229 $tmp = fgets($stream, 1024);
230 if (substr($tmp, 0, 3) != '+OK') {
231 do_err("Error connecting to POP Server ($smtpServerAddress:110)"
232 . ' '.htmlspecialchars($tmp));
234 fputs($stream, 'QUIT');
236 echo $IND . "POP-before-SMTP OK.<br />\n";
241 * Check the IMAP server
243 echo "Checking IMAP service....<br />\n";
245 /** Can we open a connection? */
246 $stream = fsockopen( ($use_imap_tls?
'tls://':'').$imapServerAddress, $imapPort,
247 $errorNumber, $errorString);
249 do_err("Error connecting to IMAP server \"$imapServerAddress:$imapPort\".".
250 "Server error: ($errorNumber) ".
251 htmlspecialchars($errorString));
254 /** Is the first response 'OK'? */
255 $imapline = fgets($stream, 1024);
256 if(substr($imapline, 0,4) != '* OK') {
257 do_err('Error connecting to IMAP server. Server error: '.
258 htmlspecialchars($imapline));
261 echo $IND . 'IMAP server ready (<tt><small>'.
262 htmlspecialchars(trim($imapline))."</small></tt>)<br />\n";
264 /** Check capabilities */
265 fputs($stream, "A001 CAPABILITY\r\n");
266 $capline = fgets($stream, 1024);
268 echo $IND . 'Capabilities: <tt>'.htmlspecialchars($capline)."</tt><br />\n";
270 if($imap_auth_mech == 'login' && stristr($capline, 'LOGINDISABLED') !== FALSE) {
271 do_err('Your server doesn\'t allow plaintext logins. '.
272 'Try enabling another authentication mechanism like CRAM-MD5, DIGEST-MD5 or TLS-encryption '.
273 'in the SquirrelMail configuration.', FALSE);
275 if($use_imap_tls && stristr($capline, 'STARTTLS') === FALSE) {
276 do_err('You have enabled TLS encryption in the config, but the server does not '.
277 'report STARTTLS capability. TLS is probably not supported.', FALSE);
280 /** OK, close connection */
281 fputs($stream, "A002 LOGOUT\r\n");
284 echo "Checking internationalization (i18n) settings...<br />\n";
285 echo "$IND gettext - ";
286 if (function_exists('gettext')) {
287 echo 'Gettext functions are available.'
288 .' On some systems you must have appropriate system locales compiled.'
291 echo 'Gettext functions are unavailable.'
292 .' SquirrelMail will use slower internal gettext functions.'
295 echo "$IND mbstring - ";
296 if (function_exists('mb_detect_encoding')) {
297 echo "Mbstring functions are available.<br />\n";
299 echo 'Mbstring functions are unavailable.'
300 ." Japanese translation won't work.<br />\n";
302 echo "$IND recode - ";
303 if (function_exists('recode')) {
304 echo "Recode functions are available.<br />\n";
305 } elseif ($use_php_recode) {
306 echo "Recode functions are unavailable.<br />\n";
307 do_err('Your configuration requires recode support, but recode support is missing.');
309 echo "Recode functions are unavailable.<br />\n";
311 echo "$IND iconv - ";
312 if (function_exists('iconv')) {
313 echo "Iconv functions are available.<br />\n";
314 } elseif ($use_php_iconv) {
315 echo "Iconv functions are unavailable.<br />\n";
316 do_err('Your configuration requires iconv support, but iconv support is missing.');
318 echo "Iconv functions are unavailable.<br />\n";
320 // same test as in include/validate.php
321 echo "$IND timezone - ";
322 if ( (!ini_get('safe_mode')) ||
323 !strcmp(ini_get('safe_mode_allowed_env_vars'),'') ||
324 preg_match('/^([\w_]+,)*TZ/', ini_get('safe_mode_allowed_env_vars')) ) {
325 echo "Webmail users can change their time zone settings.<br />\n";
327 echo "Webmail users can't change their time zone settings.<br />\n";
332 echo "Checking database functions...<br />\n";
333 if($addrbook_dsn ||
$prefs_dsn ||
$addrbook_global_dsn) {
334 @include_once
('DB.php');
335 if (class_exists('DB')) {
336 echo "$IND PHP Pear DB support is present.<br />\n";
338 'dbase' => 'dbase_open',
339 'fbsql' => 'fbsql_connect',
340 'interbase' => 'ibase_connect',
341 'informix' => 'ifx_connect',
342 'msql' => 'msql_connect',
343 'mssql' => 'mssql_connect',
344 'mysql' => 'mysql_connect',
345 'mysqli' => 'mysqli_connect',
346 'oci8' => 'ocilogon',
347 'odbc' => 'odbc_connect',
348 'pgsql' => 'pgsql_connect',
349 'sqlite' => 'sqlite_open',
350 'sybase' => 'sybase_connect'
355 $dsns['preferences'] = $prefs_dsn;
358 $dsns['addressbook'] = $addrbook_dsn;
360 if($addrbook_global_dsn) {
361 $dsns['global addressbook'] = $addrbook_global_dsn;
364 foreach($dsns as $type => $dsn) {
365 $dbtype = array_shift(explode(':', $dsn));
366 if(isset($db_functions[$dbtype]) && function_exists($db_functions[$dbtype])) {
367 echo "$IND$dbtype database support present.<br />\n";
369 // now, test this interface:
371 $dbh = DB
::connect($dsn, true);
372 if (DB
::isError($dbh)) {
373 do_err('Database error: '. htmlspecialchars(DB
::errorMessage($dbh)) .
374 ' in ' .$type .' DSN.');
377 echo "$IND$type database connect successful.<br />\n";
380 do_err($db.' database support not present!');
384 $db_error='Required PHP PEAR DB support is not available.'
385 .' Is PEAR installed and is the include path set correctly to find <tt>DB.php</tt>?'
386 .' The include path is now:<tt>' . ini_get('include_path') . '</tt>.';
390 echo $IND."not using database functionality.<br />\n";
394 echo "Checking LDAP functions...<br />\n";
395 if( empty($ldap_server) ) {
396 echo $IND."not using LDAP functionality.<br />\n";
398 if ( !function_exists(ldap_connect
) ) {
399 do_err('Required LDAP support is not available.');
401 echo "$IND LDAP support present.<br />\n";
402 foreach ( $ldap_server as $param ) {
404 $linkid = ldap_connect($param['host'], (empty($param['port']) ?
389 : $param['port']) );
407 echo "$IND LDAP connect to ".$param['host']." successful: ".$linkid."<br />\n";
409 if ( !empty($param['protocol']) &&
410 !ldap_set_option($linkid, LDAP_OPT_PROTOCOL_VERSION
, $param['protocol']) ) {
411 do_err('Unable to set LDAP protocol');
414 if ( empty($param['binddn']) ) {
415 $bind = ldap_bind($linkid);
417 $bind = ldap_bind($param['binddn'], $param['bindpw']);
421 echo "$IND LDAP Bind Successful <br />";
423 do_err('Unable to Bind to LDAP Server');
428 do_err('Connection to LDAP failed');
435 <p
>Congratulations
, your SquirrelMail setup looks fine to me
!</p
>
437 <p
><a href
="login.php">Login now
</a
></p
>