From 93f1859babd7a28de799edb84fdeadf39300daba Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 3 Feb 2019 15:13:18 +0100 Subject: [PATCH] Store regex in gravity.db as well Signed-off-by: DL6ER --- advanced/Templates/gravity.db.schema | 5 +++++ gravity.sh | 20 +++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/advanced/Templates/gravity.db.schema b/advanced/Templates/gravity.db.schema index 83141f94..b7b3808a 100644 --- a/advanced/Templates/gravity.db.schema +++ b/advanced/Templates/gravity.db.schema @@ -1,5 +1,6 @@ CREATE TABLE whitelist (domain TEXT UNIQUE NOT NULL, disabled BOOLEAN DEFAULT 0, comment TEXT, DateAdded DATETIME); CREATE TABLE blacklist (domain TEXT UNIQUE NOT NULL, disabled BOOLEAN DEFAULT 0, comment TEXT, DateAdded DATETIME); +CREATE TABLE regex (domain TEXT UNIQUE NOT NULL, disabled BOOLEAN DEFAULT 0, comment TEXT, DateAdded DATETIME); CREATE TABLE gravity (domain TEXT UNIQUE NOT NULL); CREATE VIEW vw_gravity AS SELECT DISTINCT a.domain @@ -14,3 +15,7 @@ WHERE a.disabled != 1 AND CREATE VIEW vw_whitelist AS SELECT DISTINCT a.domain FROM whitelist a WHERE a.disabled != 1; + +CREATE VIEW vw_regex AS SELECT DISTINCT a.domain +FROM regex a +WHERE a.disabled != 1; diff --git a/gravity.sh b/gravity.sh index 21338119..e3e78528 100755 --- a/gravity.sh +++ b/gravity.sh @@ -124,7 +124,7 @@ gravity_store_in_database() { gravity_Cleanup "error" fi - if [ "$table" == "whitelist" ] || [ "$table" == "blacklist" ]; then + if [ "$table" == "whitelist" ] || [ "$table" == "blacklist" ] || [ "$table" == "regex" ]; then # Set disabled to false output=$( { sqlite3 "${gravityDBfile}" <<< "UPDATE ${table} SET disabled = 0 WHERE disabled IS NULL;"; } 2>&1 ) status="$?" @@ -135,13 +135,16 @@ gravity_store_in_database() { fi fi - # Empty $template if it already exists, otherwise, create it - output=$( { : > "${template}"; } 2>&1 ) - status="$?" + # Only create template file if asked to + if [ "${template}" != "-" ]; then + # Empty $template if it already exists, otherwise, create it + output=$( { : > "${template}"; } 2>&1 ) + status="$?" - if [[ "${status}" -ne 0 ]]; then - echo -e "\\n ${CROSS} Unable to create empty ${template}\\n ${output}" - gravity_Cleanup "error" + if [[ "${status}" -ne 0 ]]; then + echo -e "\\n ${CROSS} Unable to create empty ${template}\\n ${output}" + gravity_Cleanup "error" + fi fi } @@ -586,6 +589,9 @@ gravity_ShowBlockCount() { num=$(grep -cv "^#" "${regexFile}") echo -e " ${INFO} Number of regex filters: ${num}" fi + + # Store regex files in gravity database + gravity_store_in_database "regex" "${regexFile}" "-" } # Parse list of domains into hosts format