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