1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/hotspot_ynh.git synced 2024-09-03 19:25:53 +02:00

fix unbound dns variables + check if hotspot is enabled before starting it + cleanup stuff when hotspot is disabled

This commit is contained in:
HgO 2023-09-24 11:34:54 +02:00
parent e3a4f9e34a
commit 15ef276917
2 changed files with 33 additions and 14 deletions

View file

@ -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"

View file

@ -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
@ -172,6 +175,14 @@ set__dns() {
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