From 785f1fedd9ade421aa923b997fe873dff171f942 Mon Sep 17 00:00:00 2001 From: MMotti Date: Mon, 10 Jun 2019 17:48:52 +0100 Subject: [PATCH 1/4] Tidy regexp queries Signed-off-by: MMotti --- advanced/Scripts/query.sh | 53 +++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/advanced/Scripts/query.sh b/advanced/Scripts/query.sh index 9134dc0f..e418eecf 100755 --- a/advanced/Scripts/query.sh +++ b/advanced/Scripts/query.sh @@ -133,31 +133,36 @@ scanDatabaseTable "${domainQuery}" "whitelist" "${exact}" scanDatabaseTable "${domainQuery}" "blacklist" "${exact}" # Scan Regex table -mapfile -t regexlist <<< "$(sqlite3 "${gravityDBfile}" "SELECT domain FROM vw_regex" 2> /dev/null)" -# Split results over new line and store in a string -# ready for processing -str_regexlist=$(IFS=$'\n'; echo "${regexlist[*]}") -# If there are regexps in the DB -if [[ -n "${str_regexlist}" ]]; then - # Return any regexps that match the domainQuery - mapfile -t results <<< "$(scanList "${domainQuery}" "${str_regexlist}" "regex")" +mapfile -t regexlist < <(sqlite3 "${gravityDBfile}" "SELECT domain FROM vw_regex" 2> /dev/null) - # If there are matches to the domain query - if [[ -n "${results[*]}" ]]; then - # Form output strings - str="${matchType^} found in ${COL_BOLD}Regex list${COL_NC}" - result="${COL_BOLD}$(IFS=$'\n'; echo "${results[*]}")${COL_NC}" - - if [[ -z "${blockpage}" ]]; then - wcMatch=true - echo " $str" - fi - - case "${blockpage}" in - true ) echo "π Regex list"; exit 0;; - * ) awk '{print " "$0}' <<< "${result}";; - esac - fi +# If we have regexps to process +if [[ "${#regexlist[@]}" -ne 0 ]]; then + # Split regexps over a new line + str_regexlist=$(printf '%s\n' "${regexlist[@]}") + # Check domainQuery against regexps + mapfile -t regexMatches < <(scanList "${domainQuery}" "${str_regexlist}" "regex") + # If there were regex matches + if [[ "${#regexMatches[@]}" -ne 0 ]]; then + # Split matching regexps over a new line + str_regexMatches=$(printf '%s\n' "${regexMatches[@]}") + # Form a "matched" message + str_message="${matchType^} found in ${COL_BOLD}Regex list${COL_NC}" + # Form a "results" message + str_result="${COL_BOLD}${str_regexMatches}${COL_NC}" + + if [[ -z "${blockpage}" ]]; then + # Set the wildcard match flag + wcMatch=true + # Echo the "matched" message, indented by one space + echo " ${str_message}" + # Echo the "results" message, each line indented by three spaces + echo "${str_result}" | sed 's/^/ /' + else + echo "π Regex list" + exit 0 + fi + + fi fi # Get version sorted *.domains filenames (without dir path) From 10fbed50f3e3213a5a1e836cecd144cc59562107 Mon Sep 17 00:00:00 2001 From: MMotti Date: Mon, 10 Jun 2019 18:10:25 +0100 Subject: [PATCH 2/4] Shellcheck Suggesting to use parameter expansion but we need to be able to identify the start of each line Signed-off-by: MMotti --- advanced/Scripts/query.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/Scripts/query.sh b/advanced/Scripts/query.sh index e418eecf..93d8baee 100755 --- a/advanced/Scripts/query.sh +++ b/advanced/Scripts/query.sh @@ -156,6 +156,7 @@ if [[ "${#regexlist[@]}" -ne 0 ]]; then # Echo the "matched" message, indented by one space echo " ${str_message}" # Echo the "results" message, each line indented by three spaces + # shellcheck disable=SC2001 echo "${str_result}" | sed 's/^/ /' else echo "π Regex list" From a9d0690f4dff7b081f22146cad1440eff04082a1 Mon Sep 17 00:00:00 2001 From: MMotti Date: Mon, 10 Jun 2019 18:50:52 +0100 Subject: [PATCH 3/4] Change the case of some variables Just for consistency Signed-off-by: MMotti --- advanced/Scripts/query.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/advanced/Scripts/query.sh b/advanced/Scripts/query.sh index 93d8baee..aa23ab41 100755 --- a/advanced/Scripts/query.sh +++ b/advanced/Scripts/query.sh @@ -133,14 +133,14 @@ scanDatabaseTable "${domainQuery}" "whitelist" "${exact}" scanDatabaseTable "${domainQuery}" "blacklist" "${exact}" # Scan Regex table -mapfile -t regexlist < <(sqlite3 "${gravityDBfile}" "SELECT domain FROM vw_regex" 2> /dev/null) +mapfile -t regexList < <(sqlite3 "${gravityDBfile}" "SELECT domain FROM vw_regex" 2> /dev/null) # If we have regexps to process -if [[ "${#regexlist[@]}" -ne 0 ]]; then +if [[ "${#regexList[@]}" -ne 0 ]]; then # Split regexps over a new line - str_regexlist=$(printf '%s\n' "${regexlist[@]}") + str_regexList=$(printf '%s\n' "${regexList[@]}") # Check domainQuery against regexps - mapfile -t regexMatches < <(scanList "${domainQuery}" "${str_regexlist}" "regex") + mapfile -t regexMatches < <(scanList "${domainQuery}" "${str_regexList}" "regex") # If there were regex matches if [[ "${#regexMatches[@]}" -ne 0 ]]; then # Split matching regexps over a new line From bcf03647efd8b1685bf077bfab968c327381de2a Mon Sep 17 00:00:00 2001 From: MMotti Date: Wed, 12 Jun 2019 16:02:59 +0100 Subject: [PATCH 4/4] Add comment and remove blankspace Signed-off-by: MMotti --- advanced/Scripts/query.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/advanced/Scripts/query.sh b/advanced/Scripts/query.sh index aa23ab41..42ea4395 100755 --- a/advanced/Scripts/query.sh +++ b/advanced/Scripts/query.sh @@ -149,7 +149,7 @@ if [[ "${#regexList[@]}" -ne 0 ]]; then str_message="${matchType^} found in ${COL_BOLD}Regex list${COL_NC}" # Form a "results" message str_result="${COL_BOLD}${str_regexMatches}${COL_NC}" - + # If we are displaying more than just the source of the block if [[ -z "${blockpage}" ]]; then # Set the wildcard match flag wcMatch=true @@ -162,7 +162,6 @@ if [[ "${#regexList[@]}" -ne 0 ]]; then echo "π Regex list" exit 0 fi - fi fi