Read from DB instead of regex.list

Signed-off-by: MMotti <matthew.w.motti@gmail.com>
This commit is contained in:
MMotti 2019-06-03 23:59:58 +01:00
parent 97df6d7415
commit 09532638d5

View file

@ -39,7 +39,7 @@ scanList(){
# shellcheck disable=SC2086 # shellcheck disable=SC2086
case "${type}" in case "${type}" in
"exact" ) grep -i -E -l "(^|(?<!#)\\s)${esc_domain}($|\\s|#)" ${lists} /dev/null 2>/dev/null;; "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;; * ) grep -i "${esc_domain}" ${lists} /dev/null 2>/dev/null;;
esac esac
} }
@ -98,6 +98,7 @@ scanDatabaseTable() {
# 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.
case "${type}" in case "${type}" in
"exact" ) querystr="SELECT domain FROM vw_${table} WHERE domain = '${domain}'";; "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 '\\'";; * ) querystr="SELECT domain FROM vw_${table} WHERE domain LIKE '%${domain//_/\\_}%' ESCAPE '\\'";;
esac esac
@ -108,6 +109,13 @@ scanDatabaseTable() {
return return
fi 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) # Mark domain as having been white-/blacklist matched (global variable)
wbMatch=true wbMatch=true
@ -129,14 +137,21 @@ scanDatabaseTable() {
scanDatabaseTable "${domainQuery}" "whitelist" "${exact}" scanDatabaseTable "${domainQuery}" "whitelist" "${exact}"
scanDatabaseTable "${domainQuery}" "blacklist" "${exact}" scanDatabaseTable "${domainQuery}" "blacklist" "${exact}"
# Scan Regex # Scan Regex table
if [[ -e "${regexlist}" ]]; then regexlist=$(scanDatabaseTable "" "regex" "retrievetable")
if [[ -n "${regexlist}" ]]; then
# Return portion(s) of string that is found in the regex list # Return portion(s) of string that is found in the regex list
mapfile -t results <<< "$(scanList "${domainQuery}" "${regexlist}" "rx")" mapfile -t results <<< "$(scanList "${domainQuery}" "${regexlist}" "rx")"
# If a result is found
if [[ -n "${results[*]}" ]]; then if [[ -n "${results[*]}" ]]; then
# A result is found # Count the matches
str="Phrase ${matchType}ed within ${COL_BOLD}regex list${COL_NC}" 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}" result="${COL_BOLD}$(IFS=$'\n'; echo "${results[*]}")${COL_NC}"
if [[ -z "${blockpage}" ]]; then if [[ -z "${blockpage}" ]]; then