From f1733f9c5d8a798b38e372abeba30c7ddc540a87 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Thu, 4 Jul 2019 13:11:46 -0700 Subject: [PATCH] Fetch adlists for the block page from gravity.db Signed-off-by: Mcat12 --- advanced/index.php | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/advanced/index.php b/advanced/index.php index 78135e1a..b44a725d 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -111,11 +111,30 @@ if (is_file("/etc/pihole/adlists.list")) { die("[ERROR] File not found: /etc/pihole/adlists.list"); } -// Get all URLs starting with "http" or "www" from adlists and re-index array numerically -$adlistsUrls = array_values(preg_grep("/(^http)|(^www)/i", file($adLists, FILE_IGNORE_NEW_LINES))); +// 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 adlist URL's found within $adLists"); + die("[ERROR]: There are no adlists configured"); // Get total number of blocklists (Including Whitelist, Blacklist & Wildcard lists) $adlistsCount = count($adlistsUrls) + 3;