source: subversion/trunk/roundcubemail/installer/test.php @ 1141

Last change on this file since 1141 was 1141, checked in by thomasb, 5 years ago

Fix database initialization and check write access on the DB; update INSTALL instructions

File size: 4.0 KB
Line 
1<form action="index.php?_step=3" method="post">
2
3<h3>Check config files</h3>
4<?php
5
6// load local config files
7$RCI->load_config();
8
9$read_main = is_readable('../config/main.inc.php');
10$read_db = is_readable('../config/db.inc.php');
11
12if ($read_main && !empty($RCI->config)) {
13  $RCI->pass('main.inc.php');
14}
15else if ($read_main) {
16  $RCI->fail('main.inc.php', 'Syntax error');
17}
18else if (!$read_main) {
19  $RCI->fail('main.inc.php', 'Unable to read file. Did you create the config files?');
20}
21echo '<br />';
22
23if ($read_db && !empty($RCI->config['db_table_users'])) {
24  $RCI->pass('db.inc.php');
25}
26else if ($read_db) {
27  $RCI->fail('db.inc.php', 'Syntax error');
28}
29else if (!$read_db) {
30  $RCI->fail('db.inc.php', 'Unable to read file. Did you create the config files?');
31}
32
33?>
34
35<h3>Check configured database settings</h3>
36<?php
37
38$db_working = false;
39if (!empty($RCI->config)) {
40    if (!empty($RCI->config['db_backend']) && !empty($RCI->config['db_dsnw'])) {
41
42        echo 'Backend: ';
43        echo 'PEAR::' . strtoupper($RCI->config['db_backend']) . '<br />';
44
45        $_class = 'rcube_' . strtolower($RCI->config['db_backend']);
46        require_once 'include/' . $_class . '.inc';
47
48        $DB = new $_class($RCI->config['db_dsnw'], '', false);
49        $DB->db_connect('w');
50        if (!($db_error_msg = $DB->is_error())) {
51            $RCI->pass('DSN (write)');
52            echo '<br />';
53            $db_working = true;
54        }
55        else {
56            $RCI->fail('DSN (write)', $db_error_msg);
57            echo '<p class="hint">Make sure that the configured database extists and that the user as write privileges<br />';
58            echo 'DSN: ' . $RCI->config['db_dsnw'] . '</p>';
59        }
60    }
61    else {
62        $RCI->fail('DSN (write)', 'not set');
63    }
64}
65else {
66    $RCI->fail('Config', 'Could not read config files');
67}
68
69// initialize db with schema found in /SQL/*
70if ($db_working && $_POST['initdb']) {
71    if (!($success = $RCI->init_db($DB))) {
72        $db_working = false;
73        echo '<p class="warning">Please try to inizialize the database manually as described in the INSTALL guide.
74          Make sure that the configured database extists and that the user as write privileges</p>';
75    }
76}
77
78// test database
79if ($db_working) {
80    $db_read = $DB->query("SELECT count(*) FROM {$RCI->config['db_table_users']}");
81    if (!$db_read) {
82        $RCI->fail('DB Schema', "Database not initialized");
83        $db_working = false;
84        echo '<p><input type="submit" name="initdb" value="Initialize database" /></p>';
85    }
86    else {
87        $RCI->pass('DB Schema');
88    }
89    echo '<br />';
90}
91
92// more database tests
93if ($db_working) {
94    // write test
95    $db_write = $DB->query("INSERT INTO {$RCI->config['db_table_cache']} (session_id, cache_key, data, user_id) VALUES (?, ?, ?, 0)", '1234567890abcdef', 'test', 'test');
96    $insert_id = $DB->insert_id($RCI->config['db_sequence_cache']);
97   
98    if ($db_write && $insert_id) {
99      $RCI->pass('DB Write');
100      $DB->query("DELETE FROM {$RCI->config['db_table_cache']} WHERE cache_id=?", $insert_id);
101    }
102    else {
103      $RCI->fail('DB Write', $RCI->get_error());
104    }
105    echo '<br />';   
106   
107    // check timezone settings
108    $tz_db = 'SELECT ' . $DB->unixtimestamp($DB->now()) . ' AS tz_db';
109    $tz_db = $DB->query($tz_db);
110    $tz_db = $DB->fetch_assoc($tz_db);
111    $tz_db = (int) $tz_db['tz_db'];
112    $tz_local = (int) time();
113    $tz_diff  = $tz_local - $tz_db;
114
115    // sometimes db and web servers are on separate hosts, so allow a 30 minutes delta
116    if (abs($tz_diff) > 1800) {
117        $RCI->fail('DB Time', "Database time differs {$td_ziff}s from PHP time");
118    }
119    else {
120        $RCI->pass('DB Time');
121    }
122}
123
124?>
125
126<p>[@todo Add tests for IMAP and SMTP settings]</p>
127
128</form>
129
130<p class="warning">
131
132After completing the installation and the final tests please <b>remove</b> the whole
133installer folder from the document root of the webserver.<br />
134<br />
135
136These files may expose sensitive configuration data like server passwords and encryption keys
137to the public. Make sure you cannot access this installer from your browser.
138
139</p>
Note: See TracBrowser for help on using the repository browser.