<?php
+/* dirlistozxa - Basic directory lister script written in PHP
+ * Copyright (C) 2023 ROllerozxa
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * This software is best enjoyed with soused herring!
+ */
+
// Configuration:
// List of filenames (and folder names) that should be ignored.
$ignore_file_list = [
- '.htaccess', '.htpasswd', // Apache junk files
- 'Thumbs.db', '.DS_Store', // OS junk files
- 'index.php', 'index.html', // Potential other index files
- '.git', 'vendor', // Dev
- 'dirlistozxa.php', '.dirlistozxa', '.thumbs', 'gen-thumbs' // dirlistozxa
+ 'dirlistozxa.php', 'gen-thumbs' // dirlistozxa
];
// ================
// nginx with default configuration (merge_slashes) doesn't actually need this.
$_SERVER['REQUEST_URI'] = str_replace('../', '', $_SERVER['REQUEST_URI']);
+// Allow spaces and other heretical stuff in folder names.
+$_SERVER['REQUEST_URI'] = urldecode($_SERVER['REQUEST_URI']);
+
$folder = str_replace('?'.$_SERVER['QUERY_STRING'], '', $_SERVER['REQUEST_URI']);
$path = $_SERVER['DOCUMENT_ROOT'].$folder;
};
return sprintf(
- '<tr><td class="tum"><img src="%s" loading="lazy"></td><td><a href="%s">%s</a></td><td>%s</td><td class="r">%s</td></tr>',
- $img, $name, $name, $date, $size);
+ '<tr>
+ <td class="tum"><a href="%s"><img src="%s" loading="lazy"></td>
+ <td><a href="%s">%s</a></td>
+ <td>%s</td><td class="r">%s</td>
+ </tr>',
+ $name, $img, $name, $name, $date, $size);
}
function build_blocks($items) {
$objects = [ 'directories' => [], 'files' => [] ];
foreach ($items as $item) {
- if ($item == '..' || $item == '.' || in_array($item, $ignore_file_list)) continue;
+ if (in_array($item, $ignore_file_list) || str_starts_with($item, '.')) continue;
if (is_dir($path.$item))
$objects['directories'][$item] = $item;