Moving some HTML out of PHP
[squirrelmail.git] / src / configtest.php
1 <?php
2
3 /**
4 * SquirrelMail configtest script
5 *
6 * Copyright (c) 2003-2004 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * @version $Id$
10 * @package squirrelmail
11 * @subpackage config
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
19 function do_err($str, $exit = TRUE) {
20 global $IND;
21 echo '<p>'.$IND.'<font color="red"><b>ERROR:</b></font> ' .$str. "</p>\n";
22 if($exit) {
23 echo '</body></html>';
24 exit;
25 }
26 }
27
28 $IND = str_repeat('&nbsp;',4);
29
30 ob_implicit_flush();
31 /** @ignore */
32 define('SM_PATH', '../');
33
34 /*
35 * Load config before output begins. functions/strings.php depends on
36 * functions/globals.php. functions/global.php needs to be run before
37 * any html output starts. If config.php is missing, error will be displayed
38 * later.
39 */
40 if (file_exists(SM_PATH . 'config/config.php')) {
41 include(SM_PATH . 'config/config.php');
42 include(SM_PATH . 'functions/strings.php');
43 }
44 ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
45 <html>
46 <head>
47 <title>SquirrelMail configtest</title>
48 </head>
49 <body>
50 <h1>SquirrelMail configtest</h1>
51
52 <p>This script will try to check some aspects of your SquirrelMail configuration
53 and point you to errors whereever it can find them. You need to go run <tt>conf.pl</tt>
54 in the <tt>config/</tt> directory first before you run this script.</p>
55
56 <?php
57
58
59 $included = array_map('basename', get_included_files() );
60 if(!in_array('config.php', $included)) {
61 if(!file_exists(SM_PATH . 'config/config.php')) {
62 do_err('Config file '.SM_PATH . 'config/config.php does not exist!<br />'.
63 'You need to run <tt>conf.pl</tt> first.');
64 }
65 do_err('Could not read '.SM_PATH.'config/config.php! Check file permissions.');
66 }
67 if(!in_array('strings.php', $included)) {
68 do_err('Could not include '.SM_PATH.'functions/strings.php!<br />'.
69 'Check permissions on that file.');
70 }
71
72 /* checking PHP specs */
73
74 echo "<p><table>\n<tr><td>SquirrelMail version:</td><td><b>" . $version . "</b></td></tr>\n" .
75 '<tr><td>Config file version:</td><td><b>' . $config_version . "</b></td></tr>\n" .
76 '<tr><td>Config file last modified:</td><td><b>' .
77 date ('d F Y H:i:s', filemtime(SM_PATH . 'config/config.php')) .
78 "</b></td></tr>\n</table>\n</p>\n\n";
79
80 echo "Checking PHP configuration...<br />\n";
81
82 if(!check_php_version(4,1,0)) {
83 do_err('Insufficient PHP version: '. PHP_VERSION . '! Minimum required: 4.1.0');
84 }
85
86 echo $IND . 'PHP version ' . PHP_VERSION . " OK.<br />\n";
87
88 $php_exts = array('session','pcre');
89 $diff = array_diff($php_exts, get_loaded_extensions());
90 if(count($diff)) {
91 do_err('Required PHP extensions missing: '.implode(', ',$diff) );
92 }
93
94 echo $IND . "PHP extensions OK.<br />\n";
95
96
97 /* checking paths */
98
99 echo "Checking paths...<br />\n";
100
101 if(!file_exists($data_dir)) {
102 do_err("Data dir ($data_dir) does not exist!");
103 }
104 if(!is_dir($data_dir)) {
105 do_err("Data dir ($data_dir) is not a directory!");
106 }
107 if(!is_readable($data_dir)) {
108 do_err("I cannot read from data dir ($data_dir)!");
109 }
110 if(!is_writable($data_dir)) {
111 do_err("I cannot write to data dir ($data_dir)!");
112 }
113
114 // todo_ornot: actually write something and read it back.
115 echo $IND . "Data dir OK.<br />\n";
116
117
118 if($data_dir == $attachment_dir) {
119 echo $IND . "Attachment dir is the same as data dir.<br />\n";
120 } else {
121 if(!file_exists($attachment_dir)) {
122 do_err("Attachment dir ($attachment_dir) does not exist!");
123 }
124 if (!is_dir($attachment_dir)) {
125 do_err("Attachment dir ($attachment_dir) is not a directory!");
126 }
127 if (!is_writable($attachment_dir)) {
128 do_err("I cannot write to attachment dir ($attachment_dir)!");
129 }
130 echo $IND . "Attachment dir OK.<br />\n";
131 }
132
133
134 /* check plugins and themes */
135 if (isset($plugins[0])) {
136 foreach($plugins as $plugin) {
137 if(!file_exists(SM_PATH .'plugins/'.$plugin)) {
138 do_err('You have enabled the <i>'.$plugin.'</i> plugin but I cannot find it.', FALSE);
139 } elseif (!is_readable(SM_PATH .'plugins/'.$plugin.'/setup.php')) {
140 do_err('You have enabled the <i>'.$plugin.'</i> plugin but I cannot read its setup.php file.', FALSE);
141 }
142 }
143 echo $IND . "Plugins OK.<br />\n";
144 } else {
145 echo $IND . "Plugins are not enabled in config.<br />\n";
146 }
147 foreach($theme as $thm) {
148 if(!file_exists($thm['PATH'])) {
149 do_err('You have enabled the <i>'.$thm['NAME'].'</i> theme but I cannot find it ('.$thm['PATH'].').', FALSE);
150 } elseif(!is_readable($thm['PATH'])) {
151 do_err('You have enabled the <i>'.$thm['NAME'].'</i> theme but I cannot read it ('.$thm['PATH'].').', FALSE);
152 }
153 }
154
155 echo $IND . "Themes OK.<br />\n";
156
157
158 /* check outgoing mail */
159
160 if($use_smtp_tls || $use_imap_tls) {
161 if(!check_php_version(4,3,0)) {
162 do_err('You need at least PHP 4.3.0 for SMTP/IMAP TLS!');
163 }
164 if(!extension_loaded('openssl')) {
165 do_err('You need the openssl PHP extension to use SMTP/IMAP TLS!');
166 }
167 }
168
169 echo "Checking outgoing mail service....<br />\n";
170
171 if($useSendmail) {
172 // is_executable also checks for existance, but we want to be as precise as possible with the errors
173 if(!file_exists($sendmail_path)) {
174 do_err("Location of sendmail program incorrect ($sendmail_path)!");
175 }
176 if(!is_executable($sendmail_path)) {
177 do_err("I cannot execute the sendmail program ($sendmail_path)!");
178 }
179
180 echo $IND . "sendmail OK<br />\n";
181 } else {
182 $stream = fsockopen( ($use_smtp_tls?'tls://':'').$smtpServerAddress, $smtpPort,
183 $errorNumber, $errorString);
184 if(!$stream) {
185 do_err("Error connecting to SMTP server \"$smtpServerAddress:$smtpPort\".".
186 "Server error: ($errorNumber) ".htmlspecialchars($errorString));
187 }
188
189 // check for SMTP code; should be 2xx to allow us access
190 $smtpline = fgets($stream, 1024);
191 if(((int) $smtpline{0}) > 3) {
192 do_err("Error connecting to SMTP server. Server error: ".
193 htmlspecialchars($smtpline));
194 }
195
196 fputs($stream, 'QUIT');
197 fclose($stream);
198 echo $IND . 'SMTP server OK (<tt><small>'.
199 trim(htmlspecialchars($smtpline))."</small></tt>)<br />\n";
200
201 /* POP before SMTP */
202 if($pop_before_smtp) {
203 $stream = fsockopen($smtpServerAddress, 110, $err_no, $err_str);
204 if (!$stream) {
205 do_err("Error connecting to POP Server ($smtpServerAddress:110) "
206 . $err_no . ' : ' . htmlspecialchars($err_str));
207 }
208
209 $tmp = fgets($stream, 1024);
210 if (substr($tmp, 0, 3) != '+OK') {
211 do_err("Error connecting to POP Server ($smtpServerAddress:110)"
212 . ' '.htmlspecialchars($tmp));
213 }
214 fputs($stream, 'QUIT');
215 fclose($stream);
216 echo $IND . "POP-before-SMTP OK.<br />\n";
217 }
218 }
219
220 echo "Checking IMAP service....<br />\n";
221
222 $stream = fsockopen( ($use_imap_tls?'tls://':'').$imapServerAddress, $imapPort,
223 $errorNumber, $errorString);
224 if(!$stream) {
225 do_err("Error connecting to IMAP server \"$imapServerAddress:$imapPort\".".
226 "Server error: ($errorNumber) ".
227 htmlspecialchars($errorString));
228 }
229
230 $imapline = fgets($stream, 1024);
231 if(substr($imapline, 0,4) != '* OK') {
232 do_err('Error connecting to IMAP server. Server error: '.
233 htmlspecialchars($imapline));
234 }
235
236 fputs($stream, '001 LOGOUT');
237 fclose($stream);
238
239 echo $IND . 'IMAP server OK (<tt><small>'.
240 htmlspecialchars(trim($imapline))."</small></tt>)<br />\n";
241
242 echo "Checking internationalization (i18n) settings...<br />\n";
243 echo "$IND gettext - ";
244 if (function_exists('gettext')) {
245 echo "Gettext functions are available. You must have appropriate system locales compiled.<br />\n";
246 } else {
247 echo "Gettext functions are unavailable. SquirrelMail will use slower internal gettext functions.<br />\n";
248 }
249 echo "$IND mbstring - ";
250 if (function_exists('mb_detect_encoding')) {
251 echo "Mbstring functions are available.<br />\n";
252 } else {
253 echo "Mbstring functions are unavailable. Japanese translation won't work.<br />\n";
254 }
255 echo "$IND recode - ";
256 if (function_exists('recode')) {
257 echo "Recode functions are available.<br />\n";
258 } elseif ($use_php_recode) {
259 echo "Recode functions are unavailable.<br />\n";
260 do_err('Your configuration requires recode support, but recode support is missing.');
261 } else {
262 echo "Recode functions are unavailable.<br />\n";
263 }
264 echo "$IND iconv - ";
265 if (function_exists('iconv')) {
266 echo "Iconv functions are available.<br />\n";
267 } elseif ($use_php_iconv) {
268 echo "Iconv functions are unavailable.<br />\n";
269 do_err('Your configuration requires iconv support, but iconv support is missing.');
270 } else {
271 echo "Iconv functions are unavailable.<br />\n";
272 }
273 // same test as in include/validate.php
274 echo "$IND timezone - ";
275 if ( (!ini_get('safe_mode')) ||
276 !strcmp(ini_get('safe_mode_allowed_env_vars'),'') ||
277 preg_match('/^([\w_]+,)*TZ/', ini_get('safe_mode_allowed_env_vars')) ) {
278 echo "Webmail users can change their time zone settings.<br />\n";
279 } else {
280 echo "Webmail users can't change their time zone settings.<br />\n";
281 }
282
283
284 // Pear DB tests
285 echo "Checking database functions...<br />\n";
286 if($addrbook_dsn || $prefs_dsn || $addrbook_global_dsn) {
287 @include_once('DB.php');
288 if (class_exists('DB')) {
289 echo "$IND PHP Pear DB support is present.<br />\n";
290 $db_functions=array(
291 'dbase' => 'dbase_open',
292 'fbsql' => 'fbsql_connect',
293 'interbase' => 'ibase_connect',
294 'informix' => 'ifx_connect',
295 'msql' => 'msql_connect',
296 'mssql' => 'mssql_connect',
297 'mysql' => 'mysql_connect',
298 'mysqli' => 'mysqli_connect',
299 'oci8' => 'ocilogon',
300 'odbc' => 'odbc_connect',
301 'pgsql' => 'pgsql_connect',
302 'sqlite' => 'sqlite_open',
303 'sybase' => 'sybase_connect'
304 );
305
306 $dsns = array();
307 if($prefs_dsn) {
308 $dsns['preferences'] = $prefs_dsn;
309 }
310 if($addrbook_dsn) {
311 $dsns['addressbook'] = $addrbook_dsn;
312 }
313 if($addrbook_global_dsn) {
314 $dsns['global addressbook'] = $addrbook_global_dsn;
315 }
316
317 foreach($dsns as $type => $dsn) {
318 $dbtype = array_shift(explode(':', $dsn));
319 if(isset($db_functions[$dbtype]) && function_exists($db_functions[$dbtype])) {
320 echo "$IND$dbtype database support present.<br />\n";
321
322 // now, test this interface:
323
324 $dbh = DB::connect($dsn, true);
325 if (DB::isError($dbh)) {
326 do_err('Database error: '. htmlspecialchars(DB::errorMessage($dbh)) .
327 ' in ' .$type .' DSN.');
328 }
329 $dbh->disconnect();
330 echo "$IND$type database connect successful.<br />\n";
331
332 } else {
333 do_err($db.' database support not present!');
334 }
335 }
336 } else {
337 do_err('Required PHP PEAR DB support is not available. Is PEAR installed and is the
338 include path set correctly to find <tt>DB.php</tt>? The include path is now:
339 "<tt>' . ini_get('include_path') . '</tt>".');
340 }
341 } else {
342 echo $IND."not using database functionality.<br />\n";
343 }
344
345 // LDAP DB tests
346 echo "Checking LDAP functions...<br />\n";
347 if( empty($ldap_server) ) {
348 echo $IND."not using LDAP functionality.<br />\n";
349 } else {
350 if ( !function_exists(ldap_connect) ) {
351 do_err('Required LDAP support is not available.');
352 } else {
353 echo "$IND LDAP support present.<br />\n";
354 foreach ( $ldap_server as $param ) {
355
356 $linkid = ldap_connect($param['host'], (empty($param['port']) ? 389 : $param['port']) );
357
358 if ( $linkid ) {
359 echo "$IND LDAP connect to ".$param['host']." successful: ".$linkid."<br />\n";
360
361 if ( !empty($param['protocol']) &&
362 !ldap_set_option($linkid, LDAP_OPT_PROTOCOL_VERSION, $param['protocol']) ) {
363 do_err('Unable to set LDAP protocol');
364 }
365
366 if ( empty($param['binddn']) ) {
367 $bind = ldap_bind($linkid);
368 } else {
369 $bind = ldap_bind($param['binddn'], $param['bindpw']);
370 }
371
372 if ( $bind ) {
373 echo "$IND LDAP Bind Successful <br />";
374 } else {
375 do_err('Unable to Bind to LDAP Server');
376 }
377
378 ldap_close($linkid);
379 } else {
380 do_err('Connection to LDAP failed');
381 }
382 }
383 }
384 }
385 ?>
386
387 <p>Congratulations, your SquirrelMail setup looks fine to me!</p>
388
389 <p><a href="login.php">Login now</a></p>
390
391 </body>
392 </html>
393 <?php
394 // vim: et ts=4
395 ?>