-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.php
84 lines (71 loc) · 2.55 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
<?php
if (!isset($_POST) || !isset($_POST['db_name']) || !isset($_POST['db_user'])) {
if (!file_exists("config.php")) {
include "includes/install.inc.php";
} else {
include "includes/ready.inc.php";
}
exit;
}
$secret_key = md5(microtime().rand());
$replace = array(
'<DB_NAME>' => '"' . $_POST["db_name"] . '"',
'<DB_HOST>' => '"' . $_POST["db_host"] . '"',
'<DB_PASS>' => '"' . $_POST["db_pass"] . '"',
'<DB_USER>' => '"' . $_POST["db_user"] . '"',
'<UPLOAD_FOLDER>' => '"' . addslashes($_POST["upload_folder"]) . '"',
'<SECRET_KEY>' => '"' . $secret_key . '"'
);
$config_string = file_get_contents("config.tpl");
$config_string = str_replace(array_keys($replace), array_values($replace), $config_string);
file_put_contents("config.php", $config_string);
include "config.php";
include "includes/header.inc.php";
require 'vendor/autoload.php';
echo '<div class="container mt-5 mb-5">';
$url = "mongodb://" . DB_USER . ":" . DB_PASS . "@" . DB_HOST;
try {
$client = new MongoDB\Client($url);
} catch (Exception $e) {
http_response_code(500);
echo "Error: Failed to create connection to the MongoDB server, here is why:\n";
echo $e->getMessage();
exit;
}
try {
$db = $client->{DB_NAME};
echo '<div class="alert alert-success" role="alert">Database Created Successfully</div>';
} catch (Exception $e) {
http_response_code(500);
echo "Error: Failed to select the database, here is why:\n";
echo $e->getMessage();
exit;
}
try {
$users = $db->users;
echo '<div class="alert alert-success" role="alert">Users Collection Created Successfully</div>';
} catch (Exception $e) {
http_response_code(500);
echo "Error: Failed to select the users collection, here is why:\n";
echo $e->getMessage();
exit;
}
try {
$saves = $db->saves;
echo '<div class="alert alert-success" role="alert">Saves Collection Created Successfully</div>';
} catch (Exception $e) {
http_response_code(500);
echo "Error: Failed to select the saves collection, here is why:\n";
echo $e->getMessage();
exit;
}
if (!file_exists(UPLOAD_FOLDER)) {
mkdir(UPLOAD_FOLDER, 0777, true);
echo '<div class="alert alert-success" role="alert">Upload Folder Created Successfully</div>';
} else {
echo '<div class="alert alert-warning" role="alert">Upload Folder Already Exists</div>';
}
echo "<p>Here is your secret key, Write it down to a paper or some sources, because you can't access this page again:</p>";
echo '<div class="card"><div class="card-body text-center"><strong>' . $secret_key . "</strong></div></div>";
echo "</div>";
include "includes/footer.inc.php";