-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
581 lines (525 loc) · 24.4 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
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
<?php
header('Content-Type: text/html; charset=utf-8');
session_start();
require_once "settings.php";
if (!isset($_SESSION["accessCode"]) || $_SESSION["accessCode"] != ACCESS_CODE) {
header("Location: login.php");
die();
}
if (!isset($_SESSION["current_folder"])) {
$_SESSION["current_folder"] = ROOT_FOLDER;
}
if ($_POST && isset($_POST["folder"])) {
$_SESSION["current_folder"] = $_SESSION["current_folder"] . $_POST["folder"] . "/";
}
//GO BACK
if (isset($_GET["goBack"])) {
if ($_GET["goBack"] == "root") {
$_SESSION["current_folder"] = ROOT_FOLDER;
} else {
$stepBack = $_GET["goBack"];
$folders = explode("/", $_SESSION["current_folder"]);
$folders = array_slice($folders, 0, count($folders) - $stepBack);
$_SESSION["current_folder"] = implode("/", $folders) . "/";
}
}
$protocol = $_SERVER["REQUEST_SCHEME"];
$host = $_SERVER["HTTP_HOST"];
$serverFolder = str_replace(SERVER_ROOT, "", $_SESSION["current_folder"]);
$webUrl = $protocol . "://" . $host . "/" . $serverFolder;
echo "<script>const currentFolder = '". $_SESSION["current_folder"] ."'; </script>";
echo "<script>const webUrl = '" . $webUrl . "'; </script>";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo APP_NAME; ?></title>
<meta name="color-scheme" content="light dark">
<meta name="robots" content="noindex" />
<link rel="icon" type="image/png" href="<?php echo FAVICON_LOCATION; ?>">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-dark-5@1.1.3/dist/css/bootstrap-nightfall.min.css" rel="stylesheet" media="(prefers-color-scheme: dark)">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.9.1/font/bootstrap-icons.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="partials/js/setup.js"></script>
<script src="partials/js/fileInfo.js"></script>
<link rel="stylesheet" href="partials/css/folders.css">
</head>
<body class="d-flex flex-column min-vh-100">
<header class="mt-3 mb-3">
<div class="row">
<div class="col-md-6">
<h1><?php echo APP_NAME; ?></h1>
</div>
<div class="col-md-6 text-end">
<a href="login.php?logout" class="btn btn-danger">Logout</a>
</div>
</div>
</header>
<main class="mb-4">
<div class="row">
<div class="col-sm-9">
<?php
if (ACCESS_CODE == "") {
echo "<div class='alert alert-danger mb-5' role='alert'>Access Code is not set. Set it in settings.php and refresh this page.</div>";
}
if (ACCESS_CODE == "12345") {
echo "<div class='alert alert-danger mb-5' role='alert'>You are using your default Access Code. You should change it in settings.php.</div>";
}
echo messageChecker();
?>
<div class="card">
<div class="card-body">
<div class="row card-title">
<div class="col-sm-9">
<?php
echo generatePath();
?>
</div>
<div class="col-sm-3 text-end mt-1 toolbar">
<i class="bi bi-upload mt-2 mx-2 uploadButton"></i>
<i class="bi bi-folder-plus mt-2 mx-2 addFolderButton"></i>
<i class="bi bi-arrow-clockwise mt-2 mx-2 refreshButton"></i>
</div>
</div>
<div>
<div class="row mt-3">
<?php
echo getFolders();
echo getFiles();
?>
</div>
</div>
</div>
</div>
</div>
<div class="col-sm-3 data">
<div class="card">
<div class="card-body selectedInfo">
<h4 class="card-title">Selected file info:</h4>
<div>
</div>
</div>
</div>
</div>
</div>
</main>
<div class="modal fade" id="addFolderModal">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Create Folder in this directory</h4>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<form action="api.php" method="post">
<div class="form-group">
<label for="newFolderName">Folder name:</label>
<input type="text" class="form-control mt-2" id="newFolderName" name="newFolderName" placeholder="Folder name" required>
</div>
<div class="text-end mt-3">
<button type="submit" class="btn btn-primary mt-3">Create Folder</button>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="modal fade" id="renameFolder">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Rename Folder</h4>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<form action="api.php" method="post">
<input type="hidden" class="form-control" id="renameOldName" name="renameOldName" placeholder="Folder name" required>
<div class="form-group">
<label for="renameNewFolderName">New Folder name:</label>
<input type="text" class="form-control mt-2" id="renameNewFolderName" name="renameNewFolderName" placeholder="Folder name" required>
</div>
<div class="text-end mt-3">
<button type="submit" class="btn btn-primary mt-3">Rename Folder</button>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="modal fade" id="deleteFolder">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Delete Folder</h4>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<p>Do you really want to delete folder <strong></strong>?</p>
<form action="api.php" method="post">
<input type="hidden" class="form-control" id="deleteFolderName" name="deleteFolderName" placeholder="Folder name" required>
<div class="text-end mt-3">
<button type="submit" class="btn btn-danger mt-3">Delete Folder</button>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="modal fade" id="renameFile">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Rename File</h4>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<form action="api.php" method="post">
<input type="hidden" class="form-control" id="renameOldName" name="renameOldName" placeholder="File name" required>
<div class="form-group">
<label for="renameNewFileName">New File name:</label>
<input type="text" class="form-control mt-2" id="renameNewFileName" name="renameNewFileName" placeholder="File name" required>
</div>
<div class="text-end mt-3">
<button type="submit" class="btn btn-primary mt-3">Rename Folder</button>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="modal fade" id="deleteFile">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Delete File</h4>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<p>Do you really want to delete file <strong></strong>?</p>
<form action="api.php" method="post">
<input type="hidden" class="form-control" id="deleteFileName" name="deleteFileName" placeholder="File name" required>
<div class="text-end mt-3">
<button type="submit" class="btn btn-danger mt-3">Delete File</button>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="modal fade" id="uploadFile">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Upload File</h4>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<form action="api.php" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="uploadFile">Select file(s) to upload (max: <?php echo ini_get('upload_max_filesize') ?>B):</label>
<input type="file" class="form-control mt-2" id="uploadFile" name="uploadFile[]" multiple="multiple" required>
</div>
<div class="form-check mt-3">
<label class="form-check-label" for="uploadFileOverwrite">Overwrite file(s) if exists</label>
<input class="form-check-input" type="checkbox" id="uploadFileOverwrite" name="uploadFileOverwrite">
</div>
<div class="text-end mt-3">
<button type="submit" class="btn btn-primary mt-3">Upload File(s)</button>
</div>
</form>
</div>
</div>
</div>
</div>
<footer class="bg-dark text-lg-start mt-auto pt-2 pb-3">
<div class="row">
<div class="col text-start pt-3 customMessage">
<h4><?php echo FOOTER_MESSAGE; ?></h4>
</div>
<div class="col text-end">
<h4>This site is powered by <a href="https://github.com/K-cermak/Enplated-Mirror" target="_blank">Enplated Mirror</a> v1.0.</h4>
<h4>Developed by <a href="https://k-cermak.com" target="_blank">Karlosoft Group</a>.</h4>
</div>
</div>
</footer>
<?php
function generatePath() {
//count / in root folder
$count = substr_count(ROOT_FOLDER, "/");
//split $_SESSION["current_folder"] into array
$path_array = explode("/", $_SESSION["current_folder"]);
$path_array_length = count($path_array);
$path_string = '<a href="?goBack=root"><button type="button" class="btn btn-secondary">' . DISK_NAME . '</button></a> / ';
for ($i = $count; $i < $path_array_length; $i++) {
if ($path_array[$i] != "") {
if ($i == $path_array_length - 2) {
$path_string .= '<button type="button" class="btn btn-secondary" disabled>' . $path_array[$i] . '</button> /';
} else {
$path_string .= '<a href="?goBack=' . ($path_array_length - $i - 1) . '"><button type="button" class="btn btn-secondary">' . $path_array[$i] . '</button></a> / ';
}
}
}
return $path_string;
}
function getFolders() {
$folders = array();
$files = scandir($_SESSION["current_folder"]);
foreach ($files as $file) {
if ($file != "." && $file != ".." && is_dir($_SESSION["current_folder"]."/".$file)) {
array_push($folders, $file);
}
}
//convert array to string
$foldersString = "";
foreach ($folders as $folder) {
if ($folder != "." && $folder != "..") {
$foldersString .= '
<div class="card text-center folderDataFolder m-1" style="width: 8rem;">
<img class="card-img-top mx-auto" src="partials/icons/folder.svg" alt="Folder icon" style="max-width:4rem;">
<div class="card-body">
<h6>'. $folder . '</h6>
</div>
<form method="POST">
<input type="hidden" name="folder" value="'.$folder.'">
<button type="submit" class="btn btn-secondary submitButton" style="display:none;">Submit</button>
</form>
</div>
';
}
}
return $foldersString;
}
function getFiles() {
$files = array();
$files = scandir($_SESSION["current_folder"]);
$filesString = "";
foreach ($files as $file) {
if ($file != "." && $file != ".." && !is_dir($_SESSION["current_folder"]."/".$file)) {
$filesString .= '
<div class="card text-center folderDataFile m-1" style="width: 8rem;">
<img class="card-img-top mx-auto" src="' . generateFileIcon($file) . '" alt="File icon" style="max-width:4rem;">
<div class="card-body">
<h6>'. $file . '</h6>
</div>
</div>
';
}
}
return $filesString;
}
function generateFileIcon($file) {
$folder = "partials/icons/";
$extension = pathinfo($file, PATHINFO_EXTENSION);
do {
if ($extension == "") {
$extension = "folder";
break;
}
$extension = strtolower($extension);
if ($extension == "jpg" || $extension == "jpeg" || $extension == "png" || $extension == "gif") {
$folder .= "image.svg";
break;
}
if ($extension == "svg") {
$folder .= "svg.svg";
break;
}
if ($extension == "mp3" || $extension == "wav" || $extension == "flac") {
$folder .= "audio.svg";
break;
}
if ($extension == "mp4" || $extension == "avi" || $extension == "mkv") {
$folder .= "video.svg";
break;
}
if ($extension == "pdf") {
$folder .= "pdf.svg";
break;
}
if ($extension == "doc" || $extension == "docx") {
$folder .= "word.svg";
break;
}
if ($extension == "xls" || $extension == "xlsx") {
$folder .= "excel.svg";
break;
}
if ($extension == "ppt" || $extension == "pptx") {
$folder .= "powerpoint.svg";
break;
}
if ($extension == "zip" || $extension == "rar") {
$folder .= "zip.svg";
break;
}
if ($extension == "txt") {
$folder .= "txt.svg";
break;
}
if ($extension == "html") {
$folder .= "html.svg";
break;
}
if ($extension == "js") {
$folder .= "js.svg";
break;
}
if ($extension == "css") {
$folder .= "css.svg";
break;
}
if ($extension == "xml") {
$folder .= "xml.svg";
break;
}
if ($extension == "sql") {
$folder .= "sql.svg";
break;
}
if ($extension == "php") {
$folder .= "php.svg";
break;
}
if ($extension == "py") {
$folder .= "python.svg";
break;
}
if ($extension == "rb") {
$folder .= "ruby.svg";
break;
}
if ($extension == "java") {
$folder .= "java.svg";
break;
}
if ($extension == "c") {
$folder .= "c.svg";
break;
}
if ($extension == "cpp") {
$folder .= "cpp.svg";
break;
}
if ($extension == "cs") {
$folder .= "cs.svg";
break;
}
if ($extension == "h") {
$folder .= "h.svg";
break;
}
if ($extension == "hpp") {
$folder .= "hpp.svg";
break;
}
if ($extension == "json") {
$folder .= "json.svg";
break;
}
$folder .= "file.svg";
} while (false);
return $folder;
}
function messageChecker() {
$message = "";
if (isset($_GET["folderCreate"])) {
if ($_GET["folderCreate"] == "ok") {
$message .= generateMessages("success", "Folder created successfully.");
}
if ($_GET["folderCreate"] == "error") {
$message .= generateMessages("warning", "Unknown error when creating folder.");
}
if ($_GET["folderCreate"] == "exist") {
$message .= generateMessages("warning", "Error: Folder already exists.");
}
if ($_GET["folderCreate"] == "prohibitedChars") {
$message .= generateMessages("warning", "Error: Prohibited characters in folder name or probibited name.");
}
}
if (isset($_GET["folderRename"])) {
if ($_GET["folderRename"] == "ok") {
$message .= generateMessages("success", "Folder renamed successfully.");
}
if ($_GET["folderRename"] == "error") {
$message .= generateMessages("warning", "Unknown error when renaming folder.");
}
if ($_GET["folderRename"] == "exist") {
$message .= generateMessages("warning", "Error: Folder already exists.");
}
if ($_GET["folderRename"] == "prohibitedChars") {
$message .= generateMessages("warning", "Error: Prohibited characters in folder name or probibited name.");
}
}
if (isset($_GET["folderDelete"])) {
if ($_GET["folderDelete"] == "ok") {
$message .= generateMessages("success", "Folder deleted successfully.");
}
if ($_GET["folderDelete"] == "error") {
$message .= generateMessages("warning", "Unknown error when deleting folder.");
}
}
if (isset($_GET["fileRename"])) {
if ($_GET["fileRename"] == "ok") {
$message .= generateMessages("success", "File renamed successfully.");
}
if ($_GET["fileRename"] == "error") {
$message .= generateMessages("warning", "Unknown error when renaming file.");
}
if ($_GET["fileRename"] == "exist") {
$message .= generateMessages("warning", "Error: File already exists.");
}
if ($_GET["fileRename"] == "prohibitedChars") {
$message .= generateMessages("warning", "Error: Prohibited characters in file name or probibited name.");
}
}
if (isset($_GET["fileDelete"])) {
if ($_GET["fileDelete"] == "ok") {
$message .= generateMessages("success", "File deleted successfully.");
}
if ($_GET["fileDelete"] == "error") {
$message .= generateMessages("warning", "Unknown error when deleting file.");
}
}
if (isset($_GET["fileUpload"])) {
$success = $_GET["success"];
$error = $_GET["error"];
$exist = $_GET["exist"];
$prohibitedChars = $_GET["prohibitedChars"];
if ($error == 0 && $exist == 0 && $prohibitedChars == 0) {
if ($success == 1) {
$message .= generateMessages("success", "1 File uploaded successfully.");
} else {
$message .= generateMessages("success", $success . " Files uploaded successfully.");
}
} else {
$subMessage = "Error when uploading files. Number of successfully uploaded files: " . $success . " / ". $success + $error + $exist + $prohibitedChars .".<br><strong>Reason:</strong><br>";
if ($error > 0) {
$subMessage .= $error . " file(s) failed to upload.<br>";
}
if ($exist > 0) {
$subMessage .= $exist . " file(s) already exist.<br>";
}
if ($prohibitedChars > 0) {
$subMessage .= $prohibitedChars . " file(s) contain prohibited characters.<br>";
}
$message .= generateMessages("warning", $subMessage);
}
}
return $message;
}
function generateMessages($type, $message) {
return '<div class="alert alert-'.$type.' alert-dismissible fade show" role="alert">
'.$message.'
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>';
}
?>
<!-- DELETE ALL PARAMS-->
<script>window.history.replaceState('', '', window.location.pathname);</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
</body>
</html>