1
0
mirror of https://github.com/pi-hole/pi-hole synced 2024-12-22 23:08:07 +00:00

Add filtering by domain groups to gravity database.

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER 2019-06-16 16:50:51 +02:00
parent 67dda9c8bb
commit c53ee4202b
No known key found for this signature in database
GPG Key ID: FB60471F0575164A

View File

@ -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 CREATE TABLE whitelist
( (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
@ -5,7 +15,9 @@ CREATE TABLE whitelist
enabled BOOLEAN NOT NULL DEFAULT 1, enabled BOOLEAN NOT NULL DEFAULT 1,
date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)),
date_modified 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 CREATE TABLE blacklist
( (
@ -14,7 +26,9 @@ CREATE TABLE blacklist
enabled BOOLEAN NOT NULL DEFAULT 1, enabled BOOLEAN NOT NULL DEFAULT 1,
date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)),
date_modified 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 CREATE TABLE regex
( (
@ -23,7 +37,9 @@ CREATE TABLE regex
enabled BOOLEAN NOT NULL DEFAULT 1, enabled BOOLEAN NOT NULL DEFAULT 1,
date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)),
date_modified 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 CREATE TABLE adlists
( (
@ -52,7 +68,8 @@ CREATE VIEW vw_gravity AS SELECT a.domain
CREATE VIEW vw_whitelist AS SELECT a.domain CREATE VIEW vw_whitelist AS SELECT a.domain
FROM whitelist a 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; ORDER BY a.id;
CREATE TRIGGER tr_whitelist_update AFTER UPDATE ON whitelist 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 CREATE VIEW vw_blacklist AS SELECT a.domain
FROM blacklist a 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; ORDER BY a.id;
CREATE TRIGGER tr_blacklist_update AFTER UPDATE ON blacklist 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 CREATE VIEW vw_regex AS SELECT a.domain
FROM regex a 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; ORDER BY a.id;
CREATE TRIGGER tr_regex_update AFTER UPDATE ON regex CREATE TRIGGER tr_regex_update AFTER UPDATE ON regex