| 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 | |
|---|
| 12 | if ($read_main && !empty($RCI->config)) { |
|---|
| 13 | $RCI->pass('main.inc.php'); |
|---|
| 14 | } |
|---|
| 15 | else if ($read_main) { |
|---|
| 16 | $RCI->fail('main.inc.php', 'Syntax error'); |
|---|
| 17 | } |
|---|
| 18 | else if (!$read_main) { |
|---|
| 19 | $RCI->fail('main.inc.php', 'Unable to read file. Did you create the config files?'); |
|---|
| 20 | } |
|---|
| 21 | echo '<br />'; |
|---|
| 22 | |
|---|
| 23 | if ($read_db && !empty($RCI->config['db_table_users'])) { |
|---|
| 24 | $RCI->pass('db.inc.php'); |
|---|
| 25 | } |
|---|
| 26 | else if ($read_db) { |
|---|
| 27 | $RCI->fail('db.inc.php', 'Syntax error'); |
|---|
| 28 | } |
|---|
| 29 | else 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; |
|---|
| 39 | if (!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 | } |
|---|
| 65 | else { |
|---|
| 66 | $RCI->fail('Config', 'Could not read config files'); |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | // initialize db with schema found in /SQL/* |
|---|
| 70 | if ($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 |
|---|
| 79 | if ($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 |
|---|
| 93 | if ($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 | |
|---|
| 132 | After completing the installation and the final tests please <b>remove</b> the whole |
|---|
| 133 | installer folder from the document root of the webserver.<br /> |
|---|
| 134 | <br /> |
|---|
| 135 | |
|---|
| 136 | These files may expose sensitive configuration data like server passwords and encryption keys |
|---|
| 137 | to the public. Make sure you cannot access this installer from your browser. |
|---|
| 138 | |
|---|
| 139 | </p> |
|---|