Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/pi-hole/pi-hole.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMMotti <matthew.w.motti@gmail.com>2019-06-10 19:48:52 +0300
committerMMotti <matthew.w.motti@gmail.com>2019-06-10 19:52:58 +0300
commit785f1fedd9ade421aa923b997fe873dff171f942 (patch)
tree9c62b6b51ea0db97c04a7d92afcdc7ff7c601e26 /advanced/Scripts/query.sh
parentb0c5dcf42f4d9e1b96fe86327cd72ed5e96d3fe3 (diff)
Tidy regexp queries
Signed-off-by: MMotti <matthew.w.motti@gmail.com>
Diffstat (limited to 'advanced/Scripts/query.sh')
-rwxr-xr-xadvanced/Scripts/query.sh55
1 files changed, 30 insertions, 25 deletions
diff --git a/advanced/Scripts/query.sh b/advanced/Scripts/query.sh
index 9134dc0f..e418eecf 100755
--- a/advanced/Scripts/query.sh
+++ b/advanced/Scripts/query.sh
@@ -133,31 +133,36 @@ scanDatabaseTable "${domainQuery}" "whitelist" "${exact}"
scanDatabaseTable "${domainQuery}" "blacklist" "${exact}"
# Scan Regex table
-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 [[ -n "${results[*]}" ]]; then
- # Form output strings
- str="${matchType^} found in ${COL_BOLD}Regex list${COL_NC}"
- result="${COL_BOLD}$(IFS=$'\n'; echo "${results[*]}")${COL_NC}"
-
- if [[ -z "${blockpage}" ]]; then
- wcMatch=true
- echo " $str"
- fi
-
- case "${blockpage}" in
- true ) echo "π Regex list"; exit 0;;
- * ) awk '{print " "$0}' <<< "${result}";;
- esac
- fi
+mapfile -t regexlist < <(sqlite3 "${gravityDBfile}" "SELECT domain FROM vw_regex" 2> /dev/null)
+
+# If we have regexps to process
+if [[ "${#regexlist[@]}" -ne 0 ]]; then
+ # Split regexps over a new line
+ str_regexlist=$(printf '%s\n' "${regexlist[@]}")
+ # 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
+ # 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
+ echo "${str_result}" | sed 's/^/ /'
+ else
+ echo "π Regex list"
+ exit 0
+ fi
+
+ fi
fi
# Get version sorted *.domains filenames (without dir path)