-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
97 lines (92 loc) · 2.65 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
<?php
$dir = $_GET["d"] ?? '';
if(is_dir('.\\' . $dir))
{
$files = scandir('.\\' . $dir);
unset($files[array_search('.', $files)]);
unset($files[array_search('..', $files)]);
$files = array_values($files);
}
else
{
$files = [];
}
$script = $_SERVER['SCRIPT_NAME'];
$path = preg_replace('/^(.*?\/.*)(\?.*?)$/','$1',"http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
usort($files, function ($a, $b) use ($dir)
{
if (is_dir($dir.$a) && !is_dir($dir.$b))
{
return -1;
}
else if (is_dir($dir.$b) && !is_dir($dir.$a))
{
return 1;
}
else
{
$regex = '/(?:(?:\b(?:a|an|the)\b)|[^a-z0-9.]|(?: {2,}))+/i';
return strnatcasecmp(preg_replace($regex, ' ', $a),preg_replace($regex, ' ', $b));
}
});
?>
<html>
<head>
<title>Broken Spine<?php echo (($dir)?' - ' . $dir:''); ?></title>
<link rel="stylesheet" href="/index.css">
</head>
<body>
<div>
<div class="line big">
<?php
$back = preg_replace('/(.*\/).*\//','$1',$dir);
if ($back == '')
{
echo '<span class="link">Broken Spine</span><span>/</span>';
}
else if ($back == $dir)
{
echo '<span class="link"><a href="/">Back</a></span><span>/' . $dir . '</span>';
}
else
{
echo '<span class="link"><a href="/' . $back . '">Back</a></span><span>/' . $dir . '</span>';
}
?>
<span class="info"><a href="/tree.php?d=<?php echo $dir; ?>">Tree</a> - <a href="/opds.php?d=<?php echo $dir; ?>">OPDS</a> - <form action="/search.php" style="display: inline;"><input type="hidden" name="d" value="<?php echo $dir; ?>"><input type="text" name="s" placeholder="Search" style="position: relative;"></form></span>
</div>
<?php
for ($i = 0; $i < count($files); $i++)
{
$name = htmlspecialchars(preg_replace('/(.*)(?:\..*)/','$1',$files[$i]));
$ext = preg_replace('/.*(?:\.(.*))/','$1',$files[$i]);
$url = preg_replace('/(.*\/).*/','$1',$path) . rawurlencode($files[$i]);
switch ($ext)
{
case 'htaccess':
case 'git':
case 'gitignore':
case 'ico':
case 'php':
case 'css':
continue 2;
}
echo '<div class="line big">';
if (!is_dir($dir.$files[$i]))
{
echo '<span class="link"><a href="' . $url .'">' . $name . '</a></span>';
echo '<span class="info">' . $ext . '</span>';
}
else
{
echo '<span class="link"><a href="' . rawurlencode($files[$i]) . '/">' . htmlspecialchars($files[$i]) . "/</a></span>";
echo '<span class="info">/' . htmlspecialchars($dir . $files[$i]) . '/</span>';
}
echo '<br>';
echo '</div>';
}
?>
</div>
</div>
</body>
</html>