From 4ba23512692e05ae8de0f2b5709e6ad407107161 Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Mon, 1 Jan 2024 04:06:53 +0100 Subject: [PATCH] declare needs_exposed_ports according to real user need --- scripts/config | 30 +++++++++++++++++++++++++----- scripts/install | 24 +++++++++++++++--------- scripts/restore | 14 +++++++++++--- scripts/upgrade | 24 ++++++++++++++++-------- 4 files changed, 67 insertions(+), 25 deletions(-) diff --git a/scripts/config b/scripts/config index 6bbfdca..9830f79 100644 --- a/scripts/config +++ b/scripts/config @@ -15,19 +15,19 @@ ynh_abort_if_errors # SPECIFIC SETTERS #================================================= -set__open_port_53() { +set__expose_port_53() { - if [ "$open_port_53" == "true" ]; then + if [ "$expose_port_53" == "true" ]; then ynh_print_info --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 - elif [ "$open_port_53" == "false" ]; then + elif [ "$expose_port_53" == "false" ]; then # else if false, close it ynh_print_info --message="Closing port 53..." ynh_exec_warn_less yunohost firewall disallow Both 53 else # else, throw error - ynh_print_warn --message="The variable 'open_port_53' should be 'true' or 'false' but isn't, please report this." + ynh_print_warn --message="The variable 'expose_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 @@ -49,8 +49,18 @@ set__open_port_53() { ynh_print_info --message="Updating the AGH config file..." update_agh_ip_config + if [[ $dns_over_https == 0 ]] && [[ $expose_port_53 == 0 ]]; then + yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "53" "$port_dns_over_http" "$port_dns_over_quic" + elif [[ $dns_over_https == 0 ]]; then + yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "$port_dns_over_http" "$port_dns_over_quic" + elif [[ $expose_port_53 == 0 ]]; then + yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "53" + else + yunohost service add "$app" --description="Ads & trackers blocking DNS server" + fi + # save the new setting - ynh_app_setting_set --app="$app" --key=open_port_53 --value="$open_port_53" + ynh_app_setting_set --app="$app" --key=expose_port_53 --value="$expose_port_53" } set__dns_over_https() { @@ -73,6 +83,16 @@ set__dns_over_https() { ynh_print_warn --message="The variable 'dns_over_https' should be 'true' or 'false' but isn't, please report this." fi + if [[ $dns_over_https == 0 ]] && [[ $expose_port_53 == 0 ]]; then + yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "53" "$port_dns_over_http" "$port_dns_over_quic" + elif [[ $dns_over_https == 0 ]]; then + yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "$port_dns_over_http" "$port_dns_over_quic" + elif [[ $expose_port_53 == 0 ]]; then + yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "53" + else + yunohost service add "$app" --description="Ads & trackers blocking DNS server" + fi + # save the new setting in the AGH config file ynh_write_var_in_file --file="$install_dir/AdGuardHome.yaml" --key="enabled" --after="tls:" --value="$dns_over_https" diff --git a/scripts/install b/scripts/install index 4e0fdbf..ca36abc 100644 --- a/scripts/install +++ b/scripts/install @@ -29,17 +29,15 @@ fi ynh_app_setting_set --app="$app" --key=dns_over_https --value="$dns_over_https" -if [[ $open_port_53 == 0 ]]; then - open_port_53="true" - # if open_port_53 is true, we need to open port 53 - ynh_print_info --message="Opening port 53..." - ynh_exec_warn_less yunohost firewall allow Both 53 +ynh_print_info --message="Opening port 53..." +ynh_exec_warn_less yunohost firewall allow Both 53 +if [[ $expose_port_53 == 0 ]]; then + expose_port_53="true" else - open_port_53="false" - ynh_print_info --message="Port 53 is closed." + expose_port_53="false" fi -ynh_app_setting_set --app="$app" --key=open_port_53 --value="$open_port_53" +ynh_app_setting_set --app="$app" --key=expose_port_53 --value="$expose_port_53" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -111,7 +109,15 @@ ynh_script_progression --message="Configuring a systemd service..." --weight=1 # Create a dedicated systemd config ynh_add_systemd_config -yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "53" "$port_dns_over_http" "$port_dns_over_quic" +if [[ $dns_over_https == 0 ]] && [[ $expose_port_53 == 0 ]]; then + yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "53" "$port_dns_over_http" "$port_dns_over_quic" +elif [[ $dns_over_https == 0 ]]; then + yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "$port_dns_over_http" "$port_dns_over_quic" +elif [[ $expose_port_53 == 0 ]]; then + yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "53" +else + yunohost service add "$app" --description="Ads & trackers blocking DNS server" +fi #================================================= # START SYSTEMD SERVICE diff --git a/scripts/restore b/scripts/restore index 8a43917..eb40af5 100644 --- a/scripts/restore +++ b/scripts/restore @@ -22,8 +22,8 @@ if [ "$dns_over_https" == "false" ]; then ynh_exec_warn_less yunohost firewall disallow UDP "$port_dns_over_quic" fi -if [ "$open_port_53" == "true" ]; then - # if open_port_53 is true, we need to open port 53 +if [ "$expose_port_53" == "true" ]; then + # if expose_port_53 is true, we need to open port 53 ynh_exec_warn_less yunohost firewall allow Both 53 fi @@ -80,7 +80,15 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file --origin_path="/etc/systemd/system/$app.service" systemctl enable "$app.service" --quiet -yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "53" "$port_dns_over_http" "$port_dns_over_quic" +if [[ $dns_over_https == 0 ]] && [[ $expose_port_53 == 0 ]]; then + yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "53" "$port_dns_over_http" "$port_dns_over_quic" +elif [[ $dns_over_https == 0 ]]; then + yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "$port_dns_over_http" "$port_dns_over_quic" +elif [[ $expose_port_53 == 0 ]]; then + yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "53" +else + yunohost service add "$app" --description="Ads & trackers blocking DNS server" +fi #================================================= # START SYSTEMD SERVICE diff --git a/scripts/upgrade b/scripts/upgrade index b2c8053..60d9665 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -29,15 +29,15 @@ ynh_systemd_action --service_name="$app" --action="stop" #================================================= ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 -if [ -z "${open_port_53:-}" ] && [ "${open_port_53:-}" = true ]; then - open_port_53="true" - ynh_app_setting_set --app="$app" --key=open_port_53 --value="$open_port_53" - # if open_port_53 is true, we need to open port 53 +if [ -z "${expose_port_53:-}" ] && [ "${expose_port_53:-}" = true ]; then + expose_port_53="true" + ynh_app_setting_set --app="$app" --key=expose_port_53 --value="$expose_port_53" + # if expose_port_53 is true, we need to open port 53 ynh_print_info --message="Opening port 53..." ynh_exec_warn_less yunohost firewall allow Both 53 -elif [ -n "${open_port_53:-}" ] || [ "${open_port_53:-}" = false ]; then - open_port_53="false" - ynh_app_setting_set --app="$app" --key=open_port_53 --value="$open_port_53" +elif [ -n "${expose_port_53:-}" ] || [ "${expose_port_53:-}" = false ]; then + expose_port_53="false" + ynh_app_setting_set --app="$app" --key=expose_port_53 --value="$expose_port_53" ynh_print_info --message="Port 53 is closed." fi @@ -111,7 +111,15 @@ ynh_add_nginx_config # Create a dedicated systemd config ynh_add_systemd_config -yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "53" "$port_dns_over_http" "$port_dns_over_quic" +if [[ $dns_over_https == 0 ]] && [[ $expose_port_53 == 0 ]]; then + yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "53" "$port_dns_over_http" "$port_dns_over_quic" +elif [[ $dns_over_https == 0 ]]; then + yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "$port_dns_over_http" "$port_dns_over_quic" +elif [[ $expose_port_53 == 0 ]]; then + yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "53" +else + yunohost service add "$app" --description="Ads & trackers blocking DNS server" +fi #================================================= # SPECIFIC UPGRADE