yllar
2008-02-19 cc735fbd3fc7093f294bd22e8ea4fbdf70fbc199
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',
81     'MDB2#pgsql' => 'MDB2/Driver/pgsql.php', 'MDB2#sqlite' => 'MDB2/Driver/sqlite.php');
82
83 $supported_dbs = array('MySQL' => 'mysql', 'MySQLi' => 'mysqli',
84     'PostgreSQL' => 'pgsql', 'SQLite (v2)' => 'sqlite');
198816 85
e50912 86 $required_php_exts = array('Session' => 'session', 'PCRE' => 'pcre', 'Sockets' => 'sockets');
T 87
88 $optional_php_exts = array('FileInfo' => 'fileinfo', 'Libiconv' => 'iconv', 'Multibyte' => 'mbstring', 'OpenSSL' => 'openssl');
89
90 $source_urls = array(
91     'Socket' => 'http://www.php.net/manual/en/ref.sockets.php',
92     'Session' => 'http://www.php.net/manual/en/ref.session.php',
93     'PCRE' => 'http://www.php.net/manual/en/ref.pcre.php',
94     'FileInfo' => 'http://www.php.net/manual/en/ref.fileinfo.php',
95     'Libiconv' => 'http://www.php.net/manual/en/ref.iconv.php',
96     'Multibyte' => 'http://www.php.net/manual/en/ref.mbstring.php',
97     'OpenSSL' => 'http://www.php.net/manual/en/ref.openssl.php',
98     'PEAR' => 'http://pear.php.net',
99     'MDB2' => 'http://pear.php.net/package/MDB2',
100     'Net_SMTP' => 'http://pear.php.net/package/Net_SMTP',
101     'Mail_mime' => 'http://pear.php.net/package/Mail_mime'
102 );
24e1f1 103
2868a3 104 $path  = dirname(__FILE__) . '/';
T 105 $check = basename(__FILE__);
ab9642 106
31ff9f 107 require_once 'include/bugs.inc';
e50912 108
T 109 function show_hint($key) {
110     global $source_urls;
111     if ($source_urls[$key])
112         echo '<span class="indent">(See <a href="' . $source_urls[$key] . '">' . $source_urls[$key] . '</a>)</span>';
113 }
114
198816 115 ?>
T 116 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-transitional.dtd">
117 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
118 <head>
31ff9f 119 <link rel="shortcut icon" href="skins/default/images/favicon.ico" />
S 120 <link rel="stylesheet" type="text/css" href="skins/default/common.css" />
121 <style type="text/css">
122 /* <![CDATA[ */
123 label {
124     display: block;
125 }
126
127 th {
128     text-align: left;
129 }
130
131 h4 {
132     margin-bottom: 0.2em;
133 }
134
135 .success {
136     color: #006400;
137     font-weight: bold !important;
138 }
139
140 .fail {
141     color: #ff0000 !important;
142     font-weight: bold !important;
143 }
144
145 .na {
146     color: #f60;
147     font-weight: bold;
148 }
e50912 149
T 150 .indent {
151     padding-left: 0.8em;
152 }
31ff9f 153 /* ]]> */
S 154 </style>
155 <title>RoundCube :: check</title>
198816 156 </head>
T 157 <body>
31ff9f 158 <img src="skins/default/images/roundcube_logo.png" width="165"
S 159     height="55" border="0" alt="RoundCube Webmail" hspace="12" vspace="2" />
198816 160
T 161 <h3>Check <?php echo basename(__FILE__); ?> Configuration</h3>
162 From correctly set:
163 <?php
164 if ($rctest_config['from'] == '_yourfrom_') {
89ef0e 165     echo CHECK_NOK;
198816 166 } else {
T 167     echo $rctest_config['from'] . '<br /><br />';
ab9642 168     echo '<i><b>Note:</b> We do not check if this is a <b>valid</b> email address.';
T 169     echo ' Because this settings serves as from &amp; to, make sure it is correctly set!</i>';
198816 170 }
T 171
6b9e4a 172 echo '<h3>Checking available databases</h3>';
e50912 173 echo '<p>Checks if the extension is loaded. At least one of them is required.</p>';
6b9e4a 174
T 175 $prefix = (PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : '';
176 foreach ($supported_dbs AS $database => $ext) {
177     echo "$database: ";
178     if (extension_loaded($ext)) {
179         echo CHECK_OK;
180     } else {
181         $_ext = $prefix . $ext . '.' . PHP_SHLIB_SUFFIX;
ab9642 182         echo CHECK_NA;
24e1f1 183         if (@dl($_ext)) {
T 184             echo ' (<i>Could</i> be loaded. Please add in php.ini, if you plan on using it.)';
185         } else {
186             echo ' (<b>Not</b> installed.)';
187         }
188     }
189     echo '<br />';
190 }
191
192 echo '<h3>Checking PHP extensions</h3>';
e50912 193 echo '<p>The following modules/extensions are <em>required</em> to run RoundCube</p>';
24e1f1 194     
T 195 $prefix = (PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : '';
e50912 196 foreach ($required_php_exts AS $name => $ext) {
T 197     echo "$name: ";
198     if (extension_loaded($ext)) {
199         echo CHECK_OK;
200     } else {
201         $_ext = $prefix . $ext . '.' . PHP_SHLIB_SUFFIX;
202         echo CHECK_NA;
203         if (@dl($_ext)) {
204             echo ' (<i>Could</i> be loaded. Please add in php.ini.)';
205         } else {
206             show_hint($name);
207         }
208     }
209     echo '<br />';
210 }
211
212 echo '<p>These extensions are <em>optional</em> but recommended to get the best performance.</p>';
213
214 foreach ($optional_php_exts AS $name => $ext) {
24e1f1 215     echo "$name: ";
T 216     if (extension_loaded($ext)) {
217         echo CHECK_OK;
218     } else {
219         $_ext = $prefix . $ext . '.' . PHP_SHLIB_SUFFIX;
220         echo CHECK_NA;
221         if (@dl($_ext)) {
6b9e4a 222             echo ' (<i>Could</i> be loaded. Please add in php.ini, if you plan on using it.)';
T 223         } else {
e50912 224             show_hint($name);
6b9e4a 225         }
T 226     }
227     echo '<br />';
228 }
229
89ef0e 230 echo '<h3>Check for required 3rd party libs</h3>';
T 231 echo '<p>This also checks if the include path is set correctly.</p>';
232
233 foreach ($required_libs as $classname => $file) {
6b9e4a 234     require_once $file;
89ef0e 235     echo "$classname: ";
6b9e4a 236     if (class_exists($classname)) {
89ef0e 237         echo CHECK_OK;
6b9e4a 238     } else {
e50912 239         echo CHECK_NOK . " (Failed to load $file.)";
T 240         show_hint($classname);
6b9e4a 241     }
198816 242     echo "<br />";
T 243 }
244
245 echo '<h3>Check if you setup config files</h3>';
246 echo '<p>Checks if the files exist and if they are readable.</p>';
247
248 foreach ($create_files AS $file) {
249     echo "File $file: ";
250     if (file_exists($path . $file) && is_readable($path . $file)) {
89ef0e 251         echo CHECK_OK;
198816 252     } else {
89ef0e 253         echo CHECK_NOK;
198816 254     }
T 255     echo '<br />';
89ef0e 256 }
T 257
258 echo '<h3>Check if directories are writable</h3>';
259 echo '<p>RoundCube may need to write/save files into these directories.</p>';
31ff9f 260 require_once $path . 'config/main.inc.php';
S 261 $rctest_config = array_merge($rctest_config, $rcmail_config);
89ef0e 262
31ff9f 263 if (isset($rctest_config)) {
S 264     foreach (array($rctest_config['temp_dir'], $rctest_config['log_dir']) AS $dir) {
89ef0e 265         $dir = $dir{0} == '/' ? $dir : $path . $dir;
T 266         echo "Directory $dir: ";
267         if (!is_writable($dir)) {
268             echo CHECK_NOK;
269         } else {
270             echo CHECK_OK;
271         }
272         echo "<br />";
273     }
274 } else {
275     echo 'Could not open db.inc.php config file, or file is empty.<br />';
198816 276 }
T 277
278 echo '<h3>Check supplied DB settings</h3>';
31ff9f 279 require_once $path . 'config/db.inc.php';
S 280 $rctest_config = array_merge($rctest_config, $rcmail_config);
198816 281
T 282 $db_working = false;
31ff9f 283 if (isset($rctest_config) && is_array($rctest_config)) {
e1dc8b 284     echo 'Selected backend: ';
31ff9f 285     if ($rctest_config['db_backend'] != '') {
e1dc8b 286
31ff9f 287         echo 'PEAR::' . strtoupper($rctest_config['db_backend']) . '<br />';
e1dc8b 288
31ff9f 289         $_class = 'rcube_' . strtolower($rctest_config['db_backend']);
e1dc8b 290
T 291         require_once 'include/' . $_class . '.inc';
292
293         echo 'DSN (standard): ';
31ff9f 294         $DB = new $_class($rctest_config['db_dsnw'], '', false);
e1dc8b 295         $DB->db_connect('w');
T 296         if (!($db_error_msg = $DB->is_error())) {
ab9642 297             echo CHECK_OK;
e1dc8b 298             $db_working = true;
ab9642 299         } else {
e1dc8b 300             echo CHECK_NOK . " (Error: $db_error_msg)";
T 301         }
302         echo '<br />';
303         echo 'DSN (read-only, optional): ';
31ff9f 304         if ($rctest_config['db_dsnr'] != '') {
S 305             $DB_READ = new $_class($rctest_config['db_dsnr'], '', false);
e1dc8b 306             $DB_READ->db_connect('w');
T 307             if (!($db_error_msg = $DB_READ->is_error())) {
308                 echo CHECK_OK;
309             } else {
310                 echo CHECK_NOK . " (Error: $db_error_msg)";
311             }
312         } else {
31ff9f 313             echo CHECK_NA.($db_working ? ' - <span class="success">will use DSN (standard)</span>' : '');
e1dc8b 314         }
T 315         echo '<br />';
ab9642 316     } else {
e1dc8b 317         echo CHECK_NOK . ' (not set)';
198816 318     }
T 319 } else {
320     echo 'Could not open db.inc.php config file, or file is empty.<br />';
321 }
322
323 echo '<h3>TimeZone</h3>';
324 echo 'Checks if web- and databaseserver are in the same timezone.<br /><br />';
325 echo 'Status: ';
326 if ($db_working === true) {
31ff9f 327     $tz_db    = 'SELECT ' . $DB->unixtimestamp($DB->now()) . ' AS tz_db';
198816 328     $tz_db    = $DB->query($tz_db);
T 329     $tz_db    = $DB->fetch_assoc($tz_db);
330     $tz_db    = (int) $tz_db['tz_db'];
331     $tz_local = (int) time();
332     $tz_diff  = $tz_local - $tz_db;
333
31ff9f 334     // sometimes we have 1 second gap, treat that as ok
S 335     if ($tz_diff > 1) {
89ef0e 336         echo CHECK_NOK;
198816 337     } else {
89ef0e 338         echo CHECK_OK;
198816 339     }
T 340 } else {
341     echo 'Could not test (fix DB first).';
342 }
343 echo '<br />';
344
345 echo '<h3>Checking .ini settings</h3>';
346
d7f795 347 $ini_array = array('session.auto_start' => 0, 'file_uploads' => 1,
342db9 348     'magic_quotes_sybase' => 0, 'magic_quotes_gpc' => 0,
T 349     'zlib.output_compression' => 0);
198816 350
d7f795 351 foreach ($ini_array AS $var => $val) {
T 352     $status = ini_get($var);
198816 353
d7f795 354     echo "<h4>$var = $val</h4>";
T 355     echo 'status: ';
356     if ($status != $val) {
357         echo CHECK_NOK;
198816 358     } else {
d7f795 359         echo CHECK_OK;
198816 360     }
d7f795 361     echo '<br />';
198816 362 }
T 363 ?>
364 <h3>Check email settings</h3>
365 <?php
2868a3 366 echo 'Fetching config-settings from config/main.inc.php.<br /><br />';
31ff9f 367 if (is_array($rctest_config) && count($rctest_config)) {
S 368     ?>
2868a3 369 <table border="0">
31ff9f 370     <tr>
S 371         <th>
372         <h4>SMTP Settings</h4>
373         </th>
374         <th>
375         <h4>IMAP Settings</h4>
376         </th>
377     </tr>
378     <tr>
379         <td valign="top"><?php
380         echo 'SMTP: ' . CHECK_OK . '<br />';
381         echo 'server: '.(isset($rctest_config['smtp_server']) && !empty($rctest_config['smtp_server']) ? $rctest_config['smtp_server'] : '<i>not set</i>').'<br />';
382         echo 'port: '.(isset($rctest_config['smtp_port']) && !empty($rctest_config['smtp_port']) ? $rctest_config['smtp_port'] : '<i>not set</i>').'<br />';
383         if (isset($rctest_config['smtp_user']) && !empty($rctest_config['smtp_user'])) {
384             echo 'user: '.$rctest_config['smtp_user'].'<br/>';
385         } elseif ($rctest_config['smtp_user'] == '%u') {
386             echo 'user: <i>use current session</i><br/>';
387         } else {
388             echo 'user: <i>not set</i><br/>';
389         }
390         if (isset($rctest_config['smtp_pass']) && !empty($rctest_config['smtp_pass'])) {
391             echo 'pass: '.$rctest_config['smtp_pass'].'<br/>';
392         } elseif (isset($rctest_config['smtp_pass']) && $rctest_config['smtp_pass'] == '%p') {
393             echo 'pass: <i>use current session</i><br/>';
394         } else {
395             echo 'pass: <i>not set</i><br/>';
396         }
397         ?></td>
398         <td valign="top"><?php
399         echo 'IMAP: ' . CHECK_OK . '<br />';
400         if (isset($rctest_config['default_host']) && is_array($rctest_config['default_host'])) {
401             echo 'server: '.var_export($rctest_config['default_host'], true).'<br/>';
402         } elseif (isset($rctest_config['default_host']) && !empty($rctest_config['default_host'])) {
403             echo 'server: '.$rctest_config['default_host'].'<br/>';
404         } else {
405             echo 'server: <i>not set</i><br/>';
406         }
407         echo 'port: '.(isset($rctest_config['default_port']) && !empty($rctest_config['default_port']) ? $rctest_config['default_port'] : '<i>not set</i>').'<br />';
408         ?></td>
409     </tr>
2868a3 410 </table>
198816 411 <h3>Test SMTP settings - send an email</h3>
T 412 <p>Don't abuse this!</p>
31ff9f 413 <form action="<?php echo $check; ?>" method="post"><?php
S 414 if ($rctest_config['smtp_server'] != ''):
415 if ($rctest_config['smtp_user'] == '%u'):
416 ?> <label>Username:</label><input type="text" name="smtp_test[user]" />
2868a3 417 <label>Password:</label><input type="password" name="smtp_test[pass]" /><br />
198816 418 <?php
T 419 endif;
31ff9f 420 endif;
S 421 ?> Recipient:<br />
422 <?php echo $rctest_config['from']; ?><br />
423 <br />
424 <input type="hidden" name="action" value="smtp" /> <input type="submit"
425     value="send an email" /></form>
198816 426 <?php
31ff9f 427 if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['action'] == 'smtp') {
198816 428
31ff9f 429     echo 'Trying to send email: ';
S 430     if ($rctest_config['from'] == '_yourfrom_') {
431         echo CHECK_NOK . '<br />';
432         echo '<i>Please edit $rctest_config in ' . basename(__FILE__) . '</i><br />';
433     } else {
434
435         $data   = $_POST['smtp_test'];
436         $CONFIG = $rctest_config;
437
438         require_once 'lib/rc_mail_mime.inc';
439         require_once 'include/rcube_smtp.inc';
440
441         $recipients = $rctest_config['from'];
442
443         $headers['From']    = $rctest_config['from'];
444         $headers['To']      = $recipients;
445         $headers['Subject'] = 'Test message from RoundCube';
446
447         $body = 'This is a test to confirm that RoundCube can send email.';
448
449         $mail_object = new rc_mail_mime();
450         $mail_object->headers($headers);
451
452         $smtp_response = array();
453         if (smtp_mail($rctest_config['from'], $recipients, ($foo = $mail_object->txtHeaders($send_headers)), $body, $smtp_response)) {
454             echo CHECK_OK . '<br />';
198816 455         } else {
31ff9f 456             echo CHECK_NOK;
S 457             echo '<br />' . join('<br />', $smtp_response);
198816 458         }
T 459     }
31ff9f 460 }
198816 461 } else {
89ef0e 462     echo CHECK_NOK;
1a13d6 463 }
T 464 ?>
465 <h3>Test IMAP settings</h3>
466 <?php
31ff9f 467 if ($rctest_config['default_host'] == '') {
1a13d6 468     echo '<span class="fail">We cannot test, default_host is not set in config/main.inc.php.</span>';
T 469 } else {
31ff9f 470     ?>
2868a3 471 <form action="<?php echo $check; ?>" method="post">
1a13d6 472 <label>Username:</label><input type="text" name="imap_test[user]" />
31ff9f 473 <label>Password:</label><input type="password" name="imap_test[pass]" /><br />
S 474 <br />
1a13d6 475 <input type="hidden" name="action" value="imap" />
T 476 <input type="submit" value="check email" />
31ff9f 477 </form>
S 478 <br /><br />
479     <?php
1a13d6 480     if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['action'] == 'imap') {
T 481
482         echo 'Testing IMAP connect: ';
483
484         $data = $_POST['imap_test'];
485
486         require_once 'imap.inc';
487         global $iil_error, $ICL_PORT;
488
31ff9f 489         $ICL_PORT = $rctest_config['default_port'];
S 490         $result   = iil_Connect($rctest_config['default_host'],
491         $data['user'], $data['pass']);
1a13d6 492
T 493         if ($result != true) {
89ef0e 494             echo CHECK_NOK;
2868a3 495             echo '<br />Error return: ' . $iil_error;
1a13d6 496         } else {
89ef0e 497             echo CHECK_OK;
1a13d6 498         }
T 499         echo '<br />';
500     }
198816 501 }
T 502 ?>
503 </body>
24e1f1 504 </html>