-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.php
More file actions
214 lines (191 loc) · 6.92 KB
/
index.php
File metadata and controls
214 lines (191 loc) · 6.92 KB
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
<?php
/**
* CAPYBARA INDEXING SCRIPT
* Index all of your folder with ease.
*/
/**
* Date time settings (according to your timezone)
*/
define('DATE_TIME_FORMAT', "D, j F Y - H:i:s");
//date_default_timezone_set('Asia/Jakarta');
/**
* Show the folder link, instead of using the viewer link
* if the directory have index file in it. (is recursively checked)
*/
define('AUTODETECT_INDEX', true);
/**
* The Index file direction, if you need to change the file
* name.
* Default: '/', (or change to index.php if you really worried).
*/
define('INDEX_NAME', '/');
/**
* Index file list, will be checked for each folder.
* If you have activated the AUTODETECT_INDEX, this setting
* will be crucial to detect your index file.
*/
define('AUTODETECT_INDEX_FILELIST', [
'index.html',
'index.htm',
'index.php',
'index.py'
]);
/**
* NOT ALLOWED FILE PATH (GLOBAL)
*/
define('NOT_ALLOWED_FOLDER', [
'cgi-bin',
'error_log'
]);
/**
* END OF SETTINGS, YOU CAN ENJOY YOUR DAY NOW.
*/
$_GET['q'] = isset($_GET['q'])?$_GET['q']:null;
$not_allowed_url = [
"/" => "",
"./"=> "",
"../"=>"",
];
// Query Validation
if(strpos($_GET['q'], './') || strpos($_GET['q'], '../' || $_GET['q'] == '.')){
$location = INDEX_NAME;
if($_GET['q'] == '.')
$_GET['q']='';
$location .= ltrim(str_replace(
key($not_allowed_url,
array_values($not_allowed_url),
$_SERVER['QUERY_STRING']), '/')
);
header('Location: ' . $location);
}
$checked_path = [];
function precheck($path){
global $checked_path;
if(key_exists($path, $checked_path))
return $checked_path[$path];
if($path == '/' || $path == DIRECTORY_SEPARATOR) {
$checked_path[$path] = true;
return true;
}
if(basename($path)[0] == "." ||
in_array(basename($path), NOT_ALLOWED_FOLDER) ||
is_file($path . DIRECTORY_SEPARATOR . '.noindex')) {
$checked_path[$path] = false;
return false;
}
$checked_path[$path] = precheck(dirname($path));
return $checked_path[$path];
}
function get_link($path) {
if(!is_dir("./" . $path))
return $path;
if(AUTODETECT_INDEX)
foreach(AUTODETECT_INDEX_FILELIST as $idx){
if(is_file($path . DIRECTORY_SEPARATOR . $idx))
return $path;
}
return ltrim(INDEX_NAME . '?q=' . $path);
}
// note: $path are always the full path.
$path = __DIR__;
if($_GET['q'])
$path .= DIRECTORY_SEPARATOR . $_GET['q'];
$folders = [];
$folder = array_slice(scandir($path), 2);
foreach($folder as $paths) {
if(!precheck($path . DIRECTORY_SEPARATOR . $paths))
continue;
$folders[] = (!empty($_GET['q'])?$_GET['q'] . DIRECTORY_SEPARATOR . $foldr:"") . $paths;
}
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Index of /<?= htmlentities($_GET['q']?:'') ?></title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.6.2/css/bulma.min.css">
<script defer src="https://use.fontawesome.com/releases/v5.0.0/js/all.js"></script>
</head>
<body>
<section class="hero is-dark">
<div class="hero-head">
<nav class="navbar">
<div class="container">
<div class="navbar-brand">
<a class="navbar-item" href="<?= htmlentities(INDEX_NAME) ?>">
<?= $_SERVER['HTTP_HOST'] ?>
</a>
</div>
</nav>
</div>
<div class="hero-body">
<div class="container">
<h2 class="subtitle">
/<?= htmlentities($_GET['q']?:'') ?>
</h2>
</div>
</div>
</section>
<main>
<section class="section">
<div class="container">
<div class="content">
<table class="table">
<thead>
<th width="30px"></th>
<th>Name</th>
<th>Last Modified</th>
<th>Size</th>
</thead>
<tbody>
<?php if($_GET['q'] && $_GET['q'] != '/' && $_GET['q'] != '.'): ?>
<tr>
<td><i class="fa fa-angle-up"></i></td>
<td colspan="3"><a href="<?= htmlentities(INDEX_NAME . '?q=' .
(dirname($_GET['q'])=="."?"":dirname($_GET['q']))) ?>"><i>Go Up</i></a></td>
</tr>
<?php endif; ?>
<?php
foreach($folders as $foldr):
?>
<?php if(is_dir($foldr)): ?>
<tr>
<td><i class="fa fa-folder"></i></td>
<td><a href="<?= htmlentities(get_link($foldr)) ?>"><?= htmlentities(basename($foldr)) ?></a></td>
<td><?= date(DATE_TIME_FORMAT, filemtime($foldr)) ?></td>
<td>-</td>
</tr>
<?php else: ?>
<tr>
<td><i class="fa fa-file"></i></td>
<td><a href="<?= htmlentities(get_link($foldr)) ?>"><?= htmlentities(basename($foldr)) ?></a></td>
<td><?= date(DATE_TIME_FORMAT, filemtime($foldr)) ?></td>
<td><?= filesize($foldr)?:0 ?> bytes</td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</section>
</main>
<footer class="footer">
<div class="container">
<div class="columns">
<div class="column">
<div class="content">
Indexed by <a href="https://github.com/chez14/capdex.php"><i class="fab fa-github"></i> Capdex.php</a>. <b>Special note:</b> All timezone are localized to <b><?= htmlentities(date_default_timezone_get()) ?></b>.
</div>
</div>
<div class="column has-text-right is-one-fifth">
<div class="content">
<a href="https://bulma.io"><img src="https://bulma.io/images/made-with-bulma.png" alt="Made with Bulma" width="128" height="24"></a>
</div>
</div>
</div>
</div>
</footer>
</body>
</html>