Thijs yanked this from stable, but there's no reason it can't go into devel.
[squirrelmail.git] / config / configtest.php
... / ...
CommitLineData
1<?php
2/*
3 * SquirrelMail configtest script
4 *
5 * Copyright (c) 2003 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?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
17<html>
18<head>
19 <title>SquirrelMail configtest</title>
20</head>
21<body>
22<h1>SquirrelMail configtest</h1>
23
24<p>This script will try to check some aspects of your SquirrelMail configuration
25and point you to errors whereever it can find them. You need to go run <tt>conf.pl</tt>
26in this directory first before you run this script.</p>
27
28<?php
29
30function do_err($str, $exit = TRUE) {
31 echo '<p><font color="red"><b>ERROR:</b></font> ' .$str. "</p>\n";
32 if($exit) {
33 echo '</body></html>';
34 exit;
35 }
36}
37
38$IND = str_repeat('&nbsp;',4);
39
40ob_implicit_flush();
41define('SM_PATH', '../');
42
43include(SM_PATH . 'config/config.php');
44include(SM_PATH . 'functions/strings.php');
45
46$included = array_map('basename', get_included_files() );
47if(!in_array('config.php', $included)) {
48 if(!file_exists(SM_PATH . 'config/config.php')) {
49 do_err('Config file '.SM_PATH . 'config/config.php does not exist!<br />'.
50 'You need to run <tt>conf.pl</tt> first.');
51 }
52 do_err('Could not read '.SM_PATH.'config/config.php! Check file permissions.');
53}
54if(!in_array('strings.php', $included)) {
55 do_err('Could not include '.SM_PATH.'functions/strings.php!<br />'.
56 'Check permissions on that file.');
57}
58
59/* checking PHP specs */
60
61echo '<p>SquirrelMail version: '.$version.'<br />'.
62 'Config file version: '.$config_version . '<br />'.
63 'Config file last modified: '.date ('d F Y H:i:s', filemtime(SM_PATH . 'config/config.php')).'</p>';
64
65echo "Checking PHP configuration...<br />\n";
66
67if(!check_php_version(4,0,6)) {
68 do_err('Insufficient PHP version: '. PHP_VERSION . '! Minimum required: 4.0.6');
69}
70
71echo $IND . 'PHP version '.PHP_VERSION.' OK.<br />';
72
73$php_exts = array('session','pcre');
74$diff = array_diff($php_exts, get_loaded_extensions());
75if(count($diff)) {
76 do_err('Required PHP extensions missing: '.implode(', ',$diff) );
77}
78
79echo $IND . 'PHP extensions OK.<br />';
80
81
82/* checking paths */
83
84echo "Checking paths...<br />\n";
85
86if(!file_exists($data_dir)) {
87 do_err("Data dir ($data_dir) does not exist!");
88}
89if(!is_dir($data_dir)) {
90 do_err("Data dir ($data_dir) is not a directory!");
91}
92if(!is_readable($data_dir)) {
93 do_err("I cannot read from data dir ($data_dir)!");
94}
95if(!is_writable($data_dir)) {
96 do_err("I cannot write to data dir ($data_dir)!");
97}
98
99// todo_ornot: actually write something and read it back.
100echo $IND . "Data dir OK.<br />\n";
101
102
103if($data_dir == $attachment_dir) {
104 echo $IND . "Attachment dir is the same as data dir.<br />\n";
105} else {
106 if(!file_exists($attachment_dir)) {
107 do_err("Attachment dir ($attachment_dir) does not exist!");
108 }
109 if (!is_dir($attachment_dir)) {
110 do_err("Attachment dir ($attachment_dir) is not a directory!");
111 }
112 if (!is_readable($attachment_dir)) {
113 do_err("I cannot read from attachment dir ($attachment_dir)!");
114 }
115 if (!is_writable($attachment_dir)) {
116 do_err("I cannot write to attachment dir ($attachment_dir)!");
117 }
118 echo $IND . "Attachment dir OK.<br />\n";
119}
120
121
122/* check plugins and themes */
123
124foreach($plugins as $plugin) {
125 if(!file_exists(SM_PATH .'plugins/'.$plugin)) {
126 do_err('You have enabled the <i>'.$plugin.'</i> plugin but I cannot find it.', FALSE);
127 } elseif (!is_readable(SM_PATH .'plugins/'.$plugin.'/setup.php')) {
128 do_err('You have enabled the <i>'.$plugin.'</i> plugin but I cannot read its setup.php file.', FALSE);
129 }
130}
131
132echo $IND . "Plugins OK.<br />\n";
133
134foreach($theme as $thm) {
135 if(!file_exists($thm['PATH'])) {
136 do_err('You have enabled the <i>'.$thm['NAME'].'</i> theme but I cannot find it ('.$thm['PATH'].').', FALSE);
137 } elseif(!is_readable($thm['PATH'])) {
138 do_err('You have enabled the <i>'.$thm['NAME'].'</i> theme but I cannot read it ('.$thm['PATH'].').', FALSE);
139 }
140}
141
142echo $IND . "Themes OK.<br />\n";
143
144
145/* check outgoing mail */
146
147if($use_smtp_tls || $use_imap_tls) {
148 if(!check_php_version(4,3,0)) {
149 do_err('You need at least PHP 4.3.0 for SMTP/IMAP TLS!');
150 }
151 if(!extension_loaded('openssl')) {
152 do_err('You need the openssl PHP extension to use SMTP/IMAP TLS!');
153 }
154}
155
156echo "Checking outgoing mail service....<br />\n";
157
158if($useSendmail) {
159 // is_executable also checks for existance, but we want to be as precise as possible with the errors
160 if(!file_exists($sendmail_path)) {
161 do_err("Location of sendmail program incorrect ($sendmail_path)!");
162 }
163 if(!is_executable($sendmail_path)) {
164 do_err("I cannot execute the sendmail program ($sendmail_path)!");
165 }
166
167 echo $IND . "sendmail OK<br />\n";
168} else {
169 $stream = fsockopen( ($use_smtp_tls?'tls://':'').$smtpServerAddress, $smtpPort,
170 $errorNumber, $errorString);
171 if(!$stream) {
172 do_err("Error connecting to SMTP server \"$smtpServerAddress:$smtpPort\".".
173 "Server error: ($errorNumber) $errorString");
174 }
175
176 // check for SMTP code; should be 2xx to allow us access
177 $smtpline = fgets($stream, 1024);
178 if(((int) $smtpline{0}) > 3) {
179 do_err("Error connecting to SMTP server. Server error: ".$smtpline);
180 }
181
182 fputs($stream, 'QUIT');
183 fclose($stream);
184 echo $IND . 'SMTP server OK (<tt><small>'.trim($smtpline)."</small></tt>)<br />\n";
185
186 /* POP before SMTP */
187 if($pop_before_smtp) {
188 $stream = fsockopen($smtpServerAddress, 110, $err_no, $err_str);
189 if (!$stream) {
190 do_err("Error connecting to POP Server ($smtpServerAddress:110)"
191 . " $err_no : $err_str");
192 }
193
194 $tmp = fgets($stream, 1024);
195 if (substr($tmp, 0, 3) != '+OK') {
196 do_err("Error connecting to POP Server ($smtpServerAddress:110)"
197 . ' '.$tmp);
198 }
199 fputs($stream, 'QUIT');
200 fclose($stream);
201 echo $IND . "POP-before-SMTP OK.<br />\n";
202 }
203}
204
205echo "Checking IMAP service....<br />\n";
206
207$stream = fsockopen( ($use_imap_tls?'tls://':'').$imapServerAddress, $imapPort,
208 $errorNumber, $errorString);
209if(!$stream) {
210 do_err("Error connecting to SMTP server \"$smtpServerAddress:$smtpPort\".".
211 "Server error: ($errorNumber) $errorString");
212}
213
214$imapline = fgets($stream, 1024);
215if(substr($imapline, 0,4) != '* OK') {
216 do_err('Error connecting to IMAP server. Server error: '.$imapline);
217}
218
219fputs($stream, '001 LOGOUT');
220fclose($stream);
221
222echo $IND . 'IMAP server OK (<tt><small>'.trim($imapline)."</small></tt>)<br />\n";
223
224// other possible checks:
225// ? prefs/abook DSN
226// ? locale/gettext
227// ? actually start a session to see if it works
228// ? ...
229?>
230
231<p>Congratulations, your SquirrelMail setup looks fine to me!</p>
232
233<p><a href="<?php echo SM_PATH; ?>src/login.php">Login now</a></p>
234
235</body>
236</html>