2020-01-24 17:39:13 +00:00
|
|
|
PRAGMA foreign_keys=OFF;
|
|
|
|
BEGIN TRANSACTION;
|
2019-06-16 14:50:51 +00:00
|
|
|
|
2019-06-30 18:03:22 +00:00
|
|
|
CREATE TABLE "group"
|
2019-06-16 14:50:51 +00:00
|
|
|
(
|
2019-06-30 16:58:47 +00:00
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
enabled BOOLEAN NOT NULL DEFAULT 1,
|
2020-01-24 17:39:13 +00:00
|
|
|
name TEXT UNIQUE NOT NULL,
|
|
|
|
date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)),
|
|
|
|
date_modified INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)),
|
2019-06-30 16:58:47 +00:00
|
|
|
description TEXT
|
2019-06-16 14:50:51 +00:00
|
|
|
);
|
2020-05-07 15:55:35 +00:00
|
|
|
INSERT INTO "group" (id,enabled,name,description) VALUES (0,1,'Default','The default group');
|
2019-06-16 14:50:51 +00:00
|
|
|
|
2020-01-24 17:39:13 +00:00
|
|
|
CREATE TABLE domainlist
|
2019-05-01 15:57:23 +00:00
|
|
|
(
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
2020-01-24 17:39:13 +00:00
|
|
|
type INTEGER NOT NULL DEFAULT 0,
|
2020-06-02 08:49:35 +00:00
|
|
|
domain TEXT NOT NULL,
|
2019-05-01 15:57:23 +00:00
|
|
|
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)),
|
2020-06-02 08:49:35 +00:00
|
|
|
comment TEXT,
|
|
|
|
UNIQUE(domain, type)
|
2019-06-30 16:58:47 +00:00
|
|
|
);
|
|
|
|
|
2020-01-24 17:39:13 +00:00
|
|
|
CREATE TABLE adlist
|
2019-05-01 15:57:23 +00:00
|
|
|
(
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
2024-02-11 15:54:22 +00:00
|
|
|
address TEXT NOT NULL,
|
2019-05-01 15:57:23 +00:00
|
|
|
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)),
|
2020-07-13 18:47:12 +00:00
|
|
|
comment TEXT,
|
2020-12-27 18:14:52 +00:00
|
|
|
date_updated INTEGER,
|
|
|
|
number INTEGER NOT NULL DEFAULT 0,
|
|
|
|
invalid_domains INTEGER NOT NULL DEFAULT 0,
|
2023-06-15 07:28:03 +00:00
|
|
|
status INTEGER NOT NULL DEFAULT 0,
|
2023-07-05 20:24:11 +00:00
|
|
|
abp_entries INTEGER NOT NULL DEFAULT 0,
|
2024-02-11 15:54:22 +00:00
|
|
|
type INTEGER NOT NULL DEFAULT 0,
|
|
|
|
UNIQUE(address, type)
|
2019-06-30 16:58:47 +00:00
|
|
|
);
|
|
|
|
|
2020-01-24 17:39:13 +00:00
|
|
|
CREATE TABLE adlist_by_group
|
2019-06-30 16:58:47 +00:00
|
|
|
(
|
2020-01-24 17:39:13 +00:00
|
|
|
adlist_id INTEGER NOT NULL REFERENCES adlist (id),
|
2019-06-30 18:03:22 +00:00
|
|
|
group_id INTEGER NOT NULL REFERENCES "group" (id),
|
2020-01-24 17:39:13 +00:00
|
|
|
PRIMARY KEY (adlist_id, group_id)
|
2019-05-01 15:57:23 +00:00
|
|
|
);
|
2019-06-30 16:58:47 +00:00
|
|
|
|
2020-01-24 17:39:13 +00:00
|
|
|
CREATE TABLE gravity
|
2019-05-01 15:57:23 +00:00
|
|
|
(
|
2020-01-24 17:39:13 +00:00
|
|
|
domain TEXT NOT NULL,
|
|
|
|
adlist_id INTEGER NOT NULL REFERENCES adlist (id)
|
2019-05-01 15:57:23 +00:00
|
|
|
);
|
2019-06-16 15:05:33 +00:00
|
|
|
|
2023-07-05 20:24:11 +00:00
|
|
|
CREATE TABLE antigravity
|
|
|
|
(
|
|
|
|
domain TEXT NOT NULL,
|
|
|
|
adlist_id INTEGER NOT NULL REFERENCES adlist (id)
|
|
|
|
);
|
|
|
|
|
2020-01-24 17:39:13 +00:00
|
|
|
CREATE TABLE info
|
2019-06-16 15:05:33 +00:00
|
|
|
(
|
2020-01-24 17:39:13 +00:00
|
|
|
property TEXT PRIMARY KEY,
|
|
|
|
value TEXT NOT NULL
|
2019-06-30 16:58:47 +00:00
|
|
|
);
|
|
|
|
|
2023-12-25 04:29:11 +00:00
|
|
|
INSERT INTO "info" VALUES('version','18');
|
2020-01-24 17:39:13 +00:00
|
|
|
|
|
|
|
CREATE TABLE domain_audit
|
2019-05-01 15:57:23 +00:00
|
|
|
(
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
2020-01-24 17:39:13 +00:00
|
|
|
domain TEXT UNIQUE NOT NULL,
|
|
|
|
date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int))
|
2019-05-01 15:57:23 +00:00
|
|
|
);
|
2019-06-30 16:58:47 +00:00
|
|
|
|
2020-01-24 17:39:13 +00:00
|
|
|
CREATE TABLE domainlist_by_group
|
2019-06-30 16:58:47 +00:00
|
|
|
(
|
2020-01-24 17:39:13 +00:00
|
|
|
domainlist_id INTEGER NOT NULL REFERENCES domainlist (id),
|
2019-06-30 18:03:22 +00:00
|
|
|
group_id INTEGER NOT NULL REFERENCES "group" (id),
|
2020-01-24 17:39:13 +00:00
|
|
|
PRIMARY KEY (domainlist_id, group_id)
|
2019-06-30 16:58:47 +00:00
|
|
|
);
|
|
|
|
|
2020-01-24 17:39:13 +00:00
|
|
|
CREATE TABLE client
|
2019-05-01 15:57:23 +00:00
|
|
|
(
|
2020-01-24 17:39:13 +00:00
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
2020-12-19 23:37:17 +00:00
|
|
|
ip TEXT NOT NULL UNIQUE,
|
2020-01-27 10:36:16 +00:00
|
|
|
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
|
2019-05-01 15:57:23 +00:00
|
|
|
);
|
2019-07-05 11:54:18 +00:00
|
|
|
|
2020-01-24 17:39:13 +00:00
|
|
|
CREATE TABLE client_by_group
|
2019-05-01 15:57:23 +00:00
|
|
|
(
|
2020-01-24 17:39:13 +00:00
|
|
|
client_id INTEGER NOT NULL REFERENCES client (id),
|
|
|
|
group_id INTEGER NOT NULL REFERENCES "group" (id),
|
|
|
|
PRIMARY KEY (client_id, group_id)
|
2019-05-01 15:57:23 +00:00
|
|
|
);
|
2019-02-06 17:57:48 +00:00
|
|
|
|
2020-09-07 19:11:57 +00:00
|
|
|
CREATE TRIGGER tr_adlist_update AFTER UPDATE OF address,enabled,comment ON adlist
|
2020-01-24 17:39:13 +00:00
|
|
|
BEGIN
|
2020-09-07 19:11:57 +00:00
|
|
|
UPDATE adlist SET date_modified = (cast(strftime('%s', 'now') as int)) WHERE id = NEW.id;
|
2020-01-24 17:39:13 +00:00
|
|
|
END;
|
|
|
|
|
2020-01-27 10:36:16 +00:00
|
|
|
CREATE TRIGGER tr_client_update AFTER UPDATE ON client
|
|
|
|
BEGIN
|
|
|
|
UPDATE client SET date_modified = (cast(strftime('%s', 'now') as int)) WHERE ip = NEW.ip;
|
|
|
|
END;
|
|
|
|
|
2020-01-24 17:39:13 +00:00
|
|
|
CREATE TRIGGER tr_domainlist_update AFTER UPDATE ON domainlist
|
|
|
|
BEGIN
|
|
|
|
UPDATE domainlist SET date_modified = (cast(strftime('%s', 'now') as int)) WHERE domain = NEW.domain;
|
|
|
|
END;
|
|
|
|
|
|
|
|
CREATE VIEW vw_whitelist AS SELECT domain, domainlist.id AS id, domainlist_by_group.group_id AS group_id
|
|
|
|
FROM domainlist
|
|
|
|
LEFT JOIN domainlist_by_group ON domainlist_by_group.domainlist_id = domainlist.id
|
|
|
|
LEFT JOIN "group" ON "group".id = domainlist_by_group.group_id
|
|
|
|
WHERE domainlist.enabled = 1 AND (domainlist_by_group.group_id IS NULL OR "group".enabled = 1)
|
|
|
|
AND domainlist.type = 0
|
|
|
|
ORDER BY domainlist.id;
|
|
|
|
|
|
|
|
CREATE VIEW vw_blacklist AS SELECT domain, domainlist.id AS id, domainlist_by_group.group_id AS group_id
|
|
|
|
FROM domainlist
|
|
|
|
LEFT JOIN domainlist_by_group ON domainlist_by_group.domainlist_id = domainlist.id
|
|
|
|
LEFT JOIN "group" ON "group".id = domainlist_by_group.group_id
|
|
|
|
WHERE domainlist.enabled = 1 AND (domainlist_by_group.group_id IS NULL OR "group".enabled = 1)
|
|
|
|
AND domainlist.type = 1
|
|
|
|
ORDER BY domainlist.id;
|
|
|
|
|
|
|
|
CREATE VIEW vw_regex_whitelist AS SELECT domain, domainlist.id AS id, domainlist_by_group.group_id AS group_id
|
|
|
|
FROM domainlist
|
|
|
|
LEFT JOIN domainlist_by_group ON domainlist_by_group.domainlist_id = domainlist.id
|
|
|
|
LEFT JOIN "group" ON "group".id = domainlist_by_group.group_id
|
|
|
|
WHERE domainlist.enabled = 1 AND (domainlist_by_group.group_id IS NULL OR "group".enabled = 1)
|
|
|
|
AND domainlist.type = 2
|
|
|
|
ORDER BY domainlist.id;
|
|
|
|
|
|
|
|
CREATE VIEW vw_regex_blacklist AS SELECT domain, domainlist.id AS id, domainlist_by_group.group_id AS group_id
|
|
|
|
FROM domainlist
|
|
|
|
LEFT JOIN domainlist_by_group ON domainlist_by_group.domainlist_id = domainlist.id
|
|
|
|
LEFT JOIN "group" ON "group".id = domainlist_by_group.group_id
|
|
|
|
WHERE domainlist.enabled = 1 AND (domainlist_by_group.group_id IS NULL OR "group".enabled = 1)
|
|
|
|
AND domainlist.type = 3
|
|
|
|
ORDER BY domainlist.id;
|
|
|
|
|
2023-12-25 04:29:11 +00:00
|
|
|
CREATE VIEW vw_gravity AS SELECT domain, adlist.id AS adlist_id, adlist_by_group.group_id AS group_id
|
2020-01-24 17:39:13 +00:00
|
|
|
FROM gravity
|
|
|
|
LEFT JOIN adlist_by_group ON adlist_by_group.adlist_id = gravity.adlist_id
|
|
|
|
LEFT JOIN adlist ON adlist.id = gravity.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);
|
|
|
|
|
2023-12-25 04:29:11 +00:00
|
|
|
CREATE VIEW vw_antigravity AS SELECT domain, adlist.id AS adlist_id, adlist_by_group.group_id AS group_id
|
2023-07-05 20:24:11 +00:00
|
|
|
FROM antigravity
|
|
|
|
LEFT JOIN adlist_by_group ON adlist_by_group.adlist_id = antigravity.adlist_id
|
|
|
|
LEFT JOIN adlist ON adlist.id = antigravity.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) AND adlist.type = 1;
|
|
|
|
|
2023-07-06 19:33:59 +00:00
|
|
|
CREATE VIEW vw_adlist AS SELECT DISTINCT address, id, type
|
2020-01-24 17:39:13 +00:00
|
|
|
FROM adlist
|
2021-10-08 19:03:21 +00:00
|
|
|
WHERE enabled = 1
|
|
|
|
ORDER BY id;
|
2019-02-05 18:05:11 +00:00
|
|
|
|
2020-01-24 17:39:13 +00:00
|
|
|
CREATE TRIGGER tr_domainlist_add AFTER INSERT ON domainlist
|
|
|
|
BEGIN
|
|
|
|
INSERT INTO domainlist_by_group (domainlist_id, group_id) VALUES (NEW.id, 0);
|
|
|
|
END;
|
2019-05-01 15:50:36 +00:00
|
|
|
|
2020-01-24 17:39:13 +00:00
|
|
|
CREATE TRIGGER tr_client_add AFTER INSERT ON client
|
2019-04-29 17:43:35 +00:00
|
|
|
BEGIN
|
2020-01-24 17:39:13 +00:00
|
|
|
INSERT INTO client_by_group (client_id, group_id) VALUES (NEW.id, 0);
|
2019-05-01 14:38:41 +00:00
|
|
|
END;
|
2019-02-05 18:05:11 +00:00
|
|
|
|
2020-01-24 17:39:13 +00:00
|
|
|
CREATE TRIGGER tr_adlist_add AFTER INSERT ON adlist
|
|
|
|
BEGIN
|
|
|
|
INSERT INTO adlist_by_group (adlist_id, group_id) VALUES (NEW.id, 0);
|
|
|
|
END;
|
2019-05-01 15:50:36 +00:00
|
|
|
|
2020-01-24 17:39:13 +00:00
|
|
|
CREATE TRIGGER tr_group_update AFTER UPDATE ON "group"
|
2019-04-29 17:43:35 +00:00
|
|
|
BEGIN
|
2020-01-24 17:39:13 +00:00
|
|
|
UPDATE "group" SET date_modified = (cast(strftime('%s', 'now') as int)) WHERE id = NEW.id;
|
2019-05-01 14:38:41 +00:00
|
|
|
END;
|
2019-04-28 12:42:52 +00:00
|
|
|
|
2020-01-24 17:39:13 +00:00
|
|
|
CREATE TRIGGER tr_group_zero AFTER DELETE ON "group"
|
|
|
|
BEGIN
|
2020-05-07 15:55:35 +00:00
|
|
|
INSERT OR IGNORE INTO "group" (id,enabled,name) VALUES (0,1,'Default');
|
2020-01-24 17:39:13 +00:00
|
|
|
END;
|
2019-05-01 15:50:36 +00:00
|
|
|
|
2020-01-24 17:39:13 +00:00
|
|
|
CREATE TRIGGER tr_domainlist_delete AFTER DELETE ON domainlist
|
2019-04-29 17:43:35 +00:00
|
|
|
BEGIN
|
2020-01-24 17:39:13 +00:00
|
|
|
DELETE FROM domainlist_by_group WHERE domainlist_id = OLD.id;
|
2019-05-01 14:38:41 +00:00
|
|
|
END;
|
2019-04-26 15:36:00 +00:00
|
|
|
|
2020-01-24 17:39:13 +00:00
|
|
|
CREATE TRIGGER tr_adlist_delete AFTER DELETE ON adlist
|
|
|
|
BEGIN
|
|
|
|
DELETE FROM adlist_by_group WHERE adlist_id = OLD.id;
|
|
|
|
END;
|
2019-05-01 15:50:36 +00:00
|
|
|
|
2020-01-24 17:39:13 +00:00
|
|
|
CREATE TRIGGER tr_client_delete AFTER DELETE ON client
|
2019-04-29 17:43:35 +00:00
|
|
|
BEGIN
|
2020-01-24 17:39:13 +00:00
|
|
|
DELETE FROM client_by_group WHERE client_id = OLD.id;
|
2019-05-01 14:38:41 +00:00
|
|
|
END;
|
2019-04-29 17:43:35 +00:00
|
|
|
|
2020-01-24 17:39:13 +00:00
|
|
|
COMMIT;
|