diff --git a/advanced/index.php b/advanced/index.php
index d0c5fc5d..3b320a3f 100644
--- a/advanced/index.php
+++ b/advanced/index.php
@@ -11,15 +11,6 @@ $serverName = htmlspecialchars($_SERVER["SERVER_NAME"]);
// Remove external ipv6 brackets if any
$serverName = preg_replace('/^\[(.*)\]$/', '${1}', $serverName);
-if (!is_file("/etc/pihole/setupVars.conf"))
- die("[ERROR] File not found: /etc/pihole/setupVars.conf
");
-
-// Get values from setupVars.conf
-$setupVars = parse_ini_file("/etc/pihole/setupVars.conf");
-$svPasswd = !empty($setupVars["WEBPASSWORD"]);
-$svEmail = (!empty($setupVars["ADMIN_EMAIL"]) && filter_var($setupVars["ADMIN_EMAIL"], FILTER_VALIDATE_EMAIL)) ? $setupVars["ADMIN_EMAIL"] : "";
-unset($setupVars);
-
// Set landing page location, found within /var/www/html/
$landPage = "../landing.php";
@@ -34,21 +25,6 @@ if (!empty($_SERVER["FQDN"])) {
array_push($authorizedHosts, $_SERVER["VIRTUAL_HOST"]);
}
-// Set which extension types render as Block Page (Including "" for index.ext)
-$validExtTypes = array("asp", "htm", "html", "php", "rss", "xml", "");
-
-// Get extension of current URL
-$currentUrlExt = pathinfo($_SERVER["REQUEST_URI"], PATHINFO_EXTENSION);
-
-// Set mobile friendly viewport
-$viewPort = '';
-
-// Set response header
-function setHeader($type = "x") {
- header("X-Pi-hole: A black hole for Internet advertisements.");
- if (isset($type) && $type === "js") header("Content-Type: application/javascript");
-}
-
// Determine block page type
if ($serverName === "pi.hole"
|| (!empty($_SERVER["VIRTUAL_HOST"]) && $serverName === $_SERVER["VIRTUAL_HOST"])) {
@@ -71,325 +47,26 @@ if ($serverName === "pi.hole"
- $viewPort
+
● $serverName
-
-
+
+
-
+
+
+ Pi-hole: Your black hole for Internet advertisements
+ Did you mean to go to the admin panel?
EOT;
exit($splashPage);
-} elseif ($currentUrlExt === "js") {
- // Serve Pi-hole JavaScript for blocked domains requesting JS
- exit(setHeader("js").'var x = "Pi-hole: A black hole for Internet advertisements."');
-} elseif (strpos($_SERVER["REQUEST_URI"], "?") !== FALSE && isset($_SERVER["HTTP_REFERER"])) {
- // Serve blank image upon receiving REQUEST_URI w/ query string & HTTP_REFERRER
- // e.g: An iframe of a blocked domain
- exit(setHeader().'
-
-
-
-
-
-
-
- ');
-} elseif (!in_array($currentUrlExt, $validExtTypes) || substr_count($_SERVER["REQUEST_URI"], "?")) {
- // Serve SVG upon receiving non $validExtTypes URL extension or query string
- // e.g: Not an iframe of a blocked domain, such as when browsing to a file/query directly
- // QoL addition: Allow the SVG to be clicked on in order to quickly show the full Block Page
- $blockImg = '
-
- ';
- exit(setHeader()."
-
-
-
- $viewPort
-
- $blockImg
- ");
}
-/* Start processing Block Page from here */
+exit(header("HTTP/1.1 404 Not Found"));
-// Define admin email address text based off $svEmail presence
-$bpAskAdmin = !empty($svEmail) ? '' : "";
-
-// Get possible non-standard location of FTL's database
-$FTLsettings = parse_ini_file("/etc/pihole/pihole-FTL.conf");
-if (isset($FTLsettings["GRAVITYDB"])) {
- $gravityDBFile = $FTLsettings["GRAVITYDB"];
-} else {
- $gravityDBFile = "/etc/pihole/gravity.db";
-}
-
-// Connect to gravity.db
-try {
- $db = new SQLite3($gravityDBFile, SQLITE3_OPEN_READONLY);
-} catch (Exception $exception) {
- die("[ERROR]: Failed to connect to gravity.db");
-}
-
-// Get all adlist addresses
-$adlistResults = $db->query("SELECT address FROM vw_adlist");
-$adlistsUrls = array();
-while ($row = $adlistResults->fetchArray()) {
- array_push($adlistsUrls, $row[0]);
-}
-
-if (empty($adlistsUrls))
- die("[ERROR]: There are no adlists enabled");
-
-// Get total number of blocklists (Including Whitelist, Blacklist & Wildcard lists)
-$adlistsCount = count($adlistsUrls) + 3;
-
-// Set query timeout
-ini_set("default_socket_timeout", 3);
-
-// Logic for querying blocklists
-function queryAds($serverName) {
- // Determine the time it takes while querying adlists
- $preQueryTime = microtime(true)-$_SERVER["REQUEST_TIME_FLOAT"];
- $queryAdsURL = sprintf(
- "http://127.0.0.1:%s/admin/scripts/pi-hole/php/queryads.php?domain=%s&bp",
- $_SERVER["SERVER_PORT"],
- $serverName
- );
- $queryAds = file($queryAdsURL, FILE_IGNORE_NEW_LINES);
- $queryAds = array_values(array_filter(preg_replace("/data:\s+/", "", $queryAds)));
- $queryTime = sprintf("%.0f", (microtime(true)-$_SERVER["REQUEST_TIME_FLOAT"]) - $preQueryTime);
-
- // Exception Handling
- try {
- // Define Exceptions
- if (strpos($queryAds[0], "No exact results") !== FALSE) {
- // Return "none" into $queryAds array
- return array("0" => "none");
- } else if ($queryTime >= ini_get("default_socket_timeout")) {
- // Connection Timeout
- throw new Exception ("Connection timeout (".ini_get("default_socket_timeout")."s)");
- } elseif (!strpos($queryAds[0], ".") !== false) {
- // Unknown $queryAds output
- throw new Exception ("Unhandled error message ($queryAds[0]
)");
- }
- return $queryAds;
- } catch (Exception $e) {
- // Return exception as array
- return array("0" => "error", "1" => $e->getMessage());
- }
-}
-
-// Get results of queryads.php exact search
-$queryAds = queryAds($serverName);
-
-// Pass error through to Block Page
-if ($queryAds[0] === "error")
- die("[ERROR]: Unable to parse results from queryads.php: ".$queryAds[1]."
");
-
-// Count total number of matching blocklists
-$featuredTotal = count($queryAds);
-
-// Place results into key => value array
-$queryResults = null;
-foreach ($queryAds as $str) {
- $value = explode(" ", $str);
- @$queryResults[$value[0]] .= "$value[1]";
-}
-
-// Determine if domain has been blacklisted, whitelisted, wildcarded or CNAME blocked
-if (strpos($queryAds[0], "blacklist") !== FALSE) {
- $notableFlagClass = "blacklist";
- $adlistsUrls = array("π" => substr($queryAds[0], 2));
-} elseif (strpos($queryAds[0], "whitelist") !== FALSE) {
- $notableFlagClass = "noblock";
- $adlistsUrls = array("π" => substr($queryAds[0], 2));
- $wlInfo = "recentwl";
-} elseif (strpos($queryAds[0], "wildcard") !== FALSE) {
- $notableFlagClass = "wildcard";
- $adlistsUrls = array("π" => substr($queryAds[0], 2));
-} elseif ($queryAds[0] === "none") {
- $featuredTotal = "0";
- $notableFlagClass = "noblock";
-
- // QoL addition: Determine appropriate info message if CNAME exists
- // Suggests to the user that $serverName has a CNAME (alias) that may be blocked
- $dnsRecord = dns_get_record("$serverName")[0];
- if (array_key_exists("target", $dnsRecord)) {
- $wlInfo = $dnsRecord['target'];
- } else {
- $wlInfo = "unknown";
- }
-}
-
-// Set #bpOutput notification
-$wlOutputClass = (isset($wlInfo) && $wlInfo === "recentwl") ? $wlInfo : "hidden";
-$wlOutput = (isset($wlInfo) && $wlInfo !== "recentwl") ? "$wlInfo" : "";
-
-// Get Pi-hole Core version
-$phVersion = exec("cd /etc/.pihole/ && git describe --long --tags");
-
-// Print $execTime on development branches
-// Testing for - is marginally faster than "git rev-parse --abbrev-ref HEAD"
-if (explode("-", $phVersion)[1] != "0")
- $execTime = microtime(true)-$_SERVER["REQUEST_TIME_FLOAT"];
-
-// Please Note: Text is added via CSS to allow an admin to provide a localized
-// language without the need to edit this file
-
-setHeader();
?>
-
-
-
-
-
- =$viewPort ?>
-
-
-
-
- ● =$serverName ?>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Open Source Ad Blocker
- Designed for Raspberry Pi
-
-
-
-
-
-
-
-
-
-
-
- =$wlOutput ?>
-
-
-
-
- =$bpAskAdmin ?>
-
-
-
-
=$featuredTotal ?>=$adlistsCount ?>
-
0) foreach ($queryResults as $num => $value) { echo "[$num]:$adlistsUrls[$num]\n"; } ?>
-
-
-
-
-
-
-
-
-
-
diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh
index 2e86f024..d219c2c8 100755
--- a/automated install/basic-install.sh
+++ b/automated install/basic-install.sh
@@ -74,7 +74,7 @@ PI_HOLE_FILES=(chronometer list piholeDebug piholeLogFlush setupLCD update versi
PI_HOLE_INSTALL_DIR="/opt/pihole"
PI_HOLE_CONFIG_DIR="/etc/pihole"
PI_HOLE_BIN_DIR="/usr/local/bin"
-PI_HOLE_BLOCKPAGE_DIR="${webroot}/pihole"
+PI_HOLE_404_DIR="${webroot}/pihole"
if [ -z "$useUpdateVars" ]; then
useUpdateVars=false
fi
@@ -1571,18 +1571,18 @@ install_dependent_packages() {
# Install the Web interface dashboard
installPiholeWeb() {
- printf "\\n %b Installing blocking page...\\n" "${INFO}"
+ printf "\\n %b Installing 404 page...\\n" "${INFO}"
- local str="Creating directory for blocking page, and copying files"
+ local str="Creating directory for 404 page, and copying files"
printf " %b %s..." "${INFO}" "${str}"
- # Install the directory,
- install -d -m 0755 ${PI_HOLE_BLOCKPAGE_DIR}
- # and the blockpage
- install -D -m 644 ${PI_HOLE_LOCAL_REPO}/advanced/{index,blockingpage}.* ${PI_HOLE_BLOCKPAGE_DIR}/
+ # Install the directory
+ install -d -m 0755 ${PI_HOLE_404_DIR}
+ # and the 404 handler
+ install -D -m 644 ${PI_HOLE_LOCAL_REPO}/advanced/index.php ${PI_HOLE_404_DIR}/
# Remove superseded file
- if [[ -e "${PI_HOLE_BLOCKPAGE_DIR}/index.js" ]]; then
- rm "${PI_HOLE_BLOCKPAGE_DIR}/index.js"
+ if [[ -e "${PI_HOLE_404_DIR}/index.js" ]]; then
+ rm "${PI_HOLE_404_DIR}/index.js"
fi
printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}"
diff --git a/test/test_automated_install.py b/test/test_automated_install.py
index 37ebdad2..28d84350 100644
--- a/test/test_automated_install.py
+++ b/test/test_automated_install.py
@@ -112,9 +112,9 @@ def test_installPiholeWeb_fresh_install_no_errors(Pihole):
source /opt/pihole/basic-install.sh
installPiholeWeb
''')
- expected_stdout = info_box + ' Installing blocking page...'
+ expected_stdout = info_box + ' Installing 404 page...'
assert expected_stdout in installWeb.stdout
- expected_stdout = tick_box + (' Creating directory for blocking page, '
+ expected_stdout = tick_box + (' Creating directory for 404 page, '
'and copying files')
assert expected_stdout in installWeb.stdout
expected_stdout = info_box + ' Backing up index.lighttpd.html'
@@ -126,7 +126,6 @@ def test_installPiholeWeb_fresh_install_no_errors(Pihole):
assert expected_stdout in installWeb.stdout
web_directory = Pihole.run('ls -r /var/www/html/pihole').stdout
assert 'index.php' in web_directory
- assert 'blockingpage.css' in web_directory
def test_update_package_cache_success_no_errors(Pihole):