1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/adguardhome_ynh.git synced 2024-09-03 18:06:23 +02:00

if the IP is public and the user doesn't want to expose port 53, skip it

This commit is contained in:
OniriCorpe 2023-12-27 06:24:32 +01:00
parent 77c7cedc79
commit 2c8322ce7c
3 changed files with 39 additions and 4 deletions

View file

@ -8,6 +8,21 @@
# PERSONAL HELPERS
#=================================================
is_public_ip(){
local IP
IP="$1"
if [[ "$IP" =~ ^10.*|^169.*|^172.*|^192.168.* ]] ; then
# private ipv4
returns false
elif [[ "$IP" =~ ^fd*|^fe80:* ]] ; then
# private ipv6
returns false
else
# public ip
returns true
fi
}
#=================================================
# EXPERIMENTAL HELPERS
#=================================================

View file

@ -103,18 +103,28 @@ ipv4_addr=""
for i in $(seq "$(echo "$ipv4_route_output" | wc -w)" -1 1); do
ip=$(echo "$ipv4_route_output" | awk "{print \$$i}")
if ynh_validate_ip4 --ip_address="$ip"; then
if is_public_ip "$ip" && [ "$open_port_53" == "false" ] ; then
# if the IP is public and the user doesn't want to expose port 53, skip it
break
else
ipv4_addr="- $ip"
break
fi
fi
done
ipv6_addr=""
for i in $(seq "$(echo "$ipv6_route_output" | wc -w)" -1 1); do
ip=$(echo "$ipv6_route_output" | awk "{print \$$i}")
if ynh_validate_ip6 --ip_address="$ip"; then
if is_public_ip "$ip" && [ "$open_port_53" == "false" ] ; then
# if the IP is public and the user doesn't want to expose port 53, skip it
break
else
ipv6_addr="- $ip"
break
fi
fi
done
password=$(python3 -c "import bcrypt; print(bcrypt.hashpw(b\"$password\", bcrypt.gensalt(rounds=10)).decode())")

View file

@ -154,18 +154,28 @@ ipv4_addr=""
for i in $(seq "$(echo "$ipv4_route_output" | wc -w)" -1 1); do
ip=$(echo "$ipv4_route_output" | awk "{print \$$i}")
if ynh_validate_ip4 --ip_address="$ip"; then
if is_public_ip "$ip" && [ "$open_port_53" == "false" ] ; then
# if the IP is public and the user doesn't want to expose port 53, skip it
break
else
ipv4_addr="$ip"
break
fi
fi
done
ipv6_addr=""
for i in $(seq "$(echo "$ipv6_route_output" | wc -w)" -1 1); do
ip=$(echo "$ipv6_route_output" | awk "{print \$$i}")
if ynh_validate_ip6 --ip_address="$ip"; then
if is_public_ip "$ip" && [ "$open_port_53" == "false" ] ; then
# if the IP is public and the user doesn't want to expose port 53, skip it
break
else
ipv6_addr="$ip"
break
fi
fi
done
# Reset the bind_hosts if the current ip is 0.0.0.0