-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
102 lines (88 loc) · 3.66 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Files</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Bootstrap Icons -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet">
<style>
footer {
position: fixed;
bottom: 0;
width: 100%;
}
</style>
</head>
<body>
<header class="bg-dark text-white p-3 text-center">
<h1>Files: <?php echo htmlspecialchars($_SERVER['REQUEST_URI']); ?></h1>
</header>
<div class="container">
<h2 class="my-4">Directory Listing</h2>
<?php
$baseDirectory = realpath('.');
$requestUri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$currentDirectory = realpath($baseDirectory . ($requestUri === '/' ? '' : $requestUri));
$ignoreList = array(".", "..", "awstatsicons", "index.php", "icon", "awstats-icon", "index.html", ".htaccess", ".user.ini");
if (strpos($currentDirectory, $baseDirectory) !== 0 || !is_dir($currentDirectory)) {
echo '<div class="alert alert-danger">Folder not exist.</div>';
exit;
}
$breadcrumbs = [];
$path = '';
$parts = explode('/', trim($requestUri, '/'));
foreach ($parts as $part) {
$path .= '/' . $part;
$breadcrumbs[] = [
'name' => $part,
'path' => htmlspecialchars($path)
];
}
$domain = $_SERVER['HTTP_HOST'];
echo '<nav aria-label="breadcrumb">';
echo '<ol class="breadcrumb">';
echo '<li class="breadcrumb-item"><a href="/">'.$domain.'</a></li>';
foreach ($breadcrumbs as $breadcrumb) {
echo '<li class="breadcrumb-item"><a href="' . $breadcrumb['path'] . '">' . $breadcrumb['name'] . '</a></li>';
}
echo '</ol>';
echo '</nav>';
$parentDirectory = dirname($requestUri);
if ($parentDirectory !== '/') {
$parentUrl = $parentDirectory === '.' ? '/' : $parentDirectory;
echo '<a href="' . htmlspecialchars($parentUrl) . '" class="btn btn-secondary mb-3"><i class="bi bi-arrow-left"></i> Go Back</a>';
}
if ($dir_handle = opendir($currentDirectory)) {
echo '<div class="list-group">';
while (($file = readdir($dir_handle)) !== false) {
if (!in_array($file, $ignoreList)) {
$filePath = $requestUri . '/' . $file;
$filePath = str_replace('//', '/', $filePath);
if (is_dir($currentDirectory . '/' . $file)) {
echo '<a href="' . htmlspecialchars($filePath) . '" class="list-group-item list-group-item-action list-group-item-primary">
<i class="bi bi-folder"></i> ' . htmlspecialchars($file) . '
</a>';
} else {
echo '<a href="' . htmlspecialchars($filePath) . '" download class="list-group-item list-group-item-action">
<i class="bi bi-file-earmark"></i> ' . htmlspecialchars($file) . '
</a>';
}
}
}
echo '</div>';
closedir($dir_handle);
} else {
echo '<div class="alert alert-danger">Error.</div>';
}
?>
</div>
<footer class="bg-dark text-white text-center py-3 fixed-bottom">
<p><a href="https://github.com/oytunistrator/php-dirlister/" class="text-white">PHP DirLister</a> © <?php echo date("Y"); ?></p>
</footer>
<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>