mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-12-25 06:10:20 +00:00
Scan domainlist instead of view to also catch disabled domains.
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
parent
40e8657137
commit
4be7ebe61f
1 changed files with 27 additions and 20 deletions
|
@ -88,7 +88,7 @@ if [[ -n "${str:-}" ]]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
scanDatabaseTable() {
|
scanDatabaseTable() {
|
||||||
local domain table type querystr result
|
local domain table type querystr result extra
|
||||||
domain="$(printf "%q" "${1}")"
|
domain="$(printf "%q" "${1}")"
|
||||||
table="${2}"
|
table="${2}"
|
||||||
type="${3:-}"
|
type="${3:-}"
|
||||||
|
@ -98,14 +98,14 @@ scanDatabaseTable() {
|
||||||
# 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
|
||||||
# as a literal underscore character. We pretreat the $domain variable accordingly to escape underscores.
|
# as a literal underscore character. We pretreat the $domain variable accordingly to escape underscores.
|
||||||
if [[ "${table}" == "gravity" ]]; then
|
if [[ "${table}" == "gravity" ]]; then
|
||||||
case "${type}" 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 LIKE '%${domain//_/\\_}%' ESCAPE '\\'";;
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
case "${type}" in
|
case "${exact}" in
|
||||||
"exact" ) querystr="SELECT domain FROM ${table} WHERE domain = '${domain}'";;
|
"exact" ) querystr="SELECT domain,enabled FROM domainlist WHERE type = '${type}' AND domain = '${domain}'";;
|
||||||
* ) querystr="SELECT domain FROM ${table} WHERE domain LIKE '%${domain//_/\\_}%' ESCAPE '\\'";;
|
* ) querystr="SELECT domain,enabled FROM domainlist WHERE type = '${type}' AND domain LIKE '%${domain//_/\\_}%' ESCAPE '\\'";;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ scanDatabaseTable() {
|
||||||
|
|
||||||
# Print table name
|
# Print table name
|
||||||
if [[ -z "${blockpage}" ]]; then
|
if [[ -z "${blockpage}" ]]; then
|
||||||
echo " ${matchType^} found in ${COL_BOLD}${table^}${COL_NC}"
|
echo " ${matchType^} found in ${COL_BOLD}exact ${table}${COL_NC}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Loop over results and print them
|
# Loop over results and print them
|
||||||
|
@ -136,7 +136,13 @@ scanDatabaseTable() {
|
||||||
echo "π ${result}"
|
echo "π ${result}"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
echo " ${result}"
|
domain="${result/|*}"
|
||||||
|
if [[ "${result#*|}" == "0" ]]; then
|
||||||
|
extra=" (disabled)"
|
||||||
|
else
|
||||||
|
extra=""
|
||||||
|
fi
|
||||||
|
echo " ${domain}${extra}"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,9 +150,10 @@ scanRegexDatabaseTable() {
|
||||||
local domain list
|
local domain list
|
||||||
domain="${1}"
|
domain="${1}"
|
||||||
list="${2}"
|
list="${2}"
|
||||||
|
type="${3:-}"
|
||||||
|
|
||||||
# Query all regex from the corresponding database tables
|
# Query all regex from the corresponding database tables
|
||||||
mapfile -t regexList < <(sqlite3 "${gravityDBfile}" "SELECT domain FROM vw_regex_${list}" 2> /dev/null)
|
mapfile -t regexList < <(sqlite3 "${gravityDBfile}" "SELECT domain FROM domainlist WHERE type = "${type} 2> /dev/null)
|
||||||
|
|
||||||
# If we have regexps to process
|
# If we have regexps to process
|
||||||
if [[ "${#regexList[@]}" -ne 0 ]]; then
|
if [[ "${#regexList[@]}" -ne 0 ]]; then
|
||||||
|
@ -159,7 +166,7 @@ scanRegexDatabaseTable() {
|
||||||
# Split matching regexps over a new line
|
# Split matching regexps over a new line
|
||||||
str_regexMatches=$(printf '%s\n' "${regexMatches[@]}")
|
str_regexMatches=$(printf '%s\n' "${regexMatches[@]}")
|
||||||
# Form a "matched" message
|
# Form a "matched" message
|
||||||
str_message="${matchType^} found in ${COL_BOLD}Regex ${list}${COL_NC}"
|
str_message="${matchType^} found in ${COL_BOLD}regex ${list}${COL_NC}"
|
||||||
# Form a "results" message
|
# Form a "results" message
|
||||||
str_result="${COL_BOLD}${str_regexMatches}${COL_NC}"
|
str_result="${COL_BOLD}${str_regexMatches}${COL_NC}"
|
||||||
# If we are displaying more than just the source of the block
|
# If we are displaying more than just the source of the block
|
||||||
|
@ -180,15 +187,15 @@ scanRegexDatabaseTable() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Scan Whitelist and Blacklist
|
# Scan Whitelist and Blacklist
|
||||||
scanDatabaseTable "${domainQuery}" "vw_whitelist" "${exact}"
|
scanDatabaseTable "${domainQuery}" "whitelist" "0"
|
||||||
scanDatabaseTable "${domainQuery}" "vw_blacklist" "${exact}"
|
scanDatabaseTable "${domainQuery}" "blacklist" "1"
|
||||||
|
|
||||||
# Scan Regex table
|
# Scan Regex table
|
||||||
scanRegexDatabaseTable "${domainQuery}" "whitelist"
|
scanRegexDatabaseTable "${domainQuery}" "whitelist" "2"
|
||||||
scanRegexDatabaseTable "${domainQuery}" "blacklist"
|
scanRegexDatabaseTable "${domainQuery}" "blacklist" "3"
|
||||||
|
|
||||||
# Query block lists
|
# Query block lists
|
||||||
mapfile -t results <<< "$(scanDatabaseTable "${domainQuery}" "gravity" "${exact}")"
|
mapfile -t results <<< "$(scanDatabaseTable "${domainQuery}" "gravity")"
|
||||||
|
|
||||||
# Handle notices
|
# Handle notices
|
||||||
if [[ -z "${wbMatch:-}" ]] && [[ -z "${wcMatch:-}" ]] && [[ -z "${results[*]}" ]]; then
|
if [[ -z "${wbMatch:-}" ]] && [[ -z "${wcMatch:-}" ]] && [[ -z "${results[*]}" ]]; then
|
||||||
|
@ -213,17 +220,17 @@ for result in "${results[@]}"; do
|
||||||
match="${result/|*/}"
|
match="${result/|*/}"
|
||||||
extra="${result#*|}"
|
extra="${result#*|}"
|
||||||
adlistAddress="${extra/|*/}"
|
adlistAddress="${extra/|*/}"
|
||||||
enabled="${extra#*|}"
|
extra="${extra#*|}"
|
||||||
if [[ "${enabled}" == "0" ]]; then
|
if [[ "${extra}" == "0" ]]; then
|
||||||
enabled="(disabled)"
|
extra="(disabled)"
|
||||||
else
|
else
|
||||||
enabled=""
|
extra=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n "${blockpage}" ]]; then
|
if [[ -n "${blockpage}" ]]; then
|
||||||
echo "0 ${adlistAddress}"
|
echo "0 ${adlistAddress}"
|
||||||
elif [[ -n "${exact}" ]]; then
|
elif [[ -n "${exact}" ]]; then
|
||||||
echo " - ${adlistAddress} ${enabled}"
|
echo " - ${adlistAddress} ${extra}"
|
||||||
else
|
else
|
||||||
if [[ ! "${adlistAddress}" == "${adlistAddress_prev:-}" ]]; then
|
if [[ ! "${adlistAddress}" == "${adlistAddress_prev:-}" ]]; then
|
||||||
count=""
|
count=""
|
||||||
|
@ -238,7 +245,7 @@ for result in "${results[@]}"; do
|
||||||
[[ "${count}" -gt "${max_count}" ]] && continue
|
[[ "${count}" -gt "${max_count}" ]] && continue
|
||||||
echo " ${COL_GRAY}Over ${count} results found, skipping rest of file${COL_NC}"
|
echo " ${COL_GRAY}Over ${count} results found, skipping rest of file${COL_NC}"
|
||||||
else
|
else
|
||||||
echo " ${match} ${enabled}"
|
echo " ${match} ${extra}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in a new issue