1
0
mirror of https://github.com/pi-hole/pi-hole synced 2024-11-19 22:58:16 +00:00

Add support for regex whitelist in "pihole -q".

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER 2019-08-22 14:06:42 +02:00
parent aef7892de6
commit 42ccc1ef24
No known key found for this signature in database
GPG Key ID: FB60471F0575164A

View File

@ -128,25 +128,24 @@ scanDatabaseTable() {
done done
} }
# Scan Whitelist and Blacklist scanRegexDatabaseTable() {
scanDatabaseTable "${domainQuery}" "whitelist" "${exact}" local domain list
scanDatabaseTable "${domainQuery}" "blacklist" "${exact}" domain="${1}"
list="${2}"
# Scan Regex table mapfile -t regexList < <(sqlite3 "${gravityDBfile}" "SELECT domain FROM vw_regex_${list}" 2> /dev/null)
mapfile -t regexList < <(sqlite3 "${gravityDBfile}" "SELECT domain FROM vw_regex_blacklist" 2> /dev/null)
# If we have regexps to process # If we have regexps to process
if [[ "${#regexList[@]}" -ne 0 ]]; then if [[ "${#regexList[@]}" -ne 0 ]]; then
# Split regexps over a new line # Split regexps over a new line
str_regexList=$(printf '%s\n' "${regexList[@]}") str_regexList=$(printf '%s\n' "${regexList[@]}")
# Check domainQuery against regexps # Check domain against regexps
mapfile -t regexMatches < <(scanList "${domainQuery}" "${str_regexList}" "regex") mapfile -t regexMatches < <(scanList "${domain}" "${str_regexList}" "regex")
# If there were regex matches # If there were regex matches
if [[ "${#regexMatches[@]}" -ne 0 ]]; then if [[ "${#regexMatches[@]}" -ne 0 ]]; then
# Split matching regexps over a new line # Split matching regexps over a new line
str_regexMatches=$(printf '%s\n' "${regexMatches[@]}") str_regexMatches=$(printf '%s\n' "${regexMatches[@]}")
# Form a "matched" message # Form a "matched" message
str_message="${matchType^} found in ${COL_BOLD}Regex list${COL_NC}" str_message="${matchType^} found in ${COL_BOLD}Regex ${list}${COL_NC}"
# Form a "results" message # Form a "results" message
str_result="${COL_BOLD}${str_regexMatches}${COL_NC}" str_result="${COL_BOLD}${str_regexMatches}${COL_NC}"
# If we are displaying more than just the source of the block # If we are displaying more than just the source of the block
@ -159,11 +158,20 @@ 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 "π Regex ${list}"
exit 0 exit 0
fi fi
fi fi
fi fi
}
# Scan Whitelist and Blacklist
scanDatabaseTable "${domainQuery}" "whitelist" "${exact}"
scanDatabaseTable "${domainQuery}" "blacklist" "${exact}"
# Scan Regex table
scanRegexDatabaseTable "${domainQuery}" "whitelist"
scanRegexDatabaseTable "${domainQuery}" "blacklist"
# Get version sorted *.domains filenames (without dir path) # Get version sorted *.domains filenames (without dir path)
lists=("$(cd "$piholeDir" || exit 0; printf "%s\\n" -- *.domains | sort -V)") lists=("$(cd "$piholeDir" || exit 0; printf "%s\\n" -- *.domains | sort -V)")