From b5cd8bd1a332b3afb22b660e6810ae46bd8c44ce Mon Sep 17 00:00:00 2001 From: HgO Date: Sat, 18 Nov 2023 19:18:15 +0100 Subject: [PATCH 1/7] openvpn client reload only nat rules instead of whole hotspot --- conf/openvpn_90-hotspot | 28 +++++++++++++++++++++++++++- conf/ynh-hotspot | 6 +++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/conf/openvpn_90-hotspot b/conf/openvpn_90-hotspot index ce09c25..33fe318 100644 --- a/conf/openvpn_90-hotspot +++ b/conf/openvpn_90-hotspot @@ -1,3 +1,29 @@ #!/bin/bash -systemctl restart __SERVICE_NAME__ \ No newline at end of file +source /usr/share/yunohost/helpers + +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 +} + +old_gateway_interface=$(ynh_app_setting_get --app=$app --key=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 + +set_nat "${new_gateway_interface}" + +ynh_app_setting_set --app=$app --key=gateway_interface --value="${new_gateway_interface}" diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index f190a78..e9460df 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -258,7 +258,7 @@ start) exit 1 fi - echo "[hotspot] Starting..." + echo "[$app] Starting..." touch /tmp/.${service_name}-started # Check old state of the ipv4 NAT settings @@ -295,13 +295,13 @@ start) start_dhcpd # 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 yunohost tools regen-conf dnsmasq ;; stop) - echo "[hotspot] Stopping..." + echo "[$app] Stopping..." rm -f /tmp/.${service_name}-started if ! is_other_hostapd_running; then From 31bf8493bdd53a42f60e60784cead3029eda20a1 Mon Sep 17 00:00:00 2001 From: yunohost-bot Date: Sat, 18 Nov 2023 18:18:23 +0000 Subject: [PATCH 2/7] Auto-update README --- README.md | 3 ++- README_fr.md | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d13490b..678fee1 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in * Combine with the [VPN Client app](https://github.com/labriqueinternet/vpnclient_ynh) to obtain a VPN-protected WiFi -**Shipped version:** 2.2.0~ynh1 +**Shipped version:** 2.2.1~ynh1 ## Screenshots @@ -29,6 +29,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in ## Documentation and resources * Official app website: +* YunoHost Store: * Report a bug: ## Developer info diff --git a/README_fr.md b/README_fr.md index af0814d..4c4da81 100644 --- a/README_fr.md +++ b/README_fr.md @@ -20,7 +20,7 @@ Si vous n’avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) po * À combiner avec l'[app VPN Client](https://github.com/labriqueinternet/vpnclient_ynh) pour obtenir un accès internet aumatiquement protégé par votre VPN -**Version incluse :** 2.2.0~ynh1 +**Version incluse :** 2.2.1~ynh1 ## Captures d’écran @@ -29,6 +29,7 @@ Si vous n’avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) po ## Documentations et ressources * Site officiel de l’app : +* YunoHost Store: * Signaler un bug : ## Informations pour les développeurs From 689f00983cdb90202e6fd12b7fa0079ee5231f45 Mon Sep 17 00:00:00 2001 From: HgO Date: Sat, 18 Nov 2023 21:42:48 +0100 Subject: [PATCH 3/7] check if hotspot is enabled before applying nat rules --- conf/openvpn_90-hotspot | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/conf/openvpn_90-hotspot b/conf/openvpn_90-hotspot index 33fe318..2808892 100644 --- a/conf/openvpn_90-hotspot +++ b/conf/openvpn_90-hotspot @@ -17,13 +17,15 @@ set_nat() { iptables -w -t nat -A POSTROUTING -o "${gateway_interface}" -j MASQUERADE } -old_gateway_interface=$(ynh_app_setting_get --app=$app --key=gateway_interface) -new_gateway_interface=$(ip route get 1.2.3.4 | awk '{ print $5; }') +if systemctl is-active __SERVICE_NAME__; then + old_gateway_interface=$(yunohost app setting --app=__APP__ --key=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}" + if [[ -n "$old_gateway_interface" ]] && [[ "$old_gateway_interface" != "$new_gateway_interface" ]] && is_nat_set "$old_gateway_interface"; then + unset_nat "${old_gateway_interface}" + fi + + set_nat "${new_gateway_interface}" + + ynh_app_setting_set --app=__APP__ --key=gateway_interface --value="${new_gateway_interface}" fi - -set_nat "${new_gateway_interface}" - -ynh_app_setting_set --app=$app --key=gateway_interface --value="${new_gateway_interface}" From 6ef195c8674defc30bc57bd5a87f893b68717b7b Mon Sep 17 00:00:00 2001 From: HgO Date: Sat, 18 Nov 2023 21:45:01 +0100 Subject: [PATCH 4/7] check if nat not already set before applying nat rule --- conf/openvpn_90-hotspot | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/conf/openvpn_90-hotspot b/conf/openvpn_90-hotspot index 2808892..f4d5fc5 100644 --- a/conf/openvpn_90-hotspot +++ b/conf/openvpn_90-hotspot @@ -25,7 +25,9 @@ if systemctl is-active __SERVICE_NAME__; then unset_nat "${old_gateway_interface}" fi - set_nat "${new_gateway_interface}" + if [[ -n "$new_gateway_interface" ]] && ! is_nat_set $new_gateway_interface; then + set_nat "${new_gateway_interface}" + fi ynh_app_setting_set --app=__APP__ --key=gateway_interface --value="${new_gateway_interface}" fi From 0642570974957773e0caed392419da29fc14c224 Mon Sep 17 00:00:00 2001 From: HgO Date: Sun, 19 Nov 2023 15:33:13 +0100 Subject: [PATCH 5/7] use yunohost helper instead of cli --- conf/openvpn_90-hotspot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/openvpn_90-hotspot b/conf/openvpn_90-hotspot index f4d5fc5..940148d 100644 --- a/conf/openvpn_90-hotspot +++ b/conf/openvpn_90-hotspot @@ -18,7 +18,7 @@ set_nat() { } if systemctl is-active __SERVICE_NAME__; then - old_gateway_interface=$(yunohost app setting --app=__APP__ --key=gateway_interface) + old_gateway_interface=$(ynh_app_setting_get --app=__APP__ --key=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 From 9195d3d64d273a41f7425f4f461aa2c838c262ac Mon Sep 17 00:00:00 2001 From: HgO Date: Mon, 20 Nov 2023 11:54:47 +0100 Subject: [PATCH 6/7] export PATH variable and remove yunohost helpers --- conf/openvpn_90-hotspot | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/conf/openvpn_90-hotspot b/conf/openvpn_90-hotspot index 940148d..547a630 100644 --- a/conf/openvpn_90-hotspot +++ b/conf/openvpn_90-hotspot @@ -1,6 +1,6 @@ #!/bin/bash -source /usr/share/yunohost/helpers +export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" is_nat_set() { local gateway_interface=${1} @@ -17,8 +17,8 @@ set_nat() { iptables -w -t nat -A POSTROUTING -o "${gateway_interface}" -j MASQUERADE } -if systemctl is-active __SERVICE_NAME__; then - old_gateway_interface=$(ynh_app_setting_get --app=__APP__ --key=gateway_interface) +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 @@ -29,5 +29,5 @@ if systemctl is-active __SERVICE_NAME__; then set_nat "${new_gateway_interface}" fi - ynh_app_setting_set --app=__APP__ --key=gateway_interface --value="${new_gateway_interface}" + yunohost app setting __APP__ gateway_interface --value "${new_gateway_interface}" fi From a4fe4d040633c78fa8f7c8c4776c05851f845062 Mon Sep 17 00:00:00 2001 From: HgO Date: Mon, 20 Nov 2023 17:22:17 +0100 Subject: [PATCH 7/7] remove export PATH variable as it will be provided by run-parts script --- conf/openvpn_90-hotspot | 2 -- 1 file changed, 2 deletions(-) diff --git a/conf/openvpn_90-hotspot b/conf/openvpn_90-hotspot index 547a630..1fbc11c 100644 --- a/conf/openvpn_90-hotspot +++ b/conf/openvpn_90-hotspot @@ -1,7 +1,5 @@ #!/bin/bash -export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - is_nat_set() { local gateway_interface=${1} iptables -w -nvt nat -L POSTROUTING | grep MASQUERADE | grep -q "${gateway_interface}"