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