-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathold_installer.php
215 lines (167 loc) · 6.96 KB
/
old_installer.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
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Installer</title>
<link rel="stylesheet" href="https://migmatos.alwaysdata.net/legacy/cdn/css/dashboard.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" />
<?php
echo file_get_contents("https://migmatos.alwaysdata.net/legacy/cdn/htmlext/loadingalert.html");
echo file_get_contents("https://migmatos.alwaysdata.net/legacy/cdn/htmlext/flayeralert.html");
?>
</head>
<style>
.songscontent {
border: 3px solid transparent;
}
.dashboard-container.gdbox-brown.songs {
margin-top: 1%;
margin-left: calc(5vw + (10vw / 1000));
margin-right: calc(5vw + (10vw / 1000));
margin-bottom: 1%;
}
</style>
<body>
<div class="dashboard-container gdbox-brown songs">
<h1 class="gdfont-Pusab normal">ObeyGDBrowser Installer</h1>
<label class="gdfont-Pusab small">Log into an administrator account in your database to install.</label>
<?php
require "./incl/lib/connection.php";
require "./incl/lib/generatePass.php";
function getLatestReleaseUrl($owner, $repo) {
$url = "https://api.github.com/repos/$owner/$repo/releases/latest";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['User-Agent: PHP']);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
if (isset($data['tag_name'])) {
return $data['tag_name'];
} else {
return false;
}
}
function downloadAndExtractRepo($repoUrl) {
$zipFile = 'repo.zip';
file_put_contents($zipFile, fopen($repoUrl, 'r'));
if (file_exists($zipFile)) {
$zip = new ZipArchive;
if ($zip->open($zipFile) === TRUE) {
$zip->extractTo('./browser/');
$firstDir = $zip->getNameIndex(0);
$zip->close();
unlink($zipFile);
return $firstDir;
} else {
return -1;
}
} else {
return -2;
}
}
function moveFilesToCurrentDirectory($sourceDir) {
$sourceDir = "browser/" . rtrim($sourceDir, '/');
$destinationDir = './browser/';
$files = scandir("./".$sourceDir);
foreach ($files as $file) {
if ($file != '.' && $file != '..') {
$sourcePath = $sourceDir . '/' . $file;
$destinationPath = $destinationDir . $file;
if (is_dir($sourcePath)) {
rename($sourcePath, $destinationPath);
} else {
copy($sourcePath, $destinationPath);
unlink($sourcePath);
}
}
}
rmdir("./".$sourceDir);
return true;
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$owner = 'MigMatos';
$repo = 'ObeyGDBrowser';
$flw = "./browser";
mkdir($flw, 0777, true) ?? rmdir($$flw) && mkdir($flw, 0777, true);
if (isset($_POST['userName']) && isset($_POST['password'])) {
$userName = $_POST['userName'];
$password = $_POST['password'];
$pass = GeneratePass::isValidUsrname($userName, $password);
if ($pass == "1") {
$stmt = $db->prepare("SELECT accountID, isAdmin FROM accounts WHERE userName LIKE :userName");
$stmt->bindParam(':userName', $userName);
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
if ($result['isAdmin'] == "1") {
$latesttag = getLatestReleaseUrl($owner, $repo);
if ($latesttag) {
echo "<script>";
echo 'changeLoadingAlert("Installing...");';
echo "</script>";
$dir = "https://codeload.github.com/MigMatos/ObeyGDBrowser/zip/refs/tags/$latesttag";
$dir = downloadAndExtractRepo($dir);
moveFilesToCurrentDirectory("./" . $dir);
unlink("./installer.php");
unlink("./README.md");
unlink("./browser/installer.php");
header("Location: ./browser/?alert=installed");
exit();
} else {
header("Location: ./installer.php?alert=1");
}
} else {
header("Location: ./installer.php?alert=2");
}
} else {
header("Location: ./installer.php?alert=3");
}
}
} else {
if ( isset($_GET["alert"] ) ) {
$num = $_GET["alert"];
if($num == 1){
echo '<script>CreateFLAlert("Error","`r0 Failed to get installation` \n Report in ObeyGDBrowser Support Server: [](https://discord.gg/EbYKSHh95B)");</script>';
}
elseif ($num == 2){
echo '<script>CreateFLAlert("Error","`r0 You are not an administrator` \n You need to be an **administrator account** to continue with the installation, if you need help join our Discord Support Server: [](https://discord.gg/EbYKSHh95B)");</script>';
}
elseif ($num == 3){
echo '<script>CreateFLAlert("Error","`r0 Error, your password or account is wrong...`");</script>';
}
}
}
?>
<br><br><br>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div>
<label class="gdfont-Pusab small" for="userName">UserName:</label><br>
<input class="gdInput text" type="text" id="userName" name="userName" required>
</div>
<div>
<label class="gdfont-Pusab small" for="password">Password:</label><br>
<input class="gdInput text" type="password" id="password" name="password" required>
</div>
<br>
<button class="gdButton" type="submit" onclick="submitForm()"><label class="gdfont-Pusab small">Install</label></button>
</form>
<br><br>
</div>
</body>
<script src="https://code.jquery.com/jquery-3.7.1.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
$("#loading-main").hide();
if ((window.location.search == "?alert=1") || (window.location.search == "?alert=2" ||(window.location.search == "?alert=3") || (window.location.search == "?alert=4"))) {
let newURLpush = window.location.href.replace(/(\?alert=1|\?alert=2|\?alert=3|\?alert=4)/g, '');
window.history.pushState(null, null, newURLpush);
}
function submitForm(){
$("#loading-main").show();
const event = new Event('initLoadingAlert');
document.dispatchEvent(event);
changeLoadingAlert("Loading...");
}
</script>
</html>