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

use the same IP config updating in mechanism for all scripts

This commit is contained in:
OniriCorpe 2023-12-30 23:07:52 +01:00
parent 87c31e7082
commit 68cfa98d49
6 changed files with 17 additions and 31 deletions

View file

@ -13,9 +13,7 @@ http_proxy: ""
language: ""
theme: auto
dns:
bind_hosts:
__IPV4_ADDR__
__IPV6_ADDR__
bind_hosts: []
port: 53
anonymize_client_ip: false
ratelimit: 20

View file

@ -81,16 +81,7 @@ process_ips(){
if [ "$(is_public_ip "$ip")" == 0 ] && [ "$open_port_53" == "false" ] ; then
exit 1
else
if [ "${after_first_pass:-}" = true ]; then
processed_ips+=$(printf "$processed_ips\n%s" "/n")
fi
after_first_pass=true
if [[ "${is_install:-}" = true ]]; then
# to get a dash before each IP
processed_ips+=$(printf "$processed_ips\n%s" "- $ip")
else
pprocessed_ips+=$(printf "$processed_ips\n%s" "$ip")
fi
processed_ips+=$(printf "$processed_ips\n%s" "$ip")
fi
fi
done
@ -98,26 +89,22 @@ process_ips(){
echo "${processed_ips:-}"
}
update_agh_config(){
update_agh_ip_config(){
# used to update the IP adresses in the AGHconfig file
python3 -c "import yaml
with open(\"$install_dir/AdGuardHome.yaml\", 'r') as file:
conf_file = yaml.safe_load(file)
need_file_update = False
conf_file[\"dns\"][\"bind_hosts\"] = []
if \"$ipv4_addr\":
conf_file[\"dns\"][\"bind_hosts\"].append(\"$ipv4_addr\")
need_file_update = True
if \"$ipv6_addr\":
conf_file[\"dns\"][\"bind_hosts\"].append(\"$ipv6_addr\")
need_file_update = True
if need_file_update:
with open(\"$install_dir/AdGuardHome.yaml\", 'w') as file:
yaml.dump(conf_file, file)
for ip in \"$ipv4_addr\":
conf_file[\"dns\"][\"bind_hosts\"].append(\"ip\")
for ip in \"$ipv6_addr\":
conf_file[\"dns\"][\"bind_hosts\"].append(\"ip\")
with open(\"$install_dir/AdGuardHome.yaml\", 'w') as file:
yaml.dump(conf_file, file)
"
}

View file

@ -46,7 +46,7 @@ set__open_port_53() {
ipv6_addr=$(process_ips "$(ip -6 address show "$ipv6_interface" 2> /dev/null | grep inet | sed 's&/.*&&')")
# update the IP adresses in the AGH config file
update_agh_config
update_agh_ip_config
# save the new setting
ynh_app_setting_set "$app" --key=open_port_53 --value="$open_port_53"

View file

@ -84,8 +84,6 @@ ipv6_interface="$(get_network_interface 6)"
# put the network interface in a dedicated dnsmasq config
configure_network_interface_dnsmasq "$ipv4_interface" "$ipv6_interface"
# to warn process_ips that we're doing an installation (to get a dash before each IP)
is_install=true
# get IPv4 for the AGH config file
# the 'sed' is used to get rid of the network prefix ('/24' for example) and the router IP
ipv4_addr=$(process_ips "$(ip -4 address show "$ipv4_interface" 2> /dev/null | grep inet | sed 's&/.*&&')")
@ -94,6 +92,9 @@ ipv4_addr=$(process_ips "$(ip -4 address show "$ipv4_interface" 2> /dev/null | g
# the 'sed' is used to get rid of the network prefix ('/64' for example)
ipv6_addr=$(process_ips "$(ip -6 address show "$ipv6_interface" 2> /dev/null | grep inet | sed 's&/.*&&')")
# update the IP adresses in the AGH config file
update_agh_ip_config
password=$(python3 -c "import bcrypt; print(bcrypt.hashpw(b\"$password\", bcrypt.gensalt(rounds=10)).decode())")
ynh_app_setting_set --app="$app" --key=password --value="$password"

View file

@ -60,7 +60,7 @@ ipv4_addr=$(process_ips "$(ip -4 address show "$ipv4_interface" 2> /dev/null | g
ipv6_addr=$(process_ips "$(ip -6 address show "$ipv6_interface" 2> /dev/null | grep inet | sed 's&/.*&&')")
# update the IP adresses in the AGH config file
update_agh_config
update_agh_ip_config
# this will be treated as a security issue.

View file

@ -137,7 +137,7 @@ ipv4_addr=$(process_ips "$(ip -4 address show "$ipv4_interface" 2> /dev/null | g
ipv6_addr=$(process_ips "$(ip -6 address show "$ipv6_interface" 2> /dev/null | grep inet | sed 's&/.*&&')")
# update the IP adresses in the AGH config file
update_agh_config
update_agh_ip_config
chmod 600 "$install_dir/AdGuardHome.yaml"
chown -R "$app:$app" "$install_dir/AdGuardHome.yaml"