comparison installer/test.php @ 0:4681f974d28b

vanilla 1.3.3 distro, I hope
author Charlie Root
date Thu, 04 Jan 2018 15:52:31 -0500
parents
children bf99236cc5cd
comparison
equal deleted inserted replaced
-1:000000000000 0:4681f974d28b
1 <?php
2
3 if (!class_exists('rcmail_install', false) || !is_object($RCI)) {
4 die("Not allowed! Please open installer/index.php instead.");
5 }
6
7 ?>
8 <form action="index.php?_step=3" method="post">
9
10 <h3>Check config file</h3>
11 <?php
12
13 if ($read_config = is_readable(RCUBE_CONFIG_DIR . 'defaults.inc.php')) {
14 $config = $RCI->load_config_file(RCUBE_CONFIG_DIR . 'defaults.inc.php');
15 if (!empty($config)) {
16 $RCI->pass('defaults.inc.php');
17 }
18 else {
19 $RCI->fail('defaults.inc.php', 'Syntax error');
20 }
21 }
22 else {
23 $RCI->fail('defaults.inc.php', 'Unable to read default config file?');
24 }
25 echo '<br />';
26
27 if ($read_config = is_readable(RCUBE_CONFIG_DIR . 'config.inc.php')) {
28 $config = $RCI->load_config_file(RCUBE_CONFIG_DIR . 'config.inc.php');
29 if (!empty($config)) {
30 $RCI->pass('config.inc.php');
31 }
32 else {
33 $RCI->fail('config.inc.php', 'Syntax error');
34 }
35 }
36 else {
37 $RCI->fail('config.inc.php', 'Unable to read file. Did you create the config file?');
38 }
39 echo '<br />';
40
41
42 if ($RCI->configured && ($messages = $RCI->check_config())) {
43 if (is_array($messages['replaced'])) {
44 echo '<h3 class="warning">Replaced config options</h3>';
45 echo '<p class="hint">The following config options have been replaced or renamed. ';
46 echo 'Please update them accordingly in your config files.</p>';
47
48 echo '<ul class="configwarings">';
49 foreach ($messages['replaced'] as $msg) {
50 echo html::tag('li', null, html::span('propname', $msg['prop']) .
51 ' was replaced by ' . html::span('propname', $msg['replacement']));
52 }
53 echo '</ul>';
54 }
55
56 if (is_array($messages['obsolete'])) {
57 echo '<h3>Obsolete config options</h3>';
58 echo '<p class="hint">You still have some obsolete or inexistent properties set. This isn\'t a problem but should be noticed.</p>';
59
60 echo '<ul class="configwarings">';
61 foreach ($messages['obsolete'] as $msg) {
62 echo html::tag('li', null, html::span('propname', $msg['prop']) . ($msg['name'] ? ':&nbsp;' . $msg['name'] : ''));
63 }
64 echo '</ul>';
65 }
66
67 echo '<p class="suggestion">OK, lazy people can download the updated config file here: ';
68 echo html::a(array('href' => './?_mergeconfig=1'), 'config.inc.php') . ' &nbsp;';
69 echo "</p>";
70
71 if (is_array($messages['dependencies'])) {
72 echo '<h3 class="warning">Dependency check failed</h3>';
73 echo '<p class="hint">Some of your configuration settings require other options to be configured or additional PHP modules to be installed</p>';
74
75 echo '<ul class="configwarings">';
76 foreach ($messages['dependencies'] as $msg) {
77 echo html::tag('li', null, html::span('propname', $msg['prop']) . ': ' . $msg['explain']);
78 }
79 echo '</ul>';
80 }
81 }
82
83 ?>
84
85 <h3>Check if directories are writable</h3>
86 <p>Roundcube may need to write/save files into these directories</p>
87 <?php
88
89 $dirs[] = $RCI->config['temp_dir'] ? $RCI->config['temp_dir'] : 'temp';
90 if ($RCI->config['log_driver'] != 'syslog')
91 $dirs[] = $RCI->config['log_dir'] ? $RCI->config['log_dir'] : 'logs';
92
93 foreach ($dirs as $dir) {
94 $dirpath = rcube_utils::is_absolute_path($dir) ? $dir : INSTALL_PATH . $dir;
95 if (is_writable(realpath($dirpath))) {
96 $RCI->pass($dir);
97 $pass = true;
98 }
99 else {
100 $RCI->fail($dir, 'not writeable for the webserver');
101 }
102 echo '<br />';
103 }
104
105 if (!$pass) {
106 echo '<p class="hint">Use <tt>chmod</tt> or <tt>chown</tt> to grant write privileges to the webserver</p>';
107 }
108
109 ?>
110
111 <h3>Check DB config</h3>
112 <?php
113
114 $db_working = false;
115 if ($RCI->configured) {
116 if (!empty($RCI->config['db_dsnw'])) {
117 $DB = rcube_db::factory($RCI->config['db_dsnw'], '', false);
118 $DB->set_debug((bool)$RCI->config['sql_debug']);
119 $DB->db_connect('w');
120
121 if (!($db_error_msg = $DB->is_error())) {
122 $RCI->pass('DSN (write)');
123 echo '<br />';
124 $db_working = true;
125 }
126 else {
127 $RCI->fail('DSN (write)', $db_error_msg);
128 echo '<p class="hint">Make sure that the configured database exists and that the user has write privileges<br />';
129 echo 'DSN: ' . $RCI->config['db_dsnw'] . '</p>';
130 }
131 }
132 else {
133 $RCI->fail('DSN (write)', 'not set');
134 }
135 }
136 else {
137 $RCI->fail('DSN (write)', 'Could not read config file');
138 }
139
140 // initialize db with schema found in /SQL/*
141 if ($db_working && $_POST['initdb']) {
142 if (!($success = $RCI->init_db($DB))) {
143 $db_working = false;
144 echo '<p class="warning">Please try to inizialize the database manually as described in the INSTALL guide.
145 Make sure that the configured database extists and that the user as write privileges</p>';
146 }
147 }
148
149 else if ($db_working && $_POST['updatedb']) {
150 if (!($success = $RCI->update_db($_POST['version']))) {
151 echo '<p class="warning">Database schema update failed.</p>';
152 }
153 }
154
155 // test database
156 if ($db_working) {
157 $db_read = $DB->query("SELECT count(*) FROM " . $DB->quote_identifier($RCI->config['db_prefix'] . 'users'));
158 if ($DB->is_error()) {
159 $RCI->fail('DB Schema', "Database not initialized");
160 echo '<p><input type="submit" name="initdb" value="Initialize database" /></p>';
161 $db_working = false;
162 }
163 else if ($err = $RCI->db_schema_check($DB, $update = !empty($_POST['updatedb']))) {
164 $RCI->fail('DB Schema', "Database schema differs");
165 echo '<ul style="margin:0"><li>' . join("</li>\n<li>", $err) . "</li></ul>";
166 $select = $RCI->versions_select(array('name' => 'version'));
167 $select->add('0.9 or newer', '');
168 echo '<p class="suggestion">You should run the update queries to get the schema fixed.<br/><br/>Version to update from: ' . $select->show() . '&nbsp;<input type="submit" name="updatedb" value="Update" /></p>';
169 $db_working = false;
170 }
171 else {
172 $RCI->pass('DB Schema');
173 echo '<br />';
174 }
175 }
176
177 // more database tests
178 if ($db_working) {
179 // write test
180 $insert_id = md5(uniqid());
181 $db_write = $DB->query("INSERT INTO " . $DB->quote_identifier($RCI->config['db_prefix'] . 'session')
182 . " (`sess_id`, `created`, `ip`, `vars`) VALUES (?, ".$DB->now().", '127.0.0.1', 'foo')", $insert_id);
183
184 if ($db_write) {
185 $RCI->pass('DB Write');
186 $DB->query("DELETE FROM " . $DB->quote_identifier($RCI->config['db_prefix'] . 'session')
187 . " WHERE `sess_id` = ?", $insert_id);
188 }
189 else {
190 $RCI->fail('DB Write', $RCI->get_error());
191 }
192 echo '<br />';
193
194 // check timezone settings
195 $tz_db = 'SELECT ' . $DB->unixtimestamp($DB->now()) . ' AS tz_db';
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");
205 }
206 else {
207 $RCI->pass('DB Time');
208 }
209 }
210
211 ?>
212
213 <h3>Test filetype detection</h3>
214
215 <?php
216
217 if ($errors = $RCI->check_mime_detection()) {
218 $RCI->fail('Fileinfo/mime_content_type configuration');
219 if (!empty($RCI->config['mime_magic'])) {
220 echo '<p class="hint">Try setting the <tt>mime_magic</tt> config option to <tt>null</tt>.</p>';
221 }
222 else {
223 echo '<p class="hint">Check the <a href="http://www.php.net/manual/en/function.finfo-open.php">Fileinfo functions</a> of your PHP installation.<br/>';
224 echo 'The path to the magic.mime file can be set using the <tt>mime_magic</tt> config option in Roundcube.</p>';
225 }
226 }
227 else {
228 $RCI->pass('Fileinfo/mime_content_type configuration');
229 echo "<br/>";
230 }
231
232
233 if ($errors = $RCI->check_mime_extensions()) {
234 $RCI->fail('Mimetype to file extension mapping');
235 echo '<p class="hint">Please set a valid path to your webserver\'s mime.types file to the <tt>mime_types</tt> config option.<br/>';
236 echo 'If you can\'t find such a file, download it from <a href="http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types">svn.apache.org</a>.</p>';
237 }
238 else {
239 $RCI->pass('Mimetype to file extension mapping');
240 echo "<br/>";
241 }
242
243 ?>
244
245
246 <h3>Test SMTP config</h3>
247
248 <p>
249 Server: <?php echo rcube_parse_host($RCI->getprop('smtp_server', 'PHP mail()')); ?><br />
250 Port: <?php echo $RCI->getprop('smtp_port'); ?><br />
251
252 <?php
253
254 if ($RCI->getprop('smtp_server')) {
255 $user = $RCI->getprop('smtp_user', '(none)');
256 $pass = $RCI->getprop('smtp_pass', '(none)');
257
258 if ($user == '%u') {
259 $user_field = new html_inputfield(array('name' => '_smtp_user'));
260 $user = $user_field->show($_POST['_smtp_user']);
261 }
262 if ($pass == '%p') {
263 $pass_field = new html_passwordfield(array('name' => '_smtp_pass'));
264 $pass = $pass_field->show();
265 }
266
267 echo "User: $user<br />";
268 echo "Password: $pass<br />";
269 }
270
271 $from_field = new html_inputfield(array('name' => '_from', 'id' => 'sendmailfrom'));
272 $to_field = new html_inputfield(array('name' => '_to', 'id' => 'sendmailto'));
273
274 ?>
275 </p>
276
277 <?php
278
279 if (isset($_POST['sendmail'])) {
280
281 echo '<p>Trying to send email...<br />';
282
283 $from = idn_to_ascii(trim($_POST['_from']));
284 $to = idn_to_ascii(trim($_POST['_to']));
285
286 if (preg_match('/^' . $RCI->email_pattern . '$/i', $from) &&
287 preg_match('/^' . $RCI->email_pattern . '$/i', $to)
288 ) {
289 $headers = array(
290 'From' => $from,
291 'To' => $to,
292 'Subject' => 'Test message from Roundcube',
293 );
294
295 $body = 'This is a test to confirm that Roundcube can send email.';
296 $smtp_response = array();
297
298 // send mail using configured SMTP server
299 if ($RCI->getprop('smtp_server')) {
300 $CONFIG = $RCI->config;
301
302 if (!empty($_POST['_smtp_user'])) {
303 $CONFIG['smtp_user'] = $_POST['_smtp_user'];
304 }
305 if (!empty($_POST['_smtp_pass'])) {
306 $CONFIG['smtp_pass'] = $_POST['_smtp_pass'];
307 }
308
309 $mail_object = new Mail_mime();
310 $send_headers = $mail_object->headers($headers);
311
312 $SMTP = new rcube_smtp();
313 $SMTP->connect(rcube_parse_host($RCI->getprop('smtp_server')),
314 $RCI->getprop('smtp_port'), $CONFIG['smtp_user'], $CONFIG['smtp_pass']);
315
316 $status = $SMTP->send_mail($headers['From'], $headers['To'],
317 ($foo = $mail_object->txtHeaders($send_headers)), $body);
318
319 $smtp_response = $SMTP->get_response();
320 }
321 else { // use mail()
322 $header_str = 'From: ' . $headers['From'];
323
324 if (ini_get('safe_mode'))
325 $status = mail($headers['To'], $headers['Subject'], $body, $header_str);
326 else
327 $status = mail($headers['To'], $headers['Subject'], $body, $header_str, '-f'.$headers['From']);
328
329 if (!$status)
330 $smtp_response[] = 'Mail delivery with mail() failed. Check your error logs for details';
331 }
332
333 if ($status) {
334 $RCI->pass('SMTP send');
335 }
336 else {
337 $RCI->fail('SMTP send', join('; ', $smtp_response));
338 }
339 }
340 else {
341 $RCI->fail('SMTP send', 'Invalid sender or recipient');
342 }
343
344 echo '</p>';
345 }
346
347 ?>
348
349 <table>
350 <tbody>
351 <tr>
352 <td><label for="sendmailfrom">Sender</label></td>
353 <td><?php echo $from_field->show($_POST['_from']); ?></td>
354 </tr>
355 <tr>
356 <td><label for="sendmailto">Recipient</label></td>
357 <td><?php echo $to_field->show($_POST['_to']); ?></td>
358 </tr>
359 </tbody>
360 </table>
361
362 <p><input type="submit" name="sendmail" value="Send test mail" /></p>
363
364
365 <h3>Test IMAP config</h3>
366
367 <?php
368
369 $default_hosts = $RCI->get_hostlist();
370 if (!empty($default_hosts)) {
371 $host_field = new html_select(array('name' => '_host', 'id' => 'imaphost'));
372 $host_field->add($default_hosts);
373 }
374 else {
375 $host_field = new html_inputfield(array('name' => '_host', 'id' => 'imaphost'));
376 }
377
378 $user_field = new html_inputfield(array('name' => '_user', 'id' => 'imapuser'));
379 $pass_field = new html_passwordfield(array('name' => '_pass', 'id' => 'imappass'));
380
381 ?>
382
383 <table>
384 <tbody>
385 <tr>
386 <td><label for="imaphost">Server</label></td>
387 <td><?php echo $host_field->show($_POST['_host']); ?></td>
388 </tr>
389 <tr>
390 <td>Port</td>
391 <td><?php echo $RCI->getprop('default_port'); ?></td>
392 </tr>
393 <tr>
394 <td><label for="imapuser">Username</label></td>
395 <td><?php echo $user_field->show($_POST['_user']); ?></td>
396 </tr>
397 <tr>
398 <td><label for="imappass">Password</label></td>
399 <td><?php echo $pass_field->show(); ?></td>
400 </tr>
401 </tbody>
402 </table>
403
404 <?php
405
406 if (isset($_POST['imaptest']) && !empty($_POST['_host']) && !empty($_POST['_user'])) {
407
408 echo '<p>Connecting to ' . Q($_POST['_host']) . '...<br />';
409
410 $imap_host = trim($_POST['_host']);
411 $imap_port = $RCI->getprop('default_port');
412 $a_host = parse_url($imap_host);
413
414 if ($a_host['host']) {
415 $imap_host = $a_host['host'];
416 $imap_ssl = (isset($a_host['scheme']) && in_array($a_host['scheme'], array('ssl','imaps','tls'))) ? $a_host['scheme'] : null;
417 if (isset($a_host['port']))
418 $imap_port = $a_host['port'];
419 else if ($imap_ssl && $imap_ssl != 'tls' && (!$imap_port || $imap_port == 143))
420 $imap_port = 993;
421 }
422
423 $imap_host = idn_to_ascii($imap_host);
424 $imap_user = idn_to_ascii($_POST['_user']);
425
426 $imap = new rcube_imap(null);
427 $imap->set_options(array(
428 'auth_type' => $RCI->getprop('imap_auth_type'),
429 'debug' => $RCI->getprop('imap_debug'),
430 'socket_options' => $RCI->getprop('imap_conn_options'),
431 ));
432
433 if ($imap->connect($imap_host, $imap_user, $_POST['_pass'], $imap_port, $imap_ssl)) {
434 $RCI->pass('IMAP connect', 'SORT capability: ' . ($imap->get_capability('SORT') ? 'yes' : 'no'));
435 $imap->close();
436 }
437 else {
438 $RCI->fail('IMAP connect', $RCI->get_error());
439 }
440 }
441
442 ?>
443
444 <p><input type="submit" name="imaptest" value="Check login" /></p>
445
446 </form>
447
448 <hr />
449
450 <p class="warning">
451
452 After completing the installation and the final tests please <b>remove</b> the whole
453 installer folder from the document root of the webserver or make sure that
454 <tt>enable_installer</tt> option in <tt>config.inc.php</tt> is disabled.<br />
455 <br />
456
457 These files may expose sensitive configuration data like server passwords and encryption keys
458 to the public. Make sure you cannot access this installer from your browser.
459
460 </p>