From c53ee4202b4baf58283b965d3cb2d617379bf8a4 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 16 Jun 2019 16:50:51 +0200 Subject: [PATCH 01/13] Add filtering by domain groups to gravity database. Signed-off-by: DL6ER --- advanced/Templates/gravity.db.sql | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/advanced/Templates/gravity.db.sql b/advanced/Templates/gravity.db.sql index 372a4a29..ee0caa8e 100644 --- a/advanced/Templates/gravity.db.sql +++ b/advanced/Templates/gravity.db.sql @@ -1,3 +1,13 @@ +PRAGMA FOREIGN_KEYS=ON; + +CREATE TABLE domain_groups +( + "id" INTEGER PRIMARY KEY AUTOINCREMENT, + "enabled" BOOLEAN NOT NULL DEFAULT 1, + "description" TEXT +); +INSERT INTO domain_groups ("id","description") VALUES (0,'Standard group'); + CREATE TABLE whitelist ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -5,7 +15,9 @@ CREATE TABLE whitelist enabled BOOLEAN NOT NULL DEFAULT 1, date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), date_modified INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), - comment TEXT + group_id INTEGER DEFAULT 0, + comment TEXT, + FOREIGN KEY (group_id) REFERENCES domain_groups(id) ); CREATE TABLE blacklist ( @@ -14,7 +26,9 @@ CREATE TABLE blacklist enabled BOOLEAN NOT NULL DEFAULT 1, date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), date_modified INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), - comment TEXT + group_id INTEGER DEFAULT 0, + comment TEXT, + FOREIGN KEY (group_id) REFERENCES domain_groups(id) ); CREATE TABLE regex ( @@ -23,7 +37,9 @@ CREATE TABLE regex enabled BOOLEAN NOT NULL DEFAULT 1, date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), date_modified INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), - comment TEXT + group_id INTEGER DEFAULT 0, + comment TEXT, + FOREIGN KEY (group_id) REFERENCES domain_groups(id) ); CREATE TABLE adlists ( @@ -52,7 +68,8 @@ CREATE VIEW vw_gravity AS SELECT a.domain CREATE VIEW vw_whitelist AS SELECT a.domain FROM whitelist a - WHERE a.enabled == 1 + INNER JOIN domain_groups b ON b.id = a.group_id + WHERE a.enabled = 1 AND b.enabled = 1 ORDER BY a.id; CREATE TRIGGER tr_whitelist_update AFTER UPDATE ON whitelist @@ -62,7 +79,8 @@ CREATE TRIGGER tr_whitelist_update AFTER UPDATE ON whitelist CREATE VIEW vw_blacklist AS SELECT a.domain FROM blacklist a - WHERE a.enabled == 1 AND a.domain NOT IN vw_whitelist + INNER JOIN domain_groups b ON b.id = a.group_id + WHERE a.enabled = 1 AND a.domain NOT IN vw_whitelist AND b.enabled = 1 ORDER BY a.id; CREATE TRIGGER tr_blacklist_update AFTER UPDATE ON blacklist @@ -72,7 +90,8 @@ CREATE TRIGGER tr_blacklist_update AFTER UPDATE ON blacklist CREATE VIEW vw_regex AS SELECT a.domain FROM regex a - WHERE a.enabled == 1 + INNER JOIN domain_groups b ON b.id = a.group_id + WHERE a.enabled = 1 AND b.enabled = 1 ORDER BY a.id; CREATE TRIGGER tr_regex_update AFTER UPDATE ON regex From cbc210b0145415a6aedfc28c6ae266fd0a85c3ec Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 16 Jun 2019 17:05:33 +0200 Subject: [PATCH 02/13] Add adlist_groups and mark group_id columns as NOT NULL. Signed-off-by: DL6ER --- advanced/Templates/gravity.db.sql | 22 +++++++++++++++++----- gravity.sh | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/advanced/Templates/gravity.db.sql b/advanced/Templates/gravity.db.sql index ee0caa8e..e22cc44b 100644 --- a/advanced/Templates/gravity.db.sql +++ b/advanced/Templates/gravity.db.sql @@ -15,7 +15,7 @@ CREATE TABLE whitelist enabled BOOLEAN NOT NULL DEFAULT 1, date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), date_modified INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), - group_id INTEGER DEFAULT 0, + group_id INTEGER NOT NULL DEFAULT 0, comment TEXT, FOREIGN KEY (group_id) REFERENCES domain_groups(id) ); @@ -26,7 +26,7 @@ CREATE TABLE blacklist enabled BOOLEAN NOT NULL DEFAULT 1, date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), date_modified INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), - group_id INTEGER DEFAULT 0, + group_id INTEGER NOT NULL DEFAULT 0, comment TEXT, FOREIGN KEY (group_id) REFERENCES domain_groups(id) ); @@ -37,10 +37,19 @@ CREATE TABLE regex enabled BOOLEAN NOT NULL DEFAULT 1, date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), date_modified INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), - group_id INTEGER DEFAULT 0, + group_id INTEGER NOT NULL DEFAULT 0, comment TEXT, FOREIGN KEY (group_id) REFERENCES domain_groups(id) ); + +CREATE TABLE adlist_groups +( + "id" INTEGER PRIMARY KEY AUTOINCREMENT, + "enabled" BOOLEAN NOT NULL DEFAULT 1, + "description" TEXT +); +INSERT INTO adlist_groups ("id","description") VALUES (0,'Standard group'); + CREATE TABLE adlists ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -48,7 +57,9 @@ CREATE TABLE adlists enabled BOOLEAN NOT NULL DEFAULT 1, date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), date_modified INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), - comment TEXT + group_id INTEGER NOT NULL DEFAULT 0, + comment TEXT, + FOREIGN KEY (group_id) REFERENCES adlist_groups(id) ); CREATE TABLE gravity ( @@ -101,7 +112,8 @@ CREATE TRIGGER tr_regex_update AFTER UPDATE ON regex CREATE VIEW vw_adlists AS SELECT a.address FROM adlists a - WHERE a.enabled == 1 + INNER JOIN adlist_groups b ON b.id = a.group_id + WHERE a.enabled = 1 AND b.enabled = 1 ORDER BY a.id; CREATE TRIGGER tr_adlists_update AFTER UPDATE ON adlists diff --git a/gravity.sh b/gravity.sh index 1fe2b4e3..ce7aa6ba 100755 --- a/gravity.sh +++ b/gravity.sh @@ -120,7 +120,7 @@ database_table_from_file() { do # Only add non-empty lines if [[ ! -z "${domain}" ]]; then - echo "${rowid},\"${domain}\",1,${timestamp},${timestamp},\"Migrated from ${source}\"" >> "${tmpFile}" + echo "${rowid},\"${domain}\",1,${timestamp},${timestamp},0,\"Migrated from ${source}\"" >> "${tmpFile}" rowid+=1 fi done From 01850c2128f2f9889db352028d1c296247153ca5 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 16 Jun 2019 17:15:36 +0200 Subject: [PATCH 03/13] Automatically recreate standard group after deletion to avoid violating foreign key constraints even if foreign key enforcing is disabled (SQLite's default behavior) Signed-off-by: DL6ER --- advanced/Templates/gravity.db.sql | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/advanced/Templates/gravity.db.sql b/advanced/Templates/gravity.db.sql index e22cc44b..5fb9a5eb 100644 --- a/advanced/Templates/gravity.db.sql +++ b/advanced/Templates/gravity.db.sql @@ -7,6 +7,10 @@ CREATE TABLE domain_groups "description" TEXT ); INSERT INTO domain_groups ("id","description") VALUES (0,'Standard group'); +CREATE TRIGGER domain_groups_standard_group AFTER DELETE ON domain_groups WHEN OLD.id = 0 + BEGIN + INSERT INTO domain_groups ("id","description") VALUES (0,'Standard group'); + END; CREATE TABLE whitelist ( @@ -49,6 +53,10 @@ CREATE TABLE adlist_groups "description" TEXT ); INSERT INTO adlist_groups ("id","description") VALUES (0,'Standard group'); +CREATE TRIGGER adlist_groups_standard_group AFTER DELETE ON adlist_groups WHEN OLD.id = 0 + BEGIN + INSERT INTO adlist_groups ("id","description") VALUES (0,'Standard group'); + END; CREATE TABLE adlists ( From 0774c4e5cac3acd7955ef9a53d19f0a4ed69c13b Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 16 Jun 2019 18:52:23 +0200 Subject: [PATCH 04/13] vw_gravity should actually filter using vw_whitelist. Signed-off-by: DL6ER --- advanced/Templates/gravity.db.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Templates/gravity.db.sql b/advanced/Templates/gravity.db.sql index 5fb9a5eb..f4f9cf4c 100644 --- a/advanced/Templates/gravity.db.sql +++ b/advanced/Templates/gravity.db.sql @@ -83,7 +83,7 @@ INSERT INTO info VALUES("version","1"); CREATE VIEW vw_gravity AS SELECT a.domain FROM gravity a - WHERE a.domain NOT IN (SELECT domain from whitelist WHERE enabled == 1); + WHERE a.domain NOT IN (SELECT domain from vw_whitelist); CREATE VIEW vw_whitelist AS SELECT a.domain FROM whitelist a From 87c115fc86bd0365e82d5b46f911c0c52b228463 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 30 Jun 2019 18:58:47 +0200 Subject: [PATCH 05/13] Change implementation to use linking tables (domain_groups, adlists_groups). This allows adding domains to multiple lists conveniently. Signed-off-by: DL6ER --- advanced/Templates/gravity.db.sql | 121 +++++++++++++++++------------- gravity.sh | 2 +- 2 files changed, 70 insertions(+), 53 deletions(-) diff --git a/advanced/Templates/gravity.db.sql b/advanced/Templates/gravity.db.sql index f4f9cf4c..77de31aa 100644 --- a/advanced/Templates/gravity.db.sql +++ b/advanced/Templates/gravity.db.sql @@ -2,15 +2,10 @@ PRAGMA FOREIGN_KEYS=ON; CREATE TABLE domain_groups ( - "id" INTEGER PRIMARY KEY AUTOINCREMENT, - "enabled" BOOLEAN NOT NULL DEFAULT 1, - "description" TEXT + id INTEGER PRIMARY KEY AUTOINCREMENT, + enabled BOOLEAN NOT NULL DEFAULT 1, + description TEXT ); -INSERT INTO domain_groups ("id","description") VALUES (0,'Standard group'); -CREATE TRIGGER domain_groups_standard_group AFTER DELETE ON domain_groups WHEN OLD.id = 0 - BEGIN - INSERT INTO domain_groups ("id","description") VALUES (0,'Standard group'); - END; CREATE TABLE whitelist ( @@ -19,10 +14,16 @@ CREATE TABLE whitelist enabled BOOLEAN NOT NULL DEFAULT 1, date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), date_modified INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), - group_id INTEGER NOT NULL DEFAULT 0, - comment TEXT, - FOREIGN KEY (group_id) REFERENCES domain_groups(id) + comment TEXT ); + +CREATE TABLE whitelist_by_group +( + whitelist_id INTEGER NOT NULL REFERENCES whitelist (id), + group_id INTEGER NOT NULL REFERENCES domain_groups (id), + PRIMARY KEY (whitelist_id, group_id) +); + CREATE TABLE blacklist ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -30,10 +31,16 @@ CREATE TABLE blacklist enabled BOOLEAN NOT NULL DEFAULT 1, date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), date_modified INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), - group_id INTEGER NOT NULL DEFAULT 0, - comment TEXT, - FOREIGN KEY (group_id) REFERENCES domain_groups(id) + comment TEXT ); + +CREATE TABLE blacklist_by_group +( + blacklist_id INTEGER NOT NULL REFERENCES blacklist (id), + group_id INTEGER NOT NULL REFERENCES domain_groups (id), + PRIMARY KEY (blacklist_id, group_id) +); + CREATE TABLE regex ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -41,22 +48,22 @@ CREATE TABLE regex enabled BOOLEAN NOT NULL DEFAULT 1, date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), date_modified INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), - group_id INTEGER NOT NULL DEFAULT 0, - comment TEXT, - FOREIGN KEY (group_id) REFERENCES domain_groups(id) + comment TEXT ); -CREATE TABLE adlist_groups +CREATE TABLE regex_by_group ( - "id" INTEGER PRIMARY KEY AUTOINCREMENT, - "enabled" BOOLEAN NOT NULL DEFAULT 1, - "description" TEXT + regex_id INTEGER NOT NULL REFERENCES regex (id), + group_id INTEGER NOT NULL REFERENCES domain_groups (id), + PRIMARY KEY (regex_id, group_id) +); + +CREATE TABLE adlists_groups +( + id INTEGER PRIMARY KEY AUTOINCREMENT, + enabled BOOLEAN NOT NULL DEFAULT 1, + description TEXT ); -INSERT INTO adlist_groups ("id","description") VALUES (0,'Standard group'); -CREATE TRIGGER adlist_groups_standard_group AFTER DELETE ON adlist_groups WHEN OLD.id = 0 - BEGIN - INSERT INTO adlist_groups ("id","description") VALUES (0,'Standard group'); - END; CREATE TABLE adlists ( @@ -65,10 +72,16 @@ CREATE TABLE adlists enabled BOOLEAN NOT NULL DEFAULT 1, date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), date_modified INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), - group_id INTEGER NOT NULL DEFAULT 0, - comment TEXT, - FOREIGN KEY (group_id) REFERENCES adlist_groups(id) + comment TEXT ); + +CREATE TABLE adlists_by_group +( + adlists_id INTEGER NOT NULL REFERENCES adlists (id), + group_id INTEGER NOT NULL REFERENCES adlists_groups (id), + PRIMARY KEY (adlists_id, group_id) +); + CREATE TABLE gravity ( domain TEXT PRIMARY KEY @@ -81,48 +94,52 @@ CREATE TABLE info INSERT INTO info VALUES("version","1"); -CREATE VIEW vw_gravity AS SELECT a.domain - FROM gravity a - WHERE a.domain NOT IN (SELECT domain from vw_whitelist); +CREATE VIEW vw_gravity AS SELECT domain + FROM gravity + WHERE domain NOT IN (SELECT domain from vw_whitelist); -CREATE VIEW vw_whitelist AS SELECT a.domain - FROM whitelist a - INNER JOIN domain_groups b ON b.id = a.group_id - WHERE a.enabled = 1 AND b.enabled = 1 - ORDER BY a.id; +CREATE VIEW vw_whitelist AS SELECT domain + FROM whitelist + LEFT JOIN whitelist_by_group ON whitelist_by_group.whitelist_id = whitelist.id + LEFT JOIN domain_groups ON domain_groups.id = whitelist_by_group.group_id + WHERE whitelist.enabled = 1 AND domain_groups.enabled IS NULL OR domain_groups.enabled == 1 + ORDER BY whitelist.id; CREATE TRIGGER tr_whitelist_update AFTER UPDATE ON whitelist BEGIN UPDATE whitelist SET date_modified = (cast(strftime('%s', 'now') as int)) WHERE domain = NEW.domain; END; -CREATE VIEW vw_blacklist AS SELECT a.domain - FROM blacklist a - INNER JOIN domain_groups b ON b.id = a.group_id - WHERE a.enabled = 1 AND a.domain NOT IN vw_whitelist AND b.enabled = 1 - ORDER BY a.id; +CREATE VIEW vw_blacklist AS SELECT domain + FROM blacklist + LEFT JOIN blacklist_by_group ON blacklist_by_group.blacklist_id = blacklist.id + LEFT JOIN domain_groups ON domain_groups.id = blacklist_by_group.group_id + WHERE blacklist.enabled = 1 AND domain_groups.enabled IS NULL OR domain_groups.enabled == 1 + ORDER BY blacklist.id; CREATE TRIGGER tr_blacklist_update AFTER UPDATE ON blacklist BEGIN UPDATE blacklist SET date_modified = (cast(strftime('%s', 'now') as int)) WHERE domain = NEW.domain; END; -CREATE VIEW vw_regex AS SELECT a.domain - FROM regex a - INNER JOIN domain_groups b ON b.id = a.group_id - WHERE a.enabled = 1 AND b.enabled = 1 - ORDER BY a.id; +CREATE VIEW vw_regex AS SELECT domain + FROM regex + LEFT JOIN regex_by_group ON regex_by_group.regex_id = regex.id + LEFT JOIN domain_groups ON domain_groups.id = regex_by_group.group_id + WHERE regex.enabled = 1 AND domain_groups.enabled IS NULL OR domain_groups.enabled == 1 + ORDER BY regex.id; CREATE TRIGGER tr_regex_update AFTER UPDATE ON regex BEGIN UPDATE regex SET date_modified = (cast(strftime('%s', 'now') as int)) WHERE domain = NEW.domain; END; -CREATE VIEW vw_adlists AS SELECT a.address - FROM adlists a - INNER JOIN adlist_groups b ON b.id = a.group_id - WHERE a.enabled = 1 AND b.enabled = 1 - ORDER BY a.id; +CREATE VIEW vw_adlists AS SELECT address + FROM adlists + LEFT JOIN adlists_by_group ON adlists_by_group.adlists_id = adlists.id + LEFT JOIN adlists_groups ON adlists_groups.id = adlists_by_group.group_id + WHERE adlists.enabled = 1 AND adlists_groups.enabled IS NULL OR adlists_groups.enabled == 1 + ORDER BY adlists.id; CREATE TRIGGER tr_adlists_update AFTER UPDATE ON adlists BEGIN diff --git a/gravity.sh b/gravity.sh index ce7aa6ba..1fe2b4e3 100755 --- a/gravity.sh +++ b/gravity.sh @@ -120,7 +120,7 @@ database_table_from_file() { do # Only add non-empty lines if [[ ! -z "${domain}" ]]; then - echo "${rowid},\"${domain}\",1,${timestamp},${timestamp},0,\"Migrated from ${source}\"" >> "${tmpFile}" + echo "${rowid},\"${domain}\",1,${timestamp},${timestamp},\"Migrated from ${source}\"" >> "${tmpFile}" rowid+=1 fi done From 94d83dbb2d410c0303ec09ab7e5365cb4772cb10 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 30 Jun 2019 19:33:02 +0200 Subject: [PATCH 06/13] Unify the two group tables into a single "groups" table. This allows managing adlists and domains together. Signed-off-by: DL6ER --- advanced/Templates/gravity.db.sql | 33 ++++++++++++------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/advanced/Templates/gravity.db.sql b/advanced/Templates/gravity.db.sql index 77de31aa..dfb486a8 100644 --- a/advanced/Templates/gravity.db.sql +++ b/advanced/Templates/gravity.db.sql @@ -1,6 +1,6 @@ PRAGMA FOREIGN_KEYS=ON; -CREATE TABLE domain_groups +CREATE TABLE groups ( id INTEGER PRIMARY KEY AUTOINCREMENT, enabled BOOLEAN NOT NULL DEFAULT 1, @@ -20,7 +20,7 @@ CREATE TABLE whitelist CREATE TABLE whitelist_by_group ( whitelist_id INTEGER NOT NULL REFERENCES whitelist (id), - group_id INTEGER NOT NULL REFERENCES domain_groups (id), + group_id INTEGER NOT NULL REFERENCES groups (id), PRIMARY KEY (whitelist_id, group_id) ); @@ -37,7 +37,7 @@ CREATE TABLE blacklist CREATE TABLE blacklist_by_group ( blacklist_id INTEGER NOT NULL REFERENCES blacklist (id), - group_id INTEGER NOT NULL REFERENCES domain_groups (id), + group_id INTEGER NOT NULL REFERENCES groups (id), PRIMARY KEY (blacklist_id, group_id) ); @@ -54,17 +54,10 @@ CREATE TABLE regex CREATE TABLE regex_by_group ( regex_id INTEGER NOT NULL REFERENCES regex (id), - group_id INTEGER NOT NULL REFERENCES domain_groups (id), + group_id INTEGER NOT NULL REFERENCES groups (id), PRIMARY KEY (regex_id, group_id) ); -CREATE TABLE adlists_groups -( - id INTEGER PRIMARY KEY AUTOINCREMENT, - enabled BOOLEAN NOT NULL DEFAULT 1, - description TEXT -); - CREATE TABLE adlists ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -78,7 +71,7 @@ CREATE TABLE adlists CREATE TABLE adlists_by_group ( adlists_id INTEGER NOT NULL REFERENCES adlists (id), - group_id INTEGER NOT NULL REFERENCES adlists_groups (id), + group_id INTEGER NOT NULL REFERENCES groups (id), PRIMARY KEY (adlists_id, group_id) ); @@ -101,8 +94,8 @@ CREATE VIEW vw_gravity AS SELECT domain CREATE VIEW vw_whitelist AS SELECT domain FROM whitelist LEFT JOIN whitelist_by_group ON whitelist_by_group.whitelist_id = whitelist.id - LEFT JOIN domain_groups ON domain_groups.id = whitelist_by_group.group_id - WHERE whitelist.enabled = 1 AND domain_groups.enabled IS NULL OR domain_groups.enabled == 1 + LEFT JOIN groups ON groups.id = whitelist_by_group.group_id + WHERE whitelist.enabled = 1 AND groups.enabled IS NULL OR groups.enabled == 1 ORDER BY whitelist.id; CREATE TRIGGER tr_whitelist_update AFTER UPDATE ON whitelist @@ -113,8 +106,8 @@ CREATE TRIGGER tr_whitelist_update AFTER UPDATE ON whitelist CREATE VIEW vw_blacklist AS SELECT domain FROM blacklist LEFT JOIN blacklist_by_group ON blacklist_by_group.blacklist_id = blacklist.id - LEFT JOIN domain_groups ON domain_groups.id = blacklist_by_group.group_id - WHERE blacklist.enabled = 1 AND domain_groups.enabled IS NULL OR domain_groups.enabled == 1 + LEFT JOIN groups ON groups.id = blacklist_by_group.group_id + WHERE blacklist.enabled = 1 AND groups.enabled IS NULL OR groups.enabled == 1 ORDER BY blacklist.id; CREATE TRIGGER tr_blacklist_update AFTER UPDATE ON blacklist @@ -125,8 +118,8 @@ CREATE TRIGGER tr_blacklist_update AFTER UPDATE ON blacklist CREATE VIEW vw_regex AS SELECT domain FROM regex LEFT JOIN regex_by_group ON regex_by_group.regex_id = regex.id - LEFT JOIN domain_groups ON domain_groups.id = regex_by_group.group_id - WHERE regex.enabled = 1 AND domain_groups.enabled IS NULL OR domain_groups.enabled == 1 + LEFT JOIN groups ON groups.id = regex_by_group.group_id + WHERE regex.enabled = 1 AND groups.enabled IS NULL OR groups.enabled == 1 ORDER BY regex.id; CREATE TRIGGER tr_regex_update AFTER UPDATE ON regex @@ -137,8 +130,8 @@ CREATE TRIGGER tr_regex_update AFTER UPDATE ON regex CREATE VIEW vw_adlists AS SELECT address FROM adlists LEFT JOIN adlists_by_group ON adlists_by_group.adlists_id = adlists.id - LEFT JOIN adlists_groups ON adlists_groups.id = adlists_by_group.group_id - WHERE adlists.enabled = 1 AND adlists_groups.enabled IS NULL OR adlists_groups.enabled == 1 + LEFT JOIN groups ON groups.id = adlists_by_group.group_id + WHERE adlists.enabled = 1 AND groups.enabled IS NULL OR groups.enabled == 1 ORDER BY adlists.id; CREATE TRIGGER tr_adlists_update AFTER UPDATE ON adlists From 6fe637b9ee18e657c2806ba2ba3d1c86c5e8b2bc Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 30 Jun 2019 19:43:18 +0200 Subject: [PATCH 07/13] Rename groups -> group Signed-off-by: DL6ER --- advanced/Templates/gravity.db.sql | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/advanced/Templates/gravity.db.sql b/advanced/Templates/gravity.db.sql index dfb486a8..3c2562b4 100644 --- a/advanced/Templates/gravity.db.sql +++ b/advanced/Templates/gravity.db.sql @@ -1,6 +1,6 @@ PRAGMA FOREIGN_KEYS=ON; -CREATE TABLE groups +CREATE TABLE group ( id INTEGER PRIMARY KEY AUTOINCREMENT, enabled BOOLEAN NOT NULL DEFAULT 1, @@ -20,7 +20,7 @@ CREATE TABLE whitelist CREATE TABLE whitelist_by_group ( whitelist_id INTEGER NOT NULL REFERENCES whitelist (id), - group_id INTEGER NOT NULL REFERENCES groups (id), + group_id INTEGER NOT NULL REFERENCES group (id), PRIMARY KEY (whitelist_id, group_id) ); @@ -37,7 +37,7 @@ CREATE TABLE blacklist CREATE TABLE blacklist_by_group ( blacklist_id INTEGER NOT NULL REFERENCES blacklist (id), - group_id INTEGER NOT NULL REFERENCES groups (id), + group_id INTEGER NOT NULL REFERENCES group (id), PRIMARY KEY (blacklist_id, group_id) ); @@ -54,7 +54,7 @@ CREATE TABLE regex CREATE TABLE regex_by_group ( regex_id INTEGER NOT NULL REFERENCES regex (id), - group_id INTEGER NOT NULL REFERENCES groups (id), + group_id INTEGER NOT NULL REFERENCES group (id), PRIMARY KEY (regex_id, group_id) ); @@ -71,7 +71,7 @@ CREATE TABLE adlists CREATE TABLE adlists_by_group ( adlists_id INTEGER NOT NULL REFERENCES adlists (id), - group_id INTEGER NOT NULL REFERENCES groups (id), + group_id INTEGER NOT NULL REFERENCES group (id), PRIMARY KEY (adlists_id, group_id) ); @@ -94,8 +94,8 @@ CREATE VIEW vw_gravity AS SELECT domain CREATE VIEW vw_whitelist AS SELECT domain FROM whitelist LEFT JOIN whitelist_by_group ON whitelist_by_group.whitelist_id = whitelist.id - LEFT JOIN groups ON groups.id = whitelist_by_group.group_id - WHERE whitelist.enabled = 1 AND groups.enabled IS NULL OR groups.enabled == 1 + LEFT JOIN group ON group.id = whitelist_by_group.group_id + WHERE whitelist.enabled = 1 AND group.enabled IS NULL OR group.enabled = 1 ORDER BY whitelist.id; CREATE TRIGGER tr_whitelist_update AFTER UPDATE ON whitelist @@ -106,8 +106,8 @@ CREATE TRIGGER tr_whitelist_update AFTER UPDATE ON whitelist CREATE VIEW vw_blacklist AS SELECT domain FROM blacklist LEFT JOIN blacklist_by_group ON blacklist_by_group.blacklist_id = blacklist.id - LEFT JOIN groups ON groups.id = blacklist_by_group.group_id - WHERE blacklist.enabled = 1 AND groups.enabled IS NULL OR groups.enabled == 1 + LEFT JOIN group ON group.id = blacklist_by_group.group_id + WHERE blacklist.enabled = 1 AND group.enabled IS NULL OR group.enabled = 1 ORDER BY blacklist.id; CREATE TRIGGER tr_blacklist_update AFTER UPDATE ON blacklist @@ -118,8 +118,8 @@ CREATE TRIGGER tr_blacklist_update AFTER UPDATE ON blacklist CREATE VIEW vw_regex AS SELECT domain FROM regex LEFT JOIN regex_by_group ON regex_by_group.regex_id = regex.id - LEFT JOIN groups ON groups.id = regex_by_group.group_id - WHERE regex.enabled = 1 AND groups.enabled IS NULL OR groups.enabled == 1 + LEFT JOIN group ON group.id = regex_by_group.group_id + WHERE regex.enabled = 1 AND group.enabled IS NULL OR group.enabled = 1 ORDER BY regex.id; CREATE TRIGGER tr_regex_update AFTER UPDATE ON regex @@ -130,8 +130,8 @@ CREATE TRIGGER tr_regex_update AFTER UPDATE ON regex CREATE VIEW vw_adlists AS SELECT address FROM adlists LEFT JOIN adlists_by_group ON adlists_by_group.adlists_id = adlists.id - LEFT JOIN groups ON groups.id = adlists_by_group.group_id - WHERE adlists.enabled = 1 AND groups.enabled IS NULL OR groups.enabled == 1 + LEFT JOIN group ON group.id = adlists_by_group.group_id + WHERE adlists.enabled = 1 AND group.enabled IS NULL OR group.enabled = 1 ORDER BY adlists.id; CREATE TRIGGER tr_adlists_update AFTER UPDATE ON adlists From 5b01facd73f52ccb248a65109b45a62e327c597d Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 30 Jun 2019 20:03:22 +0200 Subject: [PATCH 08/13] Fix logix on the views: AND ( OR ) Signed-off-by: DL6ER --- advanced/Templates/gravity.db.sql | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/advanced/Templates/gravity.db.sql b/advanced/Templates/gravity.db.sql index 3c2562b4..66df7111 100644 --- a/advanced/Templates/gravity.db.sql +++ b/advanced/Templates/gravity.db.sql @@ -1,6 +1,6 @@ PRAGMA FOREIGN_KEYS=ON; -CREATE TABLE group +CREATE TABLE "group" ( id INTEGER PRIMARY KEY AUTOINCREMENT, enabled BOOLEAN NOT NULL DEFAULT 1, @@ -20,7 +20,7 @@ CREATE TABLE whitelist CREATE TABLE whitelist_by_group ( whitelist_id INTEGER NOT NULL REFERENCES whitelist (id), - group_id INTEGER NOT NULL REFERENCES group (id), + group_id INTEGER NOT NULL REFERENCES "group" (id), PRIMARY KEY (whitelist_id, group_id) ); @@ -37,7 +37,7 @@ CREATE TABLE blacklist CREATE TABLE blacklist_by_group ( blacklist_id INTEGER NOT NULL REFERENCES blacklist (id), - group_id INTEGER NOT NULL REFERENCES group (id), + group_id INTEGER NOT NULL REFERENCES "group" (id), PRIMARY KEY (blacklist_id, group_id) ); @@ -54,7 +54,7 @@ CREATE TABLE regex CREATE TABLE regex_by_group ( regex_id INTEGER NOT NULL REFERENCES regex (id), - group_id INTEGER NOT NULL REFERENCES group (id), + group_id INTEGER NOT NULL REFERENCES "group" (id), PRIMARY KEY (regex_id, group_id) ); @@ -71,7 +71,7 @@ CREATE TABLE adlists CREATE TABLE adlists_by_group ( adlists_id INTEGER NOT NULL REFERENCES adlists (id), - group_id INTEGER NOT NULL REFERENCES group (id), + group_id INTEGER NOT NULL REFERENCES "group" (id), PRIMARY KEY (adlists_id, group_id) ); @@ -94,8 +94,8 @@ CREATE VIEW vw_gravity AS SELECT domain CREATE VIEW vw_whitelist AS SELECT domain FROM whitelist LEFT JOIN whitelist_by_group ON whitelist_by_group.whitelist_id = whitelist.id - LEFT JOIN group ON group.id = whitelist_by_group.group_id - WHERE whitelist.enabled = 1 AND group.enabled IS NULL OR group.enabled = 1 + LEFT JOIN "group" ON "group".id = whitelist_by_group.group_id + WHERE whitelist.enabled = 1 AND ("group".enabled IS NULL OR "group".enabled = 1) ORDER BY whitelist.id; CREATE TRIGGER tr_whitelist_update AFTER UPDATE ON whitelist @@ -106,8 +106,8 @@ CREATE TRIGGER tr_whitelist_update AFTER UPDATE ON whitelist CREATE VIEW vw_blacklist AS SELECT domain FROM blacklist LEFT JOIN blacklist_by_group ON blacklist_by_group.blacklist_id = blacklist.id - LEFT JOIN group ON group.id = blacklist_by_group.group_id - WHERE blacklist.enabled = 1 AND group.enabled IS NULL OR group.enabled = 1 + LEFT JOIN "group" ON "group".id = blacklist_by_group.group_id + WHERE blacklist.enabled = 1 AND ("group".enabled IS NULL OR "group".enabled = 1) ORDER BY blacklist.id; CREATE TRIGGER tr_blacklist_update AFTER UPDATE ON blacklist @@ -118,8 +118,8 @@ CREATE TRIGGER tr_blacklist_update AFTER UPDATE ON blacklist CREATE VIEW vw_regex AS SELECT domain FROM regex LEFT JOIN regex_by_group ON regex_by_group.regex_id = regex.id - LEFT JOIN group ON group.id = regex_by_group.group_id - WHERE regex.enabled = 1 AND group.enabled IS NULL OR group.enabled = 1 + LEFT JOIN "group" ON "group".id = regex_by_group.group_id + WHERE regex.enabled = 1 AND ("group".enabled IS NULL OR "group".enabled = 1) ORDER BY regex.id; CREATE TRIGGER tr_regex_update AFTER UPDATE ON regex @@ -130,8 +130,8 @@ CREATE TRIGGER tr_regex_update AFTER UPDATE ON regex CREATE VIEW vw_adlists AS SELECT address FROM adlists LEFT JOIN adlists_by_group ON adlists_by_group.adlists_id = adlists.id - LEFT JOIN group ON group.id = adlists_by_group.group_id - WHERE adlists.enabled = 1 AND group.enabled IS NULL OR group.enabled = 1 + LEFT JOIN "group" ON "group".id = adlists_by_group.group_id + WHERE adlists.enabled = 1 AND ("group".enabled IS NULL OR "group".enabled = 1) ORDER BY adlists.id; CREATE TRIGGER tr_adlists_update AFTER UPDATE ON adlists From ad97e95f2fbf101011ac053793dc72da15568c99 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 30 Jun 2019 23:06:15 +0200 Subject: [PATCH 09/13] Add required name column in group table. Signed-off-by: DL6ER --- advanced/Templates/gravity.db.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/Templates/gravity.db.sql b/advanced/Templates/gravity.db.sql index 66df7111..9be4bbf9 100644 --- a/advanced/Templates/gravity.db.sql +++ b/advanced/Templates/gravity.db.sql @@ -4,6 +4,7 @@ CREATE TABLE "group" ( id INTEGER PRIMARY KEY AUTOINCREMENT, enabled BOOLEAN NOT NULL DEFAULT 1, + name TEXT NOT NULL, description TEXT ); From 3a14e8b013a0ebc5e8133d78153920d6326b7fd9 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 30 Jun 2019 23:07:03 +0200 Subject: [PATCH 10/13] Check whitelist_by_group.group_id instead of group.enabled against NULL. Signed-off-by: DL6ER --- advanced/Templates/gravity.db.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/advanced/Templates/gravity.db.sql b/advanced/Templates/gravity.db.sql index 9be4bbf9..a5fd5bef 100644 --- a/advanced/Templates/gravity.db.sql +++ b/advanced/Templates/gravity.db.sql @@ -96,7 +96,7 @@ CREATE VIEW vw_whitelist AS SELECT domain FROM whitelist LEFT JOIN whitelist_by_group ON whitelist_by_group.whitelist_id = whitelist.id LEFT JOIN "group" ON "group".id = whitelist_by_group.group_id - WHERE whitelist.enabled = 1 AND ("group".enabled IS NULL OR "group".enabled = 1) + WHERE whitelist.enabled = 1 AND (whitelist_by_group.group_id IS NULL OR "group".enabled = 1) ORDER BY whitelist.id; CREATE TRIGGER tr_whitelist_update AFTER UPDATE ON whitelist @@ -108,7 +108,7 @@ CREATE VIEW vw_blacklist AS SELECT domain FROM blacklist LEFT JOIN blacklist_by_group ON blacklist_by_group.blacklist_id = blacklist.id LEFT JOIN "group" ON "group".id = blacklist_by_group.group_id - WHERE blacklist.enabled = 1 AND ("group".enabled IS NULL OR "group".enabled = 1) + WHERE blacklist.enabled = 1 AND (blacklist_by_group.group_id IS NULL OR "group".enabled = 1) ORDER BY blacklist.id; CREATE TRIGGER tr_blacklist_update AFTER UPDATE ON blacklist @@ -120,7 +120,7 @@ CREATE VIEW vw_regex AS SELECT domain FROM regex LEFT JOIN regex_by_group ON regex_by_group.regex_id = regex.id LEFT JOIN "group" ON "group".id = regex_by_group.group_id - WHERE regex.enabled = 1 AND ("group".enabled IS NULL OR "group".enabled = 1) + WHERE regex.enabled = 1 AND (regex_by_group.group_id IS NULL OR "group".enabled = 1) ORDER BY regex.id; CREATE TRIGGER tr_regex_update AFTER UPDATE ON regex @@ -132,7 +132,7 @@ CREATE VIEW vw_adlists AS SELECT address FROM adlists LEFT JOIN adlists_by_group ON adlists_by_group.adlists_id = adlists.id LEFT JOIN "group" ON "group".id = adlists_by_group.group_id - WHERE adlists.enabled = 1 AND ("group".enabled IS NULL OR "group".enabled = 1) + WHERE adlists.enabled = 1 AND (adlists_by_group.group_id IS NULL OR "group".enabled = 1) ORDER BY adlists.id; CREATE TRIGGER tr_adlists_update AFTER UPDATE ON adlists From f91421418ad3817023b53585a351a2778b644034 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 30 Jun 2019 23:21:10 +0200 Subject: [PATCH 11/13] Rename adlists -> adlist table. Signed-off-by: DL6ER --- advanced/Templates/gravity.db.sql | 24 ++++++++++++------------ gravity.sh | 10 +++++----- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/advanced/Templates/gravity.db.sql b/advanced/Templates/gravity.db.sql index a5fd5bef..3cbc7b8f 100644 --- a/advanced/Templates/gravity.db.sql +++ b/advanced/Templates/gravity.db.sql @@ -59,7 +59,7 @@ CREATE TABLE regex_by_group PRIMARY KEY (regex_id, group_id) ); -CREATE TABLE adlists +CREATE TABLE adlist ( id INTEGER PRIMARY KEY AUTOINCREMENT, address TEXT UNIQUE NOT NULL, @@ -69,11 +69,11 @@ CREATE TABLE adlists comment TEXT ); -CREATE TABLE adlists_by_group +CREATE TABLE adlist_by_group ( - adlists_id INTEGER NOT NULL REFERENCES adlists (id), + adlist_id INTEGER NOT NULL REFERENCES adlist (id), group_id INTEGER NOT NULL REFERENCES "group" (id), - PRIMARY KEY (adlists_id, group_id) + PRIMARY KEY (adlist_id, group_id) ); CREATE TABLE gravity @@ -128,15 +128,15 @@ CREATE TRIGGER tr_regex_update AFTER UPDATE ON regex UPDATE regex SET date_modified = (cast(strftime('%s', 'now') as int)) WHERE domain = NEW.domain; END; -CREATE VIEW vw_adlists AS SELECT address - FROM adlists - LEFT JOIN adlists_by_group ON adlists_by_group.adlists_id = adlists.id - LEFT JOIN "group" ON "group".id = adlists_by_group.group_id - WHERE adlists.enabled = 1 AND (adlists_by_group.group_id IS NULL OR "group".enabled = 1) - ORDER BY adlists.id; +CREATE VIEW vw_adlist AS SELECT address + FROM adlist + LEFT JOIN adlist_by_group ON adlist_by_group.adlist_id = adlist.id + LEFT JOIN "group" ON "group".id = adlist_by_group.group_id + WHERE adlist.enabled = 1 AND (adlist_by_group.group_id IS NULL OR "group".enabled = 1) + ORDER BY adlist.id; -CREATE TRIGGER tr_adlists_update AFTER UPDATE ON adlists +CREATE TRIGGER tr_adlist_update AFTER UPDATE ON adlist BEGIN - UPDATE adlists SET date_modified = (cast(strftime('%s', 'now') as int)) WHERE address = NEW.address; + UPDATE adlist SET date_modified = (cast(strftime('%s', 'now') as int)) WHERE address = NEW.address; END; diff --git a/gravity.sh b/gravity.sh index 1fe2b4e3..d2436002 100755 --- a/gravity.sh +++ b/gravity.sh @@ -111,7 +111,7 @@ database_table_from_file() { # No need to modify the input data for the gravity table inputfile="${source}" else - # Apply format for white-, blacklist, regex, and adlists tables + # Apply format for white-, blacklist, regex, and adlist tables local rowid declare -i rowid rowid=1 @@ -159,9 +159,9 @@ migrate_to_database() { # Migrate list files to new database if [[ -e "${adListFile}" ]]; then - # Store adlists domains in database + # Store adlist domains in database echo -e " ${INFO} Migrating content of ${adListFile} into new database" - database_table_from_file "adlists" "${adListFile}" + database_table_from_file "adlist" "${adListFile}" fi if [[ -e "${blacklistFile}" ]]; then # Store blacklisted domains in database @@ -236,13 +236,13 @@ gravity_CheckDNSResolutionAvailable() { gravity_CheckDNSResolutionAvailable } -# Retrieve blocklist URLs and parse domains from adlists.list +# Retrieve blocklist URLs and parse domains from adlist.list gravity_GetBlocklistUrls() { echo -e " ${INFO} ${COL_BOLD}Neutrino emissions detected${COL_NC}..." # Retrieve source URLs from gravity database # We source only enabled adlists, sqlite3 stores boolean values as 0 (false) or 1 (true) - mapfile -t sources <<< "$(sqlite3 "${gravityDBfile}" "SELECT address FROM vw_adlists;" 2> /dev/null)" + mapfile -t sources <<< "$(sqlite3 "${gravityDBfile}" "SELECT address FROM vw_adlist;" 2> /dev/null)" # Parse source domains from $sources mapfile -t sourceDomains <<< "$( From 23b3a9a650d49afd8a1fd945f88415c659cce0d9 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 1 Jul 2019 09:44:20 +0200 Subject: [PATCH 12/13] Add DISTINCT to the view\'s SELECT queries to avoid domain duplication in case they are enabled in multiple groups at the same time. Signed-off-by: DL6ER --- advanced/Templates/gravity.db.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/advanced/Templates/gravity.db.sql b/advanced/Templates/gravity.db.sql index 3cbc7b8f..91a38ef7 100644 --- a/advanced/Templates/gravity.db.sql +++ b/advanced/Templates/gravity.db.sql @@ -92,7 +92,7 @@ CREATE VIEW vw_gravity AS SELECT domain FROM gravity WHERE domain NOT IN (SELECT domain from vw_whitelist); -CREATE VIEW vw_whitelist AS SELECT domain +CREATE VIEW vw_whitelist AS SELECT DISTINCT domain FROM whitelist LEFT JOIN whitelist_by_group ON whitelist_by_group.whitelist_id = whitelist.id LEFT JOIN "group" ON "group".id = whitelist_by_group.group_id @@ -104,7 +104,7 @@ CREATE TRIGGER tr_whitelist_update AFTER UPDATE ON whitelist UPDATE whitelist SET date_modified = (cast(strftime('%s', 'now') as int)) WHERE domain = NEW.domain; END; -CREATE VIEW vw_blacklist AS SELECT domain +CREATE VIEW vw_blacklist AS SELECT DISTINCT domain FROM blacklist LEFT JOIN blacklist_by_group ON blacklist_by_group.blacklist_id = blacklist.id LEFT JOIN "group" ON "group".id = blacklist_by_group.group_id @@ -116,7 +116,7 @@ CREATE TRIGGER tr_blacklist_update AFTER UPDATE ON blacklist UPDATE blacklist SET date_modified = (cast(strftime('%s', 'now') as int)) WHERE domain = NEW.domain; END; -CREATE VIEW vw_regex AS SELECT domain +CREATE VIEW vw_regex AS SELECT DISTINCT domain FROM regex LEFT JOIN regex_by_group ON regex_by_group.regex_id = regex.id LEFT JOIN "group" ON "group".id = regex_by_group.group_id @@ -128,7 +128,7 @@ CREATE TRIGGER tr_regex_update AFTER UPDATE ON regex UPDATE regex SET date_modified = (cast(strftime('%s', 'now') as int)) WHERE domain = NEW.domain; END; -CREATE VIEW vw_adlist AS SELECT address +CREATE VIEW vw_adlist AS SELECT DISTINCT address FROM adlist LEFT JOIN adlist_by_group ON adlist_by_group.adlist_id = adlist.id LEFT JOIN "group" ON "group".id = adlist_by_group.group_id From 1fe3507bc5e5e76109eecd9bd025dd024abf858f Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 3 Jul 2019 07:56:10 +0200 Subject: [PATCH 13/13] Adlists table was renamed to Adlist. Adapt further places in the code to match the new name. Signed-off-by: DL6ER --- advanced/Scripts/piholeDebug.sh | 2 +- advanced/Scripts/query.sh | 2 +- advanced/Scripts/webpage.sh | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index b31bbdc5..2bfeef2d 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -1077,7 +1077,7 @@ show_db_entries() { } show_adlists() { - show_db_entries "Adlists" "SELECT * FROM adlists" "4 100 7 10 13 50" + show_db_entries "Adlists" "SELECT * FROM adlist" "4 100 7 10 13 50" } show_whitelist() { diff --git a/advanced/Scripts/query.sh b/advanced/Scripts/query.sh index 42ea4395..af5ae0a8 100755 --- a/advanced/Scripts/query.sh +++ b/advanced/Scripts/query.sh @@ -201,7 +201,7 @@ fi # Get adlist file content as array if [[ -n "${adlist}" ]] || [[ -n "${blockpage}" ]]; then # Retrieve source URLs from gravity database - mapfile -t adlists <<< "$(sqlite3 "${gravityDBfile}" "SELECT address FROM vw_adlists;" 2> /dev/null)" + mapfile -t adlists <<< "$(sqlite3 "${gravityDBfile}" "SELECT address FROM vw_adlist;" 2> /dev/null)" fi # Print "Exact matches for" title diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 583579b6..f744d1b9 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -400,13 +400,13 @@ CustomizeAdLists() { address="${args[3]}" if [[ "${args[2]}" == "enable" ]]; then - sqlite3 "${gravityDBfile}" "UPDATE adlists SET enabled = 1 WHERE address = '${address}'" + sqlite3 "${gravityDBfile}" "UPDATE adlist SET enabled = 1 WHERE address = '${address}'" elif [[ "${args[2]}" == "disable" ]]; then - sqlite3 "${gravityDBfile}" "UPDATE adlists SET enabled = 0 WHERE address = '${address}'" + sqlite3 "${gravityDBfile}" "UPDATE adlist SET enabled = 0 WHERE address = '${address}'" elif [[ "${args[2]}" == "add" ]]; then - sqlite3 "${gravityDBfile}" "INSERT OR IGNORE INTO adlists (address) VALUES ('${address}')" + sqlite3 "${gravityDBfile}" "INSERT OR IGNORE INTO adlist (address) VALUES ('${address}')" elif [[ "${args[2]}" == "del" ]]; then - sqlite3 "${gravityDBfile}" "DELETE FROM adlists WHERE address = '${address}'" + sqlite3 "${gravityDBfile}" "DELETE FROM adlist WHERE address = '${address}'" else echo "Not permitted" return 1