-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathindex.php
425 lines (357 loc) · 12.7 KB
/
index.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
<?php
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
include '../includes/connection.php';
include '../includes/functions.php';
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);
$uri = trim($_SERVER['REQUEST_URI'], '/');
$pieces = explode('/', $uri);
$owner = urldecode(sanitize($pieces[1]));
$server = urldecode(sanitize($pieces[2]));
if (is_null($owner) || is_null($server)) {
die("Invalid link. Link should look like https://restorecord.com/verify/{owner}/{server}");
}
premium_check($owner);
$result = mysqli_query($link, "SELECT * FROM `servers` WHERE `owner` = '$owner' AND `name` = '$server'");
if (mysqli_num_rows($result) === 0) {
$server = "Not Available";
$serverpic = "https://i.imgur.com/7kiO9No.png";
$status = "noserver"; // server not found
} else {
$status = NULL;
while ($row = mysqli_fetch_array($result)) {
$guildid = $row['guildid'];
$roleid = $row['roleid'];
$serverpic = $row['pic'];
$redirecturl = $row['redirecturl'];
$webhook = $row['webhook'];
$vpncheck = $row['vpncheck'];
$banned = $row['banned'];
}
if (!is_null($banned)) {
$_SESSION['access_token'] = NULL;
$status = "banned";
} else {
$_SESSION['server'] = $guildid;
$_SESSION['owner'] = $owner;
$_SESSION['name'] = $server;
}
}
if (session('access_token')) {
$user_check = mysqli_query($link, "SELECT * FROM `users` WHERE `username` = '$owner'");
$role = mysqli_fetch_array($user_check)["role"];
$result = mysqli_query($link, "SELECT * FROM `members` WHERE `server` = '$guildid'");
if (mysqli_num_rows($result) > 25 && $role == "free") {
$status = "needpremium";
} else {
$user = apiRequest("https://discord.com/api/users/@me");
// echo var_dump($user);
$headers = array(
'Content-Type: application/json',
'Authorization: Bot ' . $BotToken
);
$data = array(
"access_token" => session('access_token')
);
$data_string = json_encode($data);
$result = mysqli_query($link, "SELECT * FROM `blacklist` WHERE (`user` = '" . $user->id . "' OR `ip` = '" . $_SERVER['HTTP_CF_CONNECTING_IP'] . "') AND `server` = '$guildid'");
if (mysqli_num_rows($result) > 0) {
$status = "blacklisted";
} else {
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
if ($vpncheck) {
$url = "https://proxycheck.io/v2/{$ip}?key=proxyCheckKeyHere?vpn=1";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
$json = json_decode($result);
if ($json->$ip->proxy == "yes") {
$status = "vpndetect";
if (!is_null($webhook)) {
/*
WEBHOOK START
*/
$timestamp = date("c", strtotime("now"));
$json_data = json_encode([
// Embeds Array
"embeds" => [
[
// Embed Title
"title" => "Failed VPN Check",
// Embed Type
"type" => "rich",
// Timestamp of embed must be formatted as ISO8601
"timestamp" => $timestamp,
// Embed left border color in HEX
"color" => hexdec("ff0000"),
// Footer
// "footer" => [
//
// "text" => $name
//
// ],
// Additional Fields array
"fields" => [["name" => ":bust_in_silhouette: User:", "value" => "```" . $user->id . "```", "inline" => true], ["name" => ":earth_americas: Client IP:", "value" => "```" . $_SERVER["HTTP_CF_CONNECTING_IP"] . "```", "inline" => true]]
]
]
], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
$ch = curl_init($webhook);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json'
));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
curl_close($ch);
/*
WEBHOOK END
*/
}
}
}
if ($status !== "vpndetect") {
$_SESSION['userid'] = $user->id;
$url = "https://discord.com/api/guilds/{$guildid}/members/" . $user->id;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
// $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// echo var_dump($result);
// echo 'HTTP code: ' . $httpcode;
$url = "https://discord.com/api/guilds/{$guildid}/members/" . $user->id . "/roles/{$roleid}";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
// $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// echo var_dump($result);
// echo 'HTTP code: ' . $httpcode;
// mysqli_query($link, "INSERT INTO `members` (`userid`, `access_token`, `refresh_token`, `server`) VALUES ('" . $user->id . "', '" . $_SESSION['access_token'] . "', '" . $_SESSION['refresh_token'] . "', '$guildid') ON DUPLICATE KEY UPDATE `access_token` = '" . $_SESSION['access_token'] . "', `refresh_token` = '" . $_SESSION['refresh_token'] . "'");
mysqli_query($link, "REPLACE INTO `members` (`userid`, `access_token`, `refresh_token`, `server`,`ip`) VALUES ('" . $user->id . "', '" . $_SESSION['access_token'] . "', '" . $_SESSION['refresh_token'] . "', '$guildid', '$ip')");
$_SESSION['access_token'] = NULL;
$_SESSION['refresh_token'] = NULL;
if (!is_null($webhook)) {
/*
WEBHOOK START
*/
$timestamp = date("c", strtotime("now"));
$json_data = json_encode([
// Embeds Array
"embeds" => [
[
// Embed Title
"title" => "Successfully Verified",
// Embed Type
"type" => "rich",
// Timestamp of embed must be formatted as ISO8601
"timestamp" => $timestamp,
// Embed left border color in HEX
"color" => hexdec("52ef52"),
// Footer
// "footer" => [
//
// "text" => $name
//
// ],
// Additional Fields array
"fields" => [["name" => ":bust_in_silhouette: User:", "value" => "```" . $user->id . "```", "inline" => true], ["name" => ":earth_americas: Client IP:", "value" => "```" . $_SERVER["HTTP_CF_CONNECTING_IP"] . "```", "inline" => true]]
]
]
], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
$ch = curl_init($webhook);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json'
));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
curl_close($ch);
/*
WEBHOOK END
*/
}
$status = "added"; // successfully verified user
}
}
}
}
if (isset($_POST['optout'])) {
if (session('userid')) {
mysqli_query($link, "DELETE FROM `members` WHERE `userid` = '" . session('userid') . "' AND `server` = '$guildid'");
if (mysqli_affected_rows($link) != 0) {
$headers = array(
'Content-Type: application/json',
'Authorization: Bot ' . $BotToken
);
$url = "https://discord.com/api/guilds/{$guildid}/members/" . session('userid') . "/roles/{$roleid}";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
// curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
echo $result;
$status = "optedout";
if (!is_null($webhook)) {
/*
WEBHOOK START
*/
$timestamp = date("c", strtotime("now"));
$json_data = json_encode([
// Embeds Array
"embeds" => [
[
// Embed Title
"title" => "User Opted Out",
// Embed Type
"type" => "rich",
// Timestamp of embed must be formatted as ISO8601
"timestamp" => $timestamp,
// Embed left border color in HEX
"color" => hexdec("ff0000"),
// Footer
// "footer" => [
//
// "text" => $name
//
// ],
// Additional Fields array
"fields" => [["name" => ":bust_in_silhouette: User:", "value" => "```" . session('userid') . "```", "inline" => true], ["name" => ":earth_americas: Client IP:", "value" => "```" . $_SERVER["HTTP_CF_CONNECTING_IP"] . "```", "inline" => true]]
]
]
], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
$ch = curl_init($webhook);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json'
));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
curl_close($ch);
/*
WEBHOOK END
*/
}
} else {
$status = "neveroptedin";
}
} else {
$status = "notauthed";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Verify in <?php echo $server; ?></title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<link rel="icon" type="image/png" sizes="16x16" href="https://i.imgur.com/w65Dpnw.png">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<link id="mystylesheet" rel="stylesheet" type="text/css" href="../style.css">
<meta name="og:image" content="<?php echo $serverpic; ?>">
<meta name="description" content="Verify in <?php echo $server; ?> so you're added back to server if it gets raided or deleted.">
</head>
<body>
<div id="box">
<?php switch ($status) {
case 'added':
?>
<div class="alert alert-success">
<strong>Success!</strong> Successfully verified.
</div>
<?php
if (!is_null($redirecturl)) {
echo "<meta http-equiv='Refresh' Content='3;url={$redirecturl}'>";
}
break;
case 'optedout':
?>
<div class="alert alert-success">
<strong>Success!</strong> Successfully opted out from this server.
</div>
<?php
break;
case 'noserver':
?>
<div class="alert alert-danger">
<strong>Oh snap!</strong> No server found.
</div>
<?php
break;
case 'blacklisted':
?>
<div class="alert alert-danger">
<strong>Oh snap!</strong> This user is blacklisted.
</div>
<?php
break;
case 'banned':
?>
<div class="alert alert-danger">
<strong>Oh snap!</strong> This server has been banned for: <?php echo sanitize($banned); ?>
</div>
<?php
break;
case 'vpndetect':
?>
<div class="alert alert-danger">
<strong>Oh snap!</strong> Server owner has disabled VPN access, try again without VPN.
</div>
<?php
break;
case 'needpremium':
?>
<div class="alert alert-danger">
<strong>Oh snap!</strong> Server owner needs to purchase premium, he has reached 25 member limit for free users. Please tell him, thank you.
</div>
<?php
break;
case 'notauthed':
?>
<div class="alert alert-danger">
<strong>Oh snap!</strong> You need to login with discord first.
</div>
<?php
break;
case 'neveroptedin':
?>
<div class="alert alert-danger">
<strong>Oh snap!</strong> You were never opted-in.
</div>
<?php
break;
default:
break;
}
?>
<img id="server_pic" src="<?php echo $serverpic; ?>">
<h2><?php echo $server; ?></h2>
<p>Click login with Discord to be joined to server if it is ever raided or deleted. Click opt out to stop getting joined to server.</p>
<hr>
<form method="post">
<a class="btn btn-light" href="https://discord.com/api/oauth2/authorize?client_id=791106018175614988&redirect_uri=https%3A%2F%2Frestorecord.com%2Fauth%2F&response_type=code&scope=identify+guilds.join">Login With Discord</a>
<button name="optout" class="btn btn-danger">Opt Out</button>
</form>
</div>
</body>
</html>