-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstaller.php
More file actions
executable file
·141 lines (124 loc) · 3.57 KB
/
Copy pathinstaller.php
File metadata and controls
executable file
·141 lines (124 loc) · 3.57 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
<?php
/*
* Prepare this configuration file.
* This file will include global variables, and
* a boolean representing if the config has already been run or not (should only ever run once).
*/
$config = "config.php";
$fh = fopen($config, 'w') or die("ERROR: config.php does not exist.");
/*
* Gather data from the config form.
*/
$mysqlUsername = $_POST['mysqlUsername'];
$mysqlPassword = $_POST['mysqlPassword'];
$mysqlDB = $_POST['mysqlDB'];
$mysqlPort = $_POST['mysqlPort'];
$adminUsername = $_POST['adminUsername'];
$adminPassword = $_POST['adminPassword'];
$adminPassword2 = $_POST['adminPassword2'];
$adminEmail = $_POST['adminEmail'];
$forumName = $_POST['forumName'];
/*
* Validate the inputs.
*/
if ($adminPassword != $adminPassword2) {
echo "ERROR: Passwords don't match!";
die;
} else {
$adminPassword = sha1($adminPassword); // encrypt the password
}
/*
* Connect to the database using the credentials provided.
*/
$servername = getenv('IP');
$username = $mysqlUsername;
$password = $mysqlPassword;
$database = $mysqlDB;
$dbport = $mysqlPort;
$database = new mysqli($servername, $username, $password, $database, $dbport);
if ($database->connect_error) {
echo "ERROR: Failed to connect to MySQL";
die;
}
/*
* Set up the database tables.
*/
$database->query("CREATE TABLE moderators (
moderatorId INT,
PRIMARY KEY(moderatorId))");
$database->query("CREATE TABLE threads (
dateCreated DATE NOT NULL,
likes INT NOT NULL,
threadId INT AUTO_INCREMENT,
title VARCHAR(45) NOT NULL,
content VARCHAR(2500) NOT NULL,
userId INT NOT NULL,
moderatorId INT REFERENCES Moderator(moderatorId),
PRIMARY KEY(threadId)
)");
$database->query("CREATE TABLE users (
userId INT AUTO_INCREMENT,
username VARCHAR(20) NOT NULL,
password VARCHAR(250) NOT NULL,
email VARCHAR(30) NOT NULL,
avatar VARCHAR(250) DEFAULT '/avatar.png',
description VARCHAR(250),
admin BOOLEAN NOT NULL DEFAULT 0,
moderator BOOLEAN NOT NULL DEFAULT 0,
PRIMARY KEY(userId)
)");
$database->query("CREATE TABLE threadComments (
commentId INT AUTO_INCREMENT,
content VARCHAR(200) NOT NULL,
title VARCHAR(45) NOT NULL,
threadId INT REFERENCES Thread(threadId),
userId INT REFERENCES User(userId),
postDate DATE NOT NULL,
PRIMARY KEY(commentId)
)");
$database->query("CREATE TABLE messages (
messageId INT,
content VARCHAR(60),
fromUserId INT REFERENCES User(userId),
toUserId INT REFERENCES User(userId),
PRIMARY KEY(messageId)
)");
/*
* Generate admin user using provided credentials.
*/
$cmd = "INSERT INTO users
VALUES(0 , '".$adminUsername."', '".$adminPassword."', '".$adminEmail."','empty','empty', 1, 0)";
$database->query($cmd);
/*
* Configure config.php to reflect global data
* and provide confirmation that initial config was successful.
*/
$isConfigured = "true";
$label1 = "forumName";
$label2 = "isConfigured";
$label3 = "mysqlUsername";
$label4 = "mysqlPassword";
$label5 = "mysqlDB";
$label6 = "mysqlPort";
$var_str1 = var_export($forumName, true);
$var_str2 = var_export($isConfigured, true);
$var_str3 = var_export($mysqlUsername, true);
$var_str4 = var_export($mysqlPassword, true);
$var_str5 = var_export($mysqlDB, true);
$var_str6 = var_export($mysqlPort, true);
$configData = "
<?php\n\n
$$label1 = $var_str1;\n\n
$$label2 = $var_str2;\n\n
$$label3 = $var_str3;\n\n
$$label4 = $var_str4;\n\n
$$label5 = $var_str5;\n\n
$$label6 = $var_str6;\n\n
?>";
fwrite($fh, $configData);
fclose($fh);
/*
* Once successfully configured, redirect to the root URL.
*/
?>
<meta http-equiv="refresh" content="0; url=/" />