mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 02:42:58 +00:00
Review comments and fixing stickler complaints.
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
parent
2fb4256f84
commit
0405aaa3da
5 changed files with 34 additions and 17 deletions
|
@ -11,11 +11,11 @@
|
|||
# Please see LICENSE file for your rights under this license.
|
||||
|
||||
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
|
||||
1)
|
||||
if [[ "$version" == "1" ]]; then
|
||||
sqlite3 "$1" < "/etc/.pihole/advanced/Scripts/database_migration/gravity/1_to_2.sql"
|
||||
;;
|
||||
esac
|
||||
version=2
|
||||
fi
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CREATE TABLE auditlist
|
||||
CREATE TABLE domain_auditlist
|
||||
(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
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"
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
shift # skip "-a"
|
||||
shift # skip "audit"
|
||||
local domains="('${1}')"
|
||||
local domains validDomain
|
||||
domains="('$(checkDomain "${1}")')"
|
||||
shift # skip first domain, as it has already been added
|
||||
for domain in "$@"
|
||||
do
|
||||
# Insert only the domain here. The date_added field will be
|
||||
# filled with its default value (date_added = current timestamp)
|
||||
validDomain="$(checkDomain "${domain}")"
|
||||
if [[ -n "${validDomain}" ]]; then
|
||||
domains="${domains},('${domain}')"
|
||||
fi
|
||||
done
|
||||
sqlite3 "${gravityDBfile}" "INSERT INTO \"auditlist\" (domain) VALUES ${domains};"
|
||||
sqlite3 "${gravityDBfile}" "INSERT INTO \"domain_auditlist\" (domain) VALUES ${domains};"
|
||||
}
|
||||
|
||||
clearAudit()
|
||||
{
|
||||
sqlite3 "${gravityDBfile}" "DELETE FROM \"auditlist\";"
|
||||
sqlite3 "${gravityDBfile}" "DELETE FROM \"domain_auditlist\";"
|
||||
}
|
||||
|
||||
SetPrivacyLevel() {
|
||||
|
|
|
@ -81,7 +81,7 @@ CREATE TABLE gravity
|
|||
domain TEXT PRIMARY KEY
|
||||
);
|
||||
|
||||
CREATE TABLE auditlist
|
||||
CREATE TABLE domain_auditlist
|
||||
(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
domain TEXT UNIQUE NOT NULL,
|
||||
|
|
13
gravity.sh
13
gravity.sh
|
@ -115,25 +115,28 @@ database_table_from_file() {
|
|||
inputfile="${source}"
|
||||
else
|
||||
# Apply format for white-, blacklist, regex, and adlist tables
|
||||
# Read file line by line
|
||||
if [[ "${table}" == "auditlist" ]]; then
|
||||
local rowid
|
||||
declare -i rowid
|
||||
rowid=1
|
||||
# Read file line by line
|
||||
if [[ "${table}" == "auditlist" ]]; then
|
||||
grep -v '^ *#' < "${source}" | while IFS= read -r domain
|
||||
do
|
||||
# Only add non-empty lines
|
||||
if [[ ! -z "${domain}" ]]; then
|
||||
if [[ -n "${domain}" ]]; then
|
||||
# Auditlist table format
|
||||
echo "${rowid},\"${domain}\",${timestamp}" >> "${tmpFile}"
|
||||
rowid+=1
|
||||
fi
|
||||
done
|
||||
else
|
||||
local rowid
|
||||
declare -i rowid
|
||||
rowid=1
|
||||
grep -v '^ *#' < "${source}" | while IFS= read -r domain
|
||||
do
|
||||
# Only add non-empty lines
|
||||
if [[ ! -z "${domain}" ]]; then
|
||||
if [[ -n "${domain}" ]]; then
|
||||
# White-, black-, and regexlist format
|
||||
echo "${rowid},\"${domain}\",1,${timestamp},${timestamp},\"Migrated from ${source}\"" >> "${tmpFile}"
|
||||
rowid+=1
|
||||
|
@ -198,7 +201,7 @@ migrate_to_database() {
|
|||
if [ -e "${auditFile}" ]; then
|
||||
# Store audit domains in 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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue