Skip to content

Commit 46156a9

Browse files
cmstewCurtis Stewart
andauthored
Better handle mail HELO in rebuild (hestiacp#853)
* Better handle mail HELO in rebuild * Test for valid RDNS Co-authored-by: Curtis Stewart <curtisstewart@Curtiss-MacBook-Pro.local>
1 parent f9ac4ff commit 46156a9

File tree

4 files changed

+40
-10
lines changed

4 files changed

+40
-10
lines changed

bin/v-add-mail-domain

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ else
6565
get_user_ip
6666
fi
6767

68-
# Generating list of mail domains for HELO
69-
ls /etc/exim4/domains > /etc/exim4/mailhelo.conf
70-
sed -i "s \(.*\) \1:\1 " /etc/exim4/mailhelo.conf
71-
7268
# Generating timestamp
7369
new_timestamp
7470

@@ -105,6 +101,18 @@ if [[ "$MAIL_SYSTEM" =~ exim ]]; then
105101
echo "$local_ip" > $HOMEDIR/$user/conf/mail/$domain/ip
106102
fi
107103

104+
# Setting HELO for mail domain
105+
if [ ! -z "$local_ip" ]; then
106+
IP_RDNS=$(is_ip_rdns_valid "$local_ip")
107+
if [ ! -z "$IP_RDNS" ]; then
108+
if [ $(grep -s "^${domain}:" /etc/exim4/mailhelo.conf) ]; then
109+
sed -i "/^${domain}:/c\\${domain}:${IP_RDNS}" /etc/exim4/mailhelo.conf
110+
else
111+
echo ${domain}:${IP_RDNS} >> /etc/exim4/mailhelo.conf
112+
fi
113+
fi
114+
fi
115+
108116
# Adding antispam protection
109117
if [ "$antispam" = 'yes' ]; then
110118
touch $HOMEDIR/$user/conf/mail/$domain/antispam

bin/v-delete-mail-domain

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,8 @@ rm -f $USER_DATA/mail/$domain.pem
8585
rm -f $USER_DATA/mail/$domain.pub
8686
rm -f $USER_DATA/mail/*@$domain.msg
8787

88-
# Generating list of mail domains for HELO
89-
ls /etc/exim4/domains > /etc/exim4/mailhelo.conf
90-
sed -i "s \(.*\) \1:\1 " /etc/exim4/mailhelo.conf
88+
# Unsetting HELO for mail domain
89+
sed -i "/^${domain}:/d" /etc/exim4/mailhelo.conf
9190

9291
# Decreasing domain value
9392
decrease_user_value "$user" '$U_MAIL_DOMAINS'

func/ip.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ is_ip_key_empty() {
2525
fi
2626
}
2727

28+
is_ip_rdns_valid() {
29+
ip="$1"
30+
network_ip=$(echo $ip | cut -d"." -f1-3)
31+
awk_ip=$(echo $network_ip | sed 's|\.|/\&\&/|g')
32+
rev_awk_ip=$(echo $awk_ip | rev)
33+
rdns=$(dig +short -x $ip | sed 's/.$//')
34+
35+
if [ ! -z $rdns ] && [ ! $(echo $rdns | awk "/$awk_ip/ || /$rev_awk_ip/") ]; then
36+
echo $rdns
37+
fi
38+
}
39+
2840
# Update ip address value
2941
update_ip_value() {
3042
key="$1"

func/rebuild.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,20 @@ rebuild_mail_domain_conf() {
502502
echo "$local_ip" > $HOMEDIR/$user/conf/mail/$domain/ip
503503
fi
504504

505-
# Generating list of mail domains for HELO
506-
ls /etc/exim4/domains > /etc/exim4/mailhelo.conf
507-
sed -i "s \(.*\) \1:\1 " /etc/exim4/mailhelo.conf
505+
506+
# Setting HELO for mail domain
507+
if [ ! -z "$local_ip" ]; then
508+
IP_RDNS=$(is_ip_rdns_valid "$local_ip")
509+
if [ ! -z "$IP_RDNS" ]; then
510+
if [ $(grep -s "^${domain}:" /etc/exim4/mailhelo.conf) ]; then
511+
sed -i "/^${domain}:/c\\${domain}:${IP_RDNS}" /etc/exim4/mailhelo.conf
512+
else
513+
echo ${domain}:${IP_RDNS} >> /etc/exim4/mailhelo.conf
514+
fi
515+
else
516+
sed -i "/^${domain}:/d" /etc/exim4/mailhelo.conf
517+
fi
518+
fi
508519

509520
# Adding antispam protection
510521
if [ "$ANTISPAM" = 'yes' ]; then

0 commit comments

Comments
 (0)