From 15ef276917a38bed5db6622569a62ea8b3f6394a Mon Sep 17 00:00:00 2001 From: HgO Date: Sun, 24 Sep 2023 11:34:54 +0200 Subject: [PATCH] fix unbound dns variables + check if hotspot is enabled before starting it + cleanup stuff when hotspot is disabled --- config_panel.toml | 1 - scripts/config | 46 +++++++++++++++++++++++++++++++++------------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/config_panel.toml b/config_panel.toml index ff286d0..71a9384 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -103,7 +103,6 @@ name = "Configuration" [main.hotspot.dns] ask = "DNS resolvers" type = "tags" - bind = "null" visible = "advanced" pattern.regexp = '^([0-9.]{7,15}|[0-9a-fA-F:]+)$' pattern.error = "Not an ip" diff --git a/scripts/config b/scripts/config index b493dbf..bff0cab 100644 --- a/scripts/config +++ b/scripts/config @@ -136,21 +136,24 @@ validate__ip4_nat_prefix() { } validate__dns() { - if ! echo "${dns}" | grep -q "\." + if [[ -z "$ip4_dns" ]] then echo 'IPv4 DNS required' fi - if [[ -n "${ip6_net}" ]] && ! echo "${dns}" | grep -q ":" + if [[ -n "${ip6_net}" ]] && [[ -z "$ip6_dns" ]] then echo 'IPv6 DNS required' fi } -#================================================= -# SPECIFIC SETTERS FOR TOML SHORT KEYS -#================================================= +ynh_app_config_validate() { + if [[ "${advanced}" -eq 0 ]]; then + # When we aren't in advanced mode, these variables must be manually declared + dns="${old[dns]}" + ip6_net="${old[ip6_net]}" + ip4_nat_prefix="${old[ip4_nat_prefix]}" + fi -set__dns() { ip6_dns="" ip4_dns="" for ip in $(echo "${dns}" | tr ',' ' '); do @@ -171,7 +174,15 @@ set__dns() { if [[ -n "${ip4_nat_prefix}" ]] && [[ -z "${ip4_dns}" ]]; then ip4_dns="${ip4_nat_prefix}.1" fi - + + _ynh_app_config_validate +} + +#================================================= +# SPECIFIC SETTERS FOR TOML SHORT KEYS +#================================================= + +set__dns() { ynh_app_setting_set $app ip6_dns "${ip6_dns}" ynh_app_setting_set $app ip4_dns "${ip4_dns}" } @@ -192,14 +203,23 @@ ynh_app_config_apply() { _ynh_app_config_apply - configure_hostapd - configure_dnsmasq - configure_dhcp + if [[ "${service_enabled}" -eq 1 ]]; then + configure_hostapd + configure_dnsmasq + configure_dhcp - # Start hotspot - ynh_print_info --message="Starting hotspot service if needed" - /usr/local/bin/${service_name} start + # Start hotspot + ynh_print_info --message="Starting hotspot service if needed" + /usr/local/bin/${service_name} start + else + ynh_print_info --message="Cleanup hotspot config files" + ynh_secure_remove --file="/etc/hostapd/$app/hostapd.conf" + ynh_secure_remove --file="/etc/dnsmasq.d/$app.conf" + ynh_secure_remove --file="/etc/dnsmasq.$app/dhcpdv4.conf" + ynh_secure_remove --file="/etc/dnsmasq.$app/dhcpdv6.conf" + systemctl restart dnsmasq + fi } ynh_app_config_run $1