source: subversion/trunk/roundcubemail/installer/test.php @ 3749

Last change on this file since 3749 was 3749, checked in by alec, 3 years ago
  • Add note about enable_installer option (#1486787)
File size: 12.3 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
30if ($RCI->configured && ($messages = $RCI->check_config())) {
31 
32  if (is_array($messages['missing'])) {
33    echo '<h3 class="warning">Missing config options</h3>';
34    echo '<p class="hint">The following config options are not present in the current configuration.<br/>';
35    echo 'Please check the default config files and add the missing properties to your local config files.</p>';
36   
37    echo '<ul class="configwarings">';
38    foreach ($messages['missing'] as $msg) {
39      echo html::tag('li', null, html::span('propname', $msg['prop']) . ($msg['name'] ? ':&nbsp;' . $msg['name'] : ''));
40    }   
41    echo '</ul>';
42  }
43
44  if (is_array($messages['replaced'])) {
45    echo '<h3 class="warning">Replaced config options</h3>';
46    echo '<p class="hint">The following config options have been replaced or renamed. ';
47    echo 'Please update them accordingly in your config files.</p>';
48   
49    echo '<ul class="configwarings">';
50    foreach ($messages['replaced'] as $msg) {
51      echo html::tag('li', null, html::span('propname', $msg['prop']) .
52        ' was replaced by ' . html::span('propname', $msg['replacement']));
53    }
54    echo '</ul>';
55  }
56
57  if (is_array($messages['obsolete'])) {
58    echo '<h3>Obsolete config options</h3>';
59    echo '<p class="hint">You still have some obsolete or inexistent properties set. This isn\'t a problem but should be noticed.</p>';
60   
61    echo '<ul class="configwarings">';
62    foreach ($messages['obsolete'] as $msg) {
63      echo html::tag('li', null, html::span('propname', $msg['prop']) . ($msg['name'] ? ':&nbsp;' . $msg['name'] : ''));
64    }
65    echo '</ul>';
66  }
67 
68  echo '<p class="suggestion">OK, lazy people can download the updated config files here: ';
69  echo html::a(array('href' => './?_mergeconfig=main'), 'main.inc.php') . ' &nbsp;';
70  echo html::a(array('href' => './?_mergeconfig=db'), 'db.inc.php');
71  echo "</p>";
72 
73 
74  if (is_array($messages['dependencies'])) {
75    echo '<h3 class="warning">Dependency check failed</h3>';
76    echo '<p class="hint">Some of your configuration settings require other options to be configured or additional PHP modules to be installed</p>';
77   
78    echo '<ul class="configwarings">';
79    foreach ($messages['dependencies'] as $msg) {
80      echo html::tag('li', null, html::span('propname', $msg['prop']) . ': ' . $msg['explain']);
81    }
82    echo '</ul>';
83  }
84
85 
86}
87
88?>
89
90<h3>Check if directories are writable</h3>
91<p>RoundCube may need to write/save files into these directories</p>
92<?php
93
94if ($RCI->configured) {
95    $pass = false;
96
97    $dirs[] = $RCI->config['temp_dir'] ? $RCI->config['temp_dir'] : 'temp';
98    if($RCI->config['log_driver'] != 'syslog')
99      $dirs[] = $RCI->config['log_dir'] ? $RCI->config['log_dir'] : 'logs';
100
101    foreach ($dirs as $dir) {
102        $dirpath = $dir[0] == '/' ? $dir : INSTALL_PATH . $dir;
103        if (is_writable(realpath($dirpath))) {
104            $RCI->pass($dir);
105            $pass = true;
106        }
107        else {
108            $RCI->fail($dir, 'not writeable for the webserver');
109        }
110        echo '<br />';
111    }
112   
113    if (!$pass)
114        echo '<p class="hint">Use <tt>chmod</tt> or <tt>chown</tt> to grant write privileges to the webserver</p>';
115}
116else {
117    $RCI->fail('Config', 'Could not read config files');
118}
119
120?>
121
122<h3>Check DB config</h3>
123<?php
124
125$db_working = false;
126if ($RCI->configured) {
127    if (!empty($RCI->config['db_dsnw'])) {
128
129        $DB = new rcube_mdb2($RCI->config['db_dsnw'], '', false);
130        $DB->db_connect('w');
131        if (!($db_error_msg = $DB->is_error())) {
132            $RCI->pass('DSN (write)');
133            echo '<br />';
134            $db_working = true;
135        }
136        else {
137            $RCI->fail('DSN (write)', $db_error_msg);
138            echo '<p class="hint">Make sure that the configured database exists and that the user has write privileges<br />';
139            echo 'DSN: ' . $RCI->config['db_dsnw'] . '</p>';
140        }
141    }
142    else {
143        $RCI->fail('DSN (write)', 'not set');
144    }
145}
146else {
147    $RCI->fail('Config', 'Could not read config files');
148}
149
150// initialize db with schema found in /SQL/*
151if ($db_working && $_POST['initdb']) {
152    if (!($success = $RCI->init_db($DB))) {
153        $db_working = false;
154        echo '<p class="warning">Please try to inizialize the database manually as described in the INSTALL guide.
155          Make sure that the configured database extists and that the user as write privileges</p>';
156    }
157}
158
159// test database
160if ($db_working) {
161    $db_read = $DB->query("SELECT count(*) FROM {$RCI->config['db_table_users']}");
162    if ($DB->db_error) {
163        $RCI->fail('DB Schema', "Database not initialized");
164        echo '<p><input type="submit" name="initdb" value="Initialize database" /></p>';
165        $db_working = false;
166    }
167    else if ($RCI->db_schema_check($DB, $update = !empty($_POST['updatedb']))) {
168        $RCI->fail('DB Schema', "Database schema differs");
169        $updatefile = INSTALL_PATH . 'SQL/' . $DB->db_provider . '.update.sql';
170        echo '<p class="warning">Please manually execute the SQL statements from '.$updatefile.' on your database.<br/>';
171        echo 'See comments in the file and execute queries that are superscribed with the currently installed version number.</p>';
172        $db_working = false;
173    }
174    else {
175        $RCI->pass('DB Schema');
176        echo '<br />';
177    }
178}
179
180// more database tests
181if ($db_working) {
182    // write test
183    $insert_id = md5(uniqid());
184    $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);
185
186    if ($db_write) {
187      $RCI->pass('DB Write');
188      $DB->query("DELETE FROM {$RCI->config['db_table_session']} WHERE sess_id=?", $insert_id);
189    }
190    else {
191      $RCI->fail('DB Write', $RCI->get_error());
192    }
193    echo '<br />';
194   
195    // check timezone settings
196    $tz_db = 'SELECT ' . $DB->unixtimestamp($DB->now()) . ' AS tz_db';
197    $tz_db = $DB->query($tz_db);
198    $tz_db = $DB->fetch_assoc($tz_db);
199    $tz_db = (int) $tz_db['tz_db'];
200    $tz_local = (int) time();
201    $tz_diff  = $tz_local - $tz_db;
202
203    // sometimes db and web servers are on separate hosts, so allow a 30 minutes delta
204    if (abs($tz_diff) > 1800) {
205        $RCI->fail('DB Time', "Database time differs {$td_ziff}s from PHP time");
206    }
207    else {
208        $RCI->pass('DB Time');
209    }
210}
211
212?>
213
214<h3>Test SMTP config</h3>
215
216<p>
217Server: <?php echo rcube_parse_host($RCI->getprop('smtp_server', 'PHP mail()')); ?><br />
218Port: <?php echo $RCI->getprop('smtp_port'); ?><br />
219
220<?php
221
222if ($RCI->getprop('smtp_server')) {
223  $user = $RCI->getprop('smtp_user', '(none)');
224  $pass = $RCI->getprop('smtp_pass', '(none)');
225 
226  if ($user == '%u') {
227    $user_field = new html_inputfield(array('name' => '_smtp_user'));
228    $user = $user_field->show($_POST['_smtp_user']);
229  }
230  if ($pass == '%p') {
231    $pass_field = new html_passwordfield(array('name' => '_smtp_pass'));
232    $pass = $pass_field->show();
233  }
234 
235  echo "User: $user<br />";
236  echo "Password: $pass<br />";
237}
238
239$from_field = new html_inputfield(array('name' => '_from', 'id' => 'sendmailfrom'));
240$to_field = new html_inputfield(array('name' => '_to', 'id' => 'sendmailto'));
241
242?>
243</p>
244
245<?php
246
247if (isset($_POST['sendmail'])) {
248
249  echo '<p>Trying to send email...<br />';
250
251  if (preg_match('/^' . $RCI->email_pattern . '$/i', trim($_POST['_from'])) &&
252      preg_match('/^' . $RCI->email_pattern . '$/i', trim($_POST['_to']))) {
253
254    $headers = array(
255      'From'    => trim($_POST['_from']),
256      'To'      => trim($_POST['_to']),
257      'Subject' => 'Test message from RoundCube',
258    );
259
260    $body = 'This is a test to confirm that RoundCube can send email.';
261    $smtp_response = array();
262   
263    // send mail using configured SMTP server
264    if ($RCI->getprop('smtp_server')) {
265      $CONFIG = $RCI->config;
266
267      if (!empty($_POST['_smtp_user'])) {
268        $CONFIG['smtp_user'] = $_POST['_smtp_user'];
269      }
270      if (!empty($_POST['_smtp_pass'])) {
271        $CONFIG['smtp_pass'] = $_POST['_smtp_pass'];
272      }
273
274      $mail_object  = new Mail_mime();
275      $send_headers = $mail_object->headers($headers);
276
277      $SMTP = new rcube_smtp();
278      $SMTP->connect();
279
280      $status = $SMTP->send_mail($headers['From'], $headers['To'],
281          ($foo = $mail_object->txtHeaders($send_headers)), $body);
282
283      $smtp_response = $SMTP->get_response();
284    }
285    else {    // use mail()
286      $header_str = 'From: ' . $headers['From'];
287     
288      if (ini_get('safe_mode'))
289        $status = mail($headers['To'], $headers['Subject'], $body, $header_str);
290      else
291        $status = mail($headers['To'], $headers['Subject'], $body, $header_str, '-f'.$headers['From']);
292     
293      if (!$status)
294        $smtp_response[] = 'Mail delivery with mail() failed. Check your error logs for details';
295    }
296
297    if ($status) {
298        $RCI->pass('SMTP send');
299    }
300    else {
301        $RCI->fail('SMTP send', join('; ', $smtp_response));
302    }
303  }
304  else {
305    $RCI->fail('SMTP send', 'Invalid sender or recipient');
306  }
307 
308  echo '</p>';
309}
310
311?>
312
313<table>
314<tbody>
315  <tr>
316    <td><label for="sendmailfrom">Sender</label></td>
317    <td><?php echo $from_field->show($_POST['_from']); ?></td>
318  </tr>
319  <tr>
320    <td><label for="sendmailto">Recipient</label></td>
321    <td><?php echo $to_field->show($_POST['_to']); ?></td>
322  </tr>
323</tbody>
324</table>
325
326<p><input type="submit" name="sendmail" value="Send test mail" /></p>
327
328
329<h3>Test IMAP config</h3>
330
331<?php
332
333$default_hosts = $RCI->get_hostlist();
334if (!empty($default_hosts)) {
335  $host_field = new html_select(array('name' => '_host', 'id' => 'imaphost'));
336  $host_field->add($default_hosts);
337}
338else {
339  $host_field = new html_inputfield(array('name' => '_host', 'id' => 'imaphost'));
340}
341
342$user_field = new html_inputfield(array('name' => '_user', 'id' => 'imapuser'));
343$pass_field = new html_passwordfield(array('name' => '_pass', 'id' => 'imappass'));
344
345?>
346
347<table>
348<tbody>
349  <tr>
350    <td><label for="imaphost">Server</label></td>
351    <td><?php echo $host_field->show($_POST['_host']); ?></td>
352  </tr>
353  <tr>
354    <td>Port</td>
355    <td><?php echo $RCI->getprop('default_port'); ?></td>
356  </tr>
357    <tr>
358      <td><label for="imapuser">Username</label></td>
359      <td><?php echo $user_field->show($_POST['_user']); ?></td>
360    </tr>
361    <tr>
362      <td><label for="imappass">Password</label></td>
363      <td><?php echo $pass_field->show(); ?></td>
364    </tr>
365</tbody>
366</table>
367
368<?php
369
370if (isset($_POST['imaptest']) && !empty($_POST['_host']) && !empty($_POST['_user'])) {
371 
372  echo '<p>Connecting to ' . Q($_POST['_host']) . '...<br />';
373 
374  $a_host = parse_url($_POST['_host']);
375  if ($a_host['host']) {
376    $imap_host = $a_host['host'];
377    $imap_ssl = (isset($a_host['scheme']) && in_array($a_host['scheme'], array('ssl','imaps','tls'))) ? $a_host['scheme'] : null;
378    $imap_port = isset($a_host['port']) ? $a_host['port'] : ($imap_ssl ? 993 : $CONFIG['default_port']);
379  }
380  else {
381    $imap_host = trim($_POST['_host']);
382    $imap_port = $RCI->getprop('default_port');
383  }
384 
385  $imap = new rcube_imap(null);
386  if ($imap->connect($imap_host, $_POST['_user'], $_POST['_pass'], $imap_port, $imap_ssl)) {
387    $RCI->pass('IMAP connect', 'SORT capability: ' . ($imap->get_capability('SORT') ? 'yes' : 'no'));
388    $imap->close();
389  }
390  else {
391    $RCI->fail('IMAP connect', $RCI->get_error());
392  }
393}
394
395?>
396
397<p><input type="submit" name="imaptest" value="Check login" /></p>
398
399</form>
400
401<hr />
402
403<p class="warning">
404
405After completing the installation and the final tests please <b>remove</b> the whole
406installer folder from the document root of the webserver or make sure that
407enable_installer option in main.inc.php is disabled.<br />
408<br />
409
410These files may expose sensitive configuration data like server passwords and encryption keys
411to the public. Make sure you cannot access this installer from your browser.
412
413</p>
Note: See TracBrowser for help on using the repository browser.