mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-12-24 13:50:17 +00:00
Read from DB instead of regex.list
Signed-off-by: MMotti <matthew.w.motti@gmail.com>
This commit is contained in:
parent
97df6d7415
commit
09532638d5
1 changed files with 23 additions and 8 deletions
|
@ -39,7 +39,7 @@ scanList(){
|
|||
# shellcheck disable=SC2086
|
||||
case "${type}" in
|
||||
"exact" ) grep -i -E -l "(^|(?<!#)\\s)${esc_domain}($|\\s|#)" ${lists} /dev/null 2>/dev/null;;
|
||||
"rx" ) awk 'NR==FNR{regexps[$0]}{for (r in regexps)if($0 ~ r)print r}' ${lists} <(echo "$domain") 2>/dev/null;;
|
||||
"rx" ) awk 'NR==FNR{regexps[$0]}{for (r in regexps)if($0 ~ r)print r}' <(echo "$lists") <(echo "$domain") 2>/dev/null;;
|
||||
* ) grep -i "${esc_domain}" ${lists} /dev/null 2>/dev/null;;
|
||||
esac
|
||||
}
|
||||
|
@ -98,6 +98,7 @@ scanDatabaseTable() {
|
|||
# as a literal underscore character. We pretreat the $domain variable accordingly to escape underscores.
|
||||
case "${type}" in
|
||||
"exact" ) querystr="SELECT domain FROM vw_${table} WHERE domain = '${domain}'";;
|
||||
"retrievetable" ) querystr="SELECT domain FROM vw_${table}";;
|
||||
* ) querystr="SELECT domain FROM vw_${table} WHERE domain LIKE '%${domain//_/\\_}%' ESCAPE '\\'";;
|
||||
esac
|
||||
|
||||
|
@ -108,6 +109,13 @@ scanDatabaseTable() {
|
|||
return
|
||||
fi
|
||||
|
||||
# If we are only retrieving the table
|
||||
# Just output and return
|
||||
if [[ "${type}" == "retrievetable" ]]; then
|
||||
echo "${result[*]}"
|
||||
return
|
||||
fi
|
||||
|
||||
# Mark domain as having been white-/blacklist matched (global variable)
|
||||
wbMatch=true
|
||||
|
||||
|
@ -129,14 +137,21 @@ scanDatabaseTable() {
|
|||
scanDatabaseTable "${domainQuery}" "whitelist" "${exact}"
|
||||
scanDatabaseTable "${domainQuery}" "blacklist" "${exact}"
|
||||
|
||||
# Scan Regex
|
||||
if [[ -e "${regexlist}" ]]; then
|
||||
# Scan Regex table
|
||||
regexlist=$(scanDatabaseTable "" "regex" "retrievetable")
|
||||
|
||||
if [[ -n "${regexlist}" ]]; then
|
||||
# Return portion(s) of string that is found in the regex list
|
||||
mapfile -t results <<< "$(scanList "${domainQuery}" "${regexlist}" "rx")"
|
||||
|
||||
# If a result is found
|
||||
if [[ -n "${results[*]}" ]]; then
|
||||
# A result is found
|
||||
str="Phrase ${matchType}ed within ${COL_BOLD}regex list${COL_NC}"
|
||||
# Count the matches
|
||||
regexCount=${#results[@]}
|
||||
# Determine plural string
|
||||
[[ $regexCount -gt 1 ]] && plu="es"
|
||||
# Form output strings
|
||||
str="${COL_BOLD}${regexCount}${COL_NC} ${matchType}${plu:-} found in ${COL_BOLD}regex${COL_NC} table"
|
||||
result="${COL_BOLD}$(IFS=$'\n'; echo "${results[*]}")${COL_NC}"
|
||||
|
||||
if [[ -z "${blockpage}" ]]; then
|
||||
|
|
Loading…
Reference in a new issue