thomascube
2010-04-15 2491c6240cad60e68916a79c7a0689bedc2cefd9
commit | author | age
c5042d 1 <form action="index.php?_step=3" method="post">
T 2
3 <h3>Check config files</h3>
354978 4 <?php
T 5
bba657 6 $read_main = is_readable(RCMAIL_CONFIG_DIR.'/main.inc.php');
T 7 $read_db = is_readable(RCMAIL_CONFIG_DIR.'/db.inc.php');
c5042d 8
T 9 if ($read_main && !empty($RCI->config)) {
10   $RCI->pass('main.inc.php');
11 }
12 else if ($read_main) {
13   $RCI->fail('main.inc.php', 'Syntax error');
14 }
15 else if (!$read_main) {
16   $RCI->fail('main.inc.php', 'Unable to read file. Did you create the config files?');
17 }
18 echo '<br />';
19
20 if ($read_db && !empty($RCI->config['db_table_users'])) {
21   $RCI->pass('db.inc.php');
22 }
23 else if ($read_db) {
24   $RCI->fail('db.inc.php', 'Syntax error');
25 }
26 else if (!$read_db) {
27   $RCI->fail('db.inc.php', 'Unable to read file. Did you create the config files?');
28 }
354978 29
e10712 30 if ($RCI->configured && ($messages = $RCI->check_config())) {
T 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>";
871ca9 72   
T 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   
e10712 86 }
T 87
354978 88 ?>
c5042d 89
308f41 90 <h3>Check if directories are writable</h3>
T 91 <p>RoundCube may need to write/save files into these directories</p>
92 <?php
93
94 if ($RCI->configured) {
95     $pass = false;
b77d0d 96
8ee776 97     $dirs[] = $RCI->config['temp_dir'] ? $RCI->config['temp_dir'] : 'temp';
b77d0d 98     if($RCI->config['log_driver'] != 'syslog')
8ee776 99       $dirs[] = $RCI->config['log_dir'] ? $RCI->config['log_dir'] : 'logs';
b77d0d 100
A 101     foreach ($dirs as $dir) {
8ee776 102         $dirpath = $dir[0] == '/' ? $dir : INSTALL_PATH . $dir;
308f41 103         if (is_writable(realpath($dirpath))) {
T 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 }
116 else {
117     $RCI->fail('Config', 'Could not read config files');
118 }
119
120 ?>
121
c5042d 122 <h3>Check configured database settings</h3>
T 123 <?php
124
125 $db_working = false;
308f41 126 if ($RCI->configured) {
9e8e5f 127     if (!empty($RCI->config['db_dsnw'])) {
c5042d 128
9e8e5f 129         $DB = new rcube_mdb2($RCI->config['db_dsnw'], '', false);
c5042d 130         $DB->db_connect('w');
T 131         if (!($db_error_msg = $DB->is_error())) {
132             $RCI->pass('DSN (write)');
190e97 133             echo '<br />';
c5042d 134             $db_working = true;
T 135         }
136         else {
190e97 137             $RCI->fail('DSN (write)', $db_error_msg);
34eab0 138             echo '<p class="hint">Make sure that the configured database exists and that the user has write privileges<br />';
190e97 139             echo 'DSN: ' . $RCI->config['db_dsnw'] . '</p>';
c5042d 140         }
T 141     }
142     else {
143         $RCI->fail('DSN (write)', 'not set');
144     }
145 }
146 else {
147     $RCI->fail('Config', 'Could not read config files');
148 }
149
150 // initialize db with schema found in /SQL/*
151 if ($db_working && $_POST['initdb']) {
190e97 152     if (!($success = $RCI->init_db($DB))) {
c5042d 153         $db_working = false;
190e97 154         echo '<p class="warning">Please try to inizialize the database manually as described in the INSTALL guide.
T 155           Make sure that the configured database extists and that the user as write privileges</p>';
c5042d 156     }
T 157 }
158
190e97 159 // test database
c5042d 160 if ($db_working) {
190e97 161     $db_read = $DB->query("SELECT count(*) FROM {$RCI->config['db_table_users']}");
ce16bb 162     if ($DB->db_error) {
c5042d 163         $RCI->fail('DB Schema', "Database not initialized");
T 164         echo '<p><input type="submit" name="initdb" value="Initialize database" /></p>';
871ca9 165         $db_working = false;
c5042d 166     }
2491c6 167     else if ($RCI->db_schema_check($DB, $update = !empty($_POST['updatedb']))) {
871ca9 168         $RCI->fail('DB Schema', "Database schema differs");
2491c6 169         $updatefile = INSTALL_PATH . 'SQL/' . $DB->db_provider . '.update.sql';
T 170         echo '<p class="warning">Please manually execute the SQL statements from '.$updatefile.' on your database</p>';
871ca9 171         $db_working = false;
T 172     }
c5042d 173     else {
T 174         $RCI->pass('DB Schema');
871ca9 175         echo '<br />';
c5042d 176     }
190e97 177 }
T 178
179 // more database tests
180 if ($db_working) {
181     // write test
50e5ee 182     $insert_id = md5(uniqid());
T 183     $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);
184
185     if ($db_write) {
190e97 186       $RCI->pass('DB Write');
50e5ee 187       $DB->query("DELETE FROM {$RCI->config['db_table_session']} WHERE sess_id=?", $insert_id);
190e97 188     }
T 189     else {
190       $RCI->fail('DB Write', $RCI->get_error());
191     }
871ca9 192     echo '<br />';
190e97 193     
T 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
ad43e6 213 <h3>Test SMTP settings</h3>
T 214
215 <p>
216 Server: <?php echo $RCI->getprop('smtp_server', 'PHP mail()'); ?><br />
217 Port: <?php echo $RCI->getprop('smtp_port'); ?><br />
fa7539 218
T 219 <?php
220
221 if ($RCI->getprop('smtp_server')) {
222   $user = $RCI->getprop('smtp_user', '(none)');
223   $pass = $RCI->getprop('smtp_pass', '(none)');
224   
225   if ($user == '%u') {
47124c 226     $user_field = new html_inputfield(array('name' => '_smtp_user'));
7635d2 227     $user = $user_field->show($_POST['_smtp_user']);
fa7539 228   }
T 229   if ($pass == '%p') {
47124c 230     $pass_field = new html_passwordfield(array('name' => '_smtp_pass'));
fa7539 231     $pass = $pass_field->show();
T 232   }
233   
234   echo "User: $user<br />";
235   echo "Password: $pass<br />";
236 }
27564f 237
47124c 238 $from_field = new html_inputfield(array('name' => '_from', 'id' => 'sendmailfrom'));
T 239 $to_field = new html_inputfield(array('name' => '_to', 'id' => 'sendmailto'));
fa7539 240
T 241 ?>
ad43e6 242 </p>
T 243
244 <?php
245
246 if (isset($_POST['sendmail']) && !empty($_POST['_from']) && !empty($_POST['_to'])) {
247   
248   echo '<p>Trying to send email...<br />';
249   
250   if (preg_match('/^' . $RCI->email_pattern . '$/i', trim($_POST['_from'])) &&
251       preg_match('/^' . $RCI->email_pattern . '$/i', trim($_POST['_to']))) {
2c3d81 252
ad43e6 253     $headers = array(
7635d2 254       'From'    => trim($_POST['_from']),
T 255       'To'      => trim($_POST['_to']),
ad43e6 256       'Subject' => 'Test message from RoundCube',
T 257     );
258
259     $body = 'This is a test to confirm that RoundCube can send email.';
260     $smtp_response = array();
fa7539 261     
T 262     // send mail using configured SMTP server
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();
277       $SMTP->connect();
278
279       $status = $SMTP->send_mail($headers['From'], $headers['To'],
280           ($foo = $mail_object->txtHeaders($send_headers)), $body);
281
282       $smtp_response = $SMTP->get_response();
fa7539 283     }
T 284     else {    // use mail()
285       $header_str = 'From: ' . $headers['From'];
286       
287       if (ini_get('safe_mode'))
288         $status = mail($headers['To'], $headers['Subject'], $body, $header_str);
289       else
290         $status = mail($headers['To'], $headers['Subject'], $body, $header_str, '-f'.$headers['From']);
291       
292       if (!$status)
293         $smtp_response[] = 'Mail delivery with mail() failed. Check your error logs for details';
294     }
ad43e6 295
T 296     if ($status) {
297         $RCI->pass('SMTP send');
298     }
299     else {
300         $RCI->fail('SMTP send', join('; ', $smtp_response));
301     }
302   }
303   else {
304     $RCI->fail('SMTP send', 'Invalid sender or recipient');
305   }
97d659 306   
T 307   echo '</p>';
ad43e6 308 }
T 309
310 ?>
311
312 <table>
313 <tbody>
27564f 314   <tr>
T 315     <td><label for="sendmailfrom">Sender</label></td>
316     <td><?php echo $from_field->show($_POST['_from']); ?></td>
317   </tr>
318   <tr>
319     <td><label for="sendmailto">Recipient</label></td>
320     <td><?php echo $to_field->show($_POST['_to']); ?></td>
321   </tr>
ad43e6 322 </tbody>
T 323 </table>
324
325 <p><input type="submit" name="sendmail" value="Send test mail" /></p>
326
327
27564f 328 <h3>Test IMAP configuration</h3>
T 329
330 <?php
331
112c54 332 $default_hosts = $RCI->get_hostlist();
T 333 if (!empty($default_hosts)) {
47124c 334   $host_field = new html_select(array('name' => '_host', 'id' => 'imaphost'));
112c54 335   $host_field->add($default_hosts);
T 336 }
337 else {
47124c 338   $host_field = new html_inputfield(array('name' => '_host', 'id' => 'imaphost'));
112c54 339 }
27564f 340
47124c 341 $user_field = new html_inputfield(array('name' => '_user', 'id' => 'imapuser'));
T 342 $pass_field = new html_passwordfield(array('name' => '_pass', 'id' => 'imappass'));
27564f 343
T 344 ?>
345
346 <table>
347 <tbody>
348   <tr>
349     <td><label for="imaphost">Server</label></td>
112c54 350     <td><?php echo $host_field->show($_POST['_host']); ?></td>
27564f 351   </tr>
T 352   <tr>
353     <td>Port</td>
354     <td><?php echo $RCI->getprop('default_port'); ?></td>
355   </tr>
356     <tr>
357       <td><label for="imapuser">Username</label></td>
358       <td><?php echo $user_field->show($_POST['_user']); ?></td>
359     </tr>
360     <tr>
361       <td><label for="imappass">Password</label></td>
362       <td><?php echo $pass_field->show(); ?></td>
363     </tr>
364 </tbody>
365 </table>
366
367 <?php
368
369 if (isset($_POST['imaptest']) && !empty($_POST['_host']) && !empty($_POST['_user'])) {
370   
371   echo '<p>Connecting to ' . Q($_POST['_host']) . '...<br />';
372   
373   $a_host = parse_url($_POST['_host']);
374   if ($a_host['host']) {
375     $imap_host = $a_host['host'];
376     $imap_ssl = (isset($a_host['scheme']) && in_array($a_host['scheme'], array('ssl','imaps','tls'))) ? $a_host['scheme'] : null;
377     $imap_port = isset($a_host['port']) ? $a_host['port'] : ($imap_ssl ? 993 : $CONFIG['default_port']);
378   }
379   else {
380     $imap_host = trim($_POST['_host']);
381     $imap_port = $RCI->getprop('default_port');
382   }
383   
384   $imap = new rcube_imap(null);
385   if ($imap->connect($imap_host, $_POST['_user'], $_POST['_pass'], $imap_port, $imap_ssl)) {
386     $RCI->pass('IMAP connect', 'SORT capability: ' . ($imap->get_capability('SORT') ? 'yes' : 'no'));
387     $imap->close();
388   }
389   else {
390     $RCI->fail('IMAP connect', $RCI->get_error());
391   }
392 }
393
394 ?>
395
396 <p><input type="submit" name="imaptest" value="Check login" /></p>
c5042d 397
354978 398 </form>
T 399
27564f 400 <hr />
T 401
354978 402 <p class="warning">
T 403
404 After completing the installation and the final tests please <b>remove</b> the whole
405 installer folder from the document root of the webserver.<br />
406 <br />
407
408 These files may expose sensitive configuration data like server passwords and encryption keys
409 to the public. Make sure you cannot access this installer from your browser.
410
411 </p>