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:
parent
77c7cedc79
commit
2c8322ce7c
3 changed files with 39 additions and 4 deletions
|
@ -8,6 +8,21 @@
|
||||||
# PERSONAL HELPERS
|
# 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
|
# EXPERIMENTAL HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -103,18 +103,28 @@ ipv4_addr=""
|
||||||
for i in $(seq "$(echo "$ipv4_route_output" | wc -w)" -1 1); do
|
for i in $(seq "$(echo "$ipv4_route_output" | wc -w)" -1 1); do
|
||||||
ip=$(echo "$ipv4_route_output" | awk "{print \$$i}")
|
ip=$(echo "$ipv4_route_output" | awk "{print \$$i}")
|
||||||
if ynh_validate_ip4 --ip_address="$ip"; then
|
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"
|
ipv4_addr="- $ip"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
ipv6_addr=""
|
ipv6_addr=""
|
||||||
for i in $(seq "$(echo "$ipv6_route_output" | wc -w)" -1 1); do
|
for i in $(seq "$(echo "$ipv6_route_output" | wc -w)" -1 1); do
|
||||||
ip=$(echo "$ipv6_route_output" | awk "{print \$$i}")
|
ip=$(echo "$ipv6_route_output" | awk "{print \$$i}")
|
||||||
if ynh_validate_ip6 --ip_address="$ip"; then
|
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"
|
ipv6_addr="- $ip"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
password=$(python3 -c "import bcrypt; print(bcrypt.hashpw(b\"$password\", bcrypt.gensalt(rounds=10)).decode())")
|
password=$(python3 -c "import bcrypt; print(bcrypt.hashpw(b\"$password\", bcrypt.gensalt(rounds=10)).decode())")
|
||||||
|
|
|
@ -154,18 +154,28 @@ ipv4_addr=""
|
||||||
for i in $(seq "$(echo "$ipv4_route_output" | wc -w)" -1 1); do
|
for i in $(seq "$(echo "$ipv4_route_output" | wc -w)" -1 1); do
|
||||||
ip=$(echo "$ipv4_route_output" | awk "{print \$$i}")
|
ip=$(echo "$ipv4_route_output" | awk "{print \$$i}")
|
||||||
if ynh_validate_ip4 --ip_address="$ip"; then
|
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"
|
ipv4_addr="$ip"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
ipv6_addr=""
|
ipv6_addr=""
|
||||||
for i in $(seq "$(echo "$ipv6_route_output" | wc -w)" -1 1); do
|
for i in $(seq "$(echo "$ipv6_route_output" | wc -w)" -1 1); do
|
||||||
ip=$(echo "$ipv6_route_output" | awk "{print \$$i}")
|
ip=$(echo "$ipv6_route_output" | awk "{print \$$i}")
|
||||||
if ynh_validate_ip6 --ip_address="$ip"; then
|
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"
|
ipv6_addr="$ip"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Reset the bind_hosts if the current ip is 0.0.0.0
|
# Reset the bind_hosts if the current ip is 0.0.0.0
|
||||||
|
|
Loading…
Add table
Reference in a new issue