-
Notifications
You must be signed in to change notification settings - Fork 2
/
Setup.php
226 lines (198 loc) · 5.5 KB
/
Setup.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
<?php
class Configurator
{
private static function CreateDatabase()
{
$SQLLink = new mysqli($_POST['DBHostname'], $_POST['DBUsername'], $_POST['DBPassword'], '', $_POST['DBPort']);
if ($SQLLink->connect_errno)
{
echo 'Failure connecting to database: ' . $SQLLink->error;
return false;
}
// Create the database
$Query = $SQLLink->query('CREATE DATABASE IF NOT EXISTS `' . $_POST['DBPluginDatabaseName'] . '`');
if (!$Query || !$SQLLink->select_db($_POST['DBPluginDatabaseName']))
{
echo 'Failure creating database: ' . $SQLLink->error;
return false;
}
// Creates the authors table
$Query = $SQLLink->query('CREATE TABLE IF NOT EXISTS Authors (
AuthorId INT AUTO_INCREMENT,
Login TEXT NOT NULL,
DisplayName TEXT,
AvatarHyperlink TEXT NOT NULL,
PRIMARY KEY (AuthorId)
)'
);
if (!$Query)
{
echo 'Failure creating the authors table: ' . $SQLLink->error;
return false;
}
// Creates the plug-in data table
$Query = $SQLLink->query('CREATE TABLE IF NOT EXISTS PluginData (
RepositoryId INT NOT NULL,
AuthorId INT NOT NULL,
DownloadCount INT NOT NULL DEFAULT 0,
UpdateHookId INT,
RepositoryName TEXT NOT NULL,
RepositoryFullName TEXT NOT NULL,
RepositoryVersion TEXT,
License TEXT,
Description TEXT,
Readme TEXT,
IconHyperlink TEXT NOT NULL,
PRIMARY KEY (RepositoryId),
FOREIGN KEY (AuthorId) REFERENCES Authors(AuthorId) ON DELETE CASCADE
)'
);
if (!$Query)
{
echo "Failure creating the plugin data table: " . $SQLLink->error;
return false;
}
// Creates the plug-in download links table
$Query = $SQLLink->query('CREATE TABLE IF NOT EXISTS DownloadHyperlinks (
LinkId INT AUTO_INCREMENT,
RepositoryId INT NOT NULL,
Name TEXT NOT NULL,
Tag TEXT NOT NULL,
Hyperlink TEXT NOT NULL,
PRIMARY KEY (LinkId),
FOREIGN KEY (RepositoryId) REFERENCES PluginData(RepositoryId) ON DELETE CASCADE
)'
);
if (!$Query)
{
echo "Failure creating the plugin data table: " . $SQLLink->error;
return false;
}
// Creates the plug-in screenshot links table
$Query = $SQLLink->query('CREATE TABLE IF NOT EXISTS ScreenshotHyperlinks (
LinkId INT AUTO_INCREMENT,
RepositoryId INT NOT NULL,
Name TEXT NOT NULL,
Hyperlink TEXT NOT NULL,
PRIMARY KEY (LinkId),
FOREIGN KEY (RepositoryId) REFERENCES PluginData(RepositoryId) ON DELETE CASCADE
)'
);
if (!$Query)
{
echo "Failure creating the plugin data table: " . $SQLLink->error;
return false;
}
// Creates the comments table
$Query = $SQLLink->query('CREATE TABLE IF NOT EXISTS Comments (
CommentId INT AUTO_INCREMENT,
RepositoryId INT NOT NULL,
Comment TEXT NOT NULL,
CreationTime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
AuthorId INT NOT NULL,
PRIMARY KEY (CommentId),
FOREIGN KEY (RepositoryId) REFERENCES PluginData(RepositoryId) ON DELETE CASCADE,
FOREIGN KEY (AuthorId) REFERENCES Authors(AuthorId) ON DELETE CASCADE
)'
);
if (!$Query)
{
echo 'Failure creating the comments table: ' . $SQLLink->error;
return false;
}
return true;
}
static function CreateDatabaseAndConfig()
{
if (Configurator::CreateDatabase())
{
$Configuration =
'[SQL]
DatabaseHostname="' . $_POST['DBHostname'] . '"
DatabasePort="' . $_POST['DBPort'] . '"
DatabaseUsername="' . $_POST['DBUsername'] . '"
DatabasePassword="' . $_POST['DBPassword'] . '"
PluginDatabaseName="' . $_POST['DBPluginDatabaseName'] . '"
[GitHub]
GitHubClientId="' . $_POST['GHClientID'] . '"
GitHubClientSecret="' . $_POST['GHClientSecret'] . '"';
if (!($Handle = fopen('configuration.ini', 'w')) || !fwrite($Handle, $Configuration))
{
echo "Failure writing configuration file";
return false;
}
return true;
}
return false;
}
}
if (file_exists('configuration.ini'))
{
header('Location: /');
return;
}
if (isset($_POST['Submit']))
{
if (Configurator::CreateDatabaseAndConfig())
{
header('Location: /');
return;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Plugin Repository configuration</title>
</head>
<body>
<style>
label
{
display: inline-block;
width: 170px;
text-align: right;
}
#configuration-box
{
font-family: Segoe UI, Trebuchet MS;
border: solid thin black;
border-radius: 5px;
padding: 10px;
padding-top: 0px;
width: 350px;
height: 270px;
top: calc(50% - 200px / 2);
left: calc(50% - 350px / 2);
position: absolute;
}
#button-enclosure
{
text-align: center;
margin-top: 10px;
}
</style>
<div id="configuration-box">
<h2>Configuration</h2>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<label>Database hostname: </label>
<input autofocus required placeholder="localhost" type="text" name="DBHostname"/><br/>
<label>Database port: </label>
<input autofocus required placeholder="3306" type="text" name="DBPort"/><br/>
<label>Database username: </label>
<input type="text" required name="DBUsername"/><br/>
<label>Database password: </label>
<input type="text" name="DBPassword"/><br/>
<label>Plugin database name:</label>
<input type="text" required name="DBPluginDatabaseName"/><br/>
<label>GitHub Application ID:</label>
<input type="text" required name="GHClientID"/><br/>
<label>GitHub Client Secret:</label>
<input type="text" required name="GHClientSecret"/><br/>
<div id="button-enclosure">
<input type="Submit" value="Submit" name="Submit"/>
</div>
</form>
</div>
</body>
</html>