svncommit
2008-02-15 3a084db1c90eb35ea489de37b31c1cc3b4b84695
commit | author | age
198816 1 <?php
T 2 /**
3  * Copyright (c) 2008, Till Klampaeckel
4  * 
5  * All rights reserved.
6  * 
7  * Redistribution and use in source and binary forms, with or without modification,
8  * are permitted provided that the following conditions are met:
9  * 
10  *  * Redistributions of source code must retain the above copyright notice, this
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.
15  * 
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
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>');
61
1a13d6 62 error_reporting(E_ALL ^E_NOTICE);
198816 63
6b9e4a 64 $include_path  = dirname(__FILE__) . '/program/lib';
198816 65 $include_path .= PATH_SEPARATOR;
6b9e4a 66 $include_path .= dirname(__FILE__) . '/program';
198816 67 $include_path .= PATH_SEPARATOR;
T 68 $include_path .= get_include_path();
69
89ef0e 70 @ini_set('display_errors', 1);
198816 71 set_include_path($include_path);
T 72
6b9e4a 73 $create_files = array('config/db.inc.php', 'config/main.inc.php');
T 74
75 $required_libs = array('PEAR' => 'PEAR.php', 'DB' => 'DB.php',
76     'Net_SMTP' => 'Net/SMTP.php', 'Mail_mime' => 'Mail/mime.php',
77     'MDB2' => 'MDB2.php', 'iilConnection' => 'lib/imap.inc');
78
79 $supported_drivers = array('MDB2#mysql' => 'MDB2/Driver/mysql.php',
80     'MDB2#pgsql' => 'MDB2/Driver/pgsql.php', 'MDB2#sqlite' => 'MDB2/Driver/sqlite.php');
81
82 $supported_dbs = array('MySQL' => 'mysql', 'MySQLi' => 'mysqli',
83     'PostgreSQL' => 'pgsql', 'SQLite (v2)' => 'sqlite');
198816 84
2868a3 85 $path  = dirname(__FILE__) . '/';
T 86 $check = basename(__FILE__);
198816 87 ?>
T 88 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-transitional.dtd">
89 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
90 <head>
91     <link rel="shortcut icon" href="skins/default/images/favicon.ico"/>
92     <link rel="stylesheet" type="text/css" href="skins/default/common.css" />
93     <style type="text/css">
94     /* <![CDATA[ */
95     label { display:block; }
89ef0e 96     th { text-align: left; }
T 97     h4 { margin-bottom: 0.2em; }
198816 98     .success { color:#006400;font-weight:bold !important; }
T 99     .fail { color:#ff0000 !important;font-weight:bold !important; }
100     /* ]]> */
101     </style>
102     <title>RoundCube :: check</title>
103 </head>
104 <body>
105 <img src="skins/default/images/roundcube_logo.png" width="165" height="55" border="0" alt="RoundCube Webmail" hspace="12" vspace="2"/>
106
107 <h3>Check <?php echo basename(__FILE__); ?> Configuration</h3>
108 From correctly set:
109 <?php
110 if ($rctest_config['from'] == '_yourfrom_') {
89ef0e 111     echo CHECK_NOK;
198816 112 } else {
T 113     echo $rctest_config['from'] . '<br /><br />';
114     echo '<i>We do not check if this is a <b>valid</b> email address. Since this serves as from &amp; to, make sure it is correct!</i>';
115 }
116
6b9e4a 117 echo '<h3>Checking available databases</h3>';
T 118 echo '<p>Checks if the extension is loaded.</p>';
119
120 $prefix = (PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : '';
121 foreach ($supported_dbs AS $database => $ext) {
122     echo "$database: ";
123     if (extension_loaded($ext)) {
124         echo CHECK_OK;
125     } else {
126         $_ext = $prefix . $ext . '.' . PHP_SHLIB_SUFFIX;
127         echo CHECK_NOK;
128         if (@dl($_ext)) {
129             echo ' (<i>Could</i> be loaded. Please add in php.ini, if you plan on using it.)';
130         } else {
131             echo ' (<b>Not</b> installed.)';
132         }
133     }
134     echo '<br />';
135 }
136
89ef0e 137 echo '<h3>Check for required 3rd party libs</h3>';
T 138 echo '<p>This also checks if the include path is set correctly.</p>';
139
140 foreach ($required_libs as $classname => $file) {
6b9e4a 141     require_once $file;
89ef0e 142     echo "$classname: ";
6b9e4a 143     if (class_exists($classname)) {
89ef0e 144         echo CHECK_OK;
6b9e4a 145     } else {
89ef0e 146         echo CHECK_NOK . "; Failed to load $file";
6b9e4a 147     }
198816 148     echo "<br />";
T 149 }
150
151 echo '<h3>Check if you setup config files</h3>';
152 echo '<p>Checks if the files exist and if they are readable.</p>';
153
154 foreach ($create_files AS $file) {
155     echo "File $file: ";
156     if (file_exists($path . $file) && is_readable($path . $file)) {
89ef0e 157         echo CHECK_OK;
198816 158     } else {
89ef0e 159         echo CHECK_NOK;
198816 160     }
T 161     echo '<br />';
89ef0e 162 }
T 163
164 echo '<h3>Check if directories are writable</h3>';
165 echo '<p>RoundCube may need to write/save files into these directories.</p>';
166 @include $path . 'config/main.inc.php';
167
168 if (isset($rcmail_config)) {
169     foreach (array($rcmail_config['temp_dir'], $rcmail_config['log_dir']) AS $dir) {
170         $dir = $dir{0} == '/' ? $dir : $path . $dir;
171         echo "Directory $dir: ";
172         if (!is_writable($dir)) {
173             echo CHECK_NOK;
174         } else {
175             echo CHECK_OK;
176         }
177         echo "<br />";
178     }
179 } else {
180     echo 'Could not open db.inc.php config file, or file is empty.<br />';
198816 181 }
T 182
183 echo '<h3>Check supplied DB settings</h3>';
184 @include $path . 'config/db.inc.php';
185
186 $db_working = false;
187 if (isset($rcmail_config)) {
188     echo 'DB settings: ';
189     include_once 'MDB2.php';
190     $db = MDB2::connect($rcmail_config['db_dsnw']);
191     if (!MDB2::IsError($db)) {
89ef0e 192         echo CHECK_OK;
198816 193         $db->disconnect();
T 194         $db_working = true;
195     } else {
89ef0e 196         echo CHECK_NOK;
198816 197     }
T 198     echo '<br />';
199 } else {
200     echo 'Could not open db.inc.php config file, or file is empty.<br />';
201 }
202
203 echo '<h3>TimeZone</h3>';
204 echo 'Checks if web- and databaseserver are in the same timezone.<br /><br />';
205 echo 'Status: ';
206 if ($db_working === true) {
207     require_once 'include/rcube_mdb2.inc';
208     $DB = new rcube_mdb2($rcmail_config['db_dsnw'], '', false);
209     $DB->db_connect('w');
210     
211     $tz_db    = "SELECT " . $DB->unixtimestamp($DB->now()) . " AS tz_db";
212     $tz_db    = $DB->query($tz_db);
213     $tz_db    = $DB->fetch_assoc($tz_db);
214     $tz_db    = (int) $tz_db['tz_db'];
215     $tz_local = (int) time();
216     $tz_diff  = $tz_local - $tz_db;
217
218     if ($tz_db != $tz_local) {
89ef0e 219         echo CHECK_NOK;
198816 220     } else {
89ef0e 221         echo CHECK_OK;
198816 222     }
T 223 } else {
224     echo 'Could not test (fix DB first).';
225 }
226 echo '<br />';
227
228 echo '<h3>Checking .ini settings</h3>';
229
230 $auto_start   = ini_get('session.auto_start');
231 $file_uploads = ini_get('file_uploads');
232
233 echo '<h4>session.auto_start = 0</h4>';
234 echo 'status: ';
235 if ($auto_start == 1) {
89ef0e 236     echo CHECK_NOK;
198816 237 } else {
89ef0e 238     echo CHECK_OK;
198816 239 }
T 240 echo '<br />';
241
242 echo '<h4>file_uploads = On</h4>';
243 echo 'status: ';
244 if ($file_uploads == 1) {
89ef0e 245     echo CHECK_OK;
198816 246 } else {
89ef0e 247     echo CHECK_NOK;
198816 248 }
T 249
250 /*
251  * Probably not needed because we have a custom handler
252 echo '<h4>session.save_path <i>is set</i></h4>';
253 echo 'status: ';
254 $save_path = ini_get('session.save_path');
255 if (empty($save_path)) {
89ef0e 256     echo CHECK_NOK;
198816 257 } else {
89ef0e 258     echo CHECK_OK . ": $save_path";
198816 259     if (!file_exists($save_path)) {
T 260         echo ', but it does not exist';
261     } else {
262         if (!is_readable($save_path) || !is_writable($save_path)) {
263             echo ', but permissions to read and/or write are missing';
264         }
265     }
266 }
267 echo '<br />';
268  */
269
89ef0e 270 @include $path . 'config/main.inc.php';
198816 271 ?>
T 272 <h3>Check email settings</h3>
273 <?php
2868a3 274 echo 'Fetching config-settings from config/main.inc.php.<br /><br />';
198816 275 if (is_array($rcmail_config) && count($rcmail_config)) {
2868a3 276 ?>
T 277 <table border="0">
278 <tr>
279     <th><h4>SMTP Settings</h4></th>
280     <th><h4>IMAP Settings</h4></th>
281 </tr>
282 <tr><td valign="top">
283 <?php
89ef0e 284     echo 'SMTP: ' . CHECK_OK . '<br />';
198816 285     echo 'server: ' . $rcmail_config['smtp_server'] . '<br />';
T 286     echo 'port: ' . $rcmail_config['smtp_port'] . '<br />';
287     echo 'user: ' . (($rcmail_config['smtp_user'] == '%u')?'<i>use current session</i>':$rcmail_config['smtp_user']) . '<br />';
288     echo 'pass: ' . (($rcmail_config['smtp_pass'] == '%p')?'<i>use current session</i>':$rcmail_config['smtp_pass']) . '<br />';
289     //var_dump($rcmail_config);
290 ?>
2868a3 291 </td><td valign="top">
T 292 <?php
89ef0e 293     echo 'IMAP: ' . CHECK_OK . '<br />';
T 294     echo 'server: ' . (is_array($rcmail_config['default_host']) ? var_export($rcmail_config['default_host'], true) : $rcmail_config['default_host']) . '<br />';
2868a3 295     echo 'port: ' . $rcmail_config['default_port'] . '<br />';
T 296 ?>
297 </td></tr>
298 </table>
198816 299 <h3>Test SMTP settings - send an email</h3>
T 300 <p>Don't abuse this!</p>
2868a3 301 <form action="<?php echo $check; ?>" method="post">
198816 302 <?php
T 303 if ($rcmail_config['smtp_server'] != ''):
304     if ($rcmail_config['smtp_user'] == '%u'):
305 ?>
306 <label>Username:</label><input type="text" name="smtp_test[user]" />
2868a3 307 <label>Password:</label><input type="password" name="smtp_test[pass]" /><br />
198816 308 <?php
T 309     endif;
310 endif;
311 ?>
312 Recipient:<br />
313 <?php echo $rctest_config['from']; ?><br /><br />
1a13d6 314 <input type="hidden" name="action" value="smtp" />
198816 315 <input type="submit" value="send an email" />
T 316 </form>
317 <?php
1a13d6 318     if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['action'] == 'smtp') {
198816 319
T 320         echo 'Trying to send email: ';
321         if ($rctest_config['from'] == '_yourfrom_') {
89ef0e 322             echo CHECK_NOK . '<br />';
198816 323             echo '<i>Please edit $rctest_config in ' . basename(__FILE__) . '</i><br />';
T 324         } else {
325
1a13d6 326             $data   = $_POST['smtp_test'];
7886ef 327             $CONFIG = $rcmail_config;
198816 328
7886ef 329             require_once 'lib/rc_mail_mime.inc';
T 330             require_once 'include/rcube_smtp.inc';
198816 331
T 332             $recipients = $rctest_config['from'];
333
334             $headers['From']    = $rctest_config['from'];
335             $headers['To']      = $recipients;
336             $headers['Subject'] = 'Test message from RoundCube';
337
338             $body = 'This is a test to confirm that RoundCube can send email.';
339
7886ef 340             $mail_object = new rc_mail_mime();
T 341             $mail_object->headers($headers);
342             
343             $smtp_response = array();
344             if (smtp_mail($rctest_config['from'], $recipients, ($foo = $mail_object->txtHeaders($send_headers)), $body, $smtp_response)) {
89ef0e 345                 echo CHECK_OK . '<br />';
198816 346             } else {
89ef0e 347                 echo CHECK_NOK;
7886ef 348                 echo '<br />' . join('<br />', $smtp_response);
198816 349             }
T 350         }
351     }
352 } else {
89ef0e 353     echo CHECK_NOK;
1a13d6 354 }
T 355 ?>
356 <h3>Test IMAP settings</h3>
357 <?php
358 if ($rcmail_config['default_host'] == '') {
359     echo '<span class="fail">We cannot test, default_host is not set in config/main.inc.php.</span>';
360 } else {
361 ?>
2868a3 362 <form action="<?php echo $check; ?>" method="post">
1a13d6 363 <label>Username:</label><input type="text" name="imap_test[user]" />
2868a3 364 <label>Password:</label><input type="password" name="imap_test[pass]" /><br /><br />
1a13d6 365 <input type="hidden" name="action" value="imap" />
T 366 <input type="submit" value="check email" />
367 </form><br /><br />
368 <?php
369     if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['action'] == 'imap') {
370
371         echo 'Testing IMAP connect: ';
372
373         $data = $_POST['imap_test'];
374
375         require_once 'imap.inc';
376         global $iil_error, $ICL_PORT;
377
378         $ICL_PORT = $rcmail_config['default_port'];
379         $result   = iil_Connect($rcmail_config['default_host'],
380             $data['user'], $data['pass']);
381
382         if ($result != true) {
89ef0e 383             echo CHECK_NOK;
2868a3 384             echo '<br />Error return: ' . $iil_error;
1a13d6 385         } else {
89ef0e 386             echo CHECK_OK;
1a13d6 387         }
T 388         echo '<br />';
389     }
198816 390 }
T 391 ?>
392 </body>
6b9e4a 393 </html>