mirror of
https://github.com/pi-hole/pi-hole.git
synced 2025-01-25 22:09:49 +00:00
Add antigravity support to gravity
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
parent
aec852fa51
commit
00cbb8bc8a
4 changed files with 53 additions and 9 deletions
|
@ -134,4 +134,11 @@ upgrade_gravityDB(){
|
||||||
pihole-FTL sqlite3 "${database}" < "${scriptPath}/15_to_16.sql"
|
pihole-FTL sqlite3 "${database}" < "${scriptPath}/15_to_16.sql"
|
||||||
version=16
|
version=16
|
||||||
fi
|
fi
|
||||||
|
if [[ "$version" == "16" ]]; then
|
||||||
|
# Add antigravity table
|
||||||
|
# Add column type to adlist table (to support adlist types)
|
||||||
|
echo -e " ${INFO} Upgrading gravity database from version 16 to 17"
|
||||||
|
pihole-FTL sqlite3 "${database}" < "${scriptPath}/16_to_17.sql"
|
||||||
|
version=17
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
13
advanced/Scripts/database_migration/gravity/16_to_17.sql
Normal file
13
advanced/Scripts/database_migration/gravity/16_to_17.sql
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
.timeout 30000
|
||||||
|
|
||||||
|
PRAGMA FOREIGN_KEYS=OFF;
|
||||||
|
|
||||||
|
BEGIN TRANSACTION;
|
||||||
|
|
||||||
|
ALTER TABLE adlist ADD COLUMN type INTEGER NOT NULL DEFAULT 0;
|
||||||
|
|
||||||
|
UPDATE adlist SET type = 0;
|
||||||
|
|
||||||
|
UPDATE info SET value = 17 WHERE property = 'version';
|
||||||
|
|
||||||
|
COMMIT;
|
|
@ -36,7 +36,8 @@ CREATE TABLE adlist
|
||||||
number INTEGER NOT NULL DEFAULT 0,
|
number INTEGER NOT NULL DEFAULT 0,
|
||||||
invalid_domains INTEGER NOT NULL DEFAULT 0,
|
invalid_domains INTEGER NOT NULL DEFAULT 0,
|
||||||
status INTEGER NOT NULL DEFAULT 0,
|
status INTEGER NOT NULL DEFAULT 0,
|
||||||
abp_entries INTEGER NOT NULL DEFAULT 0
|
abp_entries INTEGER NOT NULL DEFAULT 0,
|
||||||
|
type INTEGER NOT NULL DEFAULT 0
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE adlist_by_group
|
CREATE TABLE adlist_by_group
|
||||||
|
@ -52,6 +53,12 @@ CREATE TABLE gravity
|
||||||
adlist_id INTEGER NOT NULL REFERENCES adlist (id)
|
adlist_id INTEGER NOT NULL REFERENCES adlist (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE antigravity
|
||||||
|
(
|
||||||
|
domain TEXT NOT NULL,
|
||||||
|
adlist_id INTEGER NOT NULL REFERENCES adlist (id)
|
||||||
|
);
|
||||||
|
|
||||||
CREATE TABLE info
|
CREATE TABLE info
|
||||||
(
|
(
|
||||||
property TEXT PRIMARY KEY,
|
property TEXT PRIMARY KEY,
|
||||||
|
@ -144,6 +151,13 @@ CREATE VIEW vw_gravity AS SELECT domain, adlist_by_group.group_id AS group_id
|
||||||
LEFT JOIN "group" ON "group".id = adlist_by_group.group_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);
|
WHERE adlist.enabled = 1 AND (adlist_by_group.group_id IS NULL OR "group".enabled = 1);
|
||||||
|
|
||||||
|
CREATE VIEW vw_antigravity AS SELECT domain, adlist_by_group.group_id AS group_id
|
||||||
|
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;
|
||||||
|
|
||||||
CREATE VIEW vw_adlist AS SELECT DISTINCT address, id
|
CREATE VIEW vw_adlist AS SELECT DISTINCT address, id
|
||||||
FROM adlist
|
FROM adlist
|
||||||
WHERE enabled = 1
|
WHERE enabled = 1
|
||||||
|
|
26
gravity.sh
26
gravity.sh
|
@ -361,6 +361,7 @@ gravity_DownloadBlocklists() {
|
||||||
# We source only enabled adlists, SQLite3 stores boolean values as 0 (false) or 1 (true)
|
# We source only enabled adlists, SQLite3 stores boolean values as 0 (false) or 1 (true)
|
||||||
mapfile -t sources <<< "$(pihole-FTL sqlite3 "${gravityDBfile}" "SELECT address FROM vw_adlist;" 2> /dev/null)"
|
mapfile -t sources <<< "$(pihole-FTL sqlite3 "${gravityDBfile}" "SELECT address FROM vw_adlist;" 2> /dev/null)"
|
||||||
mapfile -t sourceIDs <<< "$(pihole-FTL sqlite3 "${gravityDBfile}" "SELECT id FROM vw_adlist;" 2> /dev/null)"
|
mapfile -t sourceIDs <<< "$(pihole-FTL sqlite3 "${gravityDBfile}" "SELECT id FROM vw_adlist;" 2> /dev/null)"
|
||||||
|
mapfile -t sourceTypes <<< "$(pihole-FTL sqlite3 "${gravityDBfile}" "SELECT type FROM vw_adlist;" 2> /dev/null)"
|
||||||
|
|
||||||
# Parse source domains from $sources
|
# Parse source domains from $sources
|
||||||
mapfile -t sourceDomains <<< "$(
|
mapfile -t sourceDomains <<< "$(
|
||||||
|
@ -382,7 +383,7 @@ gravity_DownloadBlocklists() {
|
||||||
unset sources
|
unset sources
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local url domain agent str target compression
|
local url domain agent str target compression adlist_type
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Prepare new gravity database
|
# Prepare new gravity database
|
||||||
|
@ -394,7 +395,7 @@ gravity_DownloadBlocklists() {
|
||||||
|
|
||||||
if [[ "${status}" -ne 0 ]]; then
|
if [[ "${status}" -ne 0 ]]; then
|
||||||
echo -e "\\n ${CROSS} Unable to create new database ${gravityTEMPfile}\\n ${output}"
|
echo -e "\\n ${CROSS} Unable to create new database ${gravityTEMPfile}\\n ${output}"
|
||||||
gravity_Cleanup "error"
|
#gravity_Cleanup "error"
|
||||||
else
|
else
|
||||||
echo -e "${OVER} ${TICK} ${str}"
|
echo -e "${OVER} ${TICK} ${str}"
|
||||||
fi
|
fi
|
||||||
|
@ -433,6 +434,15 @@ gravity_DownloadBlocklists() {
|
||||||
url="${sources[$i]}"
|
url="${sources[$i]}"
|
||||||
domain="${sourceDomains[$i]}"
|
domain="${sourceDomains[$i]}"
|
||||||
id="${sourceIDs[$i]}"
|
id="${sourceIDs[$i]}"
|
||||||
|
if [[ "${sourceTypes[$i]}" -eq "0" ]]; then
|
||||||
|
# Gravity list
|
||||||
|
str="blocklist"
|
||||||
|
adlist_type="gravity"
|
||||||
|
else
|
||||||
|
# AntiGravity list
|
||||||
|
str="allowlist"
|
||||||
|
adlist_type="antigravity"
|
||||||
|
fi
|
||||||
|
|
||||||
# Save the file as list.#.domain
|
# Save the file as list.#.domain
|
||||||
saveLocation="${piholeDir}/list.${id}.${domain}.${domainsExtension}"
|
saveLocation="${piholeDir}/list.${id}.${domain}.${domainsExtension}"
|
||||||
|
@ -441,7 +451,7 @@ gravity_DownloadBlocklists() {
|
||||||
# Default user-agent (for Cloudflare's Browser Integrity Check: https://support.cloudflare.com/hc/en-us/articles/200170086-What-does-the-Browser-Integrity-Check-do-)
|
# Default user-agent (for Cloudflare's Browser Integrity Check: https://support.cloudflare.com/hc/en-us/articles/200170086-What-does-the-Browser-Integrity-Check-do-)
|
||||||
agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36"
|
agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36"
|
||||||
|
|
||||||
echo -e " ${INFO} Target: ${url}"
|
echo -e " ${INFO} Target: ${url} (${str})"
|
||||||
local regex check_url
|
local regex check_url
|
||||||
# Check for characters NOT allowed in URLs
|
# Check for characters NOT allowed in URLs
|
||||||
regex="[^a-zA-Z0-9:/?&%=~._()-;]"
|
regex="[^a-zA-Z0-9:/?&%=~._()-;]"
|
||||||
|
@ -453,7 +463,7 @@ gravity_DownloadBlocklists() {
|
||||||
if [[ "${check_url}" =~ ${regex} ]]; then
|
if [[ "${check_url}" =~ ${regex} ]]; then
|
||||||
echo -e " ${CROSS} Invalid Target"
|
echo -e " ${CROSS} Invalid Target"
|
||||||
else
|
else
|
||||||
gravity_DownloadBlocklistFromUrl "${url}" "${agent}" "${sourceIDs[$i]}" "${saveLocation}" "${target}" "${compression}"
|
gravity_DownloadBlocklistFromUrl "${url}" "${agent}" "${sourceIDs[$i]}" "${saveLocation}" "${target}" "${compression}" "${adlist_type}"
|
||||||
fi
|
fi
|
||||||
echo ""
|
echo ""
|
||||||
done
|
done
|
||||||
|
@ -485,7 +495,7 @@ compareLists() {
|
||||||
|
|
||||||
# Download specified URL and perform checks on HTTP status and file content
|
# Download specified URL and perform checks on HTTP status and file content
|
||||||
gravity_DownloadBlocklistFromUrl() {
|
gravity_DownloadBlocklistFromUrl() {
|
||||||
local url="${1}" agent="${2}" adlistID="${3}" saveLocation="${4}" target="${5}" compression="${6}"
|
local url="${1}" agent="${2}" adlistID="${3}" saveLocation="${4}" target="${5}" compression="${6}" gravity_type="${7}"
|
||||||
local heisenbergCompensator="" listCurlBuffer str httpCode success="" ip cmd_ext
|
local heisenbergCompensator="" listCurlBuffer str httpCode success="" ip cmd_ext
|
||||||
|
|
||||||
# Create temp file to store content on disk instead of RAM
|
# Create temp file to store content on disk instead of RAM
|
||||||
|
@ -579,7 +589,7 @@ gravity_DownloadBlocklistFromUrl() {
|
||||||
if [[ "${success}" == true ]]; then
|
if [[ "${success}" == true ]]; then
|
||||||
if [[ "${httpCode}" == "304" ]]; then
|
if [[ "${httpCode}" == "304" ]]; then
|
||||||
# Add domains to database table file
|
# Add domains to database table file
|
||||||
pihole-FTL gravity parseList "${saveLocation}" "${gravityTEMPfile}" "${adlistID}"
|
pihole-FTL ${gravity_type} parseList "${saveLocation}" "${gravityTEMPfile}" "${adlistID}"
|
||||||
database_adlist_status "${adlistID}" "2"
|
database_adlist_status "${adlistID}" "2"
|
||||||
done="true"
|
done="true"
|
||||||
# Check if $listCurlBuffer is a non-zero length file
|
# Check if $listCurlBuffer is a non-zero length file
|
||||||
|
@ -589,7 +599,7 @@ gravity_DownloadBlocklistFromUrl() {
|
||||||
# Remove curl buffer file after its use
|
# Remove curl buffer file after its use
|
||||||
rm "${listCurlBuffer}"
|
rm "${listCurlBuffer}"
|
||||||
# Add domains to database table file
|
# Add domains to database table file
|
||||||
pihole-FTL gravity parseList "${saveLocation}" "${gravityTEMPfile}" "${adlistID}"
|
pihole-FTL ${gravity_type} parseList "${saveLocation}" "${gravityTEMPfile}" "${adlistID}"
|
||||||
# Compare lists, are they identical?
|
# Compare lists, are they identical?
|
||||||
compareLists "${adlistID}" "${saveLocation}"
|
compareLists "${adlistID}" "${saveLocation}"
|
||||||
done="true"
|
done="true"
|
||||||
|
@ -605,7 +615,7 @@ gravity_DownloadBlocklistFromUrl() {
|
||||||
if [[ -r "${saveLocation}" ]]; then
|
if [[ -r "${saveLocation}" ]]; then
|
||||||
echo -e " ${CROSS} List download failed: ${COL_LIGHT_GREEN}using previously cached list${COL_NC}"
|
echo -e " ${CROSS} List download failed: ${COL_LIGHT_GREEN}using previously cached list${COL_NC}"
|
||||||
# Add domains to database table file
|
# Add domains to database table file
|
||||||
pihole-FTL gravity parseList "${saveLocation}" "${gravityTEMPfile}" "${adlistID}"
|
pihole-FTL ${gravity_type} parseList "${saveLocation}" "${gravityTEMPfile}" "${adlistID}"
|
||||||
database_adlist_status "${adlistID}" "3"
|
database_adlist_status "${adlistID}" "3"
|
||||||
else
|
else
|
||||||
echo -e " ${CROSS} List download failed: ${COL_LIGHT_RED}no cached list available${COL_NC}"
|
echo -e " ${CROSS} List download failed: ${COL_LIGHT_RED}no cached list available${COL_NC}"
|
||||||
|
|
Loading…
Add table
Reference in a new issue