]> git.donarmstrong.com Git - roundcube.git/blob - installer/test.php
Imported Upstream version 0.1.1
[roundcube.git] / installer / test.php
1 <form action="index.php?_step=3" method="post">
2
3 <h3>Check config files</h3>
4 <?php
5
6 require_once 'include/rcube_html.inc';
7
8 $read_main = is_readable('../config/main.inc.php');
9 $read_db = is_readable('../config/db.inc.php');
10
11 if ($read_main && !empty($RCI->config)) {
12   $RCI->pass('main.inc.php');
13 }
14 else if ($read_main) {
15   $RCI->fail('main.inc.php', 'Syntax error');
16 }
17 else if (!$read_main) {
18   $RCI->fail('main.inc.php', 'Unable to read file. Did you create the config files?');
19 }
20 echo '<br />';
21
22 if ($read_db && !empty($RCI->config['db_table_users'])) {
23   $RCI->pass('db.inc.php');
24 }
25 else if ($read_db) {
26   $RCI->fail('db.inc.php', 'Syntax error');
27 }
28 else if (!$read_db) {
29   $RCI->fail('db.inc.php', 'Unable to read file. Did you create the config files?');
30 }
31
32 ?>
33
34 <h3>Check if directories are writable</h3>
35 <p>RoundCube may need to write/save files into these directories</p>
36 <?php
37
38 if ($RCI->configured) {
39     $pass = false;
40     foreach (array($RCI->config['temp_dir'],$RCI->config['log_dir']) as $dir) {
41         $dirpath = $dir{0} == '/' ? $dir : $docroot . '/' . $dir;
42         if (is_writable(realpath($dirpath))) {
43             $RCI->pass($dir);
44             $pass = true;
45         }
46         else {
47             $RCI->fail($dir, 'not writeable for the webserver');
48         }
49         echo '<br />';
50     }
51     
52     if (!$pass)
53         echo '<p class="hint">Use <tt>chmod</tt> or <tt>chown</tt> to grant write privileges to the webserver</p>';
54 }
55 else {
56     $RCI->fail('Config', 'Could not read config files');
57 }
58
59 ?>
60
61 <h3>Check configured database settings</h3>
62 <?php
63
64 $db_working = false;
65 if ($RCI->configured) {
66     if (!empty($RCI->config['db_backend']) && !empty($RCI->config['db_dsnw'])) {
67
68         echo 'Backend: ';
69         echo 'PEAR::' . strtoupper($RCI->config['db_backend']) . '<br />';
70
71         $_class = 'rcube_' . strtolower($RCI->config['db_backend']);
72         require_once 'include/' . $_class . '.inc';
73
74         $DB = new $_class($RCI->config['db_dsnw'], '', false);
75         $DB->db_connect('w');
76         if (!($db_error_msg = $DB->is_error())) {
77             $RCI->pass('DSN (write)');
78             echo '<br />';
79             $db_working = true;
80         }
81         else {
82             $RCI->fail('DSN (write)', $db_error_msg);
83             echo '<p class="hint">Make sure that the configured database exists and that the user has write privileges<br />';
84             echo 'DSN: ' . $RCI->config['db_dsnw'] . '</p>';
85             if ($RCI->config['db_backend'] == 'mdb2')
86               echo '<p class="hint">There are known problems with MDB2 running on PHP 4. Try setting <tt>db_backend</tt> to \'db\' instead</p>';
87         }
88     }
89     else {
90         $RCI->fail('DSN (write)', 'not set');
91     }
92 }
93 else {
94     $RCI->fail('Config', 'Could not read config files');
95 }
96
97 // initialize db with schema found in /SQL/*
98 if ($db_working && $_POST['initdb']) {
99     if (!($success = $RCI->init_db($DB))) {
100         $db_working = false;
101         echo '<p class="warning">Please try to inizialize the database manually as described in the INSTALL guide.
102           Make sure that the configured database extists and that the user as write privileges</p>';
103     }
104 }
105
106 // test database
107 if ($db_working) {
108     $db_read = $DB->query("SELECT count(*) FROM {$RCI->config['db_table_users']}");
109     if (!$db_read) {
110         $RCI->fail('DB Schema', "Database not initialized");
111         $db_working = false;
112         echo '<p><input type="submit" name="initdb" value="Initialize database" /></p>';
113     }
114     else {
115         $RCI->pass('DB Schema');
116     }
117     echo '<br />';
118 }
119
120 // more database tests
121 if ($db_working) {
122     // write test
123     $insert_id = md5(uniqid());
124     $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);
125
126     if ($db_write) {
127       $RCI->pass('DB Write');
128       $DB->query("DELETE FROM {$RCI->config['db_table_session']} WHERE sess_id=?", $insert_id);
129     }
130     else {
131       $RCI->fail('DB Write', $RCI->get_error());
132     }
133     echo '<br />';    
134     
135     // check timezone settings
136     $tz_db = 'SELECT ' . $DB->unixtimestamp($DB->now()) . ' AS tz_db';
137     $tz_db = $DB->query($tz_db);
138     $tz_db = $DB->fetch_assoc($tz_db);
139     $tz_db = (int) $tz_db['tz_db'];
140     $tz_local = (int) time();
141     $tz_diff  = $tz_local - $tz_db;
142
143     // sometimes db and web servers are on separate hosts, so allow a 30 minutes delta
144     if (abs($tz_diff) > 1800) {
145         $RCI->fail('DB Time', "Database time differs {$td_ziff}s from PHP time");
146     }
147     else {
148         $RCI->pass('DB Time');
149     }
150 }
151
152 ?>
153
154 <h3>Test SMTP settings</h3>
155
156 <p>
157 Server: <?php echo $RCI->getprop('smtp_server', 'PHP mail()'); ?><br />
158 Port: <?php echo $RCI->getprop('smtp_port'); ?><br />
159
160 <?php
161
162 if ($RCI->getprop('smtp_server')) {
163   $user = $RCI->getprop('smtp_user', '(none)');
164   $pass = $RCI->getprop('smtp_pass', '(none)');
165   
166   if ($user == '%u') {
167     $user_field = new textfield(array('name' => '_smtp_user'));
168     $user = $user_field->show($_POST['_smtp_user']);
169   }
170   if ($pass == '%p') {
171     $pass_field = new passwordfield(array('name' => '_smtp_pass'));
172     $pass = $pass_field->show();
173   }
174   
175   echo "User: $user<br />";
176   echo "Password: $pass<br />";
177 }
178
179 $from_field = new textfield(array('name' => '_from', 'id' => 'sendmailfrom'));
180 $to_field = new textfield(array('name' => '_to', 'id' => 'sendmailto'));
181
182 ?>
183 </p>
184
185 <?php
186
187 if (isset($_POST['sendmail']) && !empty($_POST['_from']) && !empty($_POST['_to'])) {
188   
189   require_once 'lib/rc_mail_mime.inc';
190   require_once 'include/rcube_smtp.inc';
191   
192   echo '<p>Trying to send email...<br />';
193   
194   if (preg_match('/^' . $RCI->email_pattern . '$/i', trim($_POST['_from'])) &&
195       preg_match('/^' . $RCI->email_pattern . '$/i', trim($_POST['_to']))) {
196   
197     $headers = array(
198       'From'    => trim($_POST['_from']),
199       'To'      => trim($_POST['_to']),
200       'Subject' => 'Test message from RoundCube',
201     );
202
203     $body = 'This is a test to confirm that RoundCube can send email.';
204     $smtp_response = array();
205     
206     // send mail using configured SMTP server
207     if ($RCI->getprop('smtp_server')) {
208       $CONFIG = $RCI->config;
209       
210       if (!empty($_POST['_smtp_user'])) {
211         $CONFIG['smtp_user'] = $_POST['_smtp_user'];
212       }
213       if (!empty($_POST['_smtp_pass'])) {
214         $CONFIG['smtp_pass'] = $_POST['_smtp_pass'];
215       }
216
217       $mail_object  = new rc_mail_mime();
218       $send_headers = $mail_object->headers($headers);
219       
220       $status = smtp_mail($headers['From'], $headers['To'],
221           ($foo = $mail_object->txtHeaders($send_headers)),
222           $body, $smtp_response);
223     }
224     else {    // use mail()
225       $header_str = 'From: ' . $headers['From'];
226       
227       if (ini_get('safe_mode'))
228         $status = mail($headers['To'], $headers['Subject'], $body, $header_str);
229       else
230         $status = mail($headers['To'], $headers['Subject'], $body, $header_str, '-f'.$headers['From']);
231       
232       if (!$status)
233         $smtp_response[] = 'Mail delivery with mail() failed. Check your error logs for details';
234     }
235
236     if ($status) {
237         $RCI->pass('SMTP send');
238     }
239     else {
240         $RCI->fail('SMTP send', join('; ', $smtp_response));
241     }
242   }
243   else {
244     $RCI->fail('SMTP send', 'Invalid sender or recipient');
245   }
246 }
247
248 echo '</p>';
249
250 ?>
251
252 <table>
253 <tbody>
254   <tr>
255     <td><label for="sendmailfrom">Sender</label></td>
256     <td><?php echo $from_field->show($_POST['_from']); ?></td>
257   </tr>
258   <tr>
259     <td><label for="sendmailto">Recipient</label></td>
260     <td><?php echo $to_field->show($_POST['_to']); ?></td>
261   </tr>
262 </tbody>
263 </table>
264
265 <p><input type="submit" name="sendmail" value="Send test mail" /></p>
266
267
268 <h3>Test IMAP configuration</h3>
269
270 <?php
271
272 $default_hosts = $RCI->get_hostlist();
273 if (!empty($default_hosts)) {
274   $host_field = new select(array('name' => '_host', 'id' => 'imaphost'));
275   $host_field->add($default_hosts);
276 }
277 else {
278   $host_field = new textfield(array('name' => '_host', 'id' => 'imaphost'));
279 }
280
281 $user_field = new textfield(array('name' => '_user', 'id' => 'imapuser'));
282 $pass_field = new passwordfield(array('name' => '_pass', 'id' => 'imappass'));
283
284 ?>
285
286 <table>
287 <tbody>
288   <tr>
289     <td><label for="imaphost">Server</label></td>
290     <td><?php echo $host_field->show($_POST['_host']); ?></td>
291   </tr>
292   <tr>
293     <td>Port</td>
294     <td><?php echo $RCI->getprop('default_port'); ?></td>
295   </tr>
296     <tr>
297       <td><label for="imapuser">Username</label></td>
298       <td><?php echo $user_field->show($_POST['_user']); ?></td>
299     </tr>
300     <tr>
301       <td><label for="imappass">Password</label></td>
302       <td><?php echo $pass_field->show(); ?></td>
303     </tr>
304 </tbody>
305 </table>
306
307 <?php
308
309 if (isset($_POST['imaptest']) && !empty($_POST['_host']) && !empty($_POST['_user'])) {
310   
311   require_once 'include/rcube_imap.inc';
312   
313   echo '<p>Connecting to ' . Q($_POST['_host']) . '...<br />';
314   
315   $a_host = parse_url($_POST['_host']);
316   if ($a_host['host']) {
317     $imap_host = $a_host['host'];
318     $imap_ssl = (isset($a_host['scheme']) && in_array($a_host['scheme'], array('ssl','imaps','tls'))) ? $a_host['scheme'] : null;
319     $imap_port = isset($a_host['port']) ? $a_host['port'] : ($imap_ssl ? 993 : $CONFIG['default_port']);
320   }
321   else {
322     $imap_host = trim($_POST['_host']);
323     $imap_port = $RCI->getprop('default_port');
324   }
325   
326   $imap = new rcube_imap(null);
327   if ($imap->connect($imap_host, $_POST['_user'], $_POST['_pass'], $imap_port, $imap_ssl)) {
328     $RCI->pass('IMAP connect', 'SORT capability: ' . ($imap->get_capability('SORT') ? 'yes' : 'no'));
329     $imap->close();
330   }
331   else {
332     $RCI->fail('IMAP connect', $RCI->get_error());
333   }
334 }
335
336 ?>
337
338 <p><input type="submit" name="imaptest" value="Check login" /></p>
339
340 </form>
341
342 <hr />
343
344 <p class="warning">
345
346 After completing the installation and the final tests please <b>remove</b> the whole
347 installer folder from the document root of the webserver.<br />
348 <br />
349
350 These files may expose sensitive configuration data like server passwords and encryption keys
351 to the public. Make sure you cannot access this installer from your browser.
352
353 </p>