oops, need better error checking than that...
[squirrelmail.git] / config / 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
75if(!check_php_version(4,0,6)) {
76 do_err('Insufficient PHP version: '. PHP_VERSION . '! Minimum required: 4.0.6');
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 }
120 if (!is_readable($attachment_dir)) {
121 do_err("I cannot read from attachment dir ($attachment_dir)!");
122 }
123 if (!is_writable($attachment_dir)) {
124 do_err("I cannot write to attachment dir ($attachment_dir)!");
125 }
126 echo $IND . "Attachment dir OK.<br />\n";
127}
128
129
130/* check plugins and themes */
5b53b7e0 131if (isset($plugins[0])) {
132 foreach($plugins as $plugin) {
133 if(!file_exists(SM_PATH .'plugins/'.$plugin)) {
134 do_err('You have enabled the <i>'.$plugin.'</i> plugin but I cannot find it.', FALSE);
135 } elseif (!is_readable(SM_PATH .'plugins/'.$plugin.'/setup.php')) {
136 do_err('You have enabled the <i>'.$plugin.'</i> plugin but I cannot read its setup.php file.', FALSE);
137 }
d1ae9d4c 138 }
5b53b7e0 139 echo $IND . "Plugins OK.<br />\n";
140} else {
141 echo $IND . "Plugins are not enabled in config.<br />\n";
d1ae9d4c 142}
d1ae9d4c 143foreach($theme as $thm) {
144 if(!file_exists($thm['PATH'])) {
145 do_err('You have enabled the <i>'.$thm['NAME'].'</i> theme but I cannot find it ('.$thm['PATH'].').', FALSE);
146 } elseif(!is_readable($thm['PATH'])) {
147 do_err('You have enabled the <i>'.$thm['NAME'].'</i> theme but I cannot read it ('.$thm['PATH'].').', FALSE);
148 }
149}
150
151echo $IND . "Themes OK.<br />\n";
152
153
154/* check outgoing mail */
155
156if($use_smtp_tls || $use_imap_tls) {
157 if(!check_php_version(4,3,0)) {
158 do_err('You need at least PHP 4.3.0 for SMTP/IMAP TLS!');
159 }
160 if(!extension_loaded('openssl')) {
161 do_err('You need the openssl PHP extension to use SMTP/IMAP TLS!');
162 }
163}
164
165echo "Checking outgoing mail service....<br />\n";
166
167if($useSendmail) {
168 // is_executable also checks for existance, but we want to be as precise as possible with the errors
169 if(!file_exists($sendmail_path)) {
170 do_err("Location of sendmail program incorrect ($sendmail_path)!");
171 }
172 if(!is_executable($sendmail_path)) {
173 do_err("I cannot execute the sendmail program ($sendmail_path)!");
174 }
175
176 echo $IND . "sendmail OK<br />\n";
177} else {
178 $stream = fsockopen( ($use_smtp_tls?'tls://':'').$smtpServerAddress, $smtpPort,
179 $errorNumber, $errorString);
180 if(!$stream) {
181 do_err("Error connecting to SMTP server \"$smtpServerAddress:$smtpPort\".".
182 "Server error: ($errorNumber) $errorString");
183 }
184
185 // check for SMTP code; should be 2xx to allow us access
186 $smtpline = fgets($stream, 1024);
187 if(((int) $smtpline{0}) > 3) {
188 do_err("Error connecting to SMTP server. Server error: ".$smtpline);
189 }
190
191 fputs($stream, 'QUIT');
192 fclose($stream);
193 echo $IND . 'SMTP server OK (<tt><small>'.trim($smtpline)."</small></tt>)<br />\n";
194
195 /* POP before SMTP */
196 if($pop_before_smtp) {
197 $stream = fsockopen($smtpServerAddress, 110, $err_no, $err_str);
198 if (!$stream) {
199 do_err("Error connecting to POP Server ($smtpServerAddress:110)"
200 . " $err_no : $err_str");
201 }
202
203 $tmp = fgets($stream, 1024);
204 if (substr($tmp, 0, 3) != '+OK') {
205 do_err("Error connecting to POP Server ($smtpServerAddress:110)"
206 . ' '.$tmp);
207 }
208 fputs($stream, 'QUIT');
209 fclose($stream);
210 echo $IND . "POP-before-SMTP OK.<br />\n";
211 }
212}
213
214echo "Checking IMAP service....<br />\n";
215
216$stream = fsockopen( ($use_imap_tls?'tls://':'').$imapServerAddress, $imapPort,
217 $errorNumber, $errorString);
218if(!$stream) {
70b71161 219 do_err("Error connecting to IMAP server \"$imapServerAddress:$imapPort\".".
d1ae9d4c 220 "Server error: ($errorNumber) $errorString");
221}
222
223$imapline = fgets($stream, 1024);
224if(substr($imapline, 0,4) != '* OK') {
225 do_err('Error connecting to IMAP server. Server error: '.$imapline);
226}
227
228fputs($stream, '001 LOGOUT');
229fclose($stream);
230
231echo $IND . 'IMAP server OK (<tt><small>'.trim($imapline)."</small></tt>)<br />\n";
232
233// other possible checks:
234// ? prefs/abook DSN
235// ? locale/gettext
236// ? actually start a session to see if it works
237// ? ...
238?>
239
240<p>Congratulations, your SquirrelMail setup looks fine to me!</p>
241
242<p><a href="<?php echo SM_PATH; ?>src/login.php">Login now</a></p>
243
244</body>
245</html>