Skip to content

Commit 6ffa2ba

Browse files
authored
Merge pull request #4547 from pi-hole/development
Pi-hole Core v5.9
2 parents 5d68dac + e9250d6 commit 6ffa2ba

29 files changed

+221
-445
lines changed

advanced/Scripts/database_migration/gravity-db.sh

+15-15
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ upgrade_gravityDB(){
1919
auditFile="${piholeDir}/auditlog.list"
2020

2121
# Get database version
22-
version="$(sqlite3 "${database}" "SELECT \"value\" FROM \"info\" WHERE \"property\" = 'version';")"
22+
version="$(pihole-FTL sqlite3 "${database}" "SELECT \"value\" FROM \"info\" WHERE \"property\" = 'version';")"
2323

2424
if [[ "$version" == "1" ]]; then
2525
# This migration script upgrades the gravity.db file by
2626
# adding the domain_audit table
2727
echo -e " ${INFO} Upgrading gravity database from version 1 to 2"
28-
sqlite3 "${database}" < "${scriptPath}/1_to_2.sql"
28+
pihole-FTL sqlite3 "${database}" < "${scriptPath}/1_to_2.sql"
2929
version=2
3030

3131
# Store audit domains in database table
@@ -40,58 +40,58 @@ upgrade_gravityDB(){
4040
# renaming the regex table to regex_blacklist, and
4141
# creating a new regex_whitelist table + corresponding linking table and views
4242
echo -e " ${INFO} Upgrading gravity database from version 2 to 3"
43-
sqlite3 "${database}" < "${scriptPath}/2_to_3.sql"
43+
pihole-FTL sqlite3 "${database}" < "${scriptPath}/2_to_3.sql"
4444
version=3
4545
fi
4646
if [[ "$version" == "3" ]]; then
4747
# This migration script unifies the formally separated domain
4848
# lists into a single table with a UNIQUE domain constraint
4949
echo -e " ${INFO} Upgrading gravity database from version 3 to 4"
50-
sqlite3 "${database}" < "${scriptPath}/3_to_4.sql"
50+
pihole-FTL sqlite3 "${database}" < "${scriptPath}/3_to_4.sql"
5151
version=4
5252
fi
5353
if [[ "$version" == "4" ]]; then
5454
# This migration script upgrades the gravity and list views
5555
# implementing necessary changes for per-client blocking
5656
echo -e " ${INFO} Upgrading gravity database from version 4 to 5"
57-
sqlite3 "${database}" < "${scriptPath}/4_to_5.sql"
57+
pihole-FTL sqlite3 "${database}" < "${scriptPath}/4_to_5.sql"
5858
version=5
5959
fi
6060
if [[ "$version" == "5" ]]; then
6161
# This migration script upgrades the adlist view
6262
# to return an ID used in gravity.sh
6363
echo -e " ${INFO} Upgrading gravity database from version 5 to 6"
64-
sqlite3 "${database}" < "${scriptPath}/5_to_6.sql"
64+
pihole-FTL sqlite3 "${database}" < "${scriptPath}/5_to_6.sql"
6565
version=6
6666
fi
6767
if [[ "$version" == "6" ]]; then
6868
# This migration script adds a special group with ID 0
6969
# which is automatically associated to all clients not
7070
# having their own group assignments
7171
echo -e " ${INFO} Upgrading gravity database from version 6 to 7"
72-
sqlite3 "${database}" < "${scriptPath}/6_to_7.sql"
72+
pihole-FTL sqlite3 "${database}" < "${scriptPath}/6_to_7.sql"
7373
version=7
7474
fi
7575
if [[ "$version" == "7" ]]; then
7676
# This migration script recreated the group table
7777
# to ensure uniqueness on the group name
7878
# We also add date_added and date_modified columns
7979
echo -e " ${INFO} Upgrading gravity database from version 7 to 8"
80-
sqlite3 "${database}" < "${scriptPath}/7_to_8.sql"
80+
pihole-FTL sqlite3 "${database}" < "${scriptPath}/7_to_8.sql"
8181
version=8
8282
fi
8383
if [[ "$version" == "8" ]]; then
8484
# This migration fixes some issues that were introduced
8585
# in the previous migration script.
8686
echo -e " ${INFO} Upgrading gravity database from version 8 to 9"
87-
sqlite3 "${database}" < "${scriptPath}/8_to_9.sql"
87+
pihole-FTL sqlite3 "${database}" < "${scriptPath}/8_to_9.sql"
8888
version=9
8989
fi
9090
if [[ "$version" == "9" ]]; then
9191
# This migration drops unused tables and creates triggers to remove
9292
# obsolete groups assignments when the linked items are deleted
9393
echo -e " ${INFO} Upgrading gravity database from version 9 to 10"
94-
sqlite3 "${database}" < "${scriptPath}/9_to_10.sql"
94+
pihole-FTL sqlite3 "${database}" < "${scriptPath}/9_to_10.sql"
9595
version=10
9696
fi
9797
if [[ "$version" == "10" ]]; then
@@ -101,31 +101,31 @@ upgrade_gravityDB(){
101101
# to keep the copying process generic (needs the same columns in both the
102102
# source and the destination databases).
103103
echo -e " ${INFO} Upgrading gravity database from version 10 to 11"
104-
sqlite3 "${database}" < "${scriptPath}/10_to_11.sql"
104+
pihole-FTL sqlite3 "${database}" < "${scriptPath}/10_to_11.sql"
105105
version=11
106106
fi
107107
if [[ "$version" == "11" ]]; then
108108
# Rename group 0 from "Unassociated" to "Default"
109109
echo -e " ${INFO} Upgrading gravity database from version 11 to 12"
110-
sqlite3 "${database}" < "${scriptPath}/11_to_12.sql"
110+
pihole-FTL sqlite3 "${database}" < "${scriptPath}/11_to_12.sql"
111111
version=12
112112
fi
113113
if [[ "$version" == "12" ]]; then
114114
# Add column date_updated to adlist table
115115
echo -e " ${INFO} Upgrading gravity database from version 12 to 13"
116-
sqlite3 "${database}" < "${scriptPath}/12_to_13.sql"
116+
pihole-FTL sqlite3 "${database}" < "${scriptPath}/12_to_13.sql"
117117
version=13
118118
fi
119119
if [[ "$version" == "13" ]]; then
120120
# Add columns number and status to adlist table
121121
echo -e " ${INFO} Upgrading gravity database from version 13 to 14"
122-
sqlite3 "${database}" < "${scriptPath}/13_to_14.sql"
122+
pihole-FTL sqlite3 "${database}" < "${scriptPath}/13_to_14.sql"
123123
version=14
124124
fi
125125
if [[ "$version" == "14" ]]; then
126126
# Changes the vw_adlist created in 5_to_6
127127
echo -e " ${INFO} Upgrading gravity database from version 14 to 15"
128-
sqlite3 "${database}" < "${scriptPath}/14_to_15.sql"
128+
pihole-FTL sqlite3 "${database}" < "${scriptPath}/14_to_15.sql"
129129
version=15
130130
fi
131131
}

advanced/Scripts/list.sh

+10-10
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,18 @@ AddDomain() {
142142
domain="$1"
143143

144144
# Is the domain in the list we want to add it to?
145-
num="$(sqlite3 "${gravityDBfile}" "SELECT COUNT(*) FROM domainlist WHERE domain = '${domain}';")"
145+
num="$(pihole-FTL sqlite3 "${gravityDBfile}" "SELECT COUNT(*) FROM domainlist WHERE domain = '${domain}';")"
146146
requestedListname="$(GetListnameFromTypeId "${typeId}")"
147147

148148
if [[ "${num}" -ne 0 ]]; then
149-
existingTypeId="$(sqlite3 "${gravityDBfile}" "SELECT type FROM domainlist WHERE domain = '${domain}';")"
149+
existingTypeId="$(pihole-FTL sqlite3 "${gravityDBfile}" "SELECT type FROM domainlist WHERE domain = '${domain}';")"
150150
if [[ "${existingTypeId}" == "${typeId}" ]]; then
151151
if [[ "${verbose}" == true ]]; then
152152
echo -e " ${INFO} ${1} already exists in ${requestedListname}, no need to add!"
153153
fi
154154
else
155155
existingListname="$(GetListnameFromTypeId "${existingTypeId}")"
156-
sqlite3 "${gravityDBfile}" "UPDATE domainlist SET type = ${typeId} WHERE domain='${domain}';"
156+
pihole-FTL sqlite3 "${gravityDBfile}" "UPDATE domainlist SET type = ${typeId} WHERE domain='${domain}';"
157157
if [[ "${verbose}" == true ]]; then
158158
echo -e " ${INFO} ${1} already exists in ${existingListname}, it has been moved to ${requestedListname}!"
159159
fi
@@ -169,10 +169,10 @@ AddDomain() {
169169
# Insert only the domain here. The enabled and date_added fields will be filled
170170
# with their default values (enabled = true, date_added = current timestamp)
171171
if [[ -z "${comment}" ]]; then
172-
sqlite3 "${gravityDBfile}" "INSERT INTO domainlist (domain,type) VALUES ('${domain}',${typeId});"
172+
pihole-FTL sqlite3 "${gravityDBfile}" "INSERT INTO domainlist (domain,type) VALUES ('${domain}',${typeId});"
173173
else
174174
# also add comment when variable has been set through the "--comment" option
175-
sqlite3 "${gravityDBfile}" "INSERT INTO domainlist (domain,type,comment) VALUES ('${domain}',${typeId},'${comment}');"
175+
pihole-FTL sqlite3 "${gravityDBfile}" "INSERT INTO domainlist (domain,type,comment) VALUES ('${domain}',${typeId},'${comment}');"
176176
fi
177177
}
178178

@@ -181,7 +181,7 @@ RemoveDomain() {
181181
domain="$1"
182182

183183
# Is the domain in the list we want to remove it from?
184-
num="$(sqlite3 "${gravityDBfile}" "SELECT COUNT(*) FROM domainlist WHERE domain = '${domain}' AND type = ${typeId};")"
184+
num="$(pihole-FTL sqlite3 "${gravityDBfile}" "SELECT COUNT(*) FROM domainlist WHERE domain = '${domain}' AND type = ${typeId};")"
185185

186186
requestedListname="$(GetListnameFromTypeId "${typeId}")"
187187

@@ -198,14 +198,14 @@ RemoveDomain() {
198198
fi
199199
reload=true
200200
# Remove it from the current list
201-
sqlite3 "${gravityDBfile}" "DELETE FROM domainlist WHERE domain = '${domain}' AND type = ${typeId};"
201+
pihole-FTL sqlite3 "${gravityDBfile}" "DELETE FROM domainlist WHERE domain = '${domain}' AND type = ${typeId};"
202202
}
203203

204204
Displaylist() {
205205
local count num_pipes domain enabled status nicedate requestedListname
206206

207207
requestedListname="$(GetListnameFromTypeId "${typeId}")"
208-
data="$(sqlite3 "${gravityDBfile}" "SELECT domain,enabled,date_modified FROM domainlist WHERE type = ${typeId};" 2> /dev/null)"
208+
data="$(pihole-FTL sqlite3 "${gravityDBfile}" "SELECT domain,enabled,date_modified FROM domainlist WHERE type = ${typeId};" 2> /dev/null)"
209209

210210
if [[ -z $data ]]; then
211211
echo -e "Not showing empty list"
@@ -243,10 +243,10 @@ Displaylist() {
243243
}
244244

245245
NukeList() {
246-
count=$(sqlite3 "${gravityDBfile}" "SELECT COUNT(1) FROM domainlist WHERE type = ${typeId};")
246+
count=$(pihole-FTL sqlite3 "${gravityDBfile}" "SELECT COUNT(1) FROM domainlist WHERE type = ${typeId};")
247247
listname="$(GetListnameFromTypeId "${typeId}")"
248248
if [ "$count" -gt 0 ];then
249-
sqlite3 "${gravityDBfile}" "DELETE FROM domainlist WHERE type = ${typeId};"
249+
pihole-FTL sqlite3 "${gravityDBfile}" "DELETE FROM domainlist WHERE type = ${typeId};"
250250
echo " ${TICK} Removed ${count} domain(s) from the ${listname}"
251251
else
252252
echo " ${INFO} ${listname} already empty. Nothing to do!"

advanced/Scripts/piholeARPTable.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ flushARP(){
3939
# Truncate network_addresses table in pihole-FTL.db
4040
# This needs to be done before we can truncate the network table due to
4141
# foreign key constraints
42-
if ! output=$(sqlite3 "${DBFILE}" "DELETE FROM network_addresses" 2>&1); then
42+
if ! output=$(pihole-FTL sqlite3 "${DBFILE}" "DELETE FROM network_addresses" 2>&1); then
4343
echo -e "${OVER} ${CROSS} Failed to truncate network_addresses table"
4444
echo " Database location: ${DBFILE}"
4545
echo " Output: ${output}"
4646
return 1
4747
fi
4848

4949
# Truncate network table in pihole-FTL.db
50-
if ! output=$(sqlite3 "${DBFILE}" "DELETE FROM network" 2>&1); then
50+
if ! output=$(pihole-FTL sqlite3 "${DBFILE}" "DELETE FROM network" 2>&1); then
5151
echo -e "${OVER} ${CROSS} Failed to truncate network table"
5252
echo " Database location: ${DBFILE}"
5353
echo " Output: ${output}"

advanced/Scripts/piholeDebug.sh

+25-7
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ check_required_ports() {
753753
# Sort the addresses and remove duplicates
754754
while IFS= read -r line; do
755755
ports_in_use+=( "$line" )
756-
done < <( ss --listening --numeric --tcp --udp --processes --oneline --no-header )
756+
done < <( ss --listening --numeric --tcp --udp --processes --no-header )
757757

758758
# Now that we have the values stored,
759759
for i in "${!ports_in_use[@]}"; do
@@ -779,6 +779,21 @@ check_required_ports() {
779779
done
780780
}
781781

782+
ip_command() {
783+
# Obtain and log information from "ip XYZ show" commands
784+
echo_current_diagnostic "${2}"
785+
local entries=()
786+
mapfile -t entries < <(ip "${1}" show)
787+
for line in "${entries[@]}"; do
788+
log_write " ${line}"
789+
done
790+
}
791+
792+
check_ip_command() {
793+
ip_command "addr" "Network interfaces and addresses"
794+
ip_command "route" "Network routing table"
795+
}
796+
782797
check_networking() {
783798
# Runs through several of the functions made earlier; we just clump them
784799
# together since they are all related to the networking aspect of things
@@ -787,7 +802,9 @@ check_networking() {
787802
detect_ip_addresses "6"
788803
ping_gateway "4"
789804
ping_gateway "6"
790-
check_required_ports
805+
# Skip the following check if installed in docker container. Unpriv'ed containers do not have access to the information required
806+
# to resolve the service name listening - and the container should not start if there was a port conflict anyway
807+
[ -z "${PIHOLE_DOCKER_TAG}" ] && check_required_ports
791808
}
792809

793810
check_x_headers() {
@@ -871,7 +888,7 @@ dig_at() {
871888
# This helps emulate queries to different domains that a user might query
872889
# It will also give extra assurance that Pi-hole is correctly resolving and blocking domains
873890
local random_url
874-
random_url=$(sqlite3 "${PIHOLE_GRAVITY_DB_FILE}" "SELECT domain FROM vw_gravity ORDER BY RANDOM() LIMIT 1")
891+
random_url=$(pihole-FTL sqlite3 "${PIHOLE_GRAVITY_DB_FILE}" "SELECT domain FROM vw_gravity ORDER BY RANDOM() LIMIT 1")
875892

876893
# Next we need to check if Pi-hole can resolve a domain when the query is sent to it's IP address
877894
# This better emulates how clients will interact with Pi-hole as opposed to above where Pi-hole is
@@ -1185,7 +1202,7 @@ show_db_entries() {
11851202
IFS=$'\r\n'
11861203
local entries=()
11871204
mapfile -t entries < <(\
1188-
sqlite3 "${PIHOLE_GRAVITY_DB_FILE}" \
1205+
pihole-FTL sqlite3 "${PIHOLE_GRAVITY_DB_FILE}" \
11891206
-cmd ".headers on" \
11901207
-cmd ".mode column" \
11911208
-cmd ".width ${widths}" \
@@ -1210,7 +1227,7 @@ show_FTL_db_entries() {
12101227
IFS=$'\r\n'
12111228
local entries=()
12121229
mapfile -t entries < <(\
1213-
sqlite3 "${PIHOLE_FTL_DB_FILE}" \
1230+
pihole-FTL sqlite3 "${PIHOLE_FTL_DB_FILE}" \
12141231
-cmd ".headers on" \
12151232
-cmd ".mode column" \
12161233
-cmd ".width ${widths}" \
@@ -1267,15 +1284,15 @@ analyze_gravity_list() {
12671284
log_write "${COL_GREEN}${gravity_permissions}${COL_NC}"
12681285

12691286
show_db_entries "Info table" "SELECT property,value FROM info" "20 40"
1270-
gravity_updated_raw="$(sqlite3 "${PIHOLE_GRAVITY_DB_FILE}" "SELECT value FROM info where property = 'updated'")"
1287+
gravity_updated_raw="$(pihole-FTL sqlite3 "${PIHOLE_GRAVITY_DB_FILE}" "SELECT value FROM info where property = 'updated'")"
12711288
gravity_updated="$(date -d @"${gravity_updated_raw}")"
12721289
log_write " Last gravity run finished at: ${COL_CYAN}${gravity_updated}${COL_NC}"
12731290
log_write ""
12741291

12751292
OLD_IFS="$IFS"
12761293
IFS=$'\r\n'
12771294
local gravity_sample=()
1278-
mapfile -t gravity_sample < <(sqlite3 "${PIHOLE_GRAVITY_DB_FILE}" "SELECT domain FROM vw_gravity LIMIT 10")
1295+
mapfile -t gravity_sample < <(pihole-FTL sqlite3 "${PIHOLE_GRAVITY_DB_FILE}" "SELECT domain FROM vw_gravity LIMIT 10")
12791296
log_write " ${COL_CYAN}----- First 10 Gravity Domains -----${COL_NC}"
12801297

12811298
for line in "${gravity_sample[@]}"; do
@@ -1452,6 +1469,7 @@ check_selinux
14521469
check_firewalld
14531470
processor_check
14541471
disk_usage
1472+
check_ip_command
14551473
check_networking
14561474
check_name_resolution
14571475
check_dhcp_servers

advanced/Scripts/piholeLogFlush.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ else
6363
fi
6464
fi
6565
# Delete most recent 24 hours from FTL's database, leave even older data intact (don't wipe out all history)
66-
deleted=$(sqlite3 "${DBFILE}" "DELETE FROM queries WHERE timestamp >= strftime('%s','now')-86400; select changes() from queries limit 1")
66+
deleted=$(pihole-FTL sqlite3 "${DBFILE}" "DELETE FROM queries WHERE timestamp >= strftime('%s','now')-86400; select changes() from queries limit 1")
6767

6868
# Restart pihole-FTL to force reloading history
6969
sudo pihole restartdns

advanced/Scripts/query.sh

+5-5
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ scanDatabaseTable() {
121121
fi
122122

123123
# Send prepared query to gravity database
124-
result="$(sqlite3 "${gravityDBfile}" "${querystr}")" 2> /dev/null
124+
result="$(pihole-FTL sqlite3 "${gravityDBfile}" "${querystr}")" 2> /dev/null
125125
if [[ -z "${result}" ]]; then
126126
# Return early when there are no matches in this table
127127
return
@@ -164,7 +164,7 @@ scanRegexDatabaseTable() {
164164
type="${3:-}"
165165

166166
# Query all regex from the corresponding database tables
167-
mapfile -t regexList < <(sqlite3 "${gravityDBfile}" "SELECT domain FROM domainlist WHERE type = ${type}" 2> /dev/null)
167+
mapfile -t regexList < <(pihole-FTL sqlite3 "${gravityDBfile}" "SELECT domain FROM domainlist WHERE type = ${type}" 2> /dev/null)
168168

169169
# If we have regexps to process
170170
if [[ "${#regexList[@]}" -ne 0 ]]; then
@@ -233,15 +233,15 @@ for result in "${results[@]}"; do
233233
adlistAddress="${extra/|*/}"
234234
extra="${extra#*|}"
235235
if [[ "${extra}" == "0" ]]; then
236-
extra="(disabled)"
236+
extra=" (disabled)"
237237
else
238238
extra=""
239239
fi
240240

241241
if [[ -n "${blockpage}" ]]; then
242242
echo "0 ${adlistAddress}"
243243
elif [[ -n "${exact}" ]]; then
244-
echo " - ${adlistAddress} ${extra}"
244+
echo " - ${adlistAddress}${extra}"
245245
else
246246
if [[ ! "${adlistAddress}" == "${adlistAddress_prev:-}" ]]; then
247247
count=""
@@ -256,7 +256,7 @@ for result in "${results[@]}"; do
256256
[[ "${count}" -gt "${max_count}" ]] && continue
257257
echo " ${COL_GRAY}Over ${count} results found, skipping rest of file${COL_NC}"
258258
else
259-
echo " ${match} ${extra}"
259+
echo " ${match}${extra}"
260260
fi
261261
fi
262262
done

advanced/Scripts/update.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ GitCheckUpdateAvail() {
4141
cd "${directory}" || return
4242

4343
# Fetch latest changes in this repo
44-
git fetch --tags --quiet origin
44+
git fetch --quiet origin
4545

4646
# Check current branch. If it is master, then check for the latest available tag instead of latest commit.
4747
curBranch=$(git rev-parse --abbrev-ref HEAD)

0 commit comments

Comments
 (0)