mirror of
https://github.com/pi-hole/pi-hole.git
synced 2025-01-11 22:44:44 +00:00
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>
This commit is contained in:
parent
76133074d1
commit
989d1aff60
1 changed files with 15 additions and 14 deletions
|
@ -54,7 +54,7 @@ scanList(){
|
||||||
# /dev/null forces filename to be printed when only one list has been generated
|
# /dev/null forces filename to be printed when only one list has been generated
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
case "${type}" in
|
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;;
|
"wc" ) grep -i -o -m 1 "/${domain}/" ${lists} 2>/dev/null;;
|
||||||
* ) grep -i "${domain}" ${lists} /dev/null 2>/dev/null;;
|
* ) grep -i "${domain}" ${lists} /dev/null 2>/dev/null;;
|
||||||
esac
|
esac
|
||||||
|
@ -170,19 +170,20 @@ elif [[ -z "${all}" ]] && [[ "${#results[*]}" -ge 100 ]]; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Remove unwanted content from non-exact $results
|
# Remove unwanted content from $results
|
||||||
if [[ -z "${exact}" ]]; then
|
# Each line in $results is formatted as such: [fileName]:[line]
|
||||||
# Delete lines starting with #
|
# 1. Delete lines starting with #
|
||||||
# Remove comments after domain
|
# 2. Remove comments after domain
|
||||||
# Remove hosts format IP address
|
# 3. Remove hosts format IP address
|
||||||
mapfile -t results <<< "$(IFS=$'\n'; sed \
|
# 4. Remove any lines that no longer contain the queried domain name (in case the matched domain name was in a comment)
|
||||||
-e "/:#/d" \
|
mapfile -t results <<< "$(IFS=$'\n'; sed \
|
||||||
-e "s/[ \\t]#.*//g" \
|
-e "/:#/d" \
|
||||||
-e "s/:.*[ \\t]/:/g" \
|
-e "s/[ \\t]#.*//g" \
|
||||||
<<< "${results[*]}")"
|
-e "s/:.*[ \\t]/:/g" \
|
||||||
# Exit if result was in a comment
|
-e "/${domainQuery}/!d" \
|
||||||
[[ -z "${results[*]}" ]] && exit 0
|
<<< "${results[*]}")"
|
||||||
fi
|
# Exit if result was in a comment
|
||||||
|
[[ -z "${results[*]}" ]] && exit 0
|
||||||
|
|
||||||
# Get adlist file content as array
|
# Get adlist file content as array
|
||||||
if [[ -n "${adlist}" ]] || [[ -n "${blockpage}" ]]; then
|
if [[ -n "${adlist}" ]] || [[ -n "${blockpage}" ]]; then
|
||||||
|
|
Loading…
Reference in a new issue