-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.php
executable file
·356 lines (327 loc) · 14.6 KB
/
install.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
<?PHP
/*
*******************************************************************************
* Chronologist - web-based time tracking database
* Copyright (C) 2003 by Sylvain LAFRASSE.
*******************************************************************************
* LICENSE:
* This file is part of Chronologist.
*
* Chronologist is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Chronologist is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Chronologist; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*******************************************************************************
* FILE NAME : install.php
* DESCRIPTION : Installation script.
* AUTHORS : Sylvain LAFRASSE.
*******************************************************************************
*/
// TODO : Cautious use of '<INPUT TYPE="FILE" NAME="hello">' for restoring a backup ???
require_once("design.inc.php");
// If the database configuration file already exists
if (file_exists("db.inc.php"))
{
// Launch the login script
header("Location: index.php");
}
else
{
require_once("install.inc.php");
// Session handling.
session_start();
// Retrieve the action to perform from the URL given 'do' parameter
$Do = $_GET['do'];
switch($Do)
{
case "configure" :
$MySqlServerAddress = putslashes($_POST['mysql_server_address']);
$MySqlRootName = putslashes($_POST['mysql_root_name']);
$MySqlRootPassword = putslashes($_POST['mysql_root_password']);
$DatabaseName = putslashes($_POST['database_name']);
$WebServerAddress = putslashes($_POST['web_server_address']);
$UserName = putslashes($_POST['user_name']);
$UserPassword = putslashes($_POST['user_password']);
$AdminEmail = putslashes($_POST['admin_email']);
$AdminFirstName = putslashes($_POST['admin_first_name']);
$AdminLastName = putslashes($_POST['admin_last_name']);
$AdminPassword = putslashes($_POST['admin_password']);
$AdminPasswordConfirmed = putslashes($_POST['admin_password_confirmed']);
// Check 'mysql_server_address' parameter validity
if ($MySqlServerAddress == "")
{
$_SESSION['message'] = "Parameter 'MySql Server Address' is missing. <BR> Please try again. <BR>";
header("Location: install.php");
break;
}
// Check 'mysql_root_name' parameter validity
if ($MySqlRootName == "")
{
$_SESSION['message'] = "Parameter 'MySQL Root Name' is missing. <BR> Please try again. <BR>";
header("Location: install.php");
break;
}
// Check 'database_name' parameter validity
if ($DatabaseName == "")
{
$_SESSION['message'] = "Parameter 'Database Name' is missing. <BR> Please try again. <BR>";
header("Location: install.php");
break;
}
// Check 'web_server_address' parameter validity
if ($WebServerAddress == "")
{
$_SESSION['message'] = "Parameter 'Web Server Address' is missing. <BR> Please try again. <BR>";
header("Location: install.php");
break;
}
// Check 'user_name' parameter validity
if ($UserName == "")
{
$_SESSION['message'] = "Parameter 'Database User Name' is missing. <BR> Please try again. <BR>";
header("Location: install.php");
break;
}
// Check 'user_password' parameter validity
if ($UserPassword == "")
{
$_SESSION['message'] = "Parameter 'Database User Password' is missing. <BR> Please try again. <BR>";
header("Location: install.php");
break;
}
// Check 'admin_email' parameter validity
if ($AdminEmail == "")
{
$_SESSION['message'] = "Parameter 'Administrator E-Mail' is missing. <BR> Please try again. <BR>";
header("Location: install.php");
break;
}
// Check 'admin_password' parameter validity
if ($AdminPassword == "")
{
$_SESSION['message'] = "Parameter 'Administrator User Password' is missing. <BR> Please try again. <BR>";
header("Location: install.php");
break;
}
// Check 'admin_password_confirmed' parameter validity
if ($AdminPasswordConfirmed == "")
{
$_SESSION['message'] = "Parameter 'Confirme Administrator User Password' is missing. <BR> Please try again. <BR>";
header("Location: install.php");
break;
}
// Check 'admin_password' parameter against 'admin_password_confirmed' parameter validity
if ($AdminPassword != $AdminPasswordConfirmed)
{
$_SESSION['message'] = "'Admin Password' parameter is not the same as the 'Confirme Admin Password' parameter. <BR> Please try again. <BR>";
header("Location: install.php");
break;
}
// Try to create a new database with its associated user
if (CreateUserAndDatabase($MySqlServerAddress, $MySqlRootName, $MySqlRootPassword, $WebServerAddress, $DatabaseName, $UserName, $UserPassword)
== FALSE)
{
header("Location: install.php");
break;
}
// Try to create a new configuration file containing the database access parameters
if (CreateConfigFile($MySqlServerAddress, $UserName, $UserPassword, $DatabaseName) == FALSE)
{
header("Location: install.php");
break;
}
// Try to create and populate all the database tables
if (PopulateDatabase($MySqlServerAddress, $UserName, $UserPassword, $DatabaseName, $AdminEmail, $AdminPassword, $AdminFirstName, $AdminLastName)
== FALSE)
{
header("Location: install.php");
break;
}
// Redirect to the login page
$_SESSION['message'] = "Configuration Done. <BR> Enjoy managing your time with Chronologist. <BR>";
header("Location: index.php");
break;
default :
// Aesthetic Attributes
$BACKGROUNG_COLOR = "WHITE";
$HEADER_BACKGROUNG_COLOR = "GRAY";
$HEADER_FONT_COLOR = "WHITE";
$USERNAME_FONT_COLOR = "RED";
$MESSAGE_FONT_COLOR = "RED";
$FOOTER_BACKGROUNG_COLOR = "BLACK";
$FOOTER_FONT_COLOR = "WHITE";
echo "
<HTML>
<HEAD>
<TITLE> Welcome to Chronologist </TITLE>
</HEAD>
<BODY BGCOLOR='".$BACKGROUNG_COLOR."' TOPMARGIN='0' LEFTMARGIN='0' MARGINHEIGHT='0' MARGINWIDTH='0'>
<TABLE WIDTH='100%' HEIGHT='100%' BORDER='0' CELLSPACING='0' CELLPADDING='5'>
<TR BGCOLOR='".$HEADER_BACKGROUNG_COLOR."' HEIGHT='1' ALIGN='CENTER' VALIGN='CENTER'>
<TD WIDTH='8%'>
</TD>
<TD>
<FONT COLOR='".$HEADER_FONT_COLOR."' SIZE='+10'>
<B> Welcome to Chronologist </B>
</FONT>
</TD>
<TD WIDTH='10%'>
</TD>
</TR>
<TR ALIGN='CENTER' VALIGN='CENTER'>
<TD COLSPAN='3'>
";
// If an error message was set
if ($_SESSION['message'] != "")
{
// Displays the error message
echo "
<FONT SIZE='+1' COLOR='".$MESSAGE_FONT_COLOR."'>
<B> ".$_SESSION['message']." </B> <BR>
</FONT>
";
// Reset the error message global variable
$_SESSION['message'] = "";
}
// Display the user login form
echo "
<FORM ACTION='install.php?do=configure' METHOD='POST' NAME='configuration'>
<TABLE BORDER='0'>
<TR>
<TD ALIGN='RIGHT'>
<B> MySQL Server Host Name </B>
</TD>
<TD>
<INPUT TYPE='TEXT' NAME='mysql_server_address' VALUE='localhost'>
</TD>
</TR>
<TR>
<TD ALIGN='RIGHT'>
<B> Database Root Name </B>
</TD>
<TD>
<INPUT TYPE='TEXT' NAME='mysql_root_name' VALUE='root'>
</TD>
</TR>
<TR>
<TD ALIGN='RIGHT'>
<I> Database Root Password </I>
</TD>
<TD>
<INPUT TYPE='PASSWORD' NAME='mysql_root_password' VALUE=''>
</TD>
</TR>
<TR>
<TD ALIGN='CENTER' COLSPAN='2'>
<BR>
</TD>
</TR>
<TR>
<TD ALIGN='RIGHT'>
<B> Web Server Host Name </B>
</TD>
<TD>
<INPUT TYPE='TEXT' NAME='web_server_address' VALUE='localhost'>
</TD>
</TR>
<TR>
<TD ALIGN='RIGHT'>
<B> Database Base Name </B>
</TD>
<TD>
<INPUT TYPE='TEXT' NAME='database_name' VALUE='Chronologist'>
</TD>
</TR>
<TR>
<TD ALIGN='RIGHT'>
<B> Database User Name </B>
</TD>
<TD>
<INPUT TYPE='TEXT' NAME='user_name' VALUE='Chronologist'>
</TD>
</TR>
<TR>
<TD ALIGN='RIGHT'>
<B> Database User Password </B>
</TD>
<TD>
<INPUT TYPE='PASSWORD' NAME='user_password' VALUE=''>
</TD>
</TR>
<TR>
<TD ALIGN='CENTER' COLSPAN='2'>
<BR>
</TD>
</TR>
<TR>
<TD ALIGN='RIGHT'>
<B> Administrator E-Mail </B>
</TD>
<TD>
<INPUT TYPE='TEXT' NAME='admin_email' VALUE=''>
</TD>
</TR>
<TR>
<TD ALIGN='RIGHT'>
<I> Administrator First Name </I>
</TD>
<TD>
<INPUT TYPE='TEXT' NAME='admin_first_name' VALUE=''>
</TD>
</TR>
<TR>
<TD ALIGN='RIGHT'>
<I> Administrator Last Name </I>
</TD>
<TD>
<INPUT TYPE='TEXT' NAME='admin_last_name' VALUE=''>
</TD>
</TR>
<TR>
<TD ALIGN='RIGHT'>
<B> Administrator User Password </B>
</TD>
<TD>
<INPUT TYPE='PASSWORD' NAME='admin_password' VALUE=''>
</TD>
</TR>
<TR>
<TD ALIGN='RIGHT'>
<B> Confirme Administrator User Password </B>
</TD>
<TD>
<INPUT TYPE='PASSWORD' NAME='admin_password_confirmed' VALUE=''>
</TD>
</TR>
<TR>
<TD ALIGN='CENTER' COLSPAN='2'>
<BR> <INPUT TYPE='SUBMIT' NAME='configuration' VALUE='Configure'>
</TD>
</TR>
</TABLE>
</FORM>
</TD>
</TR>
<TR BGCOLOR='$FOOTER_BACKGROUNG_COLOR' HEIGHT='1' VALIGN='CENTER'>
<TD COLSPAN='3' ALIGN='CENTER'>
<FONT SIZE='-1' COLOR='$FOOTER_FONT_COLOR'>
Chronologist
</FONT>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>";
break;
}
}
?>