Skip to content

Commit 8e1e81d

Browse files
authored
Fix hestiacp#2044 Add checks if ip exists (hestiacp#2049)
* Improve checks if ip exists * Include tests mail / helo
1 parent 2304b93 commit 8e1e81d

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

bin/v-change-sys-ip-helo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ if [ -z "$MAIL_SYSTEM" ]; then
2626
check_result "$E_NOTEXIST" "Mail system not installed"
2727
fi
2828

29+
if [ ! -e "$HESTIA/data/ips/$ip" ]; then
30+
exit;
31+
fi
32+
2933
#----------------------------------------------------------#
3034
# Verifications #
3135
#----------------------------------------------------------#

bin/v-delete-sys-ip

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ if [ ! -z "$PROXY_SYSTEM" ]; then
126126
fi
127127
fi
128128

129+
if [ ! -z "$MAIL_SYSTEM" ]; then
130+
if [ -z "$NAT" ]; then
131+
delete_ip_helo_value $ip
132+
else
133+
delete_ip_helo_value $NAT
134+
fi
135+
fi
129136

130137
#----------------------------------------------------------#
131138
# Hestia #

func/ip.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ update_ip_helo_value() {
5050
natip="$1"
5151

5252
# In case the IP is an NAT use the real ip address
53-
if [ ! -f $HESTIA/data/ips/$ip ]; then
53+
if [ ! -e "$HESTIA/data/ips/$ip" ]; then
5454
ip=$(get_real_ip $ip);
5555
fi
5656

@@ -74,6 +74,11 @@ update_ip_helo_value() {
7474
fi
7575
}
7676

77+
delete_ip_helo_value (){
78+
ip=$1
79+
sed -i "/^$ip:/d" /etc/${MAIL_SYSTEM}/mailhelo.conf
80+
}
81+
7782
# Update ip address value
7883
update_ip_value() {
7984
key="$1"
@@ -195,7 +200,7 @@ get_real_ip() {
195200
if [ -e "$HESTIA/data/ips/$1" ]; then
196201
echo $1
197202
else
198-
nat=$(grep -H "^NAT='$1'" $HESTIA/data/ips/*)
203+
nat=$(grep -H "^NAT='$1'" $HESTIA/data/ips/* | head -n1 )
199204
if [ ! -z "$nat" ]; then
200205
echo "$nat" |cut -f 1 -d : |cut -f 7 -d /
201206
fi

test/test.bats

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,14 @@ function check_ip_not_banned(){
482482
fi
483483
}
484484

485+
@test "Ip: Change Helo" {
486+
local ip="198.18.0.121"
487+
run v-change-sys-ip-helo 198.18.0.121 dev.hestiacp.com
488+
assert_success
489+
refute_output
490+
assert_file_contains /etc/exim4/mailhelo.conf "198.18.0.121:dev.hestiacp.com"
491+
}
492+
485493
@test "Ip: Delete ips" {
486494
local ip="198.18.0.12"
487495
run v-delete-sys-ip $ip

0 commit comments

Comments
 (0)