From 8382f4d7274e893e19dbe09de5dd090daa590c24 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 7 Jul 2019 21:21:56 +0200 Subject: [PATCH] Rename table to domain_audit and simplify subroutine addAudit(). Signed-off-by: DL6ER --- advanced/Scripts/database_migration/gravity-db.sh | 4 ++-- .../Scripts/database_migration/gravity/1_to_2.sql | 2 +- advanced/Scripts/webpage.sh | 14 +++++++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/advanced/Scripts/database_migration/gravity-db.sh b/advanced/Scripts/database_migration/gravity-db.sh index 294fd32a..51a3480b 100644 --- a/advanced/Scripts/database_migration/gravity-db.sh +++ b/advanced/Scripts/database_migration/gravity-db.sh @@ -18,7 +18,7 @@ upgrade_gravityDB(){ if [[ "$version" == "1" ]]; then # This migration script upgrades the gravity.db file by - # adding the domain_auditlist table + # adding the domain_audit table sqlite3 "${database}" < "/etc/.pihole/advanced/Scripts/database_migration/gravity/1_to_2.sql" version=2 @@ -26,7 +26,7 @@ upgrade_gravityDB(){ if [ -e "${auditFile}" ]; then echo -e " ${INFO} Migrating content of ${auditFile} into new database" # database_table_from_file is defined in gravity.sh - database_table_from_file "domain_auditlist" "${auditFile}" + database_table_from_file "domain_audit" "${auditFile}" fi fi } diff --git a/advanced/Scripts/database_migration/gravity/1_to_2.sql b/advanced/Scripts/database_migration/gravity/1_to_2.sql index 073eced5..90a48418 100644 --- a/advanced/Scripts/database_migration/gravity/1_to_2.sql +++ b/advanced/Scripts/database_migration/gravity/1_to_2.sql @@ -1,4 +1,4 @@ -CREATE TABLE domain_auditlist +CREATE TABLE domain_audit ( id INTEGER PRIMARY KEY AUTOINCREMENT, domain TEXT UNIQUE NOT NULL, diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 516ea4e4..918fde27 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -557,23 +557,27 @@ addAudit() shift # skip "-a" shift # skip "audit" local domains validDomain - domains="('$(checkDomain "${1}")')" - shift # skip first domain, as it has already been added + domains="" 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}')" + # Put comma in between () when there is + # more than one domains to be added + if [[ -n "${domains}" ]]; then + domains="${domains}," + fi + domains="${domains}('${domain}')" fi done - sqlite3 "${gravityDBfile}" "INSERT INTO \"domain_auditlist\" (domain) VALUES ${domains};" + sqlite3 "${gravityDBfile}" "INSERT INTO \"domain_audit\" (domain) VALUES ${domains};" } clearAudit() { - sqlite3 "${gravityDBfile}" "DELETE FROM \"domain_auditlist\";" + sqlite3 "${gravityDBfile}" "DELETE FROM \"domain_audit\";" } SetPrivacyLevel() {