Browse Source

check if hotspot is enabled before applying nat rules

HgO 1 year ago
parent
commit
689f00983c
1 changed files with 9 additions and 7 deletions
  1. 9 7
      conf/openvpn_90-hotspot

+ 9 - 7
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}"
-fi
+  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}"
+  set_nat "${new_gateway_interface}"
 
-ynh_app_setting_set --app=$app --key=gateway_interface --value="${new_gateway_interface}"
+  ynh_app_setting_set --app=__APP__ --key=gateway_interface --value="${new_gateway_interface}"
+fi