-
Notifications
You must be signed in to change notification settings - Fork 1
/
admin.php
384 lines (305 loc) · 11.1 KB
/
admin.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
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Title bar -->
<title>Sixthworks</title>
<link rel="icon" href="media/sixthworks_transparent.ico" type="image/x-icon">
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<!-- CSS -->
<link rel="stylesheet" type="text/css" href="css/main.css">
<!-- JS -->
<script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<?php
// Account manager
include __DIR__ . '/backend/utils/accounts.php';
// Cookies
session_start();
// Data
if (isset($_SESSION['logged_in']) && $_SESSION['logged_in'])
{
$USERNAME = (isset($_SESSION['username']) ? $_SESSION['username'] : '');
$PASSWORD = (isset($_SESSION['password']) ? $_SESSION['password'] : '');
}
else
{
$USERNAME = '';
$PASSWORD = '';
}
// Necessary
$GOTO = (isset($_GET['u']) ? $_GET['u'] : '');
$OFFSET = (isset($_GET['o']) ? $_GET['o'] : '');
// 0 by default
if (empty($OFFSET))
{
$OFFSET = 0;
}
// Error
$ERROR = "<div class='container-fluid mt-3'><img src='media/sixthworks_evil.png' class='mb-2'><p><strong>Oh no</strong>, you have encountered a secret page! Now, consider <strong>going away</strong> from here, dark place.<br><br>For real, please go away. This is an administration panel for <strong>managing</strong> this service...</p></div>";
// Username/password not specified?
if (empty($USERNAME) || empty($PASSWORD))
{
die($ERROR);
}
// Verify
$ROW = DB::queryFirstRow("SELECT * FROM accounts WHERE username=%s", $USERNAME);
// Invalid?
if ($ROW == null)
{
die($ERROR);
}
// Moderator
$ADMIN = $ROW['moderator'];
// Is moderator?
if (empty($ADMIN) === true || $ADMIN == 0)
{
die($ERROR);
}
?>
<div class="container-fluid pt-3">
<?php
// All users
if (empty($GOTO))
{
// 25 rows per page.
$MAXIMUM_AMOUNT = 25;
if ($OFFSET >= 0)
{
// User count
$COUNT = 0;
// Maximum
$AMOUNT = $OFFSET + $MAXIMUM_AMOUNT;
// Range
$RESULTS = DB::query("SELECT username FROM accounts ORDER BY created DESC LIMIT %d, %d", $OFFSET, $AMOUNT - 1);
if ($RESULTS != null)
{
// Tables
?>
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Username</th>
<th scope="col">Email</th>
<th scope="col">Created</th>
<th scope="col">Verified</th>
<th scope="col">Privelege</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php
foreach ($RESULTS as $RESULT)
{
// Row
$ROW_RESULTS = DB::queryFirstRow("SELECT * FROM accounts WHERE username=%s", $RESULT['username']);
// Start
echo "<tr>";
// Count
$READABLE = $COUNT + 1;
echo "<th scope='row'>$READABLE</th>";
// Username
$USERNAME = $ROW_RESULTS['username'];
{
// Fancy
$STR = $ACCOUNT_MANAGER->has_sharing_suspicion($ROW_RESULTS) ? "<span class='text-warning'>$USERNAME</span>" : "$USERNAME";
// Print
echo "<td>$STR</td>";
}
// Username
$EMAIL = $ROW_RESULTS['email'];
{
// Print
echo "<td>$EMAIL</td>";
}
// Created
$DATE = $ROW_RESULTS['created'];
{
// Print
echo "<td>$DATE</td>";
}
// Verified
$VERIFIED = $ROW_RESULTS['verified'] === '1' ? 'Yes' : 'No';
{
// Fancy
$STR = $ACCOUNT_MANAGER->has_old_unverified($ROW_RESULTS) && $VERIFIED == false ? "<span class='text-danger'>Expiration</span>" : "$VERIFIED";
// Print
echo "<td>$STR</td>";
}
// Privelege
$ADMIN = $ROW_RESULTS['moderator'] > 0 ? 'moderator' : 'user';
{
// Print
echo "<td>$ADMIN</td>";
}
// View
$STR = "<a href='?u=$USERNAME'>View</a>";
{
// Print
echo "<td>$STR</td>";
}
// End
echo "</tr>";
$COUNT++;
}
?>
</tbody>
</table>
<?php
}
// Next page
if ($COUNT == 0)
{
echo "<p>No users here, unfortunately.</p>";
}
else
{
echo "<a href='?o=$AMOUNT' class='btn btn-primary' role='button'>Next page</a>";
}
}
}
else
{
// Row of selected user
$ROW = DB::queryFirstRow("SELECT * FROM accounts WHERE username=%s", $GOTO);
if ($ROW != null)
{
// Div begin
echo "<div class='mb-2'>";
// HWID Logs
echo "<h2 class='mb-3'>HWID logs</h2>";
{
// List
$LIST = $ROW['hwid_logs'];
// Decoded
$LIST = json_decode($LIST, true);
if ($LIST != null)
{
// Sorting by date
$SORTED = [];
foreach ($LIST as $LOG)
{
// Date
$DATE = $LOG['time'];
array_push($SORTED, $DATE);
}
// Sort in descending order
rsort($SORTED);
// Dummy
$ARRAY = [];
foreach ($SORTED as $DATE)
{
foreach ($LIST as $LOG)
{
// Data
$DECODED_HWID = $LOG['hwid'];
$DECODED_DATE = $LOG['time'];
// Push log
if ($DATE == $DECODED_DATE)
{
$MINI = array($DECODED_HWID, $DECODED_DATE);
array_push($ARRAY, $MINI);
}
}
}
// Replace sorted with dummy
$SORTED = $ARRAY;
// Erase dummy from memory
$ARRAY = null;
foreach ($SORTED as $LOG)
{
// Data
$HWID = $LOG[0];
$DATE = $LOG[1];
// Format
$CLASS = new DateTime("@$DATE");
$FORMATTED = $CLASS->format('Y-m-d H:i:s');
echo "$FORMATTED / <strong>$HWID</strong><br>";
}
}
else
{
echo "<p>Not available</p>";
}
}
// Div end
echo "</div>";
// Div begin
echo "<div class='mb-2'>";
// IP Logs
echo "<h2 class='mb-3'>IP logs</h2>";
{
// List
$LIST = $ROW['ip_logs'];
// Decoded
$LIST = json_decode($LIST, true);
if ($LIST != null)
{
// Sorting by date
$SORTED = [];
foreach ($LIST as $LOG)
{
// Date
$DATE = $LOG['time'];
array_push($SORTED, $DATE);
}
// Sort in descending order
rsort($SORTED);
// Dummy
$ARRAY = [];
foreach ($SORTED as $DATE)
{
foreach ($LIST as $LOG)
{
// Data
$DECODED_USER_AGENT = $LOG['user_agent'];
$DECODED_DATE = $LOG['time'];
$DECODED_IP = $LOG['ip'];
// Push log
if ($DATE == $DECODED_DATE)
{
$MINI = array($DECODED_DATE, $DECODED_IP, $DECODED_USER_AGENT);
array_push($ARRAY, $MINI);
}
}
}
// Replace sorted with dummy
$SORTED = $ARRAY;
// Erase dummy from memory
$ARRAY = null;
foreach ($SORTED as $LOG)
{
// Data
$DATE = $LOG[0];
$IP = $LOG[1];
$USER_AGENT = empty($LOG[2]) ? "Unknown" : $LOG[2];
// Format
$CLASS = new DateTime("@$DATE");
$FORMATTED = $CLASS->format('Y-m-d H:i:s');
echo "$FORMATTED / <strong>$IP</strong> / $USER_AGENT / <a href='http://ip-api.com/json/$IP?fields=192319'>view</a><br>";
}
}
else
{
echo "<p>Not available</p>";
}
}
// Div end
echo "</div>";
}
else
{
echo "<p>User not available.</p>";
}
}
?>
</div>
</body>
</html>