alecpl
2008-09-29 bf2f39ea6d2b49c7495a43cca19ab18f27f8292e
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
T 30 ?>
c5042d 31
308f41 32 <h3>Check if directories are writable</h3>
T 33 <p>RoundCube may need to write/save files into these directories</p>
34 <?php
35
36 if ($RCI->configured) {
37     $pass = false;
b77d0d 38
A 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) {
47124c 44         $dirpath = $dir{0} == '/' ? $dir : INSTALL_PATH . $dir;
308f41 45         if (is_writable(realpath($dirpath))) {
T 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 }
58 else {
59     $RCI->fail('Config', 'Could not read config files');
60 }
61
62 ?>
63
c5042d 64 <h3>Check configured database settings</h3>
T 65 <?php
66
67 $db_working = false;
308f41 68 if ($RCI->configured) {
9e8e5f 69     if (!empty($RCI->config['db_dsnw'])) {
c5042d 70
9e8e5f 71         $DB = new rcube_mdb2($RCI->config['db_dsnw'], '', false);
c5042d 72         $DB->db_connect('w');
T 73         if (!($db_error_msg = $DB->is_error())) {
74             $RCI->pass('DSN (write)');
190e97 75             echo '<br />';
c5042d 76             $db_working = true;
T 77         }
78         else {
190e97 79             $RCI->fail('DSN (write)', $db_error_msg);
34eab0 80             echo '<p class="hint">Make sure that the configured database exists and that the user has write privileges<br />';
190e97 81             echo 'DSN: ' . $RCI->config['db_dsnw'] . '</p>';
c5042d 82         }
T 83     }
84     else {
85         $RCI->fail('DSN (write)', 'not set');
86     }
87 }
88 else {
89     $RCI->fail('Config', 'Could not read config files');
90 }
91
92 // initialize db with schema found in /SQL/*
93 if ($db_working && $_POST['initdb']) {
190e97 94     if (!($success = $RCI->init_db($DB))) {
c5042d 95         $db_working = false;
190e97 96         echo '<p class="warning">Please try to inizialize the database manually as described in the INSTALL guide.
T 97           Make sure that the configured database extists and that the user as write privileges</p>';
c5042d 98     }
T 99 }
100
190e97 101 // test database
c5042d 102 if ($db_working) {
190e97 103     $db_read = $DB->query("SELECT count(*) FROM {$RCI->config['db_table_users']}");
T 104     if (!$db_read) {
c5042d 105         $RCI->fail('DB Schema', "Database not initialized");
190e97 106         $db_working = false;
c5042d 107         echo '<p><input type="submit" name="initdb" value="Initialize database" /></p>';
T 108     }
109     else {
110         $RCI->pass('DB Schema');
111     }
112     echo '<br />';
190e97 113 }
T 114
115 // more database tests
116 if ($db_working) {
117     // write test
50e5ee 118     $insert_id = md5(uniqid());
T 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) {
190e97 122       $RCI->pass('DB Write');
50e5ee 123       $DB->query("DELETE FROM {$RCI->config['db_table_session']} WHERE sess_id=?", $insert_id);
190e97 124     }
T 125     else {
126       $RCI->fail('DB Write', $RCI->get_error());
127     }
128     echo '<br />';    
129     
130     // check timezone settings
c5042d 131     $tz_db = 'SELECT ' . $DB->unixtimestamp($DB->now()) . ' AS tz_db';
T 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");
190e97 141     }
T 142     else {
c5042d 143         $RCI->pass('DB Time');
T 144     }
145 }
146
147 ?>
148
ad43e6 149 <h3>Test SMTP settings</h3>
T 150
151 <p>
152 Server: <?php echo $RCI->getprop('smtp_server', 'PHP mail()'); ?><br />
153 Port: <?php echo $RCI->getprop('smtp_port'); ?><br />
fa7539 154
T 155 <?php
156
157 if ($RCI->getprop('smtp_server')) {
158   $user = $RCI->getprop('smtp_user', '(none)');
159   $pass = $RCI->getprop('smtp_pass', '(none)');
160   
161   if ($user == '%u') {
47124c 162     $user_field = new html_inputfield(array('name' => '_smtp_user'));
7635d2 163     $user = $user_field->show($_POST['_smtp_user']);
fa7539 164   }
T 165   if ($pass == '%p') {
47124c 166     $pass_field = new html_passwordfield(array('name' => '_smtp_pass'));
fa7539 167     $pass = $pass_field->show();
T 168   }
169   
170   echo "User: $user<br />";
171   echo "Password: $pass<br />";
172 }
27564f 173
47124c 174 $from_field = new html_inputfield(array('name' => '_from', 'id' => 'sendmailfrom'));
T 175 $to_field = new html_inputfield(array('name' => '_to', 'id' => 'sendmailto'));
fa7539 176
T 177 ?>
ad43e6 178 </p>
T 179
180 <?php
181
182 if (isset($_POST['sendmail']) && !empty($_POST['_from']) && !empty($_POST['_to'])) {
183   
47124c 184   require_once 'rcube_smtp.inc';
ad43e6 185   
T 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(
7635d2 192       'From'    => trim($_POST['_from']),
T 193       'To'      => trim($_POST['_to']),
ad43e6 194       'Subject' => 'Test message from RoundCube',
T 195     );
196
197     $body = 'This is a test to confirm that RoundCube can send email.';
198     $smtp_response = array();
fa7539 199     
T 200     // send mail using configured SMTP server
201     if ($RCI->getprop('smtp_server')) {
202       $CONFIG = $RCI->config;
203       
7635d2 204       if (!empty($_POST['_smtp_user'])) {
T 205         $CONFIG['smtp_user'] = $_POST['_smtp_user'];
206       }
207       if (!empty($_POST['_smtp_pass'])) {
208         $CONFIG['smtp_pass'] = $_POST['_smtp_pass'];
209       }
210
47124c 211       $mail_object  = new rcube_mail_mime();
fa7539 212       $send_headers = $mail_object->headers($headers);
T 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     }
ad43e6 229
T 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
242 echo '</p>';
243
244 ?>
245
246 <table>
247 <tbody>
27564f 248   <tr>
T 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>
ad43e6 256 </tbody>
T 257 </table>
258
259 <p><input type="submit" name="sendmail" value="Send test mail" /></p>
260
261
27564f 262 <h3>Test IMAP configuration</h3>
T 263
264 <?php
265
112c54 266 $default_hosts = $RCI->get_hostlist();
T 267 if (!empty($default_hosts)) {
47124c 268   $host_field = new html_select(array('name' => '_host', 'id' => 'imaphost'));
112c54 269   $host_field->add($default_hosts);
T 270 }
271 else {
47124c 272   $host_field = new html_inputfield(array('name' => '_host', 'id' => 'imaphost'));
112c54 273 }
27564f 274
47124c 275 $user_field = new html_inputfield(array('name' => '_user', 'id' => 'imapuser'));
T 276 $pass_field = new html_passwordfield(array('name' => '_pass', 'id' => 'imappass'));
27564f 277
T 278 ?>
279
280 <table>
281 <tbody>
282   <tr>
283     <td><label for="imaphost">Server</label></td>
112c54 284     <td><?php echo $host_field->show($_POST['_host']); ?></td>
27564f 285   </tr>
T 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
303 if (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>
c5042d 331
354978 332 </form>
T 333
27564f 334 <hr />
T 335
354978 336 <p class="warning">
T 337
338 After completing the installation and the final tests please <b>remove</b> the whole
339 installer folder from the document root of the webserver.<br />
340 <br />
341
342 These files may expose sensitive configuration data like server passwords and encryption keys
343 to the public. Make sure you cannot access this installer from your browser.
344
345 </p>