commit 3309431ac70816d5d35090fafc747bbf5374fef1
Author: lolcat
Date: Thu Mar 21 00:19:41 2024 -0400
first commit
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..748d906
--- /dev/null
+++ b/README.md
@@ -0,0 +1,24 @@
+# Renadexer
+
+A no-bullshit solution to list your files! Have you ever looked at apache2's directory listing feature and went
+>damn, I really want to load and search this list of 100k+ files and folders without killing Firefox
+
+Look no further!!
+
+## Features
+- Configurable pagination
+- Configurable search function with AND, OR and Regex PCRE modes
+- Configurable MOTD
+- Mimetype detection using magic bytes
+- Seek videos, pause downloads and transfer large files with little memory consumption
+- Lighter than your average 2009 anorexic altgirl
+- Absolutely horrible URL scheme
+
+## Installation
+Requires PHP 8. Drag `listdir.php` on any server that supports PHP. Change the variables at the top of the file and you're set!!
+
+## Singular piece of shit screenshot
+![screenshot](https://i.imgur.com/Q9X9SZ1.png)
+
+## License
+Do whatever the fuck you want license (WTFPL)
diff --git a/listdir.php b/listdir.php
new file mode 100644
index 0000000..419aa48
--- /dev/null
+++ b/listdir.php
@@ -0,0 +1,464 @@
+' .
+ '' .
+ '' .
+ '' . $title . '' .
+ '' .
+ '' .
+ '' . $title . '
' .
+ '' . $text . '
' .
+ '
' .
+ $motd .
+ '' .
+ '';
+ die();
+}
+
+function do_filesize($path, $is_dir){
+
+ if($is_dir){
+
+ return null;
+ }
+
+ $filesize = filesize($path);
+
+ if($filesize === 0){
+
+ echo "0.00 B";
+ }
+
+ $s = ["B", "KB", "MB", "GB", "TB", "PB"];
+ $e = floor(log($filesize, 1024));
+
+ return round($filesize / pow(1024, $e), 2) . " " . $s[$e];
+}
+
+function do_header($title, $search, $check, $is_search, $script_name, $up){
+
+ echo
+ '' .
+ '' .
+ '' .
+ '' . $title . '' .
+ '' .
+ '' .
+ '' . $title . '
' .
+ '
' .
+ ($is_search === true ? '< Go back to index
' : "") .
+ ($up !== false ? '^ Go up
' : "") .
+ '' .
+ '' .
+ ($is_search === false ? ' | ' : "") .
+ '' .
+ 'type' .
+ ' | ' .
+ '' .
+ 'name' .
+ ' | ' .
+ '' .
+ 'size' .
+ ' | ' .
+ ($is_search === false ? ' | ' : "") .
+ '
' .
+ '' .
+ '
| ' .
+ '
';
+
+}
+
+// handle search
+if(isset($_GET["query"])){
+
+ $query =
+ (
+ isset($_GET["query"]) &&
+ !empty(trim($_GET["query"])) &&
+ is_string($_GET["query"])
+ ) ? trim($_GET["query"]) : false;
+
+ $filter =
+ (
+ isset($_GET["filter"]) &&
+ (
+ $_GET["filter"] == "and" ||
+ $_GET["filter"] == "or" ||
+ $_GET["filter"] == "pcre"
+ )
+ ) ? $_GET["filter"] : "and";
+
+ $folder_base_strlen = strlen($folder_base);
+
+ if($query === false){
+
+ do_error(
+ 400,
+ "Search query is empty",
+ "You need to search for something you dumb shit!",
+ $motd,
+ $script_name
+ );
+ }
+
+ $query_escaped = htmlspecialchars($query);
+
+ do_header("search results for "" . $query_escaped . """, $query_escaped, $filter, true, $script_name, false);
+
+ // prepare search cmp
+ $query_arr =
+ explode(
+ " ",
+ preg_replace(
+ '/ +/',
+ " ",
+ $query
+ )
+ );
+
+ $dir_iterator = new RecursiveDirectoryIterator($folder_base, FilesystemIterator::SKIP_DOTS);
+ $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST);
+
+ $matches = 0;
+ while(true){
+
+ $iterator->next();
+
+ if(!$iterator->valid()){
+
+ break;
+ }
+
+ $filename = $iterator->getFilename();
+
+ switch($filter){
+
+ case "and":
+ $check = true;
+ foreach($query_arr as $q){
+
+ if(stripos($filename, $q) === false){
+
+ $check = false;
+ break;
+ }
+ }
+ break;
+
+ case "or":
+ $check = false;
+ foreach($query_arr as $q){
+
+ if(stripos($filename, $q) !== false){
+
+ $check = true;
+ break;
+ }
+ }
+ break;
+
+ case "pcre":
+ $match = preg_match($query, $filename);
+
+ if($match === false){
+
+ if(preg_last_error() !== PREG_NO_ERROR){
+
+ // regex error
+ echo
+ 'RegEx error: ' . preg_last_error_msg() . ' |
|
' .
+ '
' .
+ $motd .
+ '' .
+ '';
+ die();
+ }
+
+ continue 2;
+ }elseif($match === 1){
+
+ $check = true;
+ }else{
+
+ $check = false;
+ }
+ break;
+ }
+
+ if($check){
+
+ $matches++;
+ $internal_path = $iterator->getPath() . "/" . $filename;
+ $fullpath =
+ substr_replace(
+ $internal_path,
+ "",
+ 0,
+ $folder_base_strlen
+ );
+
+ $is_dir = is_dir($internal_path);
+
+ echo
+ '' .
+ '' . ($is_dir ? "<DIR>" : "<FILE>") . ' | ' .
+ '' .
+ '' .
+ htmlspecialchars(
+ $filename
+ ) .
+ '' .
+ ' | ' .
+ '' . do_filesize($internal_path, $is_dir) . ' | ' .
+ '
';
+ }
+
+ if($matches === $max_results){
+
+ break;
+ }
+ }
+
+ // pagination
+ echo
+ '
|
' .
+ 'Found ' . $matches . ' matches (max=' . $max_results . ') | ' .
+ '
' .
+ $motd .
+ '