Allow pihole -q matching ABP subdomains

Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
This commit is contained in:
RD WebDesign 2023-02-27 01:46:12 -03:00
parent 75a32d22a3
commit c35ed68051
No known key found for this signature in database
GPG key ID: AE3C7FC910687F33

View file

@ -102,6 +102,16 @@ scanDatabaseTable() {
table="${2}" table="${2}"
list_type="${3:-}" list_type="${3:-}"
# Create search string for ABP entries
local abpentry="${domain}" searchstr
searchstr="'||${abpentry}^'"
while [ "${abpentry}" != "${abpentry/./}" ]
do
abpentry=$(echo "${abpentry}" | cut -f 2- -d '.')
searchstr=$(echo "$searchstr, '||${abpentry}^'")
done
# As underscores are legitimate parts of domains, we escape them when using the LIKE operator. # As underscores are legitimate parts of domains, we escape them when using the LIKE operator.
# Underscores are SQLite wildcards matching exactly one character. We obviously want to suppress this # Underscores are SQLite wildcards matching exactly one character. We obviously want to suppress this
# behavior. The "ESCAPE '\'" clause specifies that an underscore preceded by an '\' should be matched # behavior. The "ESCAPE '\'" clause specifies that an underscore preceded by an '\' should be matched
@ -109,12 +119,12 @@ scanDatabaseTable() {
if [[ "${table}" == "gravity" ]]; then if [[ "${table}" == "gravity" ]]; then
case "${exact}" in case "${exact}" in
"exact" ) querystr="SELECT gravity.domain,adlist.address,adlist.enabled FROM gravity LEFT JOIN adlist ON adlist.id = gravity.adlist_id WHERE domain = '${domain}'";; "exact" ) querystr="SELECT gravity.domain,adlist.address,adlist.enabled FROM gravity LEFT JOIN adlist ON adlist.id = gravity.adlist_id WHERE domain = '${domain}'";;
* ) querystr="SELECT gravity.domain,adlist.address,adlist.enabled FROM gravity LEFT JOIN adlist ON adlist.id = gravity.adlist_id WHERE domain LIKE '%${domain//_/\\_}%' ESCAPE '\\'";; * ) querystr="SELECT gravity.domain,adlist.address,adlist.enabled FROM gravity LEFT JOIN adlist ON adlist.id = gravity.adlist_id WHERE (domain IN (${searchstr}) OR domain LIKE '%${domain//_/\\_}%' ESCAPE '\\')";;
esac esac
else else
case "${exact}" in case "${exact}" in
"exact" ) querystr="SELECT domain,enabled FROM domainlist WHERE type = '${list_type}' AND domain = '${domain}'";; "exact" ) querystr="SELECT domain,enabled FROM domainlist WHERE type = '${list_type}' AND domain = '${domain}'";;
* ) querystr="SELECT domain,enabled FROM domainlist WHERE type = '${list_type}' AND domain LIKE '%${domain//_/\\_}%' ESCAPE '\\'";; * ) querystr="SELECT domain,enabled FROM domainlist WHERE type = '${list_type}' AND (domain IN (${searchstr}) OR domain LIKE '%${domain//_/\\_}%' ESCAPE '\\')";;
esac esac
fi fi