source: github/installer/test.php @ 97d6590

HEADcourier-fixdev-browser-capabilitiespdorelease-0.6release-0.7release-0.8
Last change on this file since 97d6590 was 97d6590, checked in by thomascube <thomas@…>, 5 years ago

Validate

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