From 3643b79b4b02fb0d1ee781be062d42f2e9513b6f Mon Sep 17 00:00:00 2001 From: lolcat Date: Thu, 21 Mar 2024 10:39:48 -0400 Subject: [PATCH] make urls more readable --- listdir.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/listdir.php b/listdir.php index 43b2f4e..4412086 100644 --- a/listdir.php +++ b/listdir.php @@ -8,6 +8,13 @@ $max_results = 100; // will break; once we reach limit, -1 for no limit $motd = "get fucked"; $script_name = "listdir.php"; +function encode_path($path){ + + return implode("/", array_map(function($v){ + return urlencode($v); + }, explode("/", $path))); +} + function do_error($code, $title, $text, $motd, $script_name){ http_response_code($code); @@ -179,7 +186,7 @@ if(isset($_GET["query"])){ break; case "pcre": - $match = preg_match($query, $filename); + $match = @preg_match($query, $filename); if($match === false){ @@ -224,7 +231,7 @@ if(isset($_GET["query"])){ '' . '' . ($is_dir ? "<DIR>" : "<FILE>") . '' . '' . - '' . + '' . htmlspecialchars( $filename ) . @@ -321,7 +328,7 @@ if(is_dir($realpath)){ $up = explode("/", $relative_path); unset($up[count($up) - 1]); - $up = $script_name . "?path=" . urlencode(implode("/", $up)); + $up = $script_name . "?path=" . encode_path(implode("/", $up)); } do_header("index of " . $relative_path, "", "and", false, "", $up); @@ -342,7 +349,7 @@ if(is_dir($realpath)){ '' . '' . ($is_dir ? "<DIR>" : "<FILE>") . '' . '' . - '' . + '' . htmlspecialchars( $filename ) . @@ -367,7 +374,7 @@ if(is_dir($realpath)){ echo '' . - '<PREV>' . + '<PREV>' . ''; }else{ @@ -382,7 +389,7 @@ if(is_dir($realpath)){ echo '' . - '<NEXT>' . + '<NEXT>' . ''; }else{