-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathconfigprocessor.php
More file actions
275 lines (219 loc) · 7.08 KB
/
configprocessor.php
File metadata and controls
275 lines (219 loc) · 7.08 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
<head></head>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Installation Processor</title>
<script>
window.onpageshow = function(evt) {
// If persisted then it is in the page cache, force a reload of the page.
if (evt.persisted) {
document.body.style.display = "none";
location.reload();
}
};
</script>
</head>
<body>
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
require_once __DIR__.'/sql_parse.php';
//Process and load form data
$servername = $_POST["servername"];
$rootpass = $_POST["rootpass"];
$dbuser = $_POST["dbuser"];
$dbpass1 = $_POST["dbpass1"];
$dbpass2 = $_POST["dbpass2"];
$adminuser = $_POST["adminuser"];
$adminpass1 = $_POST["adminpass1"];
$adminpass2 = $_POST["adminpass2"];
$action = $_POST["selectaction"];
$adminname = $_POST["adminname"];
$adminemail = $_POST["adminemail"];
//Create the MD5 hash value for the admin password
$adminhash = md5($adminpass1);
//-----------------Do some validation---------
$validerror ='';
//Validate DB password
echo "Validating Entries...";
flush();
if ($dbpass1 != $dbpass2)
{
$validerror .= "<br><strong>Your Database passwords do not match.</strong>";
}
//Validate admin password
if ($adminpass1 != $adminpass2) {
$validerror .= "<br><strong>Your Administrator account passwords do not match.</strong>";
}
echo "Success!<br>";
flush();
//Validate DB connectivity
echo "Checking DB connectivity...";
flush();
$con=mysqli_connect($servername,"root",$rootpass);
if (mysqli_connect_errno())
{
$validerror .= "<br><strong>Cannot connect the the database using the supplied information.</strong>";
}
echo "Success!<br>";
flush();
//Validate that the config directories are writable
echo "Checking config folder permissions...";
flush();
if (!is_writable(dirname('../../includes/functions.php')))
{
$validerror .= "<br><strong>Cannot write the configuration files. Please check the /includes/ folder permissions. See the RPints Installation page on www.raspberrypints.com.</strong>";
}
if (!is_writable(dirname('../../admin/includes/checklogin.php')))
{
$validerror .= "<br><strong>Cannot write the configuration files. Please check the /admin/includes/ folder permissions. See the RPints Installation page on www.raspberrypints.com.</strong>";
}
echo "Success!<br>";
flush();
//##TODO## Check if administrator account already exists
//Display errors and die
if ($validerror !='')
{
echo "<html><body>";
echo $validerror;
echo "<br /><br />Please press the back button on your browser to fix these errors";
echo "</body></html>";
die();
}
// CLEAR INSTALLATION DATA ROUTINES
if ($action == 'remove')
{
echo "Deleting raspberrypints database...";
flush();
$con=mysqli_connect($servername,"root",$rootpass);
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "DROP database raspberrypints;";
$result = mysqli_query($con,$sql);
mysqli_close($con);
echo "Success!<br>";
flush();
echo "Removing configuration files...";
flush();
try {
unlink('../../includes/config.php');
unlink('../../admin/includes/conn.php');
unlink('../../admin/includes/configp.php');
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
//unlink('../../includes/config.php');
//unlink('../../admin/includes/conn.php');
//unlink('../../admin/includes/configp.php');
echo "Success!<br>";
flush();
}
if ($action == 'install')
{
require_once __DIR__.'/config_files.php';
//-----------------Create the main config file-----------------
echo "Update config files...";
flush();
file_put_contents('../../includes/config.php', $mainconfigstring);
echo "Success!<br>";
flush();
// -----------------Create the admin files----------------------
echo "Update admin config files...";
flush();
file_put_contents('../../admin/includes/conn.php', $adminconfig1);
file_put_contents('../../admin/includes/configp.php', $adminconfig2);
echo "Success!<br>";
flush();
//-----------------Create RPints User--------------------------
echo "Creating RPints database user...";
flush();
$con=mysqli_connect($servername,"root",$rootpass);
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "GRANT ALL ON *.* TO '" . $dbuser . "'@'" . $servername . "' IDENTIFIED BY '" . $dbpass1 . "' WITH GRANT OPTION;";
$result = mysqli_query($con,$sql);
mysqli_close($con);
echo "Success!<br>";
flush();
//-----------------Run The Schema File-------------------------
echo "Running Database Script...";
flush();
$dbms_schema = "../../sql/schema.sql";
$sql_query = @fread(@fopen($dbms_schema, 'r'), @filesize($dbms_schema)) or die('Cannot find SQL schema file. ');
$sql_query = remove_remarks($sql_query);
$sql_query = remove_comments($sql_query);
$sql_query = split_sql_file($sql_query, ';');
mysql_connect($servername,'root',$rootpass) or die('error connection');
$i=1;
foreach($sql_query as $sql){
//echo $i++;
//echo " ";
//echo $sql;
//echo "<br>";
mysql_query($sql) or die('error in query');
}
echo "Success!<br>";
flush();
//-----------------Add the admin user to the Users DB----------
echo "Adding new admin user...";
flush();
$con=mysqli_connect($servername,"root",$rootpass,"raspberrypints");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$currentdate = Date('Y-m-d H:i:s');
$sql = "INSERT INTO users (username, password, name, email, createdDate, modifiedDate) VALUES ('" . $adminuser . "','" . $adminhash . "','" . $adminname . "','" . $adminemail . "','" . $currentdate . "','" . $currentdate . "');";
$result = mysqli_query($con,$sql);
mysqli_close($con);
echo "Success!<br>";
flush();
//-----------------Delete the index.html page, if it exists -----------------
$index = '../../index.html';
echo "Deleting default Apache index...";
flush();
if (file_exists($index)) {
unlink($index);
echo "Success! <br>";
}
else
echo "File already deleted <br>";
flush();
//-----------------Load the sample data if requested-----------
if(!empty($_POST['sampledata']))
{
echo "Adding sample data...";
flush();
$dbms_schema = "../../sql/test_data.sql";
$sql_query = @fread(@fopen($dbms_schema, 'r'), @filesize($dbms_schema)) or die('Cannot find SQL schema file. ');
$sql_query = remove_remarks($sql_query);
$sql_query = remove_comments($sql_query);
$sql_query = split_sql_file($sql_query, ';');
mysql_connect($servername,'root',$rootpass) or die('error connection');
$i=1;
foreach($sql_query as $sql){
//echo $i++;
//echo " ";
mysql_query($sql) or die('error in query');
}
echo "Success!<br>";
flush();
}
}
if ($action != 'remove')
{
##TODO## Add better error handling before showing the Success message
echo '<br /><br /><br /><h3> Congratulations! Your Raspberry Pints has been setup successfully.<br />';
echo 'Click for - <a href="../../index.php">Tap List</a><br />';
echo 'Click for - <a href="../../admin/index.php">Administration </a><br />';
}
?>
</body>
</html>