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