diff --git a/advanced/Templates/gravity.db.schema b/advanced/Templates/gravity.db.schema deleted file mode 100644 index b7b3808a..00000000 --- a/advanced/Templates/gravity.db.schema +++ /dev/null @@ -1,21 +0,0 @@ -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 -FROM gravity a -WHERE a.domain NOT IN (SELECT domain from whitelist WHERE disabled != 1); - -CREATE VIEW vw_blacklist AS SELECT DISTINCT a.domain -FROM blacklist a -WHERE a.disabled != 1 AND - a.domain NOT IN (SELECT domain from whitelist WHERE disabled != 1); - -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/advanced/Templates/gravity.db.sql b/advanced/Templates/gravity.db.sql new file mode 100644 index 00000000..72d64bc1 --- /dev/null +++ b/advanced/Templates/gravity.db.sql @@ -0,0 +1,21 @@ +CREATE TABLE whitelist (domain TEXT UNIQUE NOT NULL, enabled BOOLEAN DEFAULT 1, comment TEXT, DateAdded DATETIME); +CREATE TABLE blacklist (domain TEXT UNIQUE NOT NULL, enabled BOOLEAN DEFAULT 1, comment TEXT, DateAdded DATETIME); +CREATE TABLE regex (domain TEXT UNIQUE NOT NULL, enabled BOOLEAN DEFAULT 1, comment TEXT, DateAdded DATETIME); +CREATE TABLE gravity (domain TEXT UNIQUE NOT NULL); + +CREATE VIEW vw_gravity AS SELECT DISTINCT a.domain +FROM gravity a +WHERE a.domain NOT IN (SELECT domain from whitelist WHERE enabled == 1); + +CREATE VIEW vw_blacklist AS SELECT DISTINCT a.domain +FROM blacklist a +WHERE a.enabled == 1 AND + a.domain NOT IN (SELECT domain from whitelist WHERE enabled == 1); + +CREATE VIEW vw_whitelist AS SELECT DISTINCT a.domain +FROM whitelist a +WHERE a.enabled == 1; + +CREATE VIEW vw_regex AS SELECT DISTINCT a.domain +FROM regex a +WHERE a.enabled == 1; diff --git a/gravity.sh b/gravity.sh index 06e75a90..c47f7487 100755 --- a/gravity.sh +++ b/gravity.sh @@ -38,7 +38,7 @@ VPNList="/etc/openvpn/ipp.txt" piholeGitDir="/etc/.pihole" gravityDBfile="${piholeDir}/gravity.db" -gravityDBschema="${piholeGitDir}/advanced/Templates/gravity.db.schema" +gravityDBschema="${piholeGitDir}/advanced/Templates/gravity.db.sql" optimize_database=false domainsExtension="domains" @@ -123,12 +123,12 @@ gravity_store_in_database() { fi 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 ) + # Set enabled to true where it is unspecified + output=$( { sqlite3 "${gravityDBfile}" <<< "UPDATE ${table} SET enabled = 1 WHERE enabled IS NULL;"; } 2>&1 ) status="$?" if [[ "${status}" -ne 0 ]]; then - echo -e "\\n ${CROSS} Unable to set disabled states (${table}) in database ${gravityDBfile}\\n ${output}" + echo -e "\\n ${CROSS} Unable to set enabled states (${table}) in database ${gravityDBfile}\\n ${output}" gravity_Cleanup "error" fi fi