1
0
mirror of https://github.com/pi-hole/pi-hole synced 2025-01-24 06:50:57 +00:00

Merge pull request #2790 from mmotti/tidy/query

Small changes to regexp querying
This commit is contained in:
Mark Drobnak 2019-06-13 20:32:42 -04:00 committed by GitHub
commit 67dda9c8bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -133,31 +133,36 @@ scanDatabaseTable "${domainQuery}" "whitelist" "${exact}"
scanDatabaseTable "${domainQuery}" "blacklist" "${exact}" scanDatabaseTable "${domainQuery}" "blacklist" "${exact}"
# Scan Regex table # Scan Regex table
mapfile -t regexlist <<< "$(sqlite3 "${gravityDBfile}" "SELECT domain FROM vw_regex" 2> /dev/null)" mapfile -t regexList < <(sqlite3 "${gravityDBfile}" "SELECT domain FROM vw_regex" 2> /dev/null)
# Split results over new line and store in a string
# ready for processing
str_regexlist=$(IFS=$'\n'; echo "${regexlist[*]}")
# If there are regexps in the DB
if [[ -n "${str_regexlist}" ]]; then
# Return any regexps that match the domainQuery
mapfile -t results <<< "$(scanList "${domainQuery}" "${str_regexlist}" "regex")"
# If there are matches to the domain query # If we have regexps to process
if [[ -n "${results[*]}" ]]; then if [[ "${#regexList[@]}" -ne 0 ]]; then
# Form output strings # Split regexps over a new line
str="${matchType^} found in ${COL_BOLD}Regex list${COL_NC}" str_regexList=$(printf '%s\n' "${regexList[@]}")
result="${COL_BOLD}$(IFS=$'\n'; echo "${results[*]}")${COL_NC}" # Check domainQuery against regexps
mapfile -t regexMatches < <(scanList "${domainQuery}" "${str_regexList}" "regex")
if [[ -z "${blockpage}" ]]; then # If there were regex matches
wcMatch=true if [[ "${#regexMatches[@]}" -ne 0 ]]; then
echo " $str" # Split matching regexps over a new line
fi str_regexMatches=$(printf '%s\n' "${regexMatches[@]}")
# Form a "matched" message
case "${blockpage}" in str_message="${matchType^} found in ${COL_BOLD}Regex list${COL_NC}"
true ) echo "π Regex list"; exit 0;; # Form a "results" message
* ) awk '{print " "$0}' <<< "${result}";; str_result="${COL_BOLD}${str_regexMatches}${COL_NC}"
esac # If we are displaying more than just the source of the block
fi if [[ -z "${blockpage}" ]]; then
# Set the wildcard match flag
wcMatch=true
# Echo the "matched" message, indented by one space
echo " ${str_message}"
# Echo the "results" message, each line indented by three spaces
# shellcheck disable=SC2001
echo "${str_result}" | sed 's/^/ /'
else
echo "π Regex list"
exit 0
fi
fi
fi fi
# Get version sorted *.domains filenames (without dir path) # Get version sorted *.domains filenames (without dir path)