r1530: Adding an installer check in install/install.php to prevent people from attemp...
[bugdar.git] / install / install.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 define('STOP_MARK', 8);
23 define('ACTIVE_SITE', 'install.php');
24
25 require_once('./global.php');
26
27 page_start();
28
29 // ###################################################################
30
31 if ($bugsys->in['mark'] == 0)
32 {
33 ?>
34 <h1>Welcome to Bugdar</h1>
35
36 <p>This installer will take you through the procedure of setting up your Bugdar installation. If you are seeing this message, that means that your configuration file was read properly and that your database is accessible.</p>
37
38 <p>The following steps will initialize your database, place the default settings and data in your database, and finally ask you to enter in some settings to allow you to access the system when the installer finishes.</p>
39
40 <p>To begin the installation process, please click the button below.</p>
41 <?php
42 }
43
44 // ###################################################################
45
46 if ($bugsys->in['mark'] == 1)
47 {
48 ?>
49 <h1>Installation Check</h1>
50
51 <style type="text/css" media="screen">
52 <!--
53 .fail
54 {
55 font-weight: bold;
56 color: rgb(255, 0, 0);
57 }
58 .pass
59 {
60 color: rgb(0, 150, 0);
61 }
62 //-->
63 </style>
64
65 <p>This step will ensure that Bugdar can install and run properly. In all of these tests, <span class="pass">green means the test succeeded</span> and <span class="fail">red means it didn't</span>.</p>
66
67 <strong>MySQL Privileges:</strong>
68 <ul>
69 <?php
70
71 $db->showerrors = false;
72
73 $pf = $tests[] = ($db->query("CREATE TABLE install_check (col1 VARCHAR(255) NULL);") ? 'pass' : 'fail');
74 echo "\n\t<li class=\"$pf\">CREATE TABLE</li>";
75
76 $pf = $tests[] = ($db->query("INSERT INTO install_check (col1) VALUES ('example')") ? 'pass' : 'fail');
77 echo "\n\t<li class=\"$pf\">INSERT</li>";
78
79 $pf = $tests[] = ($db->query("UPDATE install_check SET col1 = 'example2'") ? 'pass' : 'fail');
80 echo "\n\t<li class=\"$pf\">UPDATE</li>";
81
82 $pf = $tests[] = ($db->query("SELECT * FROM install_check") ? 'pass' : 'fail');
83 echo "\n\t<li class=\"$pf\">SELECT</li>";
84
85 $pf = $tests[] = ($db->query("DELETE FROM install_check WHERE col1 = 'example2'") ? 'pass' : 'fail');
86 echo "\n\t<li class=\"$pf\">DELETE</li>";
87
88 $pf = $tests[] = ($db->query("ALTER TABLE install_check ADD col3 BOOL") ? 'pass' : 'fail');
89 echo "\n\t<li class=\"$pf\">ALTER</li>";
90
91 $pf = $tests[] = ($db->query("ALTER TABLE install_check ADD INDEX (col1)") ? 'pass' : 'fail');
92 echo "\n\t<li class=\"$pf\">ALTER ADD INDEX</li>";
93
94 $pf = $tests[] = ($db->query("REPLACE INTO install_check (col1) VALUES ('example3')") ? 'pass' : 'fail');
95 echo "\n\t<li class=\"$pf\">REPLACE</li>";
96
97 $pf = $tests[] = ($db->query("OPTIMIZE TABLE install_check") ? 'pass' : 'fail');
98 echo "\n\t<li class=\"$pf\">OPTIMIZE</li>";
99
100 $pf = $tests[] = ($db->query("DROP TABLE install_check") ? 'pass' : 'fail');
101 echo "\n\t<li class=\"$pf\">DROP TABLE</li>";
102
103 echo "\n</ul>";
104
105 $valcount = array_count_values($tests);
106 if ($valcount['fail'] > 0)
107 {
108 echo "<p>Please adjust your MySQL setup and refresh this page to ensure that Bugdar can operate properly. If you do not do so, Bugdar cannot be installed.</p>";
109 page_end(false);
110 }
111 }
112
113 // ###################################################################
114
115 if ($bugsys->in['mark'] == 2)
116 {
117 ?>
118 <h1>Initializing Database</h1>
119
120 <p>This step will load the tables into your database so the rest of the installation can proceed forward.</p>
121
122 <?php
123
124 require_once('./install/schema.php');
125
126 foreach ($schema AS $table => $query)
127 {
128 $db->query($query);
129 echo 'Creating table ' . $table . '<br />' . "\n";
130 }
131 }
132
133 // ###################################################################
134
135 if ($bugsys->in['mark'] == 3)
136 {
137 ?>
138 <h1>Loading Default Data</h1>
139
140 <p>Default table data for usergroups, statuses, priorities, and other various options are being loaded. This will allow you to use Bugdar with minimal setup.</p>
141
142 <?php
143
144 require_once('./install/default_data.php');
145
146 foreach ($data AS $table => $records)
147 {
148 foreach ($records AS $record)
149 {
150 $fields = $values = array();
151 foreach ($record AS $field => $value)
152 {
153 $fields[] = $field;
154 $values[] = addslashes($value);
155 }
156
157 $db->query("INSERT INTO " . TABLE_PREFIX . "$table (" . implode(',', $fields) . ") VALUES ('" . implode("', '", $values) . "')");
158 }
159
160 echo 'Populating table ' . $table . '<br />' . "\n";
161 }
162
163 $db->query("INSERT INTO " . TABLE_PREFIX . "language (title, langcode, charset, direction, userselect) VALUES ('English (US)', 'en_US', 'utf-8', 'ltr', 1)");
164 echo 'Inserting default language<br />' . "\n";
165 }
166
167 // ###################################################################
168
169 if ($bugsys->in['mark'] == 4)
170 {
171 ?>
172 <h1>Loading Settings</h1>
173
174 <p>Default settings are being loaded into the system.</p>
175
176 <?php
177
178 require_once('./install/settings.php');
179
180 foreach ($settings AS $key => $value)
181 {
182 $db->query("INSERT INTO " . TABLE_PREFIX . "setting (varname, value) VALUES ('" . $key . "', '" . $db->escape_string($value) . "')");
183 }
184
185 echo 'Settings loaded...';
186 }
187
188
189 // ###################################################################
190
191 if ($bugsys->in['mark'] == 5)
192 {
193 ?>
194 <h1>Cache Data</h1>
195
196 <p>In order to make Bugdar as efficient as possible, the system caches the portions of data it can. This reduces the load of your server without compromising usability. Currently the caches are being built.</p>
197 <?php
198
199 require_once('./includes/permissions.php');
200
201 build_settings();
202 echo "Cached settings<br />\n";
203
204 build_usergroups();
205 echo "Cached usergroups<br />\n";
206
207 build_statuses();
208 echo "Cached statuses<br />\n";
209
210 build_priorities();
211 echo "Cached priorities<br />\n";
212
213 build_severities();
214 echo "Cached severities<br />\n";
215
216 build_assignedto();
217 echo "Cached assignable users/developers<br />\n";
218
219 build_resolutions();
220 echo "Cached resolutions<br />\n";
221
222 build_products();
223 echo "Cached products<br />\n";
224
225 build_versions();
226 echo "Cached versions<br />\n";
227
228 build_languages();
229 echo "Cached languages<br />\n";
230
231 build_user_help();
232 echo "Cached user help documentation<br />\n";
233 }
234
235 // ###################################################################
236
237 if ($bugsys->in['mark'] == 6)
238 {
239 $value = 'http' . ($_SERVER['HTTPS'] == 'on' ? 's' : '') . '://' . $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] != '80' ? ':' . $_SERVER['SERVER_PORT'] : '') . str_replace('/install/install.php', '', $_SERVER['SCRIPT_NAME']);
240 ?>
241 <h1>General Settings</h1>
242
243 <p>These three settings are fundamental in setting up your bug tracking system. Please fill them in to proceed with the installation.</p>
244
245 <form name="settings-do" action="install.php" method="post">
246 <input type="hidden" name="mark" value="7" />
247
248 <div><strong>Tracker Name (the name of the entire tracking system, for instance "Acme Inc. Bug Tracker"):</strong> <input type="text" name="trackertitle" size="50" /></div>
249 <div><strong>Tracker URL (the root URL of your tracker, we have tried to guess this for you; <em>it does not end with a trailing slash!</em>):</strong> <input type="text" name="trackerurl" size="50" value="<?php echo $value; ?>" /></div>
250 <div><strong>Webmaster Email:</strong> <input type="text" name="webmasteremail" size="50" /></div>
251
252 <input type="submit" name="submit" value="Next Step" />
253
254 </form>
255
256 <?php
257
258 page_end(false);
259 }
260
261 // ###################################################################
262
263 if ($bugsys->in['mark'] == 7)
264 {
265 ?>
266 <h1>New Administrator</h1>
267
268 <p>Your settings have been saved. Now you must create a new administrative account for yourself. This account will have complete control over the system.</p>
269
270 <form name="user-do" action="install.php" method="post">
271 <input type="hidden" name="mark" value="8" />
272
273 <div><strong>Display Name:</strong> <input type="text" name="displayname" size="50" /></div>
274 <div><strong>Email Address:</strong> <input type="text" name="email" size="50" /></div>
275 <div><strong>Password:</strong> <input type="password" name="password" size="50" /></div>
276
277 <input type="submit" name="submit" value="Next Step" />
278 </form>
279
280 <?php
281
282 $db->query("UPDATE " . TABLE_PREFIX . "setting SET value = '" . $bugsys->input_escape('trackertitle') . "' WHERE varname = 'trackertitle'");
283 $db->query("UPDATE " . TABLE_PREFIX . "setting SET value = '" . $bugsys->input_escape('trackerurl') . "' WHERE varname = 'trackerurl'");
284 $db->query("UPDATE " . TABLE_PREFIX . "setting SET value = '" . $bugsys->input_escape('webmasteremail') . "' WHERE varname = 'webmasteremail'");
285
286 page_end(false);
287 }
288
289 // ###################################################################
290
291 if ($bugsys->in['mark'] == 8)
292 {
293 ?>
294 <h1>User Added</h1>
295
296 <p>Your new user has been added.</p>
297 <?php
298
299 require_once('./includes/api_user.php');
300
301 // we need to do this here because build_assignedto() uses this data and we don't have it loaded in
302 // the installer, so we need to do it manually
303 build_usergroups();
304
305 $user = new UserAPI($bugsys);
306 $user->set('email', $bugsys->in['email']);
307 $user->set('displayname', $bugsys->in['displayname']);
308 $user->set('password', $bugsys->in['password']);
309 $user->set('showcolors', 1);
310 $user->set('usergroupid', 6, true, false); // don't verify because we haven't cached usergroups yet
311 $user->insert();
312 }
313
314 // ###################################################################
315
316 page_end();
317
318 /*=====================================================================*\
319 || ###################################################################
320 || # $HeadURL$
321 || # $Id$
322 || ###################################################################
323 \*=====================================================================*/
324 ?>