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

Merge remote-tracking branch 'origin/master' into packagingv2

This commit is contained in:
Alexandre Aubin 2023-11-27 23:16:26 +01:00
commit f224340e04
5 changed files with 36 additions and 7 deletions

View file

@ -1,3 +1,31 @@
#!/bin/bash #!/bin/bash
systemctl restart __SERVICE_NAME__ is_nat_set() {
local gateway_interface=${1}
iptables -w -nvt nat -L POSTROUTING | grep MASQUERADE | grep -q "${gateway_interface}"
}
unset_nat() {
local gateway_interface=${1}
iptables -w -t nat -D POSTROUTING -o "${gateway_interface}" -j MASQUERADE
}
set_nat() {
local gateway_interface=${1}
iptables -w -t nat -A POSTROUTING -o "${gateway_interface}" -j MASQUERADE
}
if systemctl -q is-active __SERVICE_NAME__; then
old_gateway_interface=$(yunohost app setting __APP__ gateway_interface)
new_gateway_interface=$(ip route get 1.2.3.4 | awk '{ print $5; }')
if [[ -n "$old_gateway_interface" ]] && [[ "$old_gateway_interface" != "$new_gateway_interface" ]] && is_nat_set "$old_gateway_interface"; then
unset_nat "${old_gateway_interface}"
fi
if [[ -n "$new_gateway_interface" ]] && ! is_nat_set $new_gateway_interface; then
set_nat "${new_gateway_interface}"
fi
yunohost app setting __APP__ gateway_interface --value "${new_gateway_interface}"
fi

View file

@ -258,7 +258,7 @@ start)
exit 1 exit 1
fi fi
echo "[hotspot] Starting..." echo "[$app] Starting..."
touch /tmp/.${service_name}-started touch /tmp/.${service_name}-started
# Check old state of the ipv4 NAT settings # Check old state of the ipv4 NAT settings
@ -295,13 +295,13 @@ start)
start_dhcpd start_dhcpd
# Update dynamic settings # Update dynamic settings
ynh_app_setting_set hotspot gateway_interface "${new_gateway_interface}" ynh_app_setting_set --app=$app --key=gateway_interface --value="${new_gateway_interface}"
# Regen-conf dnsmasq to enable dns resolution on dnsmasq for the new interface # Regen-conf dnsmasq to enable dns resolution on dnsmasq for the new interface
yunohost tools regen-conf dnsmasq yunohost tools regen-conf dnsmasq
;; ;;
stop) stop)
echo "[hotspot] Stopping..." echo "[$app] Stopping..."
rm -f /tmp/.${service_name}-started rm -f /tmp/.${service_name}-started
if ! is_other_hostapd_running; then if ! is_other_hostapd_running; then

View file

@ -103,6 +103,7 @@ name = "Configuration"
[main.hotspot.dns] [main.hotspot.dns]
ask = "DNS resolvers" ask = "DNS resolvers"
type = "tags" type = "tags"
optional = true
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

@ -193,7 +193,7 @@ ynh_app_config_apply() {
# Stop vpn client # Stop vpn client
ynh_print_info --message="Stopping hotspot in order to edit files" ynh_print_info --message="Stopping hotspot in order to edit files"
systemctl stop ${service_name} yunohost service stop $service_name
_ynh_app_config_apply _ynh_app_config_apply
@ -203,7 +203,7 @@ ynh_app_config_apply() {
# Start hotspot # Start hotspot
ynh_print_info --message="Starting hotspot service if needed" ynh_print_info --message="Starting hotspot service if needed"
systemctl start ${service_name} yunohost service start $service_name
else else
ynh_print_info --message="Cleanup hotspot config files" ynh_print_info --message="Cleanup hotspot config files"
ynh_secure_remove --file="/etc/hostapd/$app/hostapd.conf" ynh_secure_remove --file="/etc/hostapd/$app/hostapd.conf"