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