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 |
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(' ',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 | } |
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 |
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 | |
d1ae9d4c |
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 | |
abd74f7d |
75 | if(!check_php_version(4,1,0)) { |
76 | do_err('Insufficient PHP version: '. PHP_VERSION . '! Minimum required: 4.1.0'); |
d1ae9d4c |
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_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 |
131 | if (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 |
143 | foreach($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 | |
151 | echo $IND . "Themes OK.<br />\n"; |
152 | |
153 | |
154 | /* check outgoing mail */ |
155 | |
156 | if($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 | |
165 | echo "Checking outgoing mail service....<br />\n"; |
166 | |
167 | if($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 | |
214 | echo "Checking IMAP service....<br />\n"; |
215 | |
216 | $stream = fsockopen( ($use_imap_tls?'tls://':'').$imapServerAddress, $imapPort, |
217 | $errorNumber, $errorString); |
218 | if(!$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); |
224 | if(substr($imapline, 0,4) != '* OK') { |
225 | do_err('Error connecting to IMAP server. Server error: '.$imapline); |
226 | } |
227 | |
228 | fputs($stream, '001 LOGOUT'); |
229 | fclose($stream); |
230 | |
231 | echo $IND . 'IMAP server OK (<tt><small>'.trim($imapline)."</small></tt>)<br />\n"; |
232 | |
0ed3bdc3 |
233 | echo "Checking i18n settings:<br />\n"; |
234 | echo "$IND gettext - "; |
235 | if (function_exists('gettext')) { |
236 | echo "Gettext functions are available. You must have appropriate system locales compiled.<br />\n"; |
237 | } else { |
238 | echo "Gettext functions are unavailable. SquirrelMail will use slower internal gettext functions.<br />\n"; |
239 | } |
240 | echo "$IND mbstring - "; |
241 | if (function_exists('mb_detect_encoding')) { |
242 | echo "Mbstring functions are available.<br />\n"; |
243 | } else { |
244 | echo "Mbstring functions are unavailable. Japanese translation won't work.<br />\n"; |
245 | } |
246 | echo "$IND recode - "; |
247 | if (function_exists('recode')) { |
248 | echo "Recode functions are available.<br />\n"; |
249 | } elseif ($use_php_recode) { |
250 | echo "Recode functions are unavailable.<br />\n"; |
251 | do_err('Your configuration requires recode support, but recode support is missing.'); |
252 | } else { |
253 | echo "Recode functions are unavailable.<br />\n"; |
254 | } |
255 | echo "$IND iconv - "; |
256 | if (function_exists('iconv')) { |
257 | echo "Iconv functions are available.<br />\n"; |
258 | } elseif ($use_php_iconv) { |
259 | echo "Iconv functions are unavailable.<br />\n"; |
260 | do_err('Your configuration requires iconv support, but iconv support is missing.'); |
261 | } else { |
262 | echo "Iconv functions are unavailable.<br />\n"; |
263 | } |
264 | // same test as in include/validate.php |
265 | echo "$IND timezone - "; |
266 | if ( (!ini_get('safe_mode')) || |
267 | !strcmp(ini_get('safe_mode_allowed_env_vars'),'') || |
268 | preg_match('/^([\w_]+,)*TZ/', ini_get('safe_mode_allowed_env_vars')) ) { |
269 | echo "Webmail users can change their time zone settings."; |
270 | } else { |
271 | echo "Webmail users can't change their time zone settings."; |
272 | } |
273 | |
d1ae9d4c |
274 | // other possible checks: |
275 | // ? prefs/abook DSN |
d1ae9d4c |
276 | // ? actually start a session to see if it works |
277 | // ? ... |
278 | ?> |
279 | |
280 | <p>Congratulations, your SquirrelMail setup looks fine to me!</p> |
281 | |
13721b47 |
282 | <p><a href="login.php">Login now</a></p> |
d1ae9d4c |
283 | |
284 | </body> |
285 | </html> |