diff --git a/scripts/_common.sh b/scripts/_common.sh index 944a65e..d44411c 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -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 #================================================= diff --git a/scripts/install b/scripts/install index 1edb3e6..57afc3b 100644 --- a/scripts/install +++ b/scripts/install @@ -103,8 +103,13 @@ 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 - ipv4_addr="- $ip" - break + 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 @@ -112,8 +117,13 @@ 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 - ipv6_addr="- $ip" - break + 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 diff --git a/scripts/upgrade b/scripts/upgrade index 471623b..4fd0bed 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -154,8 +154,13 @@ 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 @@ -163,8 +168,13 @@ 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