Skip to content

Commit 27149f7

Browse files
authored
Merge pull request hestiacp#2061 from myrevery/feature/improve-mail-system-tls
Improve the TLS support of mail system
2 parents 26934cb + 9a7637a commit 27149f7

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [Development]
5+
6+
- Allow custom mail domains with own certificates #2061 @myrevery
7+
48
## [1.4.11] - Service release
59

610
### Features

func/domain.sh

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -621,11 +621,25 @@ is_mail_domain_new() {
621621
if [ "$2" == 'mail' ]; then
622622
check_result $E_EXISTS "Mail domain $1 exists"
623623
fi
624-
mail_user=$(echo "$mail" |cut -f 7 -d /)
624+
mail_user=$(echo "$mail" | cut -f 7 -d /)
625625
if [ "$mail_user" != "$user" ]; then
626626
check_result $E_EXISTS "Mail domain $1 exists"
627627
fi
628628
fi
629+
mail_sub=$(echo "$1" | cut -f 1 -d .)
630+
mail_nosub=$(echo "$1" | cut -f 1 -d . --complement)
631+
for mail_reserved in $(echo "mail $WEBMAIL_ALIAS"); do
632+
if [ ! -z "$(ls $HESTIA/data/users/*/mail/$mail_reserved.$1.conf 2>/dev/null)" ]; then
633+
if [ "$2" == 'mail' ]; then
634+
check_result $E_EXISTS "Required subdomain \"$mail_reserved.$1\" already exists"
635+
fi
636+
fi
637+
if [ ! -z "$(ls $HESTIA/data/users/*/mail/$mail_nosub.conf 2>/dev/null)" ] && [ "$mail_sub" = "$mail_reserved" ]; then
638+
if [ "$2" == 'mail' ]; then
639+
check_result $E_INVALID "The subdomain \"$mail_sub.\" is reserved by \"$mail_nosub\""
640+
fi
641+
fi
642+
done
629643
}
630644

631645
# Checking mail account existance
@@ -641,16 +655,15 @@ is_mail_new() {
641655
fi
642656
}
643657

644-
645658
# Add mail server SSL configuration
646659
add_mail_ssl_config() {
647660
# Ensure that SSL certificate directories exists
648661
if [ ! -d $HOMEDIR/$user/conf/mail/$domain/ssl/ ]; then
649662
mkdir -p $HOMEDIR/$user/conf/mail/$domain/ssl/
650663
fi
651664

652-
if [ ! -d /usr/local/hestia/ssl/mail ]; then
653-
mkdir -p /usr/local/hestia/ssl/mail
665+
if [ ! -d $HESTIA/ssl/mail ]; then
666+
mkdir -p $HESTIA/ssl/mail
654667
fi
655668

656669
if [ ! -d /etc/dovecot/conf.d/domains ]; then
@@ -684,23 +697,30 @@ add_mail_ssl_config() {
684697
rm -f /etc/dovecot/conf.d/domains/$domain.conf
685698
fi
686699

700+
echo "" >> /etc/dovecot/conf.d/domains/$domain.conf
701+
echo "local_name $domain {" >> /etc/dovecot/conf.d/domains/$domain.conf
702+
echo " ssl_cert = <$HOMEDIR/$user/conf/mail/$domain/ssl/$domain.pem" >> /etc/dovecot/conf.d/domains/$domain.conf
703+
echo " ssl_key = <$HOMEDIR/$user/conf/mail/$domain/ssl/$domain.key" >> /etc/dovecot/conf.d/domains/$domain.conf
704+
echo "}" >> /etc/dovecot/conf.d/domains/$domain.conf
687705
echo "" >> /etc/dovecot/conf.d/domains/$domain.conf
688706
echo "local_name mail.$domain {" >> /etc/dovecot/conf.d/domains/$domain.conf
689707
echo " ssl_cert = <$HOMEDIR/$user/conf/mail/$domain/ssl/$domain.pem" >> /etc/dovecot/conf.d/domains/$domain.conf
690708
echo " ssl_key = <$HOMEDIR/$user/conf/mail/$domain/ssl/$domain.key" >> /etc/dovecot/conf.d/domains/$domain.conf
691709
echo "}" >> /etc/dovecot/conf.d/domains/$domain.conf
692710

693711
# Add domain SSL configuration to exim4
694-
ln -s $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.pem /usr/local/hestia/ssl/mail/mail.$domain.crt
695-
ln -s $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.key /usr/local/hestia/ssl/mail/mail.$domain.key
712+
ln -s $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.pem $HESTIA/ssl/mail/$domain.crt
713+
ln -s $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.key $HESTIA/ssl/mail/$domain.key
714+
ln -s $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.pem $HESTIA/ssl/mail/mail.$domain.crt
715+
ln -s $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.key $HESTIA/ssl/mail/mail.$domain.key
696716

697717
# Set correct permissions on certificates
698-
chmod 750 $HOMEDIR/$user/conf/mail/$domain/ssl
718+
chmod 0750 $HOMEDIR/$user/conf/mail/$domain/ssl
699719
chown -R $MAIL_USER:mail $HOMEDIR/$user/conf/mail/$domain/ssl
700720
chmod 0644 $HOMEDIR/$user/conf/mail/$domain/ssl/*
701721
chown -h $user:mail $HOMEDIR/$user/conf/mail/$domain/ssl/*
702-
chmod -R 0644 /usr/local/hestia/ssl/mail/*
703-
chown -h $user:mail /usr/local/hestia/ssl/mail/*
722+
chmod -R 0644 $HESTIA/ssl/mail/*
723+
chown -h $user:mail $HESTIA/ssl/mail/*
704724
}
705725

706726
# Delete SSL support for mail domain
@@ -719,7 +739,8 @@ del_mail_ssl_config() {
719739

720740
# Remove SSL certificates
721741
rm -f $HOMEDIR/$user/conf/mail/$domain/ssl/*
722-
rm -f /usr/local/hestia/ssl/mail/mail.$domain.*
742+
rm -f $HESTIA/ssl/mail/$domain.crt $HESTIA/ssl/mail/$domain.key
743+
rm -f $HESTIA/ssl/mail/mail.$domain.crt $HESTIA/ssl/mail/mail.$domain.key
723744
}
724745

725746
# Delete generated certificates from user configuration data directory

0 commit comments

Comments
 (0)