mirror of
https://github.com/pi-hole/pi-hole
synced 2025-01-03 12:40:56 +00:00
Review comments and fixing stickler complaints.
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
parent
2fb4256f84
commit
0405aaa3da
@ -11,11 +11,11 @@
|
|||||||
# Please see LICENSE file for your rights under this license.
|
# Please see LICENSE file for your rights under this license.
|
||||||
|
|
||||||
upgrade_gravityDB(){
|
upgrade_gravityDB(){
|
||||||
local version=$(sqlite3 "$1" "SELECT "value" FROM "info" WHERE "property" = 'version';")
|
local version
|
||||||
|
version=$(sqlite3 "$1" "SELECT "value" FROM "info" WHERE "property" = 'version';")
|
||||||
|
|
||||||
case "$version" in
|
if [[ "$version" == "1" ]]; then
|
||||||
1)
|
|
||||||
sqlite3 "$1" < "/etc/.pihole/advanced/Scripts/database_migration/gravity/1_to_2.sql"
|
sqlite3 "$1" < "/etc/.pihole/advanced/Scripts/database_migration/gravity/1_to_2.sql"
|
||||||
;;
|
version=2
|
||||||
esac
|
fi
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
CREATE TABLE auditlist
|
CREATE TABLE domain_auditlist
|
||||||
(
|
(
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
domain TEXT UNIQUE NOT NULL,
|
domain TEXT UNIQUE NOT NULL,
|
||||||
|
@ -542,24 +542,38 @@ Teleporter() {
|
|||||||
php /var/www/html/admin/scripts/pi-hole/php/teleporter.php > "pi-hole-teleporter_${datetimestamp}.tar.gz"
|
php /var/www/html/admin/scripts/pi-hole/php/teleporter.php > "pi-hole-teleporter_${datetimestamp}.tar.gz"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkDomain()
|
||||||
|
{
|
||||||
|
local domain validDomain
|
||||||
|
# Convert to lowercase
|
||||||
|
domain="${1,,}"
|
||||||
|
validDomain=$(grep -P "^((-|_)*[a-z\\d]((-|_)*[a-z\\d])*(-|_)*)(\\.(-|_)*([a-z\\d]((-|_)*[a-z\\d])*))*$" <<< "${domain}") # Valid chars check
|
||||||
|
validDomain=$(grep -P "^[^\\.]{1,63}(\\.[^\\.]{1,63})*$" <<< "${validDomain}") # Length of each label
|
||||||
|
echo "${validDomain}"
|
||||||
|
}
|
||||||
|
|
||||||
addAudit()
|
addAudit()
|
||||||
{
|
{
|
||||||
shift # skip "-a"
|
shift # skip "-a"
|
||||||
shift # skip "audit"
|
shift # skip "audit"
|
||||||
local domains="('${1}')"
|
local domains validDomain
|
||||||
|
domains="('$(checkDomain "${1}")')"
|
||||||
shift # skip first domain, as it has already been added
|
shift # skip first domain, as it has already been added
|
||||||
for domain in "$@"
|
for domain in "$@"
|
||||||
do
|
do
|
||||||
# Insert only the domain here. The date_added field will be
|
# Insert only the domain here. The date_added field will be
|
||||||
# filled with its default value (date_added = current timestamp)
|
# filled with its default value (date_added = current timestamp)
|
||||||
domains="${domains},('${domain}')"
|
validDomain="$(checkDomain "${domain}")"
|
||||||
|
if [[ -n "${validDomain}" ]]; then
|
||||||
|
domains="${domains},('${domain}')"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
sqlite3 "${gravityDBfile}" "INSERT INTO \"auditlist\" (domain) VALUES ${domains};"
|
sqlite3 "${gravityDBfile}" "INSERT INTO \"domain_auditlist\" (domain) VALUES ${domains};"
|
||||||
}
|
}
|
||||||
|
|
||||||
clearAudit()
|
clearAudit()
|
||||||
{
|
{
|
||||||
sqlite3 "${gravityDBfile}" "DELETE FROM \"auditlist\";"
|
sqlite3 "${gravityDBfile}" "DELETE FROM \"domain_auditlist\";"
|
||||||
}
|
}
|
||||||
|
|
||||||
SetPrivacyLevel() {
|
SetPrivacyLevel() {
|
||||||
|
@ -81,7 +81,7 @@ CREATE TABLE gravity
|
|||||||
domain TEXT PRIMARY KEY
|
domain TEXT PRIMARY KEY
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE auditlist
|
CREATE TABLE domain_auditlist
|
||||||
(
|
(
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
domain TEXT UNIQUE NOT NULL,
|
domain TEXT UNIQUE NOT NULL,
|
||||||
|
15
gravity.sh
15
gravity.sh
@ -115,25 +115,28 @@ database_table_from_file() {
|
|||||||
inputfile="${source}"
|
inputfile="${source}"
|
||||||
else
|
else
|
||||||
# Apply format for white-, blacklist, regex, and adlist tables
|
# Apply format for white-, blacklist, regex, and adlist tables
|
||||||
local rowid
|
|
||||||
declare -i rowid
|
|
||||||
rowid=1
|
|
||||||
# Read file line by line
|
# Read file line by line
|
||||||
if [[ "${table}" == "auditlist" ]]; then
|
if [[ "${table}" == "auditlist" ]]; then
|
||||||
|
local rowid
|
||||||
|
declare -i rowid
|
||||||
|
rowid=1
|
||||||
grep -v '^ *#' < "${source}" | while IFS= read -r domain
|
grep -v '^ *#' < "${source}" | while IFS= read -r domain
|
||||||
do
|
do
|
||||||
# Only add non-empty lines
|
# Only add non-empty lines
|
||||||
if [[ ! -z "${domain}" ]]; then
|
if [[ -n "${domain}" ]]; then
|
||||||
# Auditlist table format
|
# Auditlist table format
|
||||||
echo "${rowid},\"${domain}\",${timestamp}" >> "${tmpFile}"
|
echo "${rowid},\"${domain}\",${timestamp}" >> "${tmpFile}"
|
||||||
rowid+=1
|
rowid+=1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
|
local rowid
|
||||||
|
declare -i rowid
|
||||||
|
rowid=1
|
||||||
grep -v '^ *#' < "${source}" | while IFS= read -r domain
|
grep -v '^ *#' < "${source}" | while IFS= read -r domain
|
||||||
do
|
do
|
||||||
# Only add non-empty lines
|
# Only add non-empty lines
|
||||||
if [[ ! -z "${domain}" ]]; then
|
if [[ -n "${domain}" ]]; then
|
||||||
# White-, black-, and regexlist format
|
# White-, black-, and regexlist format
|
||||||
echo "${rowid},\"${domain}\",1,${timestamp},${timestamp},\"Migrated from ${source}\"" >> "${tmpFile}"
|
echo "${rowid},\"${domain}\",1,${timestamp},${timestamp},\"Migrated from ${source}\"" >> "${tmpFile}"
|
||||||
rowid+=1
|
rowid+=1
|
||||||
@ -198,7 +201,7 @@ migrate_to_database() {
|
|||||||
if [ -e "${auditFile}" ]; then
|
if [ -e "${auditFile}" ]; then
|
||||||
# Store audit domains in database
|
# Store audit domains in database
|
||||||
echo -e " ${INFO} Migrating content of ${auditFile} into new database"
|
echo -e " ${INFO} Migrating content of ${auditFile} into new database"
|
||||||
database_table_from_file "auditlist" "${auditFile}"
|
database_table_from_file "domain_auditlist" "${auditFile}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user