Skip to content

Commit a00adb6

Browse files
jaapmarcusKristan Kenney
andauthored
Fix issue with helo behind nat (hestiacp#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>
1 parent 6a778bc commit a00adb6

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

bin/v-change-sys-ip-helo

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,16 @@ check_hestia_demo_mode
4343
# Action #
4444
#----------------------------------------------------------#
4545

46-
# Change ip HELO/SMTP Banner
47-
update_ip_helo_value $ip $helo
46+
# Check if IP address is behind NAT configuration and if so use Public IP for HELO
47+
source $HESTIA/data/ips/$ip
48+
49+
if [ -z "$NAT" ]; then
50+
# Change ip HELO/SMTP Banner
51+
update_ip_helo_value $ip $helo
52+
else
53+
# Change ip HELO/SMTP Banner
54+
update_ip_helo_value $NAT $helo
55+
fi
4856

4957
#----------------------------------------------------------#
5058
# Hestia #

func/ip.sh

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ is_ip_rdns_valid() {
4747
update_ip_helo_value() {
4848
ip="$1"
4949
helo="$2"
50-
50+
natip="$1"
51+
52+
# In case the IP is an NAT use the real ip address
53+
if [ ! -f $HESTIA/data/ips/$ip ]; then
54+
ip=$(get_real_ip $ip);
55+
fi
56+
5157
# Create or update ip value
52-
if [ ! $(get_ip_value '$HELO') ]; then
53-
echo "HELO='$helo'" >> $HESTIA/data/ips/$ip
54-
else
55-
update_ip_value '$HELO' "$helo"
56-
fi
58+
update_ip_value_new 'HELO' "$helo"
5759

5860
# Create mailhelo.conf file if doesn't exist
5961
if [ ! -e "/etc/${MAIL_SYSTEM}/mailhelo.conf" ]; then
@@ -62,13 +64,13 @@ update_ip_helo_value() {
6264

6365
#Create or update ip:helo pair in mailhelo.conf file
6466
if [ ! -z "$helo" ]; then
65-
if [ $(cat /etc/${MAIL_SYSTEM}/mailhelo.conf | grep "$ip") ]; then
66-
sed -i "/^$ip:/c $ip:$helo" /etc/${MAIL_SYSTEM}/mailhelo.conf
67+
if [ $(cat /etc/${MAIL_SYSTEM}/mailhelo.conf | grep "$natip") ]; then
68+
sed -i "/^$natip:/c $natip:$helo" /etc/${MAIL_SYSTEM}/mailhelo.conf
6769
else
68-
echo $ip:$helo >> /etc/${MAIL_SYSTEM}/mailhelo.conf
70+
echo $natip:$helo >> /etc/${MAIL_SYSTEM}/mailhelo.conf
6971
fi
7072
else
71-
sed -i "/^$ip:/d" /etc/${MAIL_SYSTEM}/mailhelo.conf
73+
sed -i "/^$natip:/d" /etc/${MAIL_SYSTEM}/mailhelo.conf
7274
fi
7375
}
7476

@@ -87,6 +89,19 @@ update_ip_value() {
8789
$conf
8890
}
8991

92+
# New method that is improved on a later date we need to check if we can improve it for other locations
93+
update_ip_value_new() {
94+
key="$1"
95+
value="$2"
96+
conf="$HESTIA/data/ips/$ip"
97+
check_ckey=$(grep "^$key='" $conf)
98+
if [ -z "$check_ckey" ]; then
99+
echo "$key='$value'" >> $conf
100+
else
101+
sed -i "s|^$key=.*|$key='$value'|g" $conf
102+
fi
103+
}
104+
90105
# Get ip name
91106
get_ip_alias() {
92107
ip_name=$(grep "NAME=" $HESTIA/data/ips/$local_ip |cut -f 2 -d \')

0 commit comments

Comments
 (0)