diff --git a/hooks/conf_regen/43-dnsmasq b/hooks/conf_regen/43-dnsmasq index a5c4a45d1..db601b992 100755 --- a/hooks/conf_regen/43-dnsmasq +++ b/hooks/conf_regen/43-dnsmasq @@ -6,8 +6,10 @@ set -e do_pre_regen() { pending_dir=$1 - declare -a ip_yuno=(ip.yunohost.org api.ipify.org) - declare -a ip_yuno6=(ip6.yunohost.org 0-ip6.yunohost.org) + # split the mirrors URLs + IFS=',' + read -raip_yuno<<<$(yunohost settings get security.ipmirrors.v4) + read -raip_yuno6<<<$(yunohost settings get security.ipmirrors.v6) cd /usr/share/yunohost/conf/dnsmasq @@ -28,9 +30,9 @@ do_pre_regen() { ###### IPV4 ####### trouve=0 - for i in "${!ip_yuno[@]}" ; do - if [ $(curl --connect-timeout 5 -o -I -L -s -w "%{http_code}" "${ip_yuno[$i]}" 2> /dev/null) -eq 200 ] && [ $trouve -ne 0 ]; then - ipv4=$(curl -s -4 "${ip_yuno[$i]}" 2>/dev/null || true) + for link in "${ip_yuno[@]}" ; do + if [ $(curl --connect-timeout 5 -o -I -L -s -w "%{http_code}" "$link" 2> /dev/null) -eq 200 ] && [ $trouve -ne 1 ]; then + ipv4=$(curl -s -4 "$link" 2>/dev/null || true) ynh_validate_ip4 "$ipv4" || ipv4='127.0.0.1' trouve=1 fi @@ -41,7 +43,7 @@ do_pre_regen() { trouve=0 for i in "${!ip_yuno6[@]}" ; do - if [ $(curl --connect-timeout 5 -o -I -L -s -w "%{http_code}" "${ip6_yuno[$i]}" 2> /dev/null) -eq 200 ] && [ $trouve -ne 0 ]; then + if [ $(curl --connect-timeout 5 -o -I -L -s -w "%{http_code}" "${ip6_yuno[$i]}" 2> /dev/null) -eq 200 ] && [ $trouve -ne 1 ]; then ipv6=$(curl -s -6 "${ip_yuno6[$i]}" 2>/dev/null || true) ynh_validate_ip6 "$ipv6" || ipv6='' trouve=1 diff --git a/share/config_settings.toml b/share/config_settings.toml index f13072704..1024fdde8 100644 --- a/share/config_settings.toml +++ b/share/config_settings.toml @@ -3,6 +3,14 @@ i18n = "global_settings_setting" [security] name = "Security" + [security.ipmirrors] + name = "IPmirrors" + [security.ipmirrors.v4] + type = "string" + default = "https://ip.yunohost.org,https://api.ipify.net" + [security.ipmirrors.v6] + type = "string" + default = "https://ip6.yunohost.org" [security.password] name = "Passwords" [security.password.admin_strength] diff --git a/src/diagnosers/10-ip.py b/src/diagnosers/10-ip.py index 9c8140aab..dd71f3a85 100644 --- a/src/diagnosers/10-ip.py +++ b/src/diagnosers/10-ip.py @@ -12,6 +12,7 @@ from moulinette.utils.filesystem import read_file from yunohost.diagnosis import Diagnoser from yunohost.utils.network import get_network_interfaces +from yunohost.settings import settings_get logger = log.getActionLogger("yunohost.diagnosis") @@ -214,9 +215,7 @@ class MyDiagnoser(Diagnoser): protocol ) - ip4_tab = ["https://ip.yunohost.org","https://api.ipify.net"] - ip6_tab = ["https://ip6.yunohost.org"] - ip_url_yunohost_tab = ip4_tab if protocol==4 else ip6_tab + ip_url_yunohost_tab = settings_get("security.ipmirrors.v"+str(protocol)).split(",") # Check URLS for url in ip_url_yunohost_tab: