Added a field in the settings for mirrors of ip.yunohost.org

This commit is contained in:
theo@manjaro 2022-06-28 15:02:29 +02:00
parent 6f282b2bcf
commit 19482d0b96
3 changed files with 18 additions and 9 deletions

View file

@ -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

View file

@ -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]

View file

@ -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: