1
0
mirror of https://github.com/pi-hole/pi-hole synced 2024-11-18 14:18:15 +00:00

Merge pull request #1779 from pi-hole/new/locallists

Add support for local blocking lists
This commit is contained in:
Mcat12 2017-11-28 20:58:00 -05:00 committed by GitHub
commit 472f7725c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -139,7 +139,8 @@ gravity_Collapse() {
awk -F '[/:]' '{ awk -F '[/:]' '{
# Remove URL protocol & optional username:password@ # Remove URL protocol & optional username:password@
gsub(/(.*:\/\/|.*:.*@)/, "", $0) gsub(/(.*:\/\/|.*:.*@)/, "", $0)
print $1 if(length($1)>0){print $1}
else {print "local"}
}' <<< "$(printf '%s\n' "${sources[@]}")" 2> /dev/null }' <<< "$(printf '%s\n' "${sources[@]}")" 2> /dev/null
)" )"
@ -192,9 +193,10 @@ gravity_Pull() {
patternBuffer=$(mktemp -p "/tmp" --suffix=".phgpb") patternBuffer=$(mktemp -p "/tmp" --suffix=".phgpb")
# Determine if $saveLocation has read permission # Determine if $saveLocation has read permission
if [[ -r "${saveLocation}" ]]; then if [[ -r "${saveLocation}" && $url != "file"* ]]; then
# Have curl determine if a remote file has been modified since last retrieval # Have curl determine if a remote file has been modified since last retrieval
# Uses "Last-Modified" header, which certain web servers do not provide (e.g: raw github urls) # Uses "Last-Modified" header, which certain web servers do not provide (e.g: raw github urls)
# Note: Don't do this for local files, always download them
heisenbergCompensator="-z ${saveLocation}" heisenbergCompensator="-z ${saveLocation}"
fi fi
@ -203,20 +205,32 @@ gravity_Pull() {
# shellcheck disable=SC2086 # shellcheck disable=SC2086
httpCode=$(curl -s -L ${cmd_ext} ${heisenbergCompensator} -w "%{http_code}" -A "${agent}" "${url}" -o "${patternBuffer}" 2> /dev/null) httpCode=$(curl -s -L ${cmd_ext} ${heisenbergCompensator} -w "%{http_code}" -A "${agent}" "${url}" -o "${patternBuffer}" 2> /dev/null)
# Determine "Status:" output based on HTTP response case $url in
case "${httpCode}" in # Did we "download" a remote file?
"200") echo -e "${OVER} ${TICK} ${str} Retrieval successful"; success=true;; "http"*)
"304") echo -e "${OVER} ${TICK} ${str} No changes detected"; success=true;; # Determine "Status:" output based on HTTP response
"000") echo -e "${OVER} ${CROSS} ${str} Connection Refused";; case "${httpCode}" in
"403") echo -e "${OVER} ${CROSS} ${str} Forbidden";; "200") echo -e "${OVER} ${TICK} ${str} Retrieval successful"; success=true;;
"404") echo -e "${OVER} ${CROSS} ${str} Not found";; "304") echo -e "${OVER} ${TICK} ${str} No changes detected"; success=true;;
"408") echo -e "${OVER} ${CROSS} ${str} Time-out";; "000") echo -e "${OVER} ${CROSS} ${str} Connection Refused";;
"451") echo -e "${OVER} ${CROSS} ${str} Unavailable For Legal Reasons";; "403") echo -e "${OVER} ${CROSS} ${str} Forbidden";;
"500") echo -e "${OVER} ${CROSS} ${str} Internal Server Error";; "404") echo -e "${OVER} ${CROSS} ${str} Not found";;
"504") echo -e "${OVER} ${CROSS} ${str} Connection Timed Out (Gateway)";; "408") echo -e "${OVER} ${CROSS} ${str} Time-out";;
"521") echo -e "${OVER} ${CROSS} ${str} Web Server Is Down (Cloudflare)";; "451") echo -e "${OVER} ${CROSS} ${str} Unavailable For Legal Reasons";;
"522") echo -e "${OVER} ${CROSS} ${str} Connection Timed Out (Cloudflare)";; "500") echo -e "${OVER} ${CROSS} ${str} Internal Server Error";;
* ) echo -e "${OVER} ${CROSS} ${str} ${httpCode}";; "504") echo -e "${OVER} ${CROSS} ${str} Connection Timed Out (Gateway)";;
"521") echo -e "${OVER} ${CROSS} ${str} Web Server Is Down (Cloudflare)";;
"522") echo -e "${OVER} ${CROSS} ${str} Connection Timed Out (Cloudflare)";;
* ) echo -e "${OVER} ${CROSS} ${str} ${httpCode}";;
esac;;
# Did we "download" a local file?
"file"*)
if [[ -s "${patternBuffer}" ]]; then
echo -e "${OVER} ${TICK} ${str} Retrieval successful"; success=true
else
echo -e "${OVER} ${CROSS} ${str} Not found / empty list"
fi;;
*) echo -e "${OVER} ${CROSS} ${str} ${url} ${httpCode}";;
esac esac
# Determine if the blocklist was downloaded and saved correctly # Determine if the blocklist was downloaded and saved correctly
@ -407,7 +421,7 @@ gravity_Filter() {
# Whitelist unique blocklist domain sources # Whitelist unique blocklist domain sources
gravity_WhitelistBLD() { gravity_WhitelistBLD() {
local uniqDomains plural="" str local uniqDomains plural="" str
echo "" echo ""