thomascube
2008-03-09 696d0c60c391be71ac58f7fc719ced47863fe756
commit | author | age
198816 1 <?php
T 2 /**
3  * Copyright (c) 2008, Till Klampaeckel
31ff9f 4  *
198816 5  * All rights reserved.
31ff9f 6  *
198816 7  * Redistribution and use in source and binary forms, with or without modification,
T 8  * are permitted provided that the following conditions are met:
31ff9f 9  *
198816 10  *  * Redistributions of source code must retain the above copyright notice, this
T 11  *    list of conditions and the following disclaimer.
12  *  * Redistributions in binary form must reproduce the above copyright notice, this
13  *    list of conditions and the following disclaimer in the documentation and/or
14  *    other materials provided with the distribution.
31ff9f 15  *
198816 16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
T 17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * PHP Version 5
29  *
30  * @category Config
31  * @package  RoundCube
32  * @author   Till Klampaeckel <till@php.net>
33  * @license  http://www.opensource.org/licenses/bsd-license.php The BSD License
34  * @version  CVS: $Id$
35  * @link     https://svn.roundcube.net/trunk
36  * @todo     HTML/CSS to make it pretty.
37  * @todo     In devel-next, use bootstrap.
38  * @todo     Refactor to use RoundCube classes.
39  */
40
41 $rctest_config         = array();
8b661f 42
T 43 /**
44  * @var string Please edit this to an email address, such as yourname@example.org.
45  *             This email address serves as from and to for the test emails.
46  */
198816 47 $rctest_config['from'] = '_yourfrom_';
T 48
49 /*
50  ********************************************
51  ********************************************
52  ** Don't edit anything else in this file. **
53  ** Unless (of course) you know what you   **
54  ** are doing.                             **
55  ********************************************
56  ********************************************
57  */
1a13d6 58
89ef0e 59 define('CHECK_OK', '<span class="success">OK</span>');
T 60 define('CHECK_NOK', '<span class="fail">NOT OK</span>');
ab9642 61 define('CHECK_NA', '<span class="na">NOT AVAILABLE</span>');
89ef0e 62
31ff9f 63 error_reporting(E_ALL);
198816 64
6b9e4a 65 $include_path  = dirname(__FILE__) . '/program/lib';
198816 66 $include_path .= PATH_SEPARATOR;
6b9e4a 67 $include_path .= dirname(__FILE__) . '/program';
198816 68 $include_path .= PATH_SEPARATOR;
T 69 $include_path .= get_include_path();
70
31ff9f 71 ini_set('display_errors', 1);
198816 72 set_include_path($include_path);
T 73
6b9e4a 74 $create_files = array('config/db.inc.php', 'config/main.inc.php');
T 75
76 $required_libs = array('PEAR' => 'PEAR.php', 'DB' => 'DB.php',
77     'Net_SMTP' => 'Net/SMTP.php', 'Mail_mime' => 'Mail/mime.php',
78     'MDB2' => 'MDB2.php', 'iilConnection' => 'lib/imap.inc');
79
80 $supported_drivers = array('MDB2#mysql' => 'MDB2/Driver/mysql.php',
a9261c 81     'MDB2#pgsql' => 'MDB2/Driver/pgsql.php',
T 82     'MDB2#sqlite' => 'MDB2/Driver/sqlite.php');
6b9e4a 83
T 84 $supported_dbs = array('MySQL' => 'mysql', 'MySQLi' => 'mysqli',
85     'PostgreSQL' => 'pgsql', 'SQLite (v2)' => 'sqlite');
198816 86
a9261c 87 $required_php_exts = array('Session' => 'session',
T 88     'PCRE' => 'pcre', 'Sockets' => 'sockets');
e50912 89
a9261c 90 $optional_php_exts = array('FileInfo' => 'fileinfo', 'Libiconv' => 'iconv',
T 91     'Multibyte' => 'mbstring', 'OpenSSL' => 'openssl', 'GD' => 'gd');
e50912 92
T 93 $source_urls = array(
94     'Socket' => 'http://www.php.net/manual/en/ref.sockets.php',
95     'Session' => 'http://www.php.net/manual/en/ref.session.php',
96     'PCRE' => 'http://www.php.net/manual/en/ref.pcre.php',
97     'FileInfo' => 'http://www.php.net/manual/en/ref.fileinfo.php',
98     'Libiconv' => 'http://www.php.net/manual/en/ref.iconv.php',
99     'Multibyte' => 'http://www.php.net/manual/en/ref.mbstring.php',
100     'OpenSSL' => 'http://www.php.net/manual/en/ref.openssl.php',
101     'PEAR' => 'http://pear.php.net',
102     'MDB2' => 'http://pear.php.net/package/MDB2',
103     'Net_SMTP' => 'http://pear.php.net/package/Net_SMTP',
104     'Mail_mime' => 'http://pear.php.net/package/Mail_mime'
105 );
24e1f1 106
2868a3 107 $path  = dirname(__FILE__) . '/';
T 108 $check = basename(__FILE__);
ab9642 109
31ff9f 110 require_once 'include/bugs.inc';
e50912 111
T 112 function show_hint($key) {
113     global $source_urls;
a9261c 114     if ($source_urls[$key]) {
T 115         echo '<span class="indent">(See <a href="' . $source_urls[$key] . '">';
116         echo  $source_urls[$key] . '</a>)</span>';
117     }
e50912 118 }
T 119
198816 120 ?>
T 121 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-transitional.dtd">
122 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
123 <head>
31ff9f 124 <link rel="shortcut icon" href="skins/default/images/favicon.ico" />
S 125 <link rel="stylesheet" type="text/css" href="skins/default/common.css" />
126 <style type="text/css">
127 /* <![CDATA[ */
128 label {
129     display: block;
130 }
131
132 th {
133     text-align: left;
134 }
135
136 h4 {
137     margin-bottom: 0.2em;
138 }
139
140 .success {
141     color: #006400;
142     font-weight: bold !important;
143 }
144
145 .fail {
146     color: #ff0000 !important;
147     font-weight: bold !important;
148 }
149
150 .na {
151     color: #f60;
152     font-weight: bold;
153 }
e50912 154
T 155 .indent {
156     padding-left: 0.8em;
157 }
31ff9f 158 /* ]]> */
S 159 </style>
160 <title>RoundCube :: check</title>
198816 161 </head>
T 162 <body>
31ff9f 163 <img src="skins/default/images/roundcube_logo.png" width="165"
S 164     height="55" border="0" alt="RoundCube Webmail" hspace="12" vspace="2" />
198816 165
T 166 <h3>Check <?php echo basename(__FILE__); ?> Configuration</h3>
167 From correctly set:
168 <?php
169 if ($rctest_config['from'] == '_yourfrom_') {
89ef0e 170     echo CHECK_NOK;
198816 171 } else {
T 172     echo $rctest_config['from'] . '<br /><br />';
ab9642 173     echo '<i><b>Note:</b> We do not check if this is a <b>valid</b> email address.';
T 174     echo ' Because this settings serves as from &amp; to, make sure it is correctly set!</i>';
198816 175 }
T 176
6b9e4a 177 echo '<h3>Checking available databases</h3>';
e50912 178 echo '<p>Checks if the extension is loaded. At least one of them is required.</p>';
6b9e4a 179
T 180 $prefix = (PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : '';
181 foreach ($supported_dbs AS $database => $ext) {
182     echo "$database: ";
183     if (extension_loaded($ext)) {
184         echo CHECK_OK;
185     } else {
186         $_ext = $prefix . $ext . '.' . PHP_SHLIB_SUFFIX;
ab9642 187         echo CHECK_NA;
24e1f1 188         if (@dl($_ext)) {
T 189             echo ' (<i>Could</i> be loaded. Please add in php.ini, if you plan on using it.)';
190         } else {
191             echo ' (<b>Not</b> installed.)';
192         }
193     }
194     echo '<br />';
195 }
196
197 echo '<h3>Checking PHP extensions</h3>';
e50912 198 echo '<p>The following modules/extensions are <em>required</em> to run RoundCube</p>';
24e1f1 199     
T 200 $prefix = (PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : '';
e50912 201 foreach ($required_php_exts AS $name => $ext) {
T 202     echo "$name: ";
203     if (extension_loaded($ext)) {
204         echo CHECK_OK;
205     } else {
206         $_ext = $prefix . $ext . '.' . PHP_SHLIB_SUFFIX;
207         echo CHECK_NA;
208         if (@dl($_ext)) {
209             echo ' (<i>Could</i> be loaded. Please add in php.ini.)';
210         } else {
211             show_hint($name);
212         }
213     }
214     echo '<br />';
215 }
216
217 echo '<p>These extensions are <em>optional</em> but recommended to get the best performance.</p>';
218
219 foreach ($optional_php_exts AS $name => $ext) {
24e1f1 220     echo "$name: ";
T 221     if (extension_loaded($ext)) {
222         echo CHECK_OK;
223     } else {
224         $_ext = $prefix . $ext . '.' . PHP_SHLIB_SUFFIX;
225         echo CHECK_NA;
226         if (@dl($_ext)) {
6b9e4a 227             echo ' (<i>Could</i> be loaded. Please add in php.ini, if you plan on using it.)';
T 228         } else {
e50912 229             show_hint($name);
6b9e4a 230         }
T 231     }
232     echo '<br />';
233 }
234
89ef0e 235 echo '<h3>Check for required 3rd party libs</h3>';
T 236 echo '<p>This also checks if the include path is set correctly.</p>';
237
238 foreach ($required_libs as $classname => $file) {
6b9e4a 239     require_once $file;
89ef0e 240     echo "$classname: ";
6b9e4a 241     if (class_exists($classname)) {
89ef0e 242         echo CHECK_OK;
6b9e4a 243     } else {
e50912 244         echo CHECK_NOK . " (Failed to load $file.)";
T 245         show_hint($classname);
6b9e4a 246     }
198816 247     echo "<br />";
T 248 }
249
250 echo '<h3>Check if you setup config files</h3>';
251 echo '<p>Checks if the files exist and if they are readable.</p>';
252
253 foreach ($create_files AS $file) {
254     echo "File $file: ";
255     if (file_exists($path . $file) && is_readable($path . $file)) {
89ef0e 256         echo CHECK_OK;
198816 257     } else {
89ef0e 258         echo CHECK_NOK;
198816 259     }
T 260     echo '<br />';
89ef0e 261 }
T 262
263 echo '<h3>Check if directories are writable</h3>';
264 echo '<p>RoundCube may need to write/save files into these directories.</p>';
31ff9f 265 require_once $path . 'config/main.inc.php';
S 266 $rctest_config = array_merge($rctest_config, $rcmail_config);
89ef0e 267
31ff9f 268 if (isset($rctest_config)) {
S 269     foreach (array($rctest_config['temp_dir'], $rctest_config['log_dir']) AS $dir) {
89ef0e 270         $dir = $dir{0} == '/' ? $dir : $path . $dir;
T 271         echo "Directory $dir: ";
272         if (!is_writable($dir)) {
273             echo CHECK_NOK;
274         } else {
275             echo CHECK_OK;
276         }
277         echo "<br />";
278     }
279 } else {
280     echo 'Could not open db.inc.php config file, or file is empty.<br />';
198816 281 }
T 282
283 echo '<h3>Check supplied DB settings</h3>';
31ff9f 284 require_once $path . 'config/db.inc.php';
S 285 $rctest_config = array_merge($rctest_config, $rcmail_config);
198816 286
T 287 $db_working = false;
31ff9f 288 if (isset($rctest_config) && is_array($rctest_config)) {
e1dc8b 289     echo 'Selected backend: ';
31ff9f 290     if ($rctest_config['db_backend'] != '') {
e1dc8b 291
31ff9f 292         echo 'PEAR::' . strtoupper($rctest_config['db_backend']) . '<br />';
e1dc8b 293
31ff9f 294         $_class = 'rcube_' . strtolower($rctest_config['db_backend']);
e1dc8b 295
T 296         require_once 'include/' . $_class . '.inc';
297
298         echo 'DSN (standard): ';
31ff9f 299         $DB = new $_class($rctest_config['db_dsnw'], '', false);
e1dc8b 300         $DB->db_connect('w');
T 301         if (!($db_error_msg = $DB->is_error())) {
ab9642 302             echo CHECK_OK;
e1dc8b 303             $db_working = true;
ab9642 304         } else {
e1dc8b 305             echo CHECK_NOK . " (Error: $db_error_msg)";
T 306         }
307         echo '<br />';
308         echo 'DSN (read-only, optional): ';
31ff9f 309         if ($rctest_config['db_dsnr'] != '') {
S 310             $DB_READ = new $_class($rctest_config['db_dsnr'], '', false);
e1dc8b 311             $DB_READ->db_connect('w');
T 312             if (!($db_error_msg = $DB_READ->is_error())) {
313                 echo CHECK_OK;
314             } else {
315                 echo CHECK_NOK . " (Error: $db_error_msg)";
316             }
317         } else {
31ff9f 318             echo CHECK_NA.($db_working ? ' - <span class="success">will use DSN (standard)</span>' : '');
e1dc8b 319         }
T 320         echo '<br />';
ab9642 321     } else {
e1dc8b 322         echo CHECK_NOK . ' (not set)';
198816 323     }
T 324 } else {
325     echo 'Could not open db.inc.php config file, or file is empty.<br />';
326 }
327
328 echo '<h3>TimeZone</h3>';
329 echo 'Checks if web- and databaseserver are in the same timezone.<br /><br />';
330 echo 'Status: ';
331 if ($db_working === true) {
31ff9f 332     $tz_db    = 'SELECT ' . $DB->unixtimestamp($DB->now()) . ' AS tz_db';
198816 333     $tz_db    = $DB->query($tz_db);
T 334     $tz_db    = $DB->fetch_assoc($tz_db);
335     $tz_db    = (int) $tz_db['tz_db'];
336     $tz_local = (int) time();
337     $tz_diff  = $tz_local - $tz_db;
338
31ff9f 339     // sometimes we have 1 second gap, treat that as ok
S 340     if ($tz_diff > 1) {
89ef0e 341         echo CHECK_NOK;
198816 342     } else {
89ef0e 343         echo CHECK_OK;
198816 344     }
T 345 } else {
346     echo 'Could not test (fix DB first).';
347 }
348 echo '<br />';
349
350 echo '<h3>Checking .ini settings</h3>';
351
d7f795 352 $ini_array = array('session.auto_start' => 0, 'file_uploads' => 1,
342db9 353     'magic_quotes_sybase' => 0, 'magic_quotes_gpc' => 0,
T 354     'zlib.output_compression' => 0);
198816 355
d7f795 356 foreach ($ini_array AS $var => $val) {
T 357     $status = ini_get($var);
198816 358
d7f795 359     echo "<h4>$var = $val</h4>";
T 360     echo 'status: ';
361     if ($status != $val) {
362         echo CHECK_NOK;
198816 363     } else {
d7f795 364         echo CHECK_OK;
198816 365     }
d7f795 366     echo '<br />';
198816 367 }
T 368 ?>
369 <h3>Check email settings</h3>
370 <?php
2868a3 371 echo 'Fetching config-settings from config/main.inc.php.<br /><br />';
31ff9f 372 if (is_array($rctest_config) && count($rctest_config)) {
S 373     ?>
2868a3 374 <table border="0">
f0cc62 375 <tr>
T 376 <th><h4>SMTP Settings</h4></th>
377 <th><h4>IMAP Settings</h4></th>
378 </tr>
379 <tr>
380 <td valign="top"><?php
381 echo 'SMTP: ' . CHECK_OK . '<br />';
382 echo 'server: '.(isset($rctest_config['smtp_server']) && !empty($rctest_config['smtp_server']) ? $rctest_config['smtp_server'] : '<i>not set</i>').'<br />';
383 echo 'port: '.(isset($rctest_config['smtp_port']) && !empty($rctest_config['smtp_port']) ? $rctest_config['smtp_port'] : '<i>not set</i>').'<br />';
384 if (isset($rctest_config['smtp_user']) && !empty($rctest_config['smtp_user'])) {
385     echo 'user: '.$rctest_config['smtp_user'].'<br/>';
386 } elseif ($rctest_config['smtp_user'] == '%u') {
387     echo 'user: <i>use current session</i><br/>';
388 } else {
389     echo 'user: <i>not set</i><br/>';
390 }
391 if (isset($rctest_config['smtp_pass']) && !empty($rctest_config['smtp_pass'])) {
392     echo 'pass: '.$rctest_config['smtp_pass'].'<br/>';
393 } elseif (isset($rctest_config['smtp_pass']) && $rctest_config['smtp_pass'] == '%p') {
394     echo 'pass: <i>use current session</i><br/>';
395 } else {
396     echo 'pass: <i>not set</i><br/>';
397 }
398 ?></td>
399 <td valign="top">
400 <?php
401 echo 'IMAP: ' . CHECK_OK . '<br />';
402 if (isset($rctest_config['default_host']) && is_array($rctest_config['default_host'])) {
403     echo 'server: '.var_export($rctest_config['default_host'], true).'<br/>';
404 } elseif (isset($rctest_config['default_host']) && !empty($rctest_config['default_host'])) {
405     echo 'server: '.$rctest_config['default_host'].'<br/>';
406 } else {
407     echo 'server: <i>not set</i><br/>';
408 }
409 echo 'port: '.(isset($rctest_config['default_port']) && !empty($rctest_config['default_port']) ? $rctest_config['default_port'] : '<i>not set</i>').'<br />';
410 ?></td>
411 </tr>
2868a3 412 </table>
198816 413 <h3>Test SMTP settings - send an email</h3>
T 414 <p>Don't abuse this!</p>
31ff9f 415 <form action="<?php echo $check; ?>" method="post"><?php
S 416 if ($rctest_config['smtp_server'] != ''):
417 if ($rctest_config['smtp_user'] == '%u'):
418 ?> <label>Username:</label><input type="text" name="smtp_test[user]" />
2868a3 419 <label>Password:</label><input type="password" name="smtp_test[pass]" /><br />
198816 420 <?php
T 421 endif;
31ff9f 422 endif;
S 423 ?> Recipient:<br />
424 <?php echo $rctest_config['from']; ?><br />
425 <br />
e240d5 426 <?php if (!empty($rctest_config['smtp_server'])): ?>
f0cc62 427 <input type="hidden" name="action" value="smtp" />
T 428 <input type="submit" value="send an email" />
e240d5 429 <?php else: ?>
T 430 <i>Because you did not configure SMTP, you cannot test it!</i>
431 <?php endif; ?>
f0cc62 432 </form>
198816 433 <?php
31ff9f 434 if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['action'] == 'smtp') {
198816 435
31ff9f 436     echo 'Trying to send email: ';
S 437     if ($rctest_config['from'] == '_yourfrom_') {
438         echo CHECK_NOK . '<br />';
439         echo '<i>Please edit $rctest_config in ' . basename(__FILE__) . '</i><br />';
440     } else {
f0cc62 441         $data   = null;
31ff9f 442         $CONFIG = $rctest_config;
f0cc62 443         if (isset($_POST['smtp_test'])) {
T 444             $data = $_POST['smtp_test'];
445
446             // inject into config array
447             $CONFIG['smtp_user'] = $data['user'];
448             $CONFIG['smtp_pass'] = $data['pass'];
449         }
31ff9f 450
S 451         require_once 'lib/rc_mail_mime.inc';
452         require_once 'include/rcube_smtp.inc';
453
454         $recipients = $rctest_config['from'];
455
456         $headers['From']    = $rctest_config['from'];
457         $headers['To']      = $recipients;
458         $headers['Subject'] = 'Test message from RoundCube';
459
460         $body = 'This is a test to confirm that RoundCube can send email.';
461
f0cc62 462         $mail_object  = new rc_mail_mime();
T 463         $send_headers = $mail_object->headers($headers);
31ff9f 464
S 465         $smtp_response = array();
f0cc62 466
T 467         $status = smtp_mail($rctest_config['from'], $recipients,
468             ($foo = $mail_object->txtHeaders($send_headers)),
469             $body, $smtp_response);
470
471         if ($status) {
31ff9f 472             echo CHECK_OK . '<br />';
198816 473         } else {
31ff9f 474             echo CHECK_NOK;
S 475             echo '<br />' . join('<br />', $smtp_response);
198816 476         }
T 477     }
31ff9f 478 }
198816 479 } else {
89ef0e 480     echo CHECK_NOK;
1a13d6 481 }
T 482 ?>
483 <h3>Test IMAP settings</h3>
484 <?php
31ff9f 485 if ($rctest_config['default_host'] == '') {
1a13d6 486     echo '<span class="fail">We cannot test, default_host is not set in config/main.inc.php.</span>';
T 487 } else {
31ff9f 488     ?>
2868a3 489 <form action="<?php echo $check; ?>" method="post">
1a13d6 490 <label>Username:</label><input type="text" name="imap_test[user]" />
31ff9f 491 <label>Password:</label><input type="password" name="imap_test[pass]" /><br />
S 492 <br />
1a13d6 493 <input type="hidden" name="action" value="imap" />
T 494 <input type="submit" value="check email" />
31ff9f 495 </form>
S 496 <br /><br />
497     <?php
1a13d6 498     if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['action'] == 'imap') {
T 499
500         echo 'Testing IMAP connect: ';
501
502         $data = $_POST['imap_test'];
503
504         require_once 'imap.inc';
505         global $iil_error, $ICL_PORT;
506
31ff9f 507         $ICL_PORT = $rctest_config['default_port'];
S 508         $result   = iil_Connect($rctest_config['default_host'],
509         $data['user'], $data['pass']);
1a13d6 510
T 511         if ($result != true) {
89ef0e 512             echo CHECK_NOK;
2868a3 513             echo '<br />Error return: ' . $iil_error;
1a13d6 514         } else {
89ef0e 515             echo CHECK_OK;
1a13d6 516         }
T 517         echo '<br />';
518     }
198816 519 }
T 520 ?>
521 </body>
24e1f1 522 </html>