-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.php
More file actions
78 lines (68 loc) · 2.93 KB
/
setup.php
File metadata and controls
78 lines (68 loc) · 2.93 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
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="/res/style.css?<?php echo rand(0, 99); ?>">
<div class="container">
<div class="jumbotron">
<h1 class="display-3">Setup</h1>
<?php
$setup = true;
include("config.php");
if(!$setup) die("Setup is disabled. Please set setup to true in your setup.php.");
$databaseHostname = null;
$databaseUsername = null;
$databasePassword = null;
$databaseName = null;
$configFile = file("config.php");
foreach($configFile as $line) {
if(strpos($line, "const databaseHostname =") !== false) {
$databaseHostname = explode('"', $line)[1];
}
if(strpos($line, "const databaseUsername =") !== false) {
$databaseUsername = explode('"', $line)[1];
}
if(strpos($line, "const databasePassword =") !== false) {
$databasePassword = explode('"', $line)[1];
}
if(strpos($line, "const databaseName =") !== false) {
$databaseName = explode('"', $line)[1];
}
}
function fillUpDatabaseWithStuff($host, $user, $pass, $name) {
$connection = mysqli_connect($host, $user, $pass, $name);
$filename = 'geekstats.sql';
echo "$host $user $pass $name";
if(!$connection) die("There was an error connecting..?");
$op_data = '';
$lines = file($filename);
foreach ($lines as $line)
{
if (substr($line, 0, 2) == '--' || $line == '')
{
continue;
}
$op_data .= $line;
if (substr(trim($line), -1, 1) == ';')
{
mysqli_query($connection, $op_data);
$op_data = '';
}
}
if(unlink("geekstats.sql")) {
$fileDeleted = true;
} else {
$fileDeleted = false;
}
die("Database has been successfully created! You can now go to <a class='btn btn-primary' href='/'>geekstats</a>.");
}
$connection = mysqli_connect($databaseHostname, $databaseUsername, $databasePassword, $databaseName);
if(!$connection) {
die("There was an error attempting to connect to the database. Please make sure you've populated config.php correctly.");
}
$q = mysqli_query($connection, "select * from members");
if($q) {
die("It looks like a database already exists.. please reset the '$databaseName' database before running this setup.");
}
if(isset($_GET["setup"])) {
fillUpDatabaseWithStuff($databaseHostname, $databaseUsername, $databasePassword, $databaseName);
}
?>
<p>Looks like everything is configured correctly. Once you're ready, hit <a class="btn btn-primary" href="?setup">this button</a> to setup the database.