Don't gripe about not being able to read the attachment dir when we
[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 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
26 ob_implicit_flush();
27 define('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 */
35 if (file_exists(SM_PATH . 'config/config.php')) {
36 include(SM_PATH . 'config/config.php');
37 include(SM_PATH . 'functions/strings.php');
38 }
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
48 and point you to errors whereever it can find them. You need to go run <tt>conf.pl</tt>
49 in this directory first before you run this script.</p>
50
51 <?php
52
53
54 $included = array_map('basename', get_included_files() );
55 if(!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 }
62 if(!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
69 echo '<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
73 echo "Checking PHP configuration...<br />\n";
74
75 if(!check_php_version(4,1,0)) {
76 do_err('Insufficient PHP version: '. PHP_VERSION . '! Minimum required: 4.1.0');
77 }
78
79 echo $IND . 'PHP version '.PHP_VERSION.' OK.<br />';
80
81 $php_exts = array('session','pcre');
82 $diff = array_diff($php_exts, get_loaded_extensions());
83 if(count($diff)) {
84 do_err('Required PHP extensions missing: '.implode(', ',$diff) );
85 }
86
87 echo $IND . 'PHP extensions OK.<br />';
88
89
90 /* checking paths */
91
92 echo "Checking paths...<br />\n";
93
94 if(!file_exists($data_dir)) {
95 do_err("Data dir ($data_dir) does not exist!");
96 }
97 if(!is_dir($data_dir)) {
98 do_err("Data dir ($data_dir) is not a directory!");
99 }
100 if(!is_readable($data_dir)) {
101 do_err("I cannot read from data dir ($data_dir)!");
102 }
103 if(!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.
108 echo $IND . "Data dir OK.<br />\n";
109
110
111 if($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 }
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 */
128 if (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 }
135 }
136 echo $IND . "Plugins OK.<br />\n";
137 } else {
138 echo $IND . "Plugins are not enabled in config.<br />\n";
139 }
140 foreach($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
148 echo $IND . "Themes OK.<br />\n";
149
150
151 /* check outgoing mail */
152
153 if($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
162 echo "Checking outgoing mail service....<br />\n";
163
164 if($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
211 echo "Checking IMAP service....<br />\n";
212
213 $stream = fsockopen( ($use_imap_tls?'tls://':'').$imapServerAddress, $imapPort,
214 $errorNumber, $errorString);
215 if(!$stream) {
216 do_err("Error connecting to IMAP server \"$imapServerAddress:$imapPort\".".
217 "Server error: ($errorNumber) $errorString");
218 }
219
220 $imapline = fgets($stream, 1024);
221 if(substr($imapline, 0,4) != '* OK') {
222 do_err('Error connecting to IMAP server. Server error: '.$imapline);
223 }
224
225 fputs($stream, '001 LOGOUT');
226 fclose($stream);
227
228 echo $IND . 'IMAP server OK (<tt><small>'.trim($imapline)."</small></tt>)<br />\n";
229
230 echo "Checking i18n settings:<br />\n";
231 echo "$IND gettext - ";
232 if (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 }
237 echo "$IND mbstring - ";
238 if (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 }
243 echo "$IND recode - ";
244 if (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 }
252 echo "$IND iconv - ";
253 if (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
262 echo "$IND timezone - ";
263 if ( (!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')) ) {
266 echo "Webmail users can change their time zone settings.";
267 } else {
268 echo "Webmail users can't change their time zone settings.";
269 }
270
271 // other possible checks:
272 // ? prefs/abook DSN
273 // ? actually start a session to see if it works
274 // ? ...
275 ?>
276
277 <p>Congratulations, your SquirrelMail setup looks fine to me!</p>
278
279 <p><a href="login.php">Login now</a></p>
280
281 </body>
282 </html>