mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 02:42:58 +00:00
Review comments
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
parent
9984647ebb
commit
644ec36e64
2 changed files with 28 additions and 15 deletions
|
@ -1,7 +1,10 @@
|
||||||
CREATE TABLE whitelist (domain TEXT UNIQUE NOT NULL, enabled BOOLEAN DEFAULT 1, comment TEXT, dateadded DATETIME);
|
CREATE TABLE whitelist (domain TEXT UNIQUE NOT NULL, enabled BOOLEAN NOT NULL DEFAULT 1, date_added DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, comment TEXT);
|
||||||
CREATE TABLE blacklist (domain TEXT UNIQUE NOT NULL, enabled BOOLEAN DEFAULT 1, comment TEXT, dateadded DATETIME);
|
CREATE TABLE blacklist (domain TEXT UNIQUE NOT NULL, enabled BOOLEAN NOT NULL DEFAULT 1, date_added DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, comment TEXT);
|
||||||
CREATE TABLE regex (filter TEXT UNIQUE NOT NULL, enabled BOOLEAN DEFAULT 1, comment TEXT, dateadded DATETIME);
|
CREATE TABLE regex (filter TEXT UNIQUE NOT NULL, enabled BOOLEAN NOT NULL DEFAULT 1, date_added DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, comment TEXT);
|
||||||
CREATE TABLE gravity (domain TEXT UNIQUE NOT NULL);
|
CREATE TABLE gravity (domain TEXT UNIQUE NOT NULL);
|
||||||
|
CREATE TABLE info (property TEXT NOT NULL, value TEXT NOT NULL);
|
||||||
|
|
||||||
|
INSERT INTO info VALUES("version","1");
|
||||||
|
|
||||||
CREATE VIEW vw_gravity AS SELECT DISTINCT a.domain
|
CREATE VIEW vw_gravity AS SELECT DISTINCT a.domain
|
||||||
FROM gravity a
|
FROM gravity a
|
||||||
|
|
34
gravity.sh
34
gravity.sh
|
@ -20,6 +20,8 @@ source "${regexconverter}"
|
||||||
|
|
||||||
basename="pihole"
|
basename="pihole"
|
||||||
PIHOLE_COMMAND="/usr/local/bin/${basename}"
|
PIHOLE_COMMAND="/usr/local/bin/${basename}"
|
||||||
|
PIHOLE_USER="pihole"
|
||||||
|
PIHOLE_GROUP="pihole"
|
||||||
|
|
||||||
piholeDir="/etc/${basename}"
|
piholeDir="/etc/${basename}"
|
||||||
|
|
||||||
|
@ -90,6 +92,7 @@ fi
|
||||||
# Generate new sqlite3 file from schema template
|
# Generate new sqlite3 file from schema template
|
||||||
generate_gravity_database() {
|
generate_gravity_database() {
|
||||||
sqlite3 "${gravityDBfile}" < "${gravityDBschema}"
|
sqlite3 "${gravityDBfile}" < "${gravityDBschema}"
|
||||||
|
chown $PIHOLE_USER:$PIHOLE_GROUP "${gravityDBfile}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Import domains from file and store them in the specified database table
|
# Import domains from file and store them in the specified database table
|
||||||
|
@ -113,25 +116,32 @@ gravity_store_in_database() {
|
||||||
gravity_Cleanup "error"
|
gravity_Cleanup "error"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
local tmpFile=$(mktemp -p "/tmp" --suffix=".gravity")
|
||||||
|
if [ "$table" == "whitelist" ] || [ "$table" == "blacklist" ] || [ "$table" == "regex" ]; then
|
||||||
|
# Apply format for white-, blacklist, and regex tables, prevent globbing
|
||||||
|
set -f
|
||||||
|
for domain in $(cat < "${source}"); do
|
||||||
|
echo "\"${domain}\",1,$(date --utc +'%s')," >> "${tmpFile}"
|
||||||
|
done
|
||||||
|
set +f
|
||||||
|
inputfile="${tmpFile}"
|
||||||
|
else
|
||||||
|
# No need to modify the input data for the gravity table
|
||||||
|
inputfile="${source}"
|
||||||
|
fi
|
||||||
# Store domains in gravity database table ${table}
|
# Store domains in gravity database table ${table}
|
||||||
output=$( { sqlite3 "${gravityDBfile}" <<< ".import \"${source}\" ${table}"; } 2>&1 )
|
# Use printf as .mode and .import need to be on separate lines
|
||||||
|
# see https://unix.stackexchange.com/a/445615/83260
|
||||||
|
output=$( { printf ".mode csv\n.import \"${inputfile}\" ${table}\n" | sqlite3 "${gravityDBfile}"; } 2>&1 )
|
||||||
status="$?"
|
status="$?"
|
||||||
|
|
||||||
if [[ "${status}" -ne 0 ]]; then
|
if [[ "${status}" -ne 0 ]]; then
|
||||||
echo -e "\\n ${CROSS} Unable to create ${table} in database ${gravityDBfile}\\n ${output}"
|
echo -e "\\n ${CROSS} Unable to fill table ${table} in database ${gravityDBfile}\\n ${output}"
|
||||||
gravity_Cleanup "error"
|
gravity_Cleanup "error"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$table" == "whitelist" ] || [ "$table" == "blacklist" ] || [ "$table" == "regex" ]; then
|
# Delete tmpfile
|
||||||
# Set enabled to true where it is unspecified
|
#rm "$tmpFile" > /dev/null 2>&1 || true
|
||||||
output=$( { sqlite3 "${gravityDBfile}" <<< "UPDATE ${table} SET enabled = 1 WHERE enabled IS NULL;"; } 2>&1 )
|
|
||||||
status="$?"
|
|
||||||
|
|
||||||
if [[ "${status}" -ne 0 ]]; then
|
|
||||||
echo -e "\\n ${CROSS} Unable to set enabled states (${table}) in database ${gravityDBfile}\\n ${output}"
|
|
||||||
gravity_Cleanup "error"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Only create template file if asked to
|
# Only create template file if asked to
|
||||||
if [ "${template}" != "-" ]; then
|
if [ "${template}" != "-" ]; then
|
||||||
|
|
Loading…
Reference in a new issue