-
Notifications
You must be signed in to change notification settings - Fork 5
/
install.php
245 lines (217 loc) · 8.77 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
<?php
/*
* CloudLevels, an easy way to share user created level files for video games.
* Copyright (C) 2016 Alexander Aquino
*
* This program 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 3 of the License, or (at your option)
* any later version.
*
* This program 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
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
//CloudLevels Installer
//When there is input data
if(!empty($_POST["username"])){
//Check if confirm password matches password field
if($_POST["password"]!=$_POST["password_confirm"]){
echo '<div class="card hoverable red"><div class="card-content white-text"><p>ERROR: Your entered passwords do not match.</p></div></div>';
exit(0);
}
//Create configuration file:
//Open file
$configfile = fopen("configuration.php", "w") or die('<div class="card hoverable red"><div class="card-content white-text"><p>ERROR: File <strong>configuration.php</strong> could not be written to server.</p></div></div>');
fwrite($configfile, "<?php\n");
//Write database values
fwrite($configfile, "\$db_type='" . addslashes($_POST["db_type"]) . "';\n");
fwrite($configfile, "\$db_hostname='" . addslashes($_POST["db_hostname"]) . "';\n");
fwrite($configfile, "\$db_username='" . addslashes($_POST["db_username"]) . "';\n");
fwrite($configfile, "\$db_password='" . addslashes($_POST["db_password"]) . "';\n");
fwrite($configfile, "\$db_database='" . addslashes($_POST["db_database"]) . "';\n");
//Write default configuration stuff
fwrite($configfile, "\$site_name='Site Name';\n");
fwrite($configfile, "\$site_desc='Set the description here!';\n");
fwrite($configfile, "\$game_url='#';\n");
fwrite($configfile, "\$file_size_limit='1000000';\n");
fwrite($configfile, "\$tags='Each\nTag\nGoes\nOn\nA\nNew\nLine';\n");
fwrite($configfile, "\$theme='light-blue';\n");
fwrite($configfile, "\$reg_question='What is 1 plus 8 minus the number of clouds in your head?';\n");
fwrite($configfile, "\$reg_answer='9';\n");
//Close file
fwrite($configfile, "?>\n");
fclose($configfile);
//Create database:
//Configuration variables
include 'configuration.php';
//Create tables
try {
//Connect to database
$db = new PDO($db_type . ':host=' . $db_hostname . ';dbname=' . $db_database . ';charset=utf8', $db_username, $db_password, array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
//Begin
$db->beginTransaction();
//Users table
$db->exec('CREATE TABLE cl_user(
id INTEGER AUTO_INCREMENT,
usergroup TINYINT DEFAULT 0,
username TINYTEXT,
password TINYTEXT,
date TINYTEXT,
ip TINYTEXT,
uploads INTEGER DEFAULT 0,
PRIMARY KEY (id)
)');
//usergroup: 0=Normal, 1=Banned, 2=Admin
//Files table
$db->exec('CREATE TABLE cl_file(
id INTEGER AUTO_INCREMENT,
name TINYTEXT,
author INTEGER,
date TINYTEXT,
ip TINYTEXT,
downloads INTEGER DEFAULT 0,
likes INTEGER DEFAULT 0,
featured TINYINT DEFAULT 0,
description TEXT,
PRIMARY KEY (id),
FOREIGN KEY (author) REFERENCES cl_user (id)
)');
//Comments table
$db->exec('CREATE TABLE cl_comment(
id INTEGER AUTO_INCREMENT,
author INTEGER,
file INTEGER,
date TINYTEXT,
ip TINYTEXT,
comment TEXT,
PRIMARY KEY (id),
FOREIGN KEY (author) REFERENCES cl_user (id)
)');
//Likes table
$db->exec('CREATE TABLE cl_like(
author INTEGER,
file INTEGER,
PRIMARY KEY (author, file),
FOREIGN KEY (author) REFERENCES cl_user (id),
FOREIGN KEY (file) REFERENCES cl_file (id)
)');
//Tags table
$db->exec('CREATE TABLE cl_tag(
file INTEGER,
tag VARCHAR (255),
PRIMARY KEY (file, tag),
FOREIGN KEY (file) REFERENCES cl_file (id)
)');
//Create first admin user
date_default_timezone_set('America/New_York');
$stmt = $db->prepare(
INSERT INTO cl_user(usergroup, username, password, date, ip)
VALUES(2,?,?,?,?)");
$stmt->execute(array($_POST["username"], crypt($_POST["password"]), date("F j, Y"), $_SERVER['REMOTE_ADDR']));
//End
$db->commit();
}
//Handle errors
catch(PDOException $ex){
//$db->rollBack();
echo '<div class="card hoverable red"><div class="card-content white-text"><p>ERROR: ' . $ex->getMessage() . '</p></div></div>';
exit(0);
}
}
//Get available database types
$supported_db_types = PDO::getAvailableDrivers();
//HTML Template:
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0"/>
<title>CloudLevels Installer</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/css/materialize.min.css" type="text/css" rel="stylesheet" media="screen,projection"/>
</head>
<body>
<div class="container">
<?php
if(empty($supported_db_types)){
?>
<div class="card hoverable red">
<div class="card-content white-text">
<p>ERROR: No supported database types detected.</p>
</div>
</div>
<?php
}
else if(!empty($_POST["username"])){
?>
<div class="card hoverable green">
<div class="card-content white-text">
<p>SUCCESS: Installation complete! Please delete <strong>install.php</strong> from your server.</p>
</div>
</div>
<?php
}
?>
<div class="row card hoverable">
<span class="col s12 card-title light-blue white-text center" style="font-size: 200%;">Install</span>
<form action="install.php" method="post" class="col s12 m10 l8 offset-m1 offset-l2">
<div class="input-field col s12">
<i class="fa fa-user prefix" aria-hidden="true"></i>
<input id="username" name="username" type="text" class="validate" required>
<label for="username">User Name</label>
</div>
<div class="input-field col s12">
<i class="fa fa-key prefix" aria-hidden="true"></i>
<input id="password" name="password" type="password" class="validate" required>
<label for="password">Password</label>
</div>
<div class="input-field col s12">
<i class="fa fa-key prefix" aria-hidden="true"></i>
<input id="password-confirm" name="password_confirm" type="password" class="validate" required>
<label for="password-confirm">Confirm Password</label>
</div>
<i class="fa fa-database small col s1" aria-hidden="true"></i>
<div class="input-field col s11">
<select id="db_type" name="db_type">
<?php
foreach($supported_db_types as $db_driver)
echo '<option value="' . $db_driver . '">' . $db_driver . '</option>';
?>
</select>
<label for="db_type">Database Type</label>
</div>
<div class="input-field col s12">
<i class="fa fa-database prefix" aria-hidden="true"></i>
<input id="db-hostname" name="db_hostname" type="text" class="validate" required>
<label for="db-hostname">Database Hostname</label>
</div>
<div class="input-field col s12">
<i class="fa fa-database prefix" aria-hidden="true"></i>
<input id="db-username" name="db_username" type="text" class="validate" required>
<label for="db-username">Database Username</label>
</div>
<div class="input-field col s12">
<i class="fa fa-database prefix" aria-hidden="true"></i>
<input id="db-password" name="db_password" type="password" class="validate" required>
<label for="db-password">Database Password</label>
</div>
<div class="input-field col s12">
<i class="fa fa-database prefix" aria-hidden="true"></i>
<input id="db-database" name="db_database" type="text" class="validate" required>
<label for="db-database">Database Name</label>
</div>
<button class="btn waves-effect waves-light light-blue col s12" type="submit">Install</button>
</form><div class="row"></div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/js/materialize.min.js"></script>
<script>$(document).ready(function() {$('select').material_select();$("form").submit(function(){$("button").attr("disabled", true);return true;});});</script>
</body>
</html>