#!/bin/bash #================================================= # GENERIC STARTING #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers ynh_abort_if_errors #================================================= # SPECIFIC SETTERS #================================================= set__open_port_53() { if [ "$open_port_53" == "true" ]; then ynh_script_progression --message="Opening port 53..." # if the user would expose port 53 to the Internet, open it ynh_exec_warn_less yunohost firewall allow Both 53 yunohost firewall reload elif [ "$open_port_53" == "false" ]; then # else if false, close it ynh_script_progression --message="Closing port 53..." ynh_exec_warn_less yunohost firewall disallow Both 53 yunohost firewall reload else # else, throw error ynh_print_warn --message="The variable 'open_port_53' should be 'true' or 'false' but isn't, please report this." fi # regenerate config, needed to add or delete public IPs following the user's choice # get IPv4 for the AGH config file ipv4_route_output=$(echo "$(ip -4 route get 1.2.3.4 2> /dev/null)" | head -n1 | head -n1) ipv4_addr=$(process_ips "$ipv4_route_output") # get IPv6 for the AGH config file ipv6_route_output=$(echo "$(ip -6 route get ::1.2.3.4 2> /dev/null)" | head -n1) ipv6_addr=$(process_ips "$ipv6_route_output") # Reset the bind_hosts if the current ip is 0.0.0.0 python3 -c "import yaml with open(\"$install_dir/AdGuardHome.yaml\", 'r') as file: conf_file = yaml.safe_load(file) need_file_update = False if \"0.0.0.0\" in conf_file[\"dns\"][\"bind_hosts\"]: conf_file[\"dns\"][\"bind_hosts\"] = [] if \"$ipv4_addr\": conf_file[\"dns\"][\"bind_hosts\"].append(\"$ipv4_addr\") if \"$ipv6_addr\": conf_file[\"dns\"][\"bind_hosts\"].append(\"$ipv6_addr\") need_file_update = True if conf_file[\"dns\"][\"port\"] != 53: conf_file[\"dns\"][\"port\"] = 53 need_file_update = True if need_file_update: with open(\"$install_dir/AdGuardHome.yaml\", 'w') as file: yaml.dump(conf_file, file) " # save the new setting ynh_app_setting_set "$app" --key=open_port_53 --value="$open_port_53" } set__dns_over_https() { if [ "$dns_over_https" == "true" ]; then ynh_script_progression --message="Opening DoH and DoQ ports..." # if DNS over HTTPS/QUIC is activated, open the associated ports ynh_exec_warn_less yunohost firewall allow Both "$port_dns_over_http" ynh_exec_warn_less yunohost firewall allow UDP "$port_dns_over_quic" yunohost firewall reload elif [ "$dns_over_https" == "false" ]; then # else if false, close them ynh_script_progression --message="Closing DoH and DoQ ports..." ynh_exec_warn_less yunohost firewall disallow Both "$port_dns_over_http" ynh_exec_warn_less yunohost firewall disallow UDP "$port_dns_over_quic" yunohost firewall reload else # else, throw error ynh_print_warn --message="The variable 'dns_over_https' should be 'true' or 'false' but isn't, please report this." fi # save the new setting ynh_app_setting_set "$app" --key=dns_over_https --value="$dns_over_https" } #================================================= # GENERIC FINALIZATION #================================================= ynh_app_config_run "$1"