Skip to content

Commit 4119d43

Browse files
committed
Feature(multi ip):When adding/rebuilding a mail domain configure exim server to use web domain ip if present
1 parent a61196d commit 4119d43

File tree

5 files changed

+33
-1
lines changed

5 files changed

+33
-1
lines changed

bin/v-add-mail-domain

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ fi
3333
# Additional argument formatting
3434
format_domain
3535
format_domain_idn
36-
get_user_ip
3736

3837

3938
#----------------------------------------------------------#
@@ -57,6 +56,15 @@ check_hestia_demo_mode
5756
# Action #
5857
#----------------------------------------------------------#
5958

59+
# Inherit web domain local ip address
60+
domain_ip=$(get_object_value 'web' 'DOMAIN' "$domain" '$IP')
61+
local_ip=$(get_real_ip "$domain_ip")
62+
if [ ! -z "$local_ip" ]; then
63+
is_ip_valid "$local_ip" "$user"
64+
else
65+
get_user_ip
66+
fi
67+
6068
# Generating timestamp
6169
new_timestamp
6270

@@ -88,6 +96,11 @@ if [[ "$MAIL_SYSTEM" =~ exim ]]; then
8896
ln -s $HOMEDIR/$user/conf/mail/$domain \
8997
/etc/$MAIL_SYSTEM/domains/$domain_idn
9098

99+
# Seeting outgoing ip address
100+
if [ ! -z "$local_ip" ]; then
101+
echo "$local_ip" > $HOMEDIR/$user/conf/mail/$domain/ip
102+
fi
103+
91104
# Adding antispam protection
92105
if [ "$antispam" = 'yes' ]; then
93106
touch $HOMEDIR/$user/conf/mail/$domain/antispam

bin/v-rebuild-mail-domain

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ domain=$2
1717
source $HESTIA/func/main.sh
1818
source $HESTIA/func/domain.sh
1919
source $HESTIA/func/rebuild.sh
20+
source $HESTIA/func/ip.sh
2021
source $HESTIA/conf/hestia.conf
2122

2223
# Define mail user

bin/v-rebuild-mail-domains

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ user=$1
1616
source $HESTIA/func/main.sh
1717
source $HESTIA/func/domain.sh
1818
source $HESTIA/func/rebuild.sh
19+
source $HESTIA/func/ip.sh
1920
source $HESTIA/conf/hestia.conf
2021

2122
# Define mail user

func/rebuild.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,15 @@ rebuild_mail_domain_conf() {
445445
domain_idn=$domain
446446
fi
447447

448+
# Inherit web domain local ip address
449+
local domain_ip=$(get_object_value 'web' 'DOMAIN' "$domain" '$IP')
450+
local local_ip=$(get_real_ip "$domain_ip")
451+
if [ ! -z "$local_ip" ]; then
452+
is_ip_valid "$local_ip" "$user"
453+
else
454+
get_user_ip
455+
fi
456+
448457
if [ "$SUSPENDED" = 'yes' ]; then
449458
SUSPENDED_MAIL=$((SUSPENDED_MAIL +1))
450459
fi
@@ -466,10 +475,16 @@ rebuild_mail_domain_conf() {
466475
rm -f $HOMEDIR/$user/conf/mail/$domain/protection
467476
rm -f $HOMEDIR/$user/conf/mail/$domain/passwd
468477
rm -f $HOMEDIR/$user/conf/mail/$domain/fwd_only
478+
rm -f $HOMEDIR/$user/conf/mail/$domain/ip
469479
touch $HOMEDIR/$user/conf/mail/$domain/aliases
470480
touch $HOMEDIR/$user/conf/mail/$domain/passwd
471481
touch $HOMEDIR/$user/conf/mail/$domain/fwd_only
472482

483+
# Seeting outgoing ip address
484+
if [ ! -z "$local_ip" ]; then
485+
echo "$local_ip" > $HOMEDIR/$user/conf/mail/$domain/ip
486+
fi
487+
473488
# Adding antispam protection
474489
if [ "$ANTISPAM" = 'yes' ]; then
475490
touch $HOMEDIR/$user/conf/mail/$domain/antispam

install/deb/exim/exim4.conf.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ DKIM_DOMAIN = ${lc:${domain:$h_from:}}
7272
DKIM_FILE = /etc/exim4/domains/${lc:${domain:$h_from:}}/dkim.pem
7373
DKIM_PRIVATE_KEY = ${if exists{DKIM_FILE}{DKIM_FILE}{0}}
7474

75+
OUTGOING_IP = /etc/exim4/domains/$sender_address_domain/ip
7576

7677

7778
######################################################################
@@ -330,6 +331,7 @@ remote_smtp:
330331
dkim_private_key = DKIM_PRIVATE_KEY
331332
dkim_canon = relaxed
332333
dkim_strict = 0
334+
interface = ${if exists{OUTGOING_IP}{${readfile{OUTGOING_IP}}}}
333335

334336
procmail:
335337
driver = pipe

0 commit comments

Comments
 (0)