diff --git a/conf/AdGuardHome.yaml b/conf/AdGuardHome.yaml index 3ddeeee..df12248 100644 --- a/conf/AdGuardHome.yaml +++ b/conf/AdGuardHome.yaml @@ -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 diff --git a/scripts/_common.sh b/scripts/_common.sh index c66bd0e..9977d64 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -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) " } diff --git a/scripts/config b/scripts/config index 5bddc71..233efc3 100644 --- a/scripts/config +++ b/scripts/config @@ -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" diff --git a/scripts/install b/scripts/install index 746c949..4e7a224 100644 --- a/scripts/install +++ b/scripts/install @@ -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" diff --git a/scripts/restore b/scripts/restore index 322612c..ab4d976 100644 --- a/scripts/restore +++ b/scripts/restore @@ -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. diff --git a/scripts/upgrade b/scripts/upgrade index 8fb3e76..e16e59e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -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"