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