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:
authorNiklas Elmose Andersen <mail@niklasea.dk>2019-08-26 20:05:14 +0300
committerNiklas Elmose Andersen <mail@niklasea.dk>2019-08-26 21:39:56 +0300
commit989d1aff60f92f10763bfe273d5ceddeaeab631b (patch)
tree11817d68fbdaa058bfd3ab84c4bb7df0cf6f562c /advanced/Scripts/query.sh
parent76133074d121a2a45f64b13c3998745602ef07b1 (diff)
Restore and improve 'pihole -q' matching
Removes regex lookaround which 'grep -E' does not support. Restores support for blocklists in hosts format. Simplifies domain match cleanup logic by eliminating an if-condition. Improves domain matching by eliminating commented domain names, eliminating false positives in a few edge cases. Signed-off-by: Niklas Elmose Andersen <mail@niklasea.dk>
Diffstat (limited to 'advanced/Scripts/query.sh')
-rw-r--r--advanced/Scripts/query.sh29
1 files changed, 15 insertions, 14 deletions
diff --git a/advanced/Scripts/query.sh b/advanced/Scripts/query.sh
index 69a3c7a4..123f8ea6 100644
--- a/advanced/Scripts/query.sh
+++ b/advanced/Scripts/query.sh
@@ -54,7 +54,7 @@ scanList(){
# /dev/null forces filename to be printed when only one list has been generated
# shellcheck disable=SC2086
case "${type}" in
- "exact" ) grep -i -E -l "(^|(?<!#)\\s)${domain}($|\\s|#)" ${lists} /dev/null 2>/dev/null;;
+ "exact" ) grep -i -E "(^|\\s)${domain}($|\\s|#)" ${lists} /dev/null 2>/dev/null;;
"wc" ) grep -i -o -m 1 "/${domain}/" ${lists} 2>/dev/null;;
* ) grep -i "${domain}" ${lists} /dev/null 2>/dev/null;;
esac
@@ -170,19 +170,20 @@ elif [[ -z "${all}" ]] && [[ "${#results[*]}" -ge 100 ]]; then
exit 0
fi
-# Remove unwanted content from non-exact $results
-if [[ -z "${exact}" ]]; then
- # Delete lines starting with #
- # Remove comments after domain
- # Remove hosts format IP address
- mapfile -t results <<< "$(IFS=$'\n'; sed \
- -e "/:#/d" \
- -e "s/[ \\t]#.*//g" \
- -e "s/:.*[ \\t]/:/g" \
- <<< "${results[*]}")"
- # Exit if result was in a comment
- [[ -z "${results[*]}" ]] && exit 0
-fi
+# Remove unwanted content from $results
+# Each line in $results is formatted as such: [fileName]:[line]
+# 1. Delete lines starting with #
+# 2. Remove comments after domain
+# 3. Remove hosts format IP address
+# 4. Remove any lines that no longer contain the queried domain name (in case the matched domain name was in a comment)
+mapfile -t results <<< "$(IFS=$'\n'; sed \
+ -e "/:#/d" \
+ -e "s/[ \\t]#.*//g" \
+ -e "s/:.*[ \\t]/:/g" \
+ -e "/${domainQuery}/!d" \
+ <<< "${results[*]}")"
+# Exit if result was in a comment
+[[ -z "${results[*]}" ]] && exit 0
# Get adlist file content as array
if [[ -n "${adlist}" ]] || [[ -n "${blockpage}" ]]; then