Ver código fonte

Fix issue with helo behind nat (#1810)

* Fix issue with Helo bebind nat (Local networks)

* Rename ip to natip and localip to ip so updateing works later on

* Removal of $

* Fix issue where helo=‘’ it was added to ip.conf casusing 
helo=‘’
helo=“hostname.com”

* Fix issue when change helo for nated ip adresses

* Fix issue with nat checking not working

* Adjust code comments

Co-authored-by: Kristan Kenney <40798553+kristankenney@users.noreply.github.com>
Jaap Marcus 4 anos atrás
pai
commit
a00adb6a4a
2 arquivos alterados com 35 adições e 12 exclusões
  1. 10 2
      bin/v-change-sys-ip-helo
  2. 25 10
      func/ip.sh

+ 10 - 2
bin/v-change-sys-ip-helo

@@ -43,8 +43,16 @@ check_hestia_demo_mode
 #                       Action                             #
 #                       Action                             #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Change ip HELO/SMTP Banner
-update_ip_helo_value $ip $helo
+# Check if IP address is behind NAT configuration and if so use Public IP for HELO
+source $HESTIA/data/ips/$ip
+
+if [  -z "$NAT" ]; then 
+    # Change ip HELO/SMTP Banner
+    update_ip_helo_value $ip $helo
+else
+    # Change ip HELO/SMTP Banner
+    update_ip_helo_value $NAT $helo
+fi
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 #                       Hestia                             #
 #                       Hestia                             #

+ 25 - 10
func/ip.sh

@@ -47,13 +47,15 @@ is_ip_rdns_valid() {
 update_ip_helo_value() {
 update_ip_helo_value() {
     ip="$1"
     ip="$1"
     helo="$2"
     helo="$2"
-
+    natip="$1"
+    
+    # In case the IP is an NAT use the real ip address 
+    if [ ! -f $HESTIA/data/ips/$ip ]; then
+        ip=$(get_real_ip $ip);
+    fi 
+    
     # Create or update ip value
     # Create or update ip value
-    if [ ! $(get_ip_value '$HELO') ]; then
-        echo "HELO='$helo'" >> $HESTIA/data/ips/$ip
-    else
-        update_ip_value '$HELO' "$helo"
-    fi
+    update_ip_value_new 'HELO' "$helo"
 
 
     # Create mailhelo.conf file if doesn't exist
     # Create mailhelo.conf file if doesn't exist
     if [ ! -e "/etc/${MAIL_SYSTEM}/mailhelo.conf" ]; then
     if [ ! -e "/etc/${MAIL_SYSTEM}/mailhelo.conf" ]; then
@@ -62,13 +64,13 @@ update_ip_helo_value() {
 
 
     #Create or update ip:helo pair in mailhelo.conf file
     #Create or update ip:helo pair in mailhelo.conf file
     if [ ! -z "$helo" ]; then
     if [ ! -z "$helo" ]; then
-        if [ $(cat /etc/${MAIL_SYSTEM}/mailhelo.conf | grep "$ip") ]; then
-            sed -i "/^$ip:/c $ip:$helo" /etc/${MAIL_SYSTEM}/mailhelo.conf
+        if [ $(cat /etc/${MAIL_SYSTEM}/mailhelo.conf | grep "$natip") ]; then
+            sed -i "/^$natip:/c $natip:$helo" /etc/${MAIL_SYSTEM}/mailhelo.conf
         else
         else
-            echo $ip:$helo >> /etc/${MAIL_SYSTEM}/mailhelo.conf
+            echo $natip:$helo >> /etc/${MAIL_SYSTEM}/mailhelo.conf
         fi
         fi
     else
     else
-        sed -i "/^$ip:/d" /etc/${MAIL_SYSTEM}/mailhelo.conf
+        sed -i "/^$natip:/d" /etc/${MAIL_SYSTEM}/mailhelo.conf
     fi
     fi
 }
 }
 
 
@@ -87,6 +89,19 @@ update_ip_value() {
         $conf
         $conf
 }
 }
 
 
+# New method that is improved on a later date we need to check if we can improve it for other locations
+update_ip_value_new() {
+    key="$1"
+    value="$2"
+    conf="$HESTIA/data/ips/$ip"
+    check_ckey=$(grep "^$key='" $conf)
+    if [ -z "$check_ckey" ]; then
+        echo "$key='$value'" >> $conf
+    else
+        sed -i "s|^$key=.*|$key='$value'|g" $conf
+    fi
+}
+
 # Get ip name
 # Get ip name
 get_ip_alias() {
 get_ip_alias() {
     ip_name=$(grep "NAME=" $HESTIA/data/ips/$local_ip |cut -f 2 -d \')
     ip_name=$(grep "NAME=" $HESTIA/data/ips/$local_ip |cut -f 2 -d \')