Parcourir la source

Better handle mail HELO in rebuild (#853)

* Better handle mail HELO in rebuild

* Test for valid RDNS

Co-authored-by: Curtis Stewart <curtisstewart@Curtiss-MacBook-Pro.local>
cmstew il y a 5 ans
Parent
commit
46156a99f0
4 fichiers modifiés avec 40 ajouts et 10 suppressions
  1. 12 4
      bin/v-add-mail-domain
  2. 2 3
      bin/v-delete-mail-domain
  3. 12 0
      func/ip.sh
  4. 14 3
      func/rebuild.sh

+ 12 - 4
bin/v-add-mail-domain

@@ -65,10 +65,6 @@ else
     get_user_ip
 fi
 
-# Generating list of mail domains for HELO
-ls /etc/exim4/domains > /etc/exim4/mailhelo.conf
-sed -i "s \(.*\) \1:\1 " /etc/exim4/mailhelo.conf
-        
 # Generating timestamp
 new_timestamp
 
@@ -105,6 +101,18 @@ if [[ "$MAIL_SYSTEM" =~ exim ]]; then
         echo "$local_ip" > $HOMEDIR/$user/conf/mail/$domain/ip
     fi
 
+    # Setting HELO for mail domain
+    if [ ! -z "$local_ip" ]; then
+        IP_RDNS=$(is_ip_rdns_valid "$local_ip")
+        if [ ! -z "$IP_RDNS" ]; then
+            if [ $(grep -s "^${domain}:" /etc/exim4/mailhelo.conf) ]; then
+                sed -i "/^${domain}:/c\\${domain}:${IP_RDNS}" /etc/exim4/mailhelo.conf
+            else
+                echo ${domain}:${IP_RDNS} >> /etc/exim4/mailhelo.conf
+            fi
+        fi        
+    fi
+
     # Adding antispam protection
     if [ "$antispam" = 'yes' ]; then
         touch $HOMEDIR/$user/conf/mail/$domain/antispam

+ 2 - 3
bin/v-delete-mail-domain

@@ -85,9 +85,8 @@ rm -f $USER_DATA/mail/$domain.pem
 rm -f $USER_DATA/mail/$domain.pub
 rm -f $USER_DATA/mail/*@$domain.msg
 
-# Generating list of mail domains for HELO
-ls /etc/exim4/domains > /etc/exim4/mailhelo.conf
-sed -i "s \(.*\) \1:\1 " /etc/exim4/mailhelo.conf
+# Unsetting HELO for mail domain
+sed -i "/^${domain}:/d" /etc/exim4/mailhelo.conf
 
 # Decreasing domain value
 decrease_user_value "$user" '$U_MAIL_DOMAINS'

+ 12 - 0
func/ip.sh

@@ -25,6 +25,18 @@ is_ip_key_empty() {
     fi
 }
 
+is_ip_rdns_valid() {
+    ip="$1"
+    network_ip=$(echo $ip | cut -d"." -f1-3)
+    awk_ip=$(echo $network_ip | sed 's|\.|/\&\&/|g')
+    rev_awk_ip=$(echo $awk_ip | rev)
+    rdns=$(dig +short -x $ip | sed 's/.$//')
+
+    if [ ! -z $rdns ] && [ ! $(echo $rdns | awk "/$awk_ip/ || /$rev_awk_ip/") ]; then
+        echo $rdns
+    fi
+}
+
 # Update ip address value
 update_ip_value() {
     key="$1"

+ 14 - 3
func/rebuild.sh

@@ -502,9 +502,20 @@ rebuild_mail_domain_conf() {
             echo "$local_ip" > $HOMEDIR/$user/conf/mail/$domain/ip
         fi
 
-        # Generating list of mail domains for HELO
-        ls /etc/exim4/domains > /etc/exim4/mailhelo.conf
-        sed -i "s \(.*\) \1:\1 " /etc/exim4/mailhelo.conf
+        
+        # Setting HELO for mail domain
+        if [ ! -z "$local_ip" ]; then
+            IP_RDNS=$(is_ip_rdns_valid "$local_ip")
+            if [ ! -z "$IP_RDNS" ]; then
+                if [ $(grep -s "^${domain}:" /etc/exim4/mailhelo.conf) ]; then
+                    sed -i "/^${domain}:/c\\${domain}:${IP_RDNS}" /etc/exim4/mailhelo.conf
+                else
+                    echo ${domain}:${IP_RDNS} >> /etc/exim4/mailhelo.conf
+                fi
+            else
+                sed -i "/^${domain}:/d" /etc/exim4/mailhelo.conf
+            fi
+        fi
 
         # Adding antispam protection
         if [ "$ANTISPAM" = 'yes' ]; then