source: subversion/trunk/roundcubemail/check.php-dist @ 1088

Last change on this file since 1088 was 1088, checked in by till, 5 years ago
  • revised .ini checks and added magic_quotes_*
File size: 11.9 KB
Line 
1<?php
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();
42
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 */
47$rctest_config['from'] = '_yourfrom_';
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 */
58
59define('CHECK_OK', '<span class="success">OK</span>');
60define('CHECK_NOK', '<span class="fail">NOT OK</span>');
61
62error_reporting(E_ALL ^E_NOTICE);
63
64$include_path  = dirname(__FILE__) . '/program/lib';
65$include_path .= PATH_SEPARATOR;
66$include_path .= dirname(__FILE__) . '/program';
67$include_path .= PATH_SEPARATOR;
68$include_path .= get_include_path();
69
70@ini_set('display_errors', 1);
71set_include_path($include_path);
72
73$create_files = array('config/db.inc.php', 'config/main.inc.php');
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');
84
85$path  = dirname(__FILE__) . '/';
86$check = basename(__FILE__);
87?>
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; }
96    th { text-align: left; }
97    h4 { margin-bottom: 0.2em; }
98    .success { color:#006400;font-weight:bold !important; }
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>
108From correctly set:
109<?php
110if ($rctest_config['from'] == '_yourfrom_') {
111    echo CHECK_NOK;
112} else {
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
117echo '<h3>Checking available databases</h3>';
118echo '<p>Checks if the extension is loaded.</p>';
119
120$prefix = (PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : '';
121foreach ($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
137echo '<h3>Check for required 3rd party libs</h3>';
138echo '<p>This also checks if the include path is set correctly.</p>';
139
140foreach ($required_libs as $classname => $file) {
141    require_once $file;
142    echo "$classname: ";
143    if (class_exists($classname)) {
144        echo CHECK_OK;
145    } else {
146        echo CHECK_NOK . "; Failed to load $file";
147    }
148    echo "<br />";
149}
150
151echo '<h3>Check if you setup config files</h3>';
152echo '<p>Checks if the files exist and if they are readable.</p>';
153
154foreach ($create_files AS $file) {
155    echo "File $file: ";
156    if (file_exists($path . $file) && is_readable($path . $file)) {
157        echo CHECK_OK;
158    } else {
159        echo CHECK_NOK;
160    }
161    echo '<br />';
162}
163
164echo '<h3>Check if directories are writable</h3>';
165echo '<p>RoundCube may need to write/save files into these directories.</p>';
166@include $path . 'config/main.inc.php';
167
168if (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 />';
181}
182
183echo '<h3>Check supplied DB settings</h3>';
184@include $path . 'config/db.inc.php';
185
186$db_working = false;
187if (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)) {
192        echo CHECK_OK;
193        $db->disconnect();
194        $db_working = true;
195    } else {
196        echo CHECK_NOK;
197    }
198    echo '<br />';
199} else {
200    echo 'Could not open db.inc.php config file, or file is empty.<br />';
201}
202
203echo '<h3>TimeZone</h3>';
204echo 'Checks if web- and databaseserver are in the same timezone.<br /><br />';
205echo 'Status: ';
206if ($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) {
219        echo CHECK_NOK;
220    } else {
221        echo CHECK_OK;
222    }
223} else {
224    echo 'Could not test (fix DB first).';
225}
226echo '<br />';
227
228echo '<h3>Checking .ini settings</h3>';
229
230$ini_array = array('session.auto_start' => 0, 'file_uploads' => 1,
231    'magic_quotes_sybase' => 0, 'magic_quotes_gpc' => 0);
232
233foreach ($ini_array AS $var => $val) {
234    $status = ini_get($var);
235
236    echo "<h4>$var = $val</h4>";
237    echo 'status: ';
238    if ($status != $val) {
239        echo CHECK_NOK;
240    } else {
241        echo CHECK_OK;
242    }
243    echo '<br />';
244}
245
246@include $path . 'config/main.inc.php';
247?>
248<h3>Check email settings</h3>
249<?php
250echo 'Fetching config-settings from config/main.inc.php.<br /><br />';
251if (is_array($rcmail_config) && count($rcmail_config)) {
252?>
253<table border="0">
254<tr>
255    <th><h4>SMTP Settings</h4></th>
256    <th><h4>IMAP Settings</h4></th>
257</tr>
258<tr><td valign="top">
259<?php
260    echo 'SMTP: ' . CHECK_OK . '<br />';
261    echo 'server: ' . $rcmail_config['smtp_server'] . '<br />';
262    echo 'port: ' . $rcmail_config['smtp_port'] . '<br />';
263    echo 'user: ' . (($rcmail_config['smtp_user'] == '%u')?'<i>use current session</i>':$rcmail_config['smtp_user']) . '<br />';
264    echo 'pass: ' . (($rcmail_config['smtp_pass'] == '%p')?'<i>use current session</i>':$rcmail_config['smtp_pass']) . '<br />';
265    //var_dump($rcmail_config);
266?>
267</td><td valign="top">
268<?php
269    echo 'IMAP: ' . CHECK_OK . '<br />';
270    echo 'server: ' . (is_array($rcmail_config['default_host']) ? var_export($rcmail_config['default_host'], true) : $rcmail_config['default_host']) . '<br />';
271    echo 'port: ' . $rcmail_config['default_port'] . '<br />';
272?>
273</td></tr>
274</table>
275<h3>Test SMTP settings - send an email</h3>
276<p>Don't abuse this!</p>
277<form action="<?php echo $check; ?>" method="post">
278<?php
279if ($rcmail_config['smtp_server'] != ''):
280    if ($rcmail_config['smtp_user'] == '%u'):
281?>
282<label>Username:</label><input type="text" name="smtp_test[user]" />
283<label>Password:</label><input type="password" name="smtp_test[pass]" /><br />
284<?php
285    endif;
286endif;
287?>
288Recipient:<br />
289<?php echo $rctest_config['from']; ?><br /><br />
290<input type="hidden" name="action" value="smtp" />
291<input type="submit" value="send an email" />
292</form>
293<?php
294    if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['action'] == 'smtp') {
295
296        echo 'Trying to send email: ';
297        if ($rctest_config['from'] == '_yourfrom_') {
298            echo CHECK_NOK . '<br />';
299            echo '<i>Please edit $rctest_config in ' . basename(__FILE__) . '</i><br />';
300        } else {
301
302            $data   = $_POST['smtp_test'];
303            $CONFIG = $rcmail_config;
304
305            require_once 'lib/rc_mail_mime.inc';
306            require_once 'include/rcube_smtp.inc';
307
308            $recipients = $rctest_config['from'];
309
310            $headers['From']    = $rctest_config['from'];
311            $headers['To']      = $recipients;
312            $headers['Subject'] = 'Test message from RoundCube';
313
314            $body = 'This is a test to confirm that RoundCube can send email.';
315
316            $mail_object = new rc_mail_mime();
317            $mail_object->headers($headers);
318           
319            $smtp_response = array();
320            if (smtp_mail($rctest_config['from'], $recipients, ($foo = $mail_object->txtHeaders($send_headers)), $body, $smtp_response)) {
321                echo CHECK_OK . '<br />';
322            } else {
323                echo CHECK_NOK;
324                echo '<br />' . join('<br />', $smtp_response);
325            }
326        }
327    }
328} else {
329    echo CHECK_NOK;
330}
331?>
332<h3>Test IMAP settings</h3>
333<?php
334if ($rcmail_config['default_host'] == '') {
335    echo '<span class="fail">We cannot test, default_host is not set in config/main.inc.php.</span>';
336} else {
337?>
338<form action="<?php echo $check; ?>" method="post">
339<label>Username:</label><input type="text" name="imap_test[user]" />
340<label>Password:</label><input type="password" name="imap_test[pass]" /><br /><br />
341<input type="hidden" name="action" value="imap" />
342<input type="submit" value="check email" />
343</form><br /><br />
344<?php
345    if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['action'] == 'imap') {
346
347        echo 'Testing IMAP connect: ';
348
349        $data = $_POST['imap_test'];
350
351        require_once 'imap.inc';
352        global $iil_error, $ICL_PORT;
353
354        $ICL_PORT = $rcmail_config['default_port'];
355        $result   = iil_Connect($rcmail_config['default_host'],
356            $data['user'], $data['pass']);
357
358        if ($result != true) {
359            echo CHECK_NOK;
360            echo '<br />Error return: ' . $iil_error;
361        } else {
362            echo CHECK_OK;
363        }
364        echo '<br />';
365    }
366}
367?>
368</body>
369</html>
Note: See TracBrowser for help on using the repository browser.