Merge pull request #2831 from pi-hole/fix/block-page-adlists

Fix block page errors due to gravity DB and changes to queryAds
This commit is contained in:
Mark Drobnak 2019-07-20 14:55:37 -04:00 committed by GitHub
commit ab3f6dfcc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 11 deletions

View file

@ -115,7 +115,9 @@ scanDatabaseTable() {
wbMatch=true wbMatch=true
# Print table name # Print table name
echo " ${matchType^} found in ${COL_BOLD}${table^}${COL_NC}" if [[ -z "${blockpage}" ]]; then
echo " ${matchType^} found in ${COL_BOLD}${table^}${COL_NC}"
fi
# Loop over results and print them # Loop over results and print them
mapfile -t results <<< "${result}" mapfile -t results <<< "${result}"
@ -159,7 +161,7 @@ if [[ "${#regexList[@]}" -ne 0 ]]; then
# shellcheck disable=SC2001 # shellcheck disable=SC2001
echo "${str_result}" | sed 's/^/ /' echo "${str_result}" | sed 's/^/ /'
else else
echo Regex list" echo .wildcard"
exit 0 exit 0
fi fi
fi fi

View file

@ -102,20 +102,30 @@ if ($blocklistglob === array()) {
die("[ERROR] There are no domain lists generated lists within <code>/etc/pihole/</code>! Please update gravity by running <code>pihole -g</code>, or repair Pi-hole using <code>pihole -r</code>."); die("[ERROR] There are no domain lists generated lists within <code>/etc/pihole/</code>! Please update gravity by running <code>pihole -g</code>, or repair Pi-hole using <code>pihole -r</code>.");
} }
// Set location of adlists file // Get possible non-standard location of FTL's database
if (is_file("/etc/pihole/adlists.list")) { $FTLsettings = parse_ini_file("/etc/pihole/pihole-FTL.conf");
$adLists = "/etc/pihole/adlists.list"; if (isset($FTLsettings["GRAVITYDB"])) {
} elseif (is_file("/etc/pihole/adlists.default")) { $gravityDBFile = $FTLsettings["GRAVITYDB"];
$adLists = "/etc/pihole/adlists.default";
} else { } else {
die("[ERROR] File not found: <code>/etc/pihole/adlists.list</code>"); $gravityDBFile = "/etc/pihole/gravity.db";
} }
// Get all URLs starting with "http" or "www" from adlists and re-index array numerically // Connect to gravity.db
$adlistsUrls = array_values(preg_grep("/(^http)|(^www)/i", file($adLists, FILE_IGNORE_NEW_LINES))); 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)) if (empty($adlistsUrls))
die("[ERROR]: There are no adlist URL's found within <code>$adLists</code>"); die("[ERROR]: There are no adlists enabled");
// Get total number of blocklists (Including Whitelist, Blacklist & Wildcard lists) // Get total number of blocklists (Including Whitelist, Blacklist & Wildcard lists)
$adlistsCount = count($adlistsUrls) + 3; $adlistsCount = count($adlistsUrls) + 3;