Merge branch 'master' into fix/etag
Some checks are pending
Check for merge conflicts / main (push) Waiting to run
CodeQL / Analyze (pull_request) Waiting to run
Test Supported Distributions / smoke-tests (pull_request) Waiting to run
Test Supported Distributions / distro-test (alpine_3_21) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (alpine_3_22) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (alpine_3_23) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (centos_10) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (centos_9) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (debian_11) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (debian_12) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (debian_13) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (fedora_40) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (fedora_41) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (fedora_42) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (fedora_43) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (ubuntu_20) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (ubuntu_22) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (ubuntu_24) (pull_request) Blocked by required conditions
Check for merge conflicts / main (pull_request_target) Waiting to run
Some checks are pending
Check for merge conflicts / main (push) Waiting to run
CodeQL / Analyze (pull_request) Waiting to run
Test Supported Distributions / smoke-tests (pull_request) Waiting to run
Test Supported Distributions / distro-test (alpine_3_21) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (alpine_3_22) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (alpine_3_23) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (centos_10) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (centos_9) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (debian_11) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (debian_12) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (debian_13) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (fedora_40) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (fedora_41) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (fedora_42) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (fedora_43) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (ubuntu_20) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (ubuntu_22) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (ubuntu_24) (pull_request) Blocked by required conditions
Check for merge conflicts / main (pull_request_target) Waiting to run
This commit is contained in:
68
gravity.sh
68
gravity.sh
@@ -118,9 +118,12 @@ gravity_swap_databases() {
|
||||
|
||||
# Swap databases and remove or conditionally rename old database
|
||||
# Number of available blocks on disk
|
||||
availableBlocks=$(stat -f --format "%a" "${gravityDIR}")
|
||||
# Busybox Compat: `stat` long flags unsupported
|
||||
# -f flag is short form of --file-system.
|
||||
# -c flag is short form of --format.
|
||||
availableBlocks=$(stat -f -c "%a" "${gravityDIR}")
|
||||
# Number of blocks, used by gravity.db
|
||||
gravityBlocks=$(stat --format "%b" "${gravityDBfile}")
|
||||
gravityBlocks=$(stat -c "%b" "${gravityDBfile}")
|
||||
# Only keep the old database if available disk space is at least twice the size of the existing gravity.db.
|
||||
# Better be safe than sorry...
|
||||
oldAvail=false
|
||||
@@ -609,7 +612,7 @@ compareLists() {
|
||||
gravity_DownloadBlocklistFromUrl() {
|
||||
local url="${1}" adlistID="${2}" saveLocation="${3}" compression="${4}" gravity_type="${5}" domain="${6}"
|
||||
local listCurlBuffer str httpCode success="" ip customUpstreamResolver=""
|
||||
local file_path permissions ip_addr port blocked=false download=true
|
||||
local file_path ip_addr port blocked=false download=true
|
||||
# modifiedOptions is an array to store all the options used to check if the adlist has been changed upstream
|
||||
local modifiedOptions=()
|
||||
|
||||
@@ -718,36 +721,47 @@ gravity_DownloadBlocklistFromUrl() {
|
||||
fi
|
||||
fi
|
||||
|
||||
# If we are going to "download" a local file, we first check if the target
|
||||
# file has a+r permission. We explicitly check for all+read because we want
|
||||
# to make sure that the file is readable by everyone and not just the user
|
||||
# running the script.
|
||||
if [[ $url == "file://"* ]]; then
|
||||
# If we "download" a local file (file://), verify read access before using it.
|
||||
# When running as root (e.g., via pihole -g), check that the 'pihole' user can read the file
|
||||
# to match the effective runtime user of FTL; otherwise, check the current user's read access
|
||||
# (e.g., in Docker or when invoked by a non-root user). The target must
|
||||
# resolve to a regular file and be readable by the evaluated user.
|
||||
if [[ "${url}" == "file:/"* ]]; then
|
||||
# Get the file path
|
||||
file_path=$(echo "$url" | cut -d'/' -f3-)
|
||||
file_path=$(echo "${url}" | cut -d'/' -f3-)
|
||||
# Check if the file exists and is a regular file (i.e. not a socket, fifo, tty, block). Might still be a symlink.
|
||||
if [[ ! -f $file_path ]]; then
|
||||
# Output that the file does not exist
|
||||
echo -e "${OVER} ${CROSS} ${file_path} does not exist"
|
||||
download=false
|
||||
else
|
||||
# Check if the file or a file referenced by the symlink has a+r permissions
|
||||
permissions=$(stat -L -c "%a" "$file_path")
|
||||
if [[ $permissions == *4 || $permissions == *5 || $permissions == *6 || $permissions == *7 ]]; then
|
||||
# Output that we are using the local file
|
||||
echo -e "${OVER} ${INFO} Using local file ${file_path}"
|
||||
else
|
||||
# Output that the file does not have the correct permissions
|
||||
echo -e "${OVER} ${CROSS} Cannot read file (file needs to have a+r permission)"
|
||||
if [[ ! -f ${file_path} ]]; then
|
||||
# Output that the file does not exist
|
||||
echo -e "${OVER} ${CROSS} ${file_path} does not exist"
|
||||
download=false
|
||||
fi
|
||||
else
|
||||
if [ "$(id -un)" == "root" ]; then
|
||||
# If we are root, we need to check if the pihole user has read permission
|
||||
# otherwise, we might read files that the pihole user should not be able to read
|
||||
if sudo -u pihole test -r "${file_path}"; then
|
||||
echo -e "${OVER} ${INFO} Using local file ${file_path}"
|
||||
else
|
||||
echo -e "${OVER} ${CROSS} Cannot read file (user 'pihole' lacks read permission)"
|
||||
download=false
|
||||
fi
|
||||
else
|
||||
# If we are not root, we just check if the current user has read permission
|
||||
if [[ -r "${file_path}" ]]; then
|
||||
# Output that we are using the local file
|
||||
echo -e "${OVER} ${INFO} Using local file ${file_path}"
|
||||
else
|
||||
# Output that the file is not readable by the current user
|
||||
echo -e "${OVER} ${CROSS} Cannot read file (current user '$(id -un)' lacks read permission)"
|
||||
download=false
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check for allowed protocols
|
||||
if [[ $url != "http"* && $url != "https"* && $url != "file"* && $url != "ftp"* && $url != "ftps"* && $url != "sftp"* ]]; then
|
||||
echo -e "${OVER} ${CROSS} ${str} Invalid protocol specified. Ignoring list."
|
||||
echo -e "Ensure your URL starts with a valid protocol like http:// , https:// or file:// ."
|
||||
echo -e " Ensure your URL starts with a valid protocol like http:// , https:// or file:// ."
|
||||
download=false
|
||||
fi
|
||||
|
||||
@@ -855,7 +869,7 @@ gravity_Table_Count() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Output count of blacklisted domains and regex filters
|
||||
# Output count of denied and allowed domains and regex filters
|
||||
gravity_ShowCount() {
|
||||
# Here we use the table "gravity" instead of the view "vw_gravity" for speed.
|
||||
# It's safe to replace it here, because right after a gravity run both will show the exactly same number of domains.
|
||||
@@ -948,7 +962,7 @@ database_recovery() {
|
||||
else
|
||||
echo -e "${OVER} ${CROSS} ${str} - the following errors happened:"
|
||||
while IFS= read -r line; do echo " - $line"; done <<<"$result"
|
||||
echo -e " ${CROSS} Recovery failed. Try \"pihole -r recreate\" instead."
|
||||
echo -e " ${CROSS} Recovery failed. Try \"pihole -g -r recreate\" instead."
|
||||
exit 1
|
||||
fi
|
||||
echo ""
|
||||
@@ -1131,7 +1145,7 @@ fi
|
||||
|
||||
if [[ "${forceDelete:-}" == true ]]; then
|
||||
str="Deleting existing list cache"
|
||||
echo -ne "${INFO} ${str}..."
|
||||
echo -ne " ${INFO} ${str}..."
|
||||
|
||||
rm "${listsCacheDir}/list.*" 2>/dev/null || true
|
||||
echo -e "${OVER} ${TICK} ${str}"
|
||||
|
||||
Reference in New Issue
Block a user