mirror of
https://github.com/pi-hole/pi-hole
synced 2025-01-03 12:40:56 +00:00
Fix indentation in query.sh. No functional change in this commit.
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
parent
42ccc1ef24
commit
23b688287f
@ -36,14 +36,14 @@ 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)${esc_domain}($|\\s|#)" ${lists} /dev/null 2>/dev/null;;
|
"exact" ) grep -i -E -l "(^|(?<!#)\\s)${esc_domain}($|\\s|#)" ${lists} /dev/null 2>/dev/null;;
|
||||||
# Create array of regexps
|
# Create array of regexps
|
||||||
# Iterate through each regexp and check whether it matches the domainQuery
|
# Iterate through each regexp and check whether it matches the domainQuery
|
||||||
# If it does, print the matching regexp and continue looping
|
# If it does, print the matching regexp and continue looping
|
||||||
# Input 1 - regexps | Input 2 - domainQuery
|
# Input 1 - regexps | Input 2 - domainQuery
|
||||||
"regex" ) awk 'NR==FNR{regexps[$0];next}{for (r in regexps)if($0 ~ r)print r}' \
|
"regex" ) awk 'NR==FNR{regexps[$0];next}{for (r in regexps)if($0 ~ r)print r}' \
|
||||||
<(echo "${lists}") <(echo "${domain}") 2>/dev/null;;
|
<(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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,8 +100,8 @@ 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.
|
||||||
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}'";;
|
||||||
* ) querystr="SELECT domain FROM vw_${table} WHERE domain LIKE '%${domain//_/\\_}%' ESCAPE '\\'";;
|
* ) querystr="SELECT domain FROM vw_${table} WHERE domain LIKE '%${domain//_/\\_}%' ESCAPE '\\'";;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Send prepared query to gravity database
|
# Send prepared query to gravity database
|
||||||
@ -129,40 +129,42 @@ scanDatabaseTable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
scanRegexDatabaseTable() {
|
scanRegexDatabaseTable() {
|
||||||
local domain list
|
local domain list
|
||||||
domain="${1}"
|
domain="${1}"
|
||||||
list="${2}"
|
list="${2}"
|
||||||
mapfile -t regexList < <(sqlite3 "${gravityDBfile}" "SELECT domain FROM vw_regex_${list}" 2> /dev/null)
|
|
||||||
|
|
||||||
# If we have regexps to process
|
# Query all regex from the corresponding database tables
|
||||||
if [[ "${#regexList[@]}" -ne 0 ]]; then
|
mapfile -t regexList < <(sqlite3 "${gravityDBfile}" "SELECT domain FROM vw_regex_${list}" 2> /dev/null)
|
||||||
# Split regexps over a new line
|
|
||||||
str_regexList=$(printf '%s\n' "${regexList[@]}")
|
# If we have regexps to process
|
||||||
# Check domain against regexps
|
if [[ "${#regexList[@]}" -ne 0 ]]; then
|
||||||
mapfile -t regexMatches < <(scanList "${domain}" "${str_regexList}" "regex")
|
# Split regexps over a new line
|
||||||
# If there were regex matches
|
str_regexList=$(printf '%s\n' "${regexList[@]}")
|
||||||
if [[ "${#regexMatches[@]}" -ne 0 ]]; then
|
# Check domain against regexps
|
||||||
# Split matching regexps over a new line
|
mapfile -t regexMatches < <(scanList "${domain}" "${str_regexList}" "regex")
|
||||||
str_regexMatches=$(printf '%s\n' "${regexMatches[@]}")
|
# If there were regex matches
|
||||||
# Form a "matched" message
|
if [[ "${#regexMatches[@]}" -ne 0 ]]; then
|
||||||
str_message="${matchType^} found in ${COL_BOLD}Regex ${list}${COL_NC}"
|
# Split matching regexps over a new line
|
||||||
# Form a "results" message
|
str_regexMatches=$(printf '%s\n' "${regexMatches[@]}")
|
||||||
str_result="${COL_BOLD}${str_regexMatches}${COL_NC}"
|
# Form a "matched" message
|
||||||
# If we are displaying more than just the source of the block
|
str_message="${matchType^} found in ${COL_BOLD}Regex ${list}${COL_NC}"
|
||||||
if [[ -z "${blockpage}" ]]; then
|
# Form a "results" message
|
||||||
# Set the wildcard match flag
|
str_result="${COL_BOLD}${str_regexMatches}${COL_NC}"
|
||||||
wcMatch=true
|
# If we are displaying more than just the source of the block
|
||||||
# Echo the "matched" message, indented by one space
|
if [[ -z "${blockpage}" ]]; then
|
||||||
echo " ${str_message}"
|
# Set the wildcard match flag
|
||||||
# Echo the "results" message, each line indented by three spaces
|
wcMatch=true
|
||||||
# shellcheck disable=SC2001
|
# Echo the "matched" message, indented by one space
|
||||||
echo "${str_result}" | sed 's/^/ /'
|
echo " ${str_message}"
|
||||||
else
|
# Echo the "results" message, each line indented by three spaces
|
||||||
echo "π Regex ${list}"
|
# shellcheck disable=SC2001
|
||||||
exit 0
|
echo "${str_result}" | sed 's/^/ /'
|
||||||
fi
|
else
|
||||||
fi
|
echo "π Regex ${list}"
|
||||||
fi
|
exit 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Scan Whitelist and Blacklist
|
# Scan Whitelist and Blacklist
|
||||||
|
Loading…
Reference in New Issue
Block a user