From f09c1663508aceca758a39a1912c549fa6339042 Mon Sep 17 00:00:00 2001 From: DL6ER <dl6er@dl6er.de> Date: Tue, 28 Mar 2017 23:02:00 +0100 Subject: [PATCH] Improve Error 404 page behavior --- advanced/index.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/advanced/index.php b/advanced/index.php index 4cce2857..830ff4f5 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -1,15 +1,31 @@ <?php /* Detailed Pi-Hole Block Page: Show "Website Blocked" if user browses to site, but not to image/file requests based on the work of WaLLy3K for DietPi & Pi-Hole */ +function validIP($address){ + if (preg_match('/[.:0]/', $address) && !preg_match('/[1-9a-f]/', $address)) { + // Test if address contains either `:` or `0` but not 1-9 or a-f + return false; + } + return !filter_var($address, FILTER_VALIDATE_IP) === false; +} + $uri = escapeshellcmd($_SERVER['REQUEST_URI']); $serverName = escapeshellcmd($_SERVER['SERVER_NAME']); // Retrieve server URI extension (EG: jpg, exe, php) +ini_set('pcre.recursion_limit',100); $uriExt = pathinfo($uri, PATHINFO_EXTENSION); // Define which URL extensions get rendered as "Website Blocked" $webExt = array('asp', 'htm', 'html', 'php', 'rss', 'xml'); +// Immediately quit since we didn't block this page (the IP address or pi.hole is explicitly requested) +if(validIP($serverName) || $serverName === "pi.hole") +{ + http_response_code(404); + die(); +} + if(in_array($uriExt, $webExt) || empty($uriExt)) { // Requested resource has an extension listed in $webExt