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

Merge pull request #109 from YunoHost-Apps/fix-dns-config

Fix DNS config + cleanup stuff when hotspot is disabled
This commit is contained in:
HgO 2023-09-24 19:38:13 +02:00 committed by GitHub
commit 29110a389a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 14 deletions

View file

@ -103,7 +103,6 @@ name = "Configuration"
[main.hotspot.dns] [main.hotspot.dns]
ask = "DNS resolvers" ask = "DNS resolvers"
type = "tags" type = "tags"
bind = "null"
visible = "advanced" visible = "advanced"
pattern.regexp = '^([0-9.]{7,15}|[0-9a-fA-F:]+)$' pattern.regexp = '^([0-9.]{7,15}|[0-9a-fA-F:]+)$'
pattern.error = "Not an ip" pattern.error = "Not an ip"

View file

@ -136,21 +136,24 @@ validate__ip4_nat_prefix() {
} }
validate__dns() { validate__dns() {
if ! echo "${dns}" | grep -q "\." if [[ -z "$ip4_dns" ]]
then then
echo 'IPv4 DNS required' echo 'IPv4 DNS required'
fi fi
if [[ -n "${ip6_net}" ]] && ! echo "${dns}" | grep -q ":" if [[ -n "${ip6_net}" ]] && [[ -z "$ip6_dns" ]]
then then
echo 'IPv6 DNS required' echo 'IPv6 DNS required'
fi fi
} }
#================================================= ynh_app_config_validate() {
# SPECIFIC SETTERS FOR TOML SHORT KEYS 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="" ip6_dns=""
ip4_dns="" ip4_dns=""
for ip in $(echo "${dns}" | tr ',' ' '); do for ip in $(echo "${dns}" | tr ',' ' '); do
@ -172,6 +175,14 @@ set__dns() {
ip4_dns="${ip4_nat_prefix}.1" ip4_dns="${ip4_nat_prefix}.1"
fi 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 ip6_dns "${ip6_dns}"
ynh_app_setting_set $app ip4_dns "${ip4_dns}" ynh_app_setting_set $app ip4_dns "${ip4_dns}"
} }
@ -192,14 +203,23 @@ ynh_app_config_apply() {
_ynh_app_config_apply _ynh_app_config_apply
configure_hostapd if [[ "${service_enabled}" -eq 1 ]]; then
configure_dnsmasq configure_hostapd
configure_dhcp configure_dnsmasq
configure_dhcp
# Start hotspot # Start hotspot
ynh_print_info --message="Starting hotspot service if needed" ynh_print_info --message="Starting hotspot service if needed"
/usr/local/bin/${service_name} start /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 ynh_app_config_run $1