-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstaller.php
More file actions
386 lines (341 loc) · 18.9 KB
/
installer.php
File metadata and controls
386 lines (341 loc) · 18.9 KB
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
<?php
$show_results = false;
if(isset($_POST['codex_installer_submit'])){
//Setup the variables
$db_host = $_POST["db_host"];
$db_username = $_POST["db_username"];
$db_password = $_POST["db_password"];
$db_database = $_POST["db_database"];
$first_username = $_POST["first_username"];
$first_password = $_POST["first_password"];
$file_contents=<<<EOD
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| DATABASE CONNECTIVITY SETTINGS
| -------------------------------------------------------------------
| This file will contain the settings needed to access your database.
|
| For complete instructions please consult the "Database Connection"
| page of the User Guide.
|
| -------------------------------------------------------------------
| EXPLANATION OF VARIABLES
| -------------------------------------------------------------------
|
| ['hostname'] The hostname of your database server.
| ['username'] The username used to connect to the database
| ['password'] The password used to connect to the database
| ['database'] The name of the database you want to connect to
| ['dbdriver'] The database type. ie: mysql. Currently supported:
mysql, mysqli, postgre, odbc, mssql
| ['dbprefix'] You can add an optional prefix, which will be added
| to the table name when using the Active Record class
| ['pconnect'] TRUE/FALSE - Whether to use a persistent connection
| ['db_debug'] TRUE/FALSE - Whether database warnings should be displayed.
| ['active_r'] TRUE/FALSE - Whether to load the active record class
| ['cache_on'] TRUE/FALSE - Enables/disables query caching
| ['cachedir'] The path to the folder where cache files should be stored
|
| The \$active_group variable lets you choose which connection group to
| make active. By default there is only one group (the "default" group).
|
*/
\$active_group = "default";
\$db['default']['hostname'] = "$db_host";
\$db['default']['username'] = "$db_username";
\$db['default']['password'] = "$db_password";
\$db['default']['database'] = "$db_database";
\$db['default']['dbdriver'] = "mysql";
\$db['default']['dbprefix'] = "";
\$db['default']['active_r'] = TRUE;
\$db['default']['pconnect'] = TRUE;
\$db['default']['db_debug'] = TRUE;
\$db['default']['cache_on'] = FALSE;
\$db['default']['cachedir'] = "";
\$db['default']['char_set'] = "utf8";
\$db['default']['dbcollat'] = "utf8_unicode_ci";
?>
EOD;
$warnings = array();
$errors = array();
$success = array();
$file_path = './codex/application/config/database.php';
if(!file_exists($file_path))
$errors['insufficient_permissions'] = "$file_path Doesn't exist.";
if(!is_writable($file_path))
$errors['insufficient_permissions'] = "Insufficient permissions on $file_path. Please fix the permissions.";
else{
$fp = fopen($file_path,'w+');
if(!$fp){
$errors[] = "There was a problem opening the database.php file.";
}
else{
fwrite($fp,$file_contents,strlen($file_contents));
fclose($fp);
$success['updating_file'] = "Successfully updated the database.php file.<br>";
if(empty($first_username) OR empty($first_password))
$errors[] = "Username and password are not optional. Please specify them.";
else{
$db = @mysql_connect($db_host,$db_username,$db_password);
if(!$db)
$errors[] = "Problem connecting to the database. Make sure you database host, username, pass, and database name are correct.";
else{
if(!mysql_select_db($db_database)){
$sql = "CREATE DATABASE $db_database";
$result = mysql_query($sql);
if($result){
$success[] = "Successfully created the new database.";
mysql_select_db($db_database);
}
else
$errors[] = "Problem creating the new database. Do you have enough privleges to do so?";
}
///
$sql = 'CREATE TABLE IF NOT EXISTS `modules` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`alias` varchar(50) NOT NULL,
`date_install` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;';
$result = mysql_query($sql);
if(!$result)
$warnings['modules'] = "Problem creating the modules table: ".mysql_error();
$sql = 'CREATE TABLE IF NOT EXISTS `access` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) NOT NULL,
`access_link` varchar(255) NOT NULL,
`link` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;';
$result = mysql_query($sql);
if(!$result)
$warnings['ci_sessions'] = "Problem creating the access table: ".mysql_error();
$affected_rows = mysql_affected_rows();
if($affected_rows == 1)
$success['ci_sessions'] = "Successfully created the table (access).";
//
$sql = 'CREATE TABLE IF NOT EXISTS `access_level` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;';
$result = mysql_query($sql);
if(!$result)
$warnings['ci_sessions'] = "Problem creating the access_level table: ".mysql_error();
$affected_rows = mysql_affected_rows();
if($affected_rows == 1)
$success['ci_sessions'] = "Successfully created the table (access_level).";
$sql = 'CREATE TABLE IF NOT EXISTS `admin_data_logs` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`date` datetime NOT NULL,
`user_id` int(11) NOT NULL,
`table` varchar(100) NOT NULL,
`id_records` int(11) NOT NULL,
`before` text NOT NULL,
`after` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;';
$result = mysql_query($sql);
if(!$result)
$warnings['ci_sessions'] = "Problem creating the admin_data_logs table: ".mysql_error();
$affected_rows = mysql_affected_rows();
if($affected_rows == 1)
$success['ci_sessions'] = "Successfully created the table (admin_data_logs).";
$sql = 'CREATE TABLE IF NOT EXISTS `access_access_level` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`access_id` int(11) NOT NULL,
`access_level_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;';
$result = mysql_query($sql);
if(!$result)
$warnings['ci_sessions'] = "Problem creating the access_access_level table: ".mysql_error();
$affected_rows = mysql_affected_rows();
if($affected_rows == 1)
$success['ci_sessions'] = "Successfully created the table (access_access_level).";
///
$sql = "
CREATE TABLE `ci_sessions` (
`session_id` varchar(40) NOT NULL default '0',
`session_start` int(10) unsigned NOT NULL default '0',
`session_last_activity` int(10) unsigned NOT NULL default '0',
`session_ip_address` varchar(16) NOT NULL default '0',
`session_user_agent` varchar(50) NOT NULL,
`session_data` text NOT NULL,
PRIMARY KEY (`session_id`)
);
";
$result = mysql_query($sql);
if(!$result)
$warnings['ci_sessions'] = "Problem creating the ci_sessions table: ".mysql_error();
$affected_rows = mysql_affected_rows();
if($affected_rows == 1)
$success['ci_sessions'] = "Successfully created the table to handle sessions (ci_sessions).";
$sql = "
CREATE TABLE `example` (
`my_id` int(11) NOT NULL auto_increment,
`checkbox_test` set('yes','no') NOT NULL,
`date_test` date NOT NULL,
`dbdropdown_test` varchar(100) NOT NULL,
`dropdown_test` varchar(100) NOT NULL,
`hidden_test` varchar(100) NOT NULL,
`password_test` varchar(100) NOT NULL,
`radiogroup_test` varchar(100) NOT NULL,
`sessiondata_test` varchar(100) NOT NULL,
`textarea_test` text NOT NULL,
`textbox_test` varchar(100) NOT NULL,
`time_test` int(11) NOT NULL,
`file_test` varchar(100) NOT NULL,
`image_test` varchar(100) NOT NULL,
PRIMARY KEY (`my_id`)
);
";
$result = mysql_query($sql);
if(!$result)
$warnings['example'] = "Problem creating the example table: ".mysql_error();
$affected_rows = mysql_affected_rows();
if($affected_rows == 1)
$success['example'] = "Successfully created the example table (example).";
$sql = "
CREATE TABLE `related_example` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(200) NOT NULL,
`description` text NOT NULL,
`example_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
);
";
$result = mysql_query($sql);
if(!$result)
$warnings['related_example'] = "Problem creating the related_example table: ".mysql_error();
$affected_rows = mysql_affected_rows();
if($affected_rows == 1)
$success['related_example'] = "Successfully created the related_example table (related_example).";
$sql = "CREATE TABLE `users` (
`id` int(11) NOT NULL auto_increment,
`username` varchar(40) NOT NULL,
`password` varchar(40) NOT NULL,
`access_level` int(11) NOT NULL,
PRIMARY KEY (`id`)
);";
$result = mysql_query($sql);
if(!$result)
$warnings['users'] = "Problem creating the users table: ".mysql_error();
$affected_rows = mysql_affected_rows();
if($affected_rows == 1)
$success['users'] = "Successfully created the table to handle users (users).";
$sql = "INSERT INTO users VALUES(NULL,'$first_username','".sha1($first_password)."','3')";
$result = mysql_query($sql);
if(!$result)
$warnings['new_user'] = "Problem adding the new user to the database: ".mysql_error();
$affected_rows = mysql_affected_rows();
if($affected_rows == 1)
$success['new_user'] = "Successfully created the new account. <br>";
$sql = "
CREATE TABLE `user_records` (
`id` int(11) NOT NULL auto_increment,
`user_id` int(11) NOT NULL,
`record_id` int(11) NOT NULL,
`permissions` varchar(30) NOT NULL,
`table_name` varchar(250) NOT NULL,
PRIMARY KEY (`id`)
);
";
$result = mysql_query($sql);
if(!$result)
$warnings['users_records'] = "Problem creating the user records table: ".mysql_error();
$affected_rows = mysql_affected_rows();
if($affected_rows == 1)
$success['users_records'] = "Successfully created the table to handle user permissions (users_records).";
$sql = "
INSERT INTO `user_records` VALUES ( NULL , '1', '1', 'owner', 'users');
";
$result = mysql_query($sql);
if(!$result)
$warnings['new_user_record'] = "Problem adding the new permissions for the new user: ".mysql_error();
$affected_rows = mysql_affected_rows();
if($affected_rows == 1)
$success['new_user_record'] = "Successfully created the permissions for the new account. <br>";
mysql_close();
}
}
}
}
$show_results = true;
}
$base_url = "http://".$_SERVER['HTTP_HOST'];
$base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>CodeExtinguisher Installer</title>
<meta name="author" content="Majd J Taby">
<style type="text/css">
body{
font-family: "Lucida Grande", Lucida, Verdana, sans-serif;
}
input{
display: block;
margin: 10px 0 30px 0;
}
</style>
</head>
<body>
<div class="container">
<?php
if($show_results){ ?>
<div id="result-top"></div>
<div id="result-box">
<div id="result-box-bottom">
<h3>In total, there were <span class="err-highlight"><?=count($errors)?> errors</span>, <span class="war-highlight"><?=count($warnings)?> warnings</span> and <span class="suc-highlight"><?=count($success)?> success</span> messages. Here's the low-down:</h3>
<?php
foreach($errors as $err){
echo '<div class="result-bubble"><b><span class="err-highlight">Error</span></b>: '.$err.'</div>';
}
foreach($warnings as $err){
echo '<div class="result-bubble"><b><span class="war-highlight">Warning</span></b>: '.$err.'</div>';
}
foreach($success as $suc){
echo '<div class="result-bubble"><b><span class="suc-highlight">Success</span></b>: '.$suc.'</div>';
}
if(count($errors) == 0){
?>
<h3><a href="backend.php">Proceed now to your CodeExtinguisher Installation...</a></h3>
<?php
}
?>
</div>
</div>
<?php }
else{ ?>
<form method="POST" action="">
<div id="top"></div>
<div id="first">
<div class="installer-box-contents">
<h2>Setup the database configuration:</h2>
<label for="db_host"> <b>Hostname</b>:</label> <input class="textbox" type="text" value="localhost" name="db_host">
<label for="db_username"><b>Username</b>:</label> <input class="textbox" type="text" value="" name="db_username">
<label for="db_password"><b>Password</b>:</label> <input class="textbox" type="password" value="" name="db_password">
<label for="db_database"><b>Database</b>: If the database you specify already exists, <br>nothing happens. However, if the database doesn't <br>exist, it will be created.<br></label> <input class="textbox" type="database" value="" name="db_database">
</div>
</div>
<div id="middle">
<div class="installer-box-contents">
<h2>Setup the database configuration:</h2>
Here you can specify the username and password of <br>the first account that you will need to access the <br>backend with.<br><br>
<label for="first_username"><b>Username</b>:</label> <input class="textbox" type="text" value="" name="first_username">
<label for="first_password"><b>Password</b>:</label> <input class="textbox" type="password" value="" name="first_password">
</div>
</div>
<div id="last">
<input type="submit" value="That's it, you're done. Now just press this button!" id="installer-submit" name="codex_installer_submit">
</div>
</form>
<?php }
?>
</div>
</body>
</html>