Aleksander Machniak
2013-06-14 461a30d771edd8bc6606f2c92dfde363514b93b1
commit | author | age
619c32 1 <?php
TB 2
3 if (!class_exists('rcube_install') || !is_object($RCI)) {
4     die("Not allowed! Please open installer/index.php instead.");
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) {
AM 94     $dirpath = $dir[0] == '/' ? $dir : INSTALL_PATH . $dir;
95     if (is_writable(realpath($dirpath))) {
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);
c5042d 118         $DB->db_connect('w');
398bff 119
c5042d 120         if (!($db_error_msg = $DB->is_error())) {
T 121             $RCI->pass('DSN (write)');
190e97 122             echo '<br />';
c5042d 123             $db_working = true;
T 124         }
125         else {
190e97 126             $RCI->fail('DSN (write)', $db_error_msg);
34eab0 127             echo '<p class="hint">Make sure that the configured database exists and that the user has write privileges<br />';
190e97 128             echo 'DSN: ' . $RCI->config['db_dsnw'] . '</p>';
c5042d 129         }
T 130     }
131     else {
132         $RCI->fail('DSN (write)', 'not set');
133     }
134 }
135 else {
461a30 136     $RCI->fail('DSN (write)', 'Could not read config file');
c5042d 137 }
T 138
139 // initialize db with schema found in /SQL/*
140 if ($db_working && $_POST['initdb']) {
190e97 141     if (!($success = $RCI->init_db($DB))) {
c5042d 142         $db_working = false;
190e97 143         echo '<p class="warning">Please try to inizialize the database manually as described in the INSTALL guide.
T 144           Make sure that the configured database extists and that the user as write privileges</p>';
c5042d 145     }
T 146 }
147
e6bb83 148 else if ($db_working && $_POST['updatedb']) {
4490d0 149     if (!($success = $RCI->update_db($_POST['version']))) {
AM 150         echo '<p class="warning">Database schema update failed.</p>';
151     }
e6bb83 152 }
T 153
190e97 154 // test database
c5042d 155 if ($db_working) {
399db1 156     $db_read = $DB->query("SELECT count(*) FROM {$RCI->config['db_prefix']}users");
159691 157     if ($DB->is_error()) {
c5042d 158         $RCI->fail('DB Schema', "Database not initialized");
T 159         echo '<p><input type="submit" name="initdb" value="Initialize database" /></p>';
871ca9 160         $db_working = false;
c5042d 161     }
e6bb83 162     else if ($err = $RCI->db_schema_check($DB, $update = !empty($_POST['updatedb']))) {
871ca9 163         $RCI->fail('DB Schema', "Database schema differs");
e6bb83 164         echo '<ul style="margin:0"><li>' . join("</li>\n<li>", $err) . "</li></ul>";
T 165         $select = $RCI->versions_select(array('name' => 'version'));
4490d0 166         $select->add('0.9 or newer', '');
AM 167         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 168         $db_working = false;
T 169     }
c5042d 170     else {
T 171         $RCI->pass('DB Schema');
871ca9 172         echo '<br />';
c5042d 173     }
190e97 174 }
T 175
176 // more database tests
177 if ($db_working) {
178     // write test
50e5ee 179     $insert_id = md5(uniqid());
399db1 180     $db_write = $DB->query("INSERT INTO {$RCI->config['db_prefix']}session (sess_id, created, ip, vars) VALUES (?, ".$DB->now().", '127.0.0.1', 'foo')", $insert_id);
50e5ee 181
T 182     if ($db_write) {
190e97 183       $RCI->pass('DB Write');
399db1 184       $DB->query("DELETE FROM {$RCI->config['db_prefix']}session WHERE sess_id=?", $insert_id);
190e97 185     }
T 186     else {
187       $RCI->fail('DB Write', $RCI->get_error());
188     }
871ca9 189     echo '<br />';
190e97 190     
T 191     // check timezone settings
c5042d 192     $tz_db = 'SELECT ' . $DB->unixtimestamp($DB->now()) . ' AS tz_db';
T 193     $tz_db = $DB->query($tz_db);
194     $tz_db = $DB->fetch_assoc($tz_db);
195     $tz_db = (int) $tz_db['tz_db'];
196     $tz_local = (int) time();
197     $tz_diff  = $tz_local - $tz_db;
198
199     // sometimes db and web servers are on separate hosts, so allow a 30 minutes delta
200     if (abs($tz_diff) > 1800) {
201         $RCI->fail('DB Time', "Database time differs {$td_ziff}s from PHP time");
190e97 202     }
T 203     else {
c5042d 204         $RCI->pass('DB Time');
T 205     }
206 }
207
208 ?>
209
256361 210 <h3>Test SMTP config</h3>
ad43e6 211
T 212 <p>
058eb6 213 Server: <?php echo rcube_parse_host($RCI->getprop('smtp_server', 'PHP mail()')); ?><br />
ad43e6 214 Port: <?php echo $RCI->getprop('smtp_port'); ?><br />
fa7539 215
T 216 <?php
217
218 if ($RCI->getprop('smtp_server')) {
219   $user = $RCI->getprop('smtp_user', '(none)');
220   $pass = $RCI->getprop('smtp_pass', '(none)');
221   
222   if ($user == '%u') {
47124c 223     $user_field = new html_inputfield(array('name' => '_smtp_user'));
7635d2 224     $user = $user_field->show($_POST['_smtp_user']);
fa7539 225   }
T 226   if ($pass == '%p') {
47124c 227     $pass_field = new html_passwordfield(array('name' => '_smtp_pass'));
fa7539 228     $pass = $pass_field->show();
T 229   }
230   
231   echo "User: $user<br />";
232   echo "Password: $pass<br />";
233 }
27564f 234
47124c 235 $from_field = new html_inputfield(array('name' => '_from', 'id' => 'sendmailfrom'));
T 236 $to_field = new html_inputfield(array('name' => '_to', 'id' => 'sendmailto'));
fa7539 237
T 238 ?>
ad43e6 239 </p>
T 240
241 <?php
242
256361 243 if (isset($_POST['sendmail'])) {
A 244
ad43e6 245   echo '<p>Trying to send email...<br />';
256361 246
e99991 247   $from = idn_to_ascii(trim($_POST['_from']));
A 248   $to   = idn_to_ascii(trim($_POST['_to']));
2c3d81 249
e99991 250   if (preg_match('/^' . $RCI->email_pattern . '$/i', $from) &&
A 251       preg_match('/^' . $RCI->email_pattern . '$/i', $to)
252   ) {
ad43e6 253     $headers = array(
e99991 254       'From'    => $from,
A 255       'To'      => $to,
e019f2 256       'Subject' => 'Test message from Roundcube',
ad43e6 257     );
T 258
e019f2 259     $body = 'This is a test to confirm that Roundcube can send email.';
ad43e6 260     $smtp_response = array();
e99991 261
fa7539 262     // send mail using configured SMTP server
T 263     if ($RCI->getprop('smtp_server')) {
264       $CONFIG = $RCI->config;
2c3d81 265
7635d2 266       if (!empty($_POST['_smtp_user'])) {
T 267         $CONFIG['smtp_user'] = $_POST['_smtp_user'];
268       }
269       if (!empty($_POST['_smtp_pass'])) {
270         $CONFIG['smtp_pass'] = $_POST['_smtp_pass'];
271       }
272
e987db 273       $mail_object  = new Mail_mime();
fa7539 274       $send_headers = $mail_object->headers($headers);
2c3d81 275
A 276       $SMTP = new rcube_smtp();
d1dd13 277       $SMTP->connect(rcube_parse_host($RCI->getprop('smtp_server')),
A 278         $RCI->getprop('smtp_port'), $CONFIG['smtp_user'], $CONFIG['smtp_pass']);
2c3d81 279
A 280       $status = $SMTP->send_mail($headers['From'], $headers['To'],
281           ($foo = $mail_object->txtHeaders($send_headers)), $body);
282
283       $smtp_response = $SMTP->get_response();
fa7539 284     }
T 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     }
ad43e6 296
T 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   }
97d659 307   
T 308   echo '</p>';
ad43e6 309 }
T 310
311 ?>
312
313 <table>
314 <tbody>
27564f 315   <tr>
T 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>
ad43e6 323 </tbody>
T 324 </table>
325
326 <p><input type="submit" name="sendmail" value="Send test mail" /></p>
327
328
256361 329 <h3>Test IMAP config</h3>
27564f 330
T 331 <?php
332
112c54 333 $default_hosts = $RCI->get_hostlist();
T 334 if (!empty($default_hosts)) {
47124c 335   $host_field = new html_select(array('name' => '_host', 'id' => 'imaphost'));
112c54 336   $host_field->add($default_hosts);
T 337 }
338 else {
47124c 339   $host_field = new html_inputfield(array('name' => '_host', 'id' => 'imaphost'));
112c54 340 }
27564f 341
47124c 342 $user_field = new html_inputfield(array('name' => '_user', 'id' => 'imapuser'));
T 343 $pass_field = new html_passwordfield(array('name' => '_pass', 'id' => 'imappass'));
27564f 344
T 345 ?>
346
347 <table>
348 <tbody>
349   <tr>
350     <td><label for="imaphost">Server</label></td>
112c54 351     <td><?php echo $host_field->show($_POST['_host']); ?></td>
27564f 352   </tr>
T 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
370 if (isset($_POST['imaptest']) && !empty($_POST['_host']) && !empty($_POST['_user'])) {
3be904 371
27564f 372   echo '<p>Connecting to ' . Q($_POST['_host']) . '...<br />';
3be904 373
A 374   $imap_host = trim($_POST['_host']);
375   $imap_port = $RCI->getprop('default_port');
376   $a_host    = parse_url($imap_host);
377
27564f 378   if ($a_host['host']) {
T 379     $imap_host = $a_host['host'];
3be904 380     $imap_ssl  = (isset($a_host['scheme']) && in_array($a_host['scheme'], array('ssl','imaps','tls'))) ? $a_host['scheme'] : null;
A 381     if (isset($a_host['port']))
382       $imap_port = $a_host['port'];
383     else if ($imap_ssl && $imap_ssl != 'tls' && (!$imap_port || $imap_port == 143))
384       $imap_port = 993;
27564f 385   }
e99991 386
A 387   $imap_host = idn_to_ascii($imap_host);
388   $imap_user = idn_to_ascii($_POST['_user']);
389
27564f 390   $imap = new rcube_imap(null);
e99991 391   if ($imap->connect($imap_host, $imap_user, $_POST['_pass'], $imap_port, $imap_ssl)) {
27564f 392     $RCI->pass('IMAP connect', 'SORT capability: ' . ($imap->get_capability('SORT') ? 'yes' : 'no'));
T 393     $imap->close();
394   }
395   else {
396     $RCI->fail('IMAP connect', $RCI->get_error());
397   }
398 }
399
400 ?>
401
402 <p><input type="submit" name="imaptest" value="Check login" /></p>
c5042d 403
354978 404 </form>
T 405
27564f 406 <hr />
T 407
354978 408 <p class="warning">
T 409
410 After completing the installation and the final tests please <b>remove</b> the whole
8062c0 411 installer folder from the document root of the webserver or make sure that
461a30 412 <tt>enable_installer</tt> option in <tt>config.inc.php</tt> is disabled.<br />
354978 413 <br />
T 414
415 These files may expose sensitive configuration data like server passwords and encryption keys
416 to the public. Make sure you cannot access this installer from your browser.
417
418 </p>