From 3b79b7eb6034eacd58001b7fc82f63d067c1f7a6 Mon Sep 17 00:00:00 2001 From: "codeberg.org" Date: Mon, 11 May 2020 09:06:23 +0200 Subject: [PATCH] - var/www/pages/index.php : try adding .html suffix for incomplete URIs --- var/www/pages/index.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/var/www/pages/index.php b/var/www/pages/index.php index 40e5e62..43454d4 100644 --- a/var/www/pages/index.php +++ b/var/www/pages/index.php @@ -97,13 +97,18 @@ if (array_key_exists($ext, $mime_types)) { $command = "sh -c \"cd '$git_root' && /usr/bin/git show 'master:$file_url'\""; exec($command . " > /dev/null", $output, $retval); if ($retval != 0) { - # Render user-provided 404.html if exists, generic 404 message if not: - http_response_code(404); - header("Content-Type: text/html"); - $command = "sh -c \"cd '$git_root' && /usr/bin/git show 'master:404.html'\""; + # Try adding '.html' suffix, if this does not work either, report error + $command = "sh -c \"cd '$git_root' && /usr/bin/git show 'master:$file_url.html'\""; exec($command . " > /dev/null", $output, $retval); - if ($retval != 0) - send_response(404 , "no such file in repo: '" . htmlspecialchars($file_url) . "'"); + header("Content-Type: text/html"); + if ($retval != 0) { + # Render user-provided 404.html if exists, generic 404 message if not: + http_response_code(404); + $command = "sh -c \"cd '$git_root' && /usr/bin/git show 'master:404.html'\""; + exec($command . " > /dev/null", $output, $retval); + if ($retval != 0) + send_response(404 , "no such file in repo: '" . htmlspecialchars($file_url) . "'"); + } } ## If we could directly exec+echo raw output from above, we wouldn't need to execute command twice: