source: github/installer/test.php @ bba657e

HEADcourier-fixdev-browser-capabilitiespdorelease-0.6release-0.7release-0.8
Last change on this file since bba657e was bba657e, checked in by thomascube <thomas@…>, 5 years ago

Made config files location configurable (#1485215)

  • Property mode set to 100644
File size: 9.4 KB
Line 
1<form action="index.php?_step=3" method="post">
2
3<h3>Check config files</h3>
4<?php
5
6$read_main = is_readable(RCMAIL_CONFIG_DIR.'/main.inc.php');
7$read_db = is_readable(RCMAIL_CONFIG_DIR.'/db.inc.php');
8
9if ($read_main && !empty($RCI->config)) {
10  $RCI->pass('main.inc.php');
11}
12else if ($read_main) {
13  $RCI->fail('main.inc.php', 'Syntax error');
14}
15else if (!$read_main) {
16  $RCI->fail('main.inc.php', 'Unable to read file. Did you create the config files?');
17}
18echo '<br />';
19
20if ($read_db && !empty($RCI->config['db_table_users'])) {
21  $RCI->pass('db.inc.php');
22}
23else if ($read_db) {
24  $RCI->fail('db.inc.php', 'Syntax error');
25}
26else if (!$read_db) {
27  $RCI->fail('db.inc.php', 'Unable to read file. Did you create the config files?');
28}
29
30?>
31
32<h3>Check if directories are writable</h3>
33<p>RoundCube may need to write/save files into these directories</p>
34<?php
35
36if ($RCI->configured) {
37    $pass = false;
38
39    $dirs[] = $RCI->config['temp_dir'];
40    if($RCI->config['log_driver'] != 'syslog')
41      $dirs[] = $RCI->config['log_dir'];
42
43    foreach ($dirs as $dir) {
44        $dirpath = $dir{0} == '/' ? $dir : INSTALL_PATH . $dir;
45        if (is_writable(realpath($dirpath))) {
46            $RCI->pass($dir);
47            $pass = true;
48        }
49        else {
50            $RCI->fail($dir, 'not writeable for the webserver');
51        }
52        echo '<br />';
53    }
54   
55    if (!$pass)
56        echo '<p class="hint">Use <tt>chmod</tt> or <tt>chown</tt> to grant write privileges to the webserver</p>';
57}
58else {
59    $RCI->fail('Config', 'Could not read config files');
60}
61
62?>
63
64<h3>Check configured database settings</h3>
65<?php
66
67$db_working = false;
68if ($RCI->configured) {
69    if (!empty($RCI->config['db_dsnw'])) {
70
71        $DB = new rcube_mdb2($RCI->config['db_dsnw'], '', false);
72        $DB->db_connect('w');
73        if (!($db_error_msg = $DB->is_error())) {
74            $RCI->pass('DSN (write)');
75            echo '<br />';
76            $db_working = true;
77        }
78        else {
79            $RCI->fail('DSN (write)', $db_error_msg);
80            echo '<p class="hint">Make sure that the configured database exists and that the user has write privileges<br />';
81            echo 'DSN: ' . $RCI->config['db_dsnw'] . '</p>';
82        }
83    }
84    else {
85        $RCI->fail('DSN (write)', 'not set');
86    }
87}
88else {
89    $RCI->fail('Config', 'Could not read config files');
90}
91
92// initialize db with schema found in /SQL/*
93if ($db_working && $_POST['initdb']) {
94    if (!($success = $RCI->init_db($DB))) {
95        $db_working = false;
96        echo '<p class="warning">Please try to inizialize the database manually as described in the INSTALL guide.
97          Make sure that the configured database extists and that the user as write privileges</p>';
98    }
99}
100
101// test database
102if ($db_working) {
103    $db_read = $DB->query("SELECT count(*) FROM {$RCI->config['db_table_users']}");
104    if (!$db_read) {
105        $RCI->fail('DB Schema', "Database not initialized");
106        $db_working = false;
107        echo '<p><input type="submit" name="initdb" value="Initialize database" /></p>';
108    }
109    else {
110        $RCI->pass('DB Schema');
111    }
112    echo '<br />';
113}
114
115// more database tests
116if ($db_working) {
117    // write test
118    $insert_id = md5(uniqid());
119    $db_write = $DB->query("INSERT INTO {$RCI->config['db_table_session']} (sess_id, created, ip, vars) VALUES (?, ".$DB->now().", '127.0.0.1', 'foo')", $insert_id);
120
121    if ($db_write) {
122      $RCI->pass('DB Write');
123      $DB->query("DELETE FROM {$RCI->config['db_table_session']} WHERE sess_id=?", $insert_id);
124    }
125    else {
126      $RCI->fail('DB Write', $RCI->get_error());
127    }
128    echo '<br />';   
129   
130    // check timezone settings
131    $tz_db = 'SELECT ' . $DB->unixtimestamp($DB->now()) . ' AS tz_db';
132    $tz_db = $DB->query($tz_db);
133    $tz_db = $DB->fetch_assoc($tz_db);
134    $tz_db = (int) $tz_db['tz_db'];
135    $tz_local = (int) time();
136    $tz_diff  = $tz_local - $tz_db;
137
138    // sometimes db and web servers are on separate hosts, so allow a 30 minutes delta
139    if (abs($tz_diff) > 1800) {
140        $RCI->fail('DB Time', "Database time differs {$td_ziff}s from PHP time");
141    }
142    else {
143        $RCI->pass('DB Time');
144    }
145}
146
147?>
148
149<h3>Test SMTP settings</h3>
150
151<p>
152Server: <?php echo $RCI->getprop('smtp_server', 'PHP mail()'); ?><br />
153Port: <?php echo $RCI->getprop('smtp_port'); ?><br />
154
155<?php
156
157if ($RCI->getprop('smtp_server')) {
158  $user = $RCI->getprop('smtp_user', '(none)');
159  $pass = $RCI->getprop('smtp_pass', '(none)');
160 
161  if ($user == '%u') {
162    $user_field = new html_inputfield(array('name' => '_smtp_user'));
163    $user = $user_field->show($_POST['_smtp_user']);
164  }
165  if ($pass == '%p') {
166    $pass_field = new html_passwordfield(array('name' => '_smtp_pass'));
167    $pass = $pass_field->show();
168  }
169 
170  echo "User: $user<br />";
171  echo "Password: $pass<br />";
172}
173
174$from_field = new html_inputfield(array('name' => '_from', 'id' => 'sendmailfrom'));
175$to_field = new html_inputfield(array('name' => '_to', 'id' => 'sendmailto'));
176
177?>
178</p>
179
180<?php
181
182if (isset($_POST['sendmail']) && !empty($_POST['_from']) && !empty($_POST['_to'])) {
183 
184  require_once 'rcube_smtp.inc';
185 
186  echo '<p>Trying to send email...<br />';
187 
188  if (preg_match('/^' . $RCI->email_pattern . '$/i', trim($_POST['_from'])) &&
189      preg_match('/^' . $RCI->email_pattern . '$/i', trim($_POST['_to']))) {
190 
191    $headers = array(
192      'From'    => trim($_POST['_from']),
193      'To'      => trim($_POST['_to']),
194      'Subject' => 'Test message from RoundCube',
195    );
196
197    $body = 'This is a test to confirm that RoundCube can send email.';
198    $smtp_response = array();
199   
200    // send mail using configured SMTP server
201    if ($RCI->getprop('smtp_server')) {
202      $CONFIG = $RCI->config;
203     
204      if (!empty($_POST['_smtp_user'])) {
205        $CONFIG['smtp_user'] = $_POST['_smtp_user'];
206      }
207      if (!empty($_POST['_smtp_pass'])) {
208        $CONFIG['smtp_pass'] = $_POST['_smtp_pass'];
209      }
210
211      $mail_object  = new rcube_mail_mime();
212      $send_headers = $mail_object->headers($headers);
213     
214      $status = smtp_mail($headers['From'], $headers['To'],
215          ($foo = $mail_object->txtHeaders($send_headers)),
216          $body, $smtp_response);
217    }
218    else {    // use mail()
219      $header_str = 'From: ' . $headers['From'];
220     
221      if (ini_get('safe_mode'))
222        $status = mail($headers['To'], $headers['Subject'], $body, $header_str);
223      else
224        $status = mail($headers['To'], $headers['Subject'], $body, $header_str, '-f'.$headers['From']);
225     
226      if (!$status)
227        $smtp_response[] = 'Mail delivery with mail() failed. Check your error logs for details';
228    }
229
230    if ($status) {
231        $RCI->pass('SMTP send');
232    }
233    else {
234        $RCI->fail('SMTP send', join('; ', $smtp_response));
235    }
236  }
237  else {
238    $RCI->fail('SMTP send', 'Invalid sender or recipient');
239  }
240}
241
242echo '</p>';
243
244?>
245
246<table>
247<tbody>
248  <tr>
249    <td><label for="sendmailfrom">Sender</label></td>
250    <td><?php echo $from_field->show($_POST['_from']); ?></td>
251  </tr>
252  <tr>
253    <td><label for="sendmailto">Recipient</label></td>
254    <td><?php echo $to_field->show($_POST['_to']); ?></td>
255  </tr>
256</tbody>
257</table>
258
259<p><input type="submit" name="sendmail" value="Send test mail" /></p>
260
261
262<h3>Test IMAP configuration</h3>
263
264<?php
265
266$default_hosts = $RCI->get_hostlist();
267if (!empty($default_hosts)) {
268  $host_field = new html_select(array('name' => '_host', 'id' => 'imaphost'));
269  $host_field->add($default_hosts);
270}
271else {
272  $host_field = new html_inputfield(array('name' => '_host', 'id' => 'imaphost'));
273}
274
275$user_field = new html_inputfield(array('name' => '_user', 'id' => 'imapuser'));
276$pass_field = new html_passwordfield(array('name' => '_pass', 'id' => 'imappass'));
277
278?>
279
280<table>
281<tbody>
282  <tr>
283    <td><label for="imaphost">Server</label></td>
284    <td><?php echo $host_field->show($_POST['_host']); ?></td>
285  </tr>
286  <tr>
287    <td>Port</td>
288    <td><?php echo $RCI->getprop('default_port'); ?></td>
289  </tr>
290    <tr>
291      <td><label for="imapuser">Username</label></td>
292      <td><?php echo $user_field->show($_POST['_user']); ?></td>
293    </tr>
294    <tr>
295      <td><label for="imappass">Password</label></td>
296      <td><?php echo $pass_field->show(); ?></td>
297    </tr>
298</tbody>
299</table>
300
301<?php
302
303if (isset($_POST['imaptest']) && !empty($_POST['_host']) && !empty($_POST['_user'])) {
304 
305  echo '<p>Connecting to ' . Q($_POST['_host']) . '...<br />';
306 
307  $a_host = parse_url($_POST['_host']);
308  if ($a_host['host']) {
309    $imap_host = $a_host['host'];
310    $imap_ssl = (isset($a_host['scheme']) && in_array($a_host['scheme'], array('ssl','imaps','tls'))) ? $a_host['scheme'] : null;
311    $imap_port = isset($a_host['port']) ? $a_host['port'] : ($imap_ssl ? 993 : $CONFIG['default_port']);
312  }
313  else {
314    $imap_host = trim($_POST['_host']);
315    $imap_port = $RCI->getprop('default_port');
316  }
317 
318  $imap = new rcube_imap(null);
319  if ($imap->connect($imap_host, $_POST['_user'], $_POST['_pass'], $imap_port, $imap_ssl)) {
320    $RCI->pass('IMAP connect', 'SORT capability: ' . ($imap->get_capability('SORT') ? 'yes' : 'no'));
321    $imap->close();
322  }
323  else {
324    $RCI->fail('IMAP connect', $RCI->get_error());
325  }
326}
327
328?>
329
330<p><input type="submit" name="imaptest" value="Check login" /></p>
331
332</form>
333
334<hr />
335
336<p class="warning">
337
338After completing the installation and the final tests please <b>remove</b> the whole
339installer folder from the document root of the webserver.<br />
340<br />
341
342These files may expose sensitive configuration data like server passwords and encryption keys
343to the public. Make sure you cannot access this installer from your browser.
344
345</p>
Note: See TracBrowser for help on using the repository browser.