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