mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-12-25 06:10:20 +00:00
Tidy regexp queries
Signed-off-by: MMotti <matthew.w.motti@gmail.com>
This commit is contained in:
parent
b0c5dcf42f
commit
785f1fedd9
1 changed files with 29 additions and 24 deletions
|
@ -133,30 +133,35 @@ 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 there were regex matches
|
||||||
|
if [[ "${#regexMatches[@]}" -ne 0 ]]; then
|
||||||
|
# Split matching regexps over a new line
|
||||||
|
str_regexMatches=$(printf '%s\n' "${regexMatches[@]}")
|
||||||
|
# Form a "matched" message
|
||||||
|
str_message="${matchType^} found in ${COL_BOLD}Regex list${COL_NC}"
|
||||||
|
# Form a "results" message
|
||||||
|
str_result="${COL_BOLD}${str_regexMatches}${COL_NC}"
|
||||||
|
|
||||||
if [[ -z "${blockpage}" ]]; then
|
if [[ -z "${blockpage}" ]]; then
|
||||||
|
# Set the wildcard match flag
|
||||||
wcMatch=true
|
wcMatch=true
|
||||||
echo " $str"
|
# Echo the "matched" message, indented by one space
|
||||||
|
echo " ${str_message}"
|
||||||
|
# Echo the "results" message, each line indented by three spaces
|
||||||
|
echo "${str_result}" | sed 's/^/ /'
|
||||||
|
else
|
||||||
|
echo "π Regex list"
|
||||||
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case "${blockpage}" in
|
|
||||||
true ) echo "π Regex list"; exit 0;;
|
|
||||||
* ) awk '{print " "$0}' <<< "${result}";;
|
|
||||||
esac
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue