Aleksander Machniak
2016-05-09 5b3a86da57a47a723f89d8dd64ce484002b8e4bb
commit | author | age
619c32 1 <?php
TB 2
eea11e 3 if (!class_exists('rcmail_install', false) || !is_object($RCI)) {
619c32 4     die("Not allowed! Please open installer/index.php instead.");
TB 5 }
6
7 ?>
c5042d 8 <form action="index.php?_step=3" method="post">
T 9
461a30 10 <h3>Check config file</h3>
354978 11 <?php
T 12
461a30 13 if ($read_config = is_readable(RCUBE_CONFIG_DIR . 'defaults.inc.php')) {
AM 14   $config = $RCI->load_config_file(RCUBE_CONFIG_DIR . 'defaults.inc.php');
15   if (!empty($config)) {
16     $RCI->pass('defaults.inc.php');
17   }
18   else {
19     $RCI->fail('defaults.inc.php', 'Syntax error');
20   }
c5042d 21 }
461a30 22 else {
AM 23   $RCI->fail('defaults.inc.php', 'Unable to read default config file?');
c5042d 24 }
T 25 echo '<br />';
26
461a30 27 if ($read_config = is_readable(RCUBE_CONFIG_DIR . 'config.inc.php')) {
AM 28   $config = $RCI->load_config_file(RCUBE_CONFIG_DIR . 'config.inc.php');
29   if (!empty($config)) {
30     $RCI->pass('config.inc.php');
31   }
32   else {
33     $RCI->fail('config.inc.php', 'Syntax error');
34   }
c5042d 35 }
461a30 36 else {
AM 37   $RCI->fail('config.inc.php', 'Unable to read file. Did you create the config file?');
c5042d 38 }
461a30 39 echo '<br />';
AM 40
354978 41
e10712 42 if ($RCI->configured && ($messages = $RCI->check_config())) {
T 43   if (is_array($messages['replaced'])) {
44     echo '<h3 class="warning">Replaced config options</h3>';
45     echo '<p class="hint">The following config options have been replaced or renamed. ';
46     echo 'Please update them accordingly in your config files.</p>';
461a30 47
e10712 48     echo '<ul class="configwarings">';
T 49     foreach ($messages['replaced'] as $msg) {
50       echo html::tag('li', null, html::span('propname', $msg['prop']) .
51         ' was replaced by ' . html::span('propname', $msg['replacement']));
52     }
53     echo '</ul>';
54   }
55
56   if (is_array($messages['obsolete'])) {
57     echo '<h3>Obsolete config options</h3>';
58     echo '<p class="hint">You still have some obsolete or inexistent properties set. This isn\'t a problem but should be noticed.</p>';
461a30 59
e10712 60     echo '<ul class="configwarings">';
T 61     foreach ($messages['obsolete'] as $msg) {
62       echo html::tag('li', null, html::span('propname', $msg['prop']) . ($msg['name'] ? ':&nbsp;' . $msg['name'] : ''));
63     }
64     echo '</ul>';
65   }
461a30 66
AM 67   echo '<p class="suggestion">OK, lazy people can download the updated config file here: ';
68   echo html::a(array('href' => './?_mergeconfig=1'), 'config.inc.php') . ' &nbsp;';
e10712 69   echo "</p>";
461a30 70
871ca9 71   if (is_array($messages['dependencies'])) {
T 72     echo '<h3 class="warning">Dependency check failed</h3>';
73     echo '<p class="hint">Some of your configuration settings require other options to be configured or additional PHP modules to be installed</p>';
461a30 74
871ca9 75     echo '<ul class="configwarings">';
T 76     foreach ($messages['dependencies'] as $msg) {
77       echo html::tag('li', null, html::span('propname', $msg['prop']) . ': ' . $msg['explain']);
78     }
79     echo '</ul>';
80   }
e10712 81 }
T 82
354978 83 ?>
c5042d 84
308f41 85 <h3>Check if directories are writable</h3>
e019f2 86 <p>Roundcube may need to write/save files into these directories</p>
308f41 87 <?php
T 88
461a30 89 $dirs[] = $RCI->config['temp_dir'] ? $RCI->config['temp_dir'] : 'temp';
AM 90 if ($RCI->config['log_driver'] != 'syslog')
91     $dirs[] = $RCI->config['log_dir'] ? $RCI->config['log_dir'] : 'logs';
b77d0d 92
461a30 93 foreach ($dirs as $dir) {
517c9f 94     $dirpath = rcube_utils::is_absolute_path($dir) ? $dir : INSTALL_PATH . $dir;
461a30 95     if (is_writable(realpath($dirpath))) {
AM 96         $RCI->pass($dir);
97         $pass = true;
308f41 98     }
461a30 99     else {
AM 100         $RCI->fail($dir, 'not writeable for the webserver');
101     }
102     echo '<br />';
308f41 103 }
461a30 104
AM 105 if (!$pass) {
106     echo '<p class="hint">Use <tt>chmod</tt> or <tt>chown</tt> to grant write privileges to the webserver</p>';
308f41 107 }
T 108
109 ?>
110
256361 111 <h3>Check DB config</h3>
c5042d 112 <?php
T 113
114 $db_working = false;
308f41 115 if ($RCI->configured) {
9e8e5f 116     if (!empty($RCI->config['db_dsnw'])) {
91f227 117         $DB = rcube_db::factory($RCI->config['db_dsnw'], '', false);
90f7aa 118         $DB->set_debug((bool)$RCI->config['sql_debug']);
c5042d 119         $DB->db_connect('w');
398bff 120
c5042d 121         if (!($db_error_msg = $DB->is_error())) {
T 122             $RCI->pass('DSN (write)');
190e97 123             echo '<br />';
c5042d 124             $db_working = true;
T 125         }
126         else {
190e97 127             $RCI->fail('DSN (write)', $db_error_msg);
34eab0 128             echo '<p class="hint">Make sure that the configured database exists and that the user has write privileges<br />';
190e97 129             echo 'DSN: ' . $RCI->config['db_dsnw'] . '</p>';
c5042d 130         }
T 131     }
132     else {
133         $RCI->fail('DSN (write)', 'not set');
134     }
135 }
136 else {
461a30 137     $RCI->fail('DSN (write)', 'Could not read config file');
c5042d 138 }
T 139
140 // initialize db with schema found in /SQL/*
141 if ($db_working && $_POST['initdb']) {
190e97 142     if (!($success = $RCI->init_db($DB))) {
c5042d 143         $db_working = false;
190e97 144         echo '<p class="warning">Please try to inizialize the database manually as described in the INSTALL guide.
T 145           Make sure that the configured database extists and that the user as write privileges</p>';
c5042d 146     }
T 147 }
148
e6bb83 149 else if ($db_working && $_POST['updatedb']) {
4490d0 150     if (!($success = $RCI->update_db($_POST['version']))) {
AM 151         echo '<p class="warning">Database schema update failed.</p>';
152     }
e6bb83 153 }
T 154
190e97 155 // test database
c5042d 156 if ($db_working) {
34a090 157     $db_read = $DB->query("SELECT count(*) FROM " . $DB->quote_identifier($RCI->config['db_prefix'] . 'users'));
159691 158     if ($DB->is_error()) {
c5042d 159         $RCI->fail('DB Schema', "Database not initialized");
T 160         echo '<p><input type="submit" name="initdb" value="Initialize database" /></p>';
871ca9 161         $db_working = false;
c5042d 162     }
e6bb83 163     else if ($err = $RCI->db_schema_check($DB, $update = !empty($_POST['updatedb']))) {
871ca9 164         $RCI->fail('DB Schema', "Database schema differs");
e6bb83 165         echo '<ul style="margin:0"><li>' . join("</li>\n<li>", $err) . "</li></ul>";
T 166         $select = $RCI->versions_select(array('name' => 'version'));
4490d0 167         $select->add('0.9 or newer', '');
AM 168         echo '<p class="suggestion">You should run the update queries to get the schema fixed.<br/><br/>Version to update from: ' . $select->show() . '&nbsp;<input type="submit" name="updatedb" value="Update" /></p>';
871ca9 169         $db_working = false;
T 170     }
c5042d 171     else {
T 172         $RCI->pass('DB Schema');
871ca9 173         echo '<br />';
c5042d 174     }
190e97 175 }
T 176
177 // more database tests
178 if ($db_working) {
179     // write test
50e5ee 180     $insert_id = md5(uniqid());
34a090 181     $db_write = $DB->query("INSERT INTO " . $DB->quote_identifier($RCI->config['db_prefix'] . 'session')
AM 182         . " (`sess_id`, `created`, `ip`, `vars`) VALUES (?, ".$DB->now().", '127.0.0.1', 'foo')", $insert_id);
50e5ee 183
T 184     if ($db_write) {
190e97 185       $RCI->pass('DB Write');
34a090 186       $DB->query("DELETE FROM " . $DB->quote_identifier($RCI->config['db_prefix'] . 'session')
AM 187         . " WHERE `sess_id` = ?", $insert_id);
190e97 188     }
T 189     else {
190       $RCI->fail('DB Write', $RCI->get_error());
191     }
871ca9 192     echo '<br />';
34a090 193
190e97 194     // check timezone settings
c5042d 195     $tz_db = 'SELECT ' . $DB->unixtimestamp($DB->now()) . ' AS tz_db';
T 196     $tz_db = $DB->query($tz_db);
197     $tz_db = $DB->fetch_assoc($tz_db);
198     $tz_db = (int) $tz_db['tz_db'];
199     $tz_local = (int) time();
200     $tz_diff  = $tz_local - $tz_db;
201
202     // sometimes db and web servers are on separate hosts, so allow a 30 minutes delta
203     if (abs($tz_diff) > 1800) {
204         $RCI->fail('DB Time', "Database time differs {$td_ziff}s from PHP time");
190e97 205     }
T 206     else {
c5042d 207         $RCI->pass('DB Time');
T 208     }
209 }
210
211 ?>
212
8f49e4 213 <h3>Test filetype detection</h3>
TB 214
215 <?php
216
217 if ($errors = $RCI->check_mime_detection()) {
218   $RCI->fail('Fileinfo/mime_content_type configuration');
219   if (!empty($RCI->config['mime_magic'])) {
220     echo '<p class="hint">Try setting the <tt>mime_magic</tt> config option to <tt>null</tt>.</p>';
221   }
222   else {
223     echo '<p class="hint">Check the <a href="http://www.php.net/manual/en/function.finfo-open.php">Fileinfo functions</a> of your PHP installation.<br/>';
224     echo 'The path to the magic.mime file can be set using the <tt>mime_magic</tt> config option in Roundcube.</p>';
225   }
226 }
227 else {
228   $RCI->pass('Fileinfo/mime_content_type configuration');
6b0106 229   echo "<br/>";
8f49e4 230 }
TB 231
232
233 if ($errors = $RCI->check_mime_extensions()) {
234   $RCI->fail('Mimetype to file extension mapping');
235   echo '<p class="hint">Please set a valid path to your webserver\'s mime.types file to the <tt>mime_types</tt> config option.<br/>';
236   echo 'If you can\'t find such a file, download it from <a href="http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types">svn.apache.org</a>.</p>';
237 }
238 else {
239   $RCI->pass('Mimetype to file extension mapping');
6b0106 240   echo "<br/>";
8f49e4 241 }
TB 242
243 ?>
244
245
256361 246 <h3>Test SMTP config</h3>
ad43e6 247
T 248 <p>
69a1e4 249 Server: <?php echo rcube_utils::parse_host($RCI->getprop('smtp_server', 'PHP mail()')); ?><br />
ad43e6 250 Port: <?php echo $RCI->getprop('smtp_port'); ?><br />
fa7539 251
T 252 <?php
253
254 if ($RCI->getprop('smtp_server')) {
255   $user = $RCI->getprop('smtp_user', '(none)');
256   $pass = $RCI->getprop('smtp_pass', '(none)');
257   
258   if ($user == '%u') {
47124c 259     $user_field = new html_inputfield(array('name' => '_smtp_user'));
7635d2 260     $user = $user_field->show($_POST['_smtp_user']);
fa7539 261   }
T 262   if ($pass == '%p') {
47124c 263     $pass_field = new html_passwordfield(array('name' => '_smtp_pass'));
fa7539 264     $pass = $pass_field->show();
T 265   }
266   
267   echo "User: $user<br />";
268   echo "Password: $pass<br />";
269 }
27564f 270
47124c 271 $from_field = new html_inputfield(array('name' => '_from', 'id' => 'sendmailfrom'));
T 272 $to_field = new html_inputfield(array('name' => '_to', 'id' => 'sendmailto'));
fa7539 273
T 274 ?>
ad43e6 275 </p>
T 276
277 <?php
278
256361 279 if (isset($_POST['sendmail'])) {
A 280
ad43e6 281   echo '<p>Trying to send email...<br />';
256361 282
e99991 283   $from = idn_to_ascii(trim($_POST['_from']));
A 284   $to   = idn_to_ascii(trim($_POST['_to']));
2c3d81 285
e99991 286   if (preg_match('/^' . $RCI->email_pattern . '$/i', $from) &&
A 287       preg_match('/^' . $RCI->email_pattern . '$/i', $to)
288   ) {
ad43e6 289     $headers = array(
e99991 290       'From'    => $from,
A 291       'To'      => $to,
e019f2 292       'Subject' => 'Test message from Roundcube',
ad43e6 293     );
T 294
e019f2 295     $body = 'This is a test to confirm that Roundcube can send email.';
ad43e6 296     $smtp_response = array();
e99991 297
fa7539 298     // send mail using configured SMTP server
T 299     if ($RCI->getprop('smtp_server')) {
300       $CONFIG = $RCI->config;
2c3d81 301
7635d2 302       if (!empty($_POST['_smtp_user'])) {
T 303         $CONFIG['smtp_user'] = $_POST['_smtp_user'];
304       }
305       if (!empty($_POST['_smtp_pass'])) {
306         $CONFIG['smtp_pass'] = $_POST['_smtp_pass'];
307       }
308
e987db 309       $mail_object  = new Mail_mime();
fa7539 310       $send_headers = $mail_object->headers($headers);
2c3d81 311
A 312       $SMTP = new rcube_smtp();
69a1e4 313       $SMTP->connect(rcube_utils::parse_host($RCI->getprop('smtp_server')),
d1dd13 314         $RCI->getprop('smtp_port'), $CONFIG['smtp_user'], $CONFIG['smtp_pass']);
2c3d81 315
A 316       $status = $SMTP->send_mail($headers['From'], $headers['To'],
317           ($foo = $mail_object->txtHeaders($send_headers)), $body);
318
319       $smtp_response = $SMTP->get_response();
fa7539 320     }
T 321     else {    // use mail()
322       $header_str = 'From: ' . $headers['From'];
323       
324       if (ini_get('safe_mode'))
325         $status = mail($headers['To'], $headers['Subject'], $body, $header_str);
326       else
327         $status = mail($headers['To'], $headers['Subject'], $body, $header_str, '-f'.$headers['From']);
74ce01 328
fa7539 329       if (!$status)
T 330         $smtp_response[] = 'Mail delivery with mail() failed. Check your error logs for details';
331     }
ad43e6 332
T 333     if ($status) {
334         $RCI->pass('SMTP send');
335     }
336     else {
337         $RCI->fail('SMTP send', join('; ', $smtp_response));
338     }
339   }
340   else {
341     $RCI->fail('SMTP send', 'Invalid sender or recipient');
342   }
74ce01 343
97d659 344   echo '</p>';
ad43e6 345 }
T 346
347 ?>
348
349 <table>
350 <tbody>
27564f 351   <tr>
T 352     <td><label for="sendmailfrom">Sender</label></td>
353     <td><?php echo $from_field->show($_POST['_from']); ?></td>
354   </tr>
355   <tr>
356     <td><label for="sendmailto">Recipient</label></td>
357     <td><?php echo $to_field->show($_POST['_to']); ?></td>
358   </tr>
ad43e6 359 </tbody>
T 360 </table>
361
362 <p><input type="submit" name="sendmail" value="Send test mail" /></p>
363
364
256361 365 <h3>Test IMAP config</h3>
27564f 366
T 367 <?php
368
112c54 369 $default_hosts = $RCI->get_hostlist();
T 370 if (!empty($default_hosts)) {
47124c 371   $host_field = new html_select(array('name' => '_host', 'id' => 'imaphost'));
112c54 372   $host_field->add($default_hosts);
T 373 }
374 else {
47124c 375   $host_field = new html_inputfield(array('name' => '_host', 'id' => 'imaphost'));
112c54 376 }
27564f 377
47124c 378 $user_field = new html_inputfield(array('name' => '_user', 'id' => 'imapuser'));
T 379 $pass_field = new html_passwordfield(array('name' => '_pass', 'id' => 'imappass'));
27564f 380
T 381 ?>
382
383 <table>
384 <tbody>
385   <tr>
386     <td><label for="imaphost">Server</label></td>
112c54 387     <td><?php echo $host_field->show($_POST['_host']); ?></td>
27564f 388   </tr>
T 389   <tr>
390     <td>Port</td>
391     <td><?php echo $RCI->getprop('default_port'); ?></td>
392   </tr>
393     <tr>
394       <td><label for="imapuser">Username</label></td>
395       <td><?php echo $user_field->show($_POST['_user']); ?></td>
396     </tr>
397     <tr>
398       <td><label for="imappass">Password</label></td>
399       <td><?php echo $pass_field->show(); ?></td>
400     </tr>
401 </tbody>
402 </table>
403
404 <?php
405
406 if (isset($_POST['imaptest']) && !empty($_POST['_host']) && !empty($_POST['_user'])) {
3be904 407
74ce01 408   echo '<p>Connecting to ' . rcube::Q($_POST['_host']) . '...<br />';
3be904 409
A 410   $imap_host = trim($_POST['_host']);
411   $imap_port = $RCI->getprop('default_port');
412   $a_host    = parse_url($imap_host);
413
27564f 414   if ($a_host['host']) {
T 415     $imap_host = $a_host['host'];
3be904 416     $imap_ssl  = (isset($a_host['scheme']) && in_array($a_host['scheme'], array('ssl','imaps','tls'))) ? $a_host['scheme'] : null;
A 417     if (isset($a_host['port']))
418       $imap_port = $a_host['port'];
419     else if ($imap_ssl && $imap_ssl != 'tls' && (!$imap_port || $imap_port == 143))
420       $imap_port = 993;
27564f 421   }
e99991 422
A 423   $imap_host = idn_to_ascii($imap_host);
424   $imap_user = idn_to_ascii($_POST['_user']);
425
27564f 426   $imap = new rcube_imap(null);
37ac40 427   $imap->set_options(array(
AM 428     'auth_type' => $RCI->getprop('imap_auth_type'),
429     'debug'     => $RCI->getprop('imap_debug'),
df10bd 430     'socket_options' => $RCI->getprop('imap_conn_options'),
37ac40 431   ));
AM 432
e99991 433   if ($imap->connect($imap_host, $imap_user, $_POST['_pass'], $imap_port, $imap_ssl)) {
27564f 434     $RCI->pass('IMAP connect', 'SORT capability: ' . ($imap->get_capability('SORT') ? 'yes' : 'no'));
T 435     $imap->close();
436   }
437   else {
438     $RCI->fail('IMAP connect', $RCI->get_error());
439   }
440 }
441
442 ?>
443
444 <p><input type="submit" name="imaptest" value="Check login" /></p>
c5042d 445
354978 446 </form>
T 447
27564f 448 <hr />
T 449
354978 450 <p class="warning">
T 451
452 After completing the installation and the final tests please <b>remove</b> the whole
8062c0 453 installer folder from the document root of the webserver or make sure that
461a30 454 <tt>enable_installer</tt> option in <tt>config.inc.php</tt> is disabled.<br />
354978 455 <br />
T 456
457 These files may expose sensitive configuration data like server passwords and encryption keys
458 to the public. Make sure you cannot access this installer from your browser.
459
460 </p>