Adds 404 page

This commit is contained in:
Christophe HENRY 2021-03-09 01:21:50 +01:00
parent dcc36b1d66
commit e74beaba67
2 changed files with 34 additions and 8 deletions

1
TODO
View File

@ -1,6 +1,5 @@
* manage url encoding: The filename fetched on disk may differ from that was asked by URL.
* check /etc/passwd not accessible: Perform sanity checks against unauthorized access.
* manage 404: Display better errors.
* a way to get the source of a page, using urlrewriting
* options to activate the text decoration
* HTML caching: Nginx tries the html, if not found use this script to build it

View File

@ -13,6 +13,9 @@ define("DASHES"
);
$url = @$_REQUEST["url"];
######################################## Installation page
if (empty($url)) {
?>
@ -31,17 +34,41 @@ if (empty($url)) {
echo "</body>\n</html>\n";
die();
}
######################################## /Installation page
# Removes the trailling slash, to be sure there's not any.
$GMI_DIR = rtrim($_SERVER['DOCUMENT_ROOT'], "/");
$filePath = $GMI_DIR."/".$url;
$GMI_DIR = $_SERVER['DOCUMENT_ROOT'];
$filePath = $GMI_DIR.$url;
$fileContents = @file_get_contents($filePath);
if (!$fileContents) {
http_response_code(404);
die("404: $url");
######################################## 404 page
if (empty($fileContents)) {
http_response_code(404); ?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
<?php include("htmgem.css"); ?>
</style>
</head>
<body>
<?php
$text404 = <<<EOF
# Page non trouvée
**$url**
=> $url rééssayer ?
=> / index
EOF;
echo translateGemToHtml($text404);
echo "</body>\n</html>";
die();
}
######################################## /404 page
# Removes the Byte Order Mark
$fileContents = preg_replace("/\xEF\xBB\xBF/", "", $fileContents);