mirror of
https://github.com/pi-hole/pi-hole
synced 2024-11-18 06:08:21 +00:00
Pass correct options to gravity.sh
* Optimise $validDomain function by using bashism and `grep` * Add black/white/wildcard variables to pass to Reload() * Revert reload variable behaviour * Ensure Reload() function passes correct options to gravity.sh Signed-off-by: WaLLy3K <wally3k@pi-hole.net>
This commit is contained in:
parent
61ff0452e1
commit
2d8fff099f
@ -66,15 +66,15 @@ HandleOther() {
|
|||||||
domain="${1,,}"
|
domain="${1,,}"
|
||||||
|
|
||||||
# Check validity of domain
|
# Check validity of domain
|
||||||
validDomain=$(perl -lne 'print if /^((-|_)*[a-z\d]((-|_)*[a-z\d])*(-|_)*)(\.(-|_)*([a-z\d]((-|_)*[a-z\d])*))*$/' <<< "${domain}") # Valid chars check
|
if [[ "${#domain}" -le 253 ]]; then
|
||||||
validDomain=$(perl -lne 'print if /^.{1,253}$/' <<< "${validDomain}") # Overall length check
|
validDomain=$(grep -P "^((-|_)*[a-z\d]((-|_)*[a-z\d])*(-|_)*)(\.(-|_)*([a-z\d]((-|_)*[a-z\d])*))*$" <<< "${domain}") # Valid chars check
|
||||||
validDomain=$(perl -lne 'print if /^[^\.]{1,63}(\.[^\.]{1,63})*$/' <<< "${validDomain}") # Length of each label
|
validDomain=$(grep -P "^[^\.]{1,63}(\.[^\.]{1,63})*$" <<< "${validDomain}") # Length of each label
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ -z "${validDomain}" ]]; then
|
if [[ -n "${validDomain}" ]]; then
|
||||||
echo -e " ${CROSS} $1 is not a valid argument or domain name!"
|
|
||||||
else
|
|
||||||
echo -e " ${TICK} $1 is a valid domain name!"
|
|
||||||
domList=("${domList[@]}" ${validDomain})
|
domList=("${domList[@]}" ${validDomain})
|
||||||
|
else
|
||||||
|
echo -e " ${CROSS} ${domain} is not a valid argument or domain name!"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,6 +107,8 @@ AddDomain() {
|
|||||||
[[ "${list}" == "${wildcardlist}" ]] && listname="wildcard blacklist"
|
[[ "${list}" == "${wildcardlist}" ]] && listname="wildcard blacklist"
|
||||||
|
|
||||||
if [[ "${list}" == "${whitelist}" || "${list}" == "${blacklist}" ]]; then
|
if [[ "${list}" == "${whitelist}" || "${list}" == "${blacklist}" ]]; then
|
||||||
|
[[ "${list}" == "${whitelist}" && -z "${type}" ]] && type="--whitelist-only"
|
||||||
|
[[ "${list}" == "${blacklist}" && -z "${type}" ]] && type="--blacklist-only"
|
||||||
bool=true
|
bool=true
|
||||||
# Is the domain in the list we want to add it to?
|
# Is the domain in the list we want to add it to?
|
||||||
grep -Ex -q "${domain}" "${list}" > /dev/null 2>&1 || bool=false
|
grep -Ex -q "${domain}" "${list}" > /dev/null 2>&1 || bool=false
|
||||||
@ -129,7 +131,7 @@ AddDomain() {
|
|||||||
# Remove the /* from the end of the IP addresses
|
# Remove the /* from the end of the IP addresses
|
||||||
IPV4_ADDRESS=${IPV4_ADDRESS%/*}
|
IPV4_ADDRESS=${IPV4_ADDRESS%/*}
|
||||||
IPV6_ADDRESS=${IPV6_ADDRESS%/*}
|
IPV6_ADDRESS=${IPV6_ADDRESS%/*}
|
||||||
|
[[ -z "${type}" ]] && type="--wildcard-only"
|
||||||
bool=true
|
bool=true
|
||||||
# Is the domain in the list?
|
# Is the domain in the list?
|
||||||
grep -e "address=\/${domain}\/" "${wildcardlist}" > /dev/null 2>&1 || bool=false
|
grep -e "address=\/${domain}\/" "${wildcardlist}" > /dev/null 2>&1 || bool=false
|
||||||
@ -161,6 +163,8 @@ RemoveDomain() {
|
|||||||
|
|
||||||
if [[ "${list}" == "${whitelist}" || "${list}" == "${blacklist}" ]]; then
|
if [[ "${list}" == "${whitelist}" || "${list}" == "${blacklist}" ]]; then
|
||||||
bool=true
|
bool=true
|
||||||
|
[[ "${list}" == "${whitelist}" && -z "${type}" ]] && type="--whitelist-only"
|
||||||
|
[[ "${list}" == "${blacklist}" && -z "${type}" ]] && type="--blacklist-only"
|
||||||
# Is it in the list? Logic follows that if its whitelisted it should not be blacklisted and vice versa
|
# Is it in the list? Logic follows that if its whitelisted it should not be blacklisted and vice versa
|
||||||
grep -Ex -q "${domain}" "${list}" > /dev/null 2>&1 || bool=false
|
grep -Ex -q "${domain}" "${list}" > /dev/null 2>&1 || bool=false
|
||||||
if [[ "${bool}" == true ]]; then
|
if [[ "${bool}" == true ]]; then
|
||||||
@ -175,6 +179,7 @@ RemoveDomain() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
elif [[ "${list}" == "${wildcardlist}" ]]; then
|
elif [[ "${list}" == "${wildcardlist}" ]]; then
|
||||||
|
[[ -z "${type}" ]] && type="--wildcard-only"
|
||||||
bool=true
|
bool=true
|
||||||
# Is it in the list?
|
# Is it in the list?
|
||||||
grep -e "address=\/${domain}\/" "${wildcardlist}" > /dev/null 2>&1 || bool=false
|
grep -e "address=\/${domain}\/" "${wildcardlist}" > /dev/null 2>&1 || bool=false
|
||||||
@ -183,7 +188,7 @@ RemoveDomain() {
|
|||||||
echo -e " ${INFO} Removing $1 from $listname..."
|
echo -e " ${INFO} Removing $1 from $listname..."
|
||||||
# /I flag: search case-insensitive
|
# /I flag: search case-insensitive
|
||||||
sed -i "/address=\/${domain}/Id" "${list}"
|
sed -i "/address=\/${domain}/Id" "${list}"
|
||||||
reload="restart"
|
reload=true
|
||||||
else
|
else
|
||||||
if [[ "${verbose}" == true ]]; then
|
if [[ "${verbose}" == true ]]; then
|
||||||
echo -e " ${INFO} ${1} does not exist in ${listname}, no need to remove!"
|
echo -e " ${INFO} ${1} does not exist in ${listname}, no need to remove!"
|
||||||
@ -195,13 +200,7 @@ RemoveDomain() {
|
|||||||
# Update Gravity
|
# Update Gravity
|
||||||
Reload() {
|
Reload() {
|
||||||
echo ""
|
echo ""
|
||||||
|
pihole -g --skip-download "${type:-}"
|
||||||
# Ensure that "restart" is used for Wildcard updates
|
|
||||||
if [[ "${1}" == "restart" ]]; then
|
|
||||||
local type="--wildcard"
|
|
||||||
fi
|
|
||||||
|
|
||||||
pihole -g --skip-download --blacklist-only "${type:-}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Displaylist() {
|
Displaylist() {
|
||||||
|
Loading…
Reference in New Issue
Block a user