Skip to content

Commit 9bab92c

Browse files
authored
Merge pull request hestiacp#2097 from jaapmarcus/fix/2096-ssl-hostname-overwritten
Add check if domain.com exists in certificate
2 parents c127b25 + 42094e5 commit 9bab92c

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

func/domain.sh

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -697,20 +697,25 @@ add_mail_ssl_config() {
697697
rm -f /etc/dovecot/conf.d/domains/$domain.conf
698698
fi
699699

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
700+
mail_check=$(v-list-mail-domain-ssl $user $domain | grep SUBJECT | grep " $domain");
701+
mail_check_alias=$(v-list-mail-domain-ssl $user $domain | grep ALIASES | grep " $domain");
702+
if [ ! -z "$mail_check" ] || [ ! -z "$mail_check_alias" ]; then
703+
echo "" >> /etc/dovecot/conf.d/domains/$domain.conf
704+
echo "local_name $domain {" >> /etc/dovecot/conf.d/domains/$domain.conf
705+
echo " ssl_cert = <$HOMEDIR/$user/conf/mail/$domain/ssl/$domain.pem" >> /etc/dovecot/conf.d/domains/$domain.conf
706+
echo " ssl_key = <$HOMEDIR/$user/conf/mail/$domain/ssl/$domain.key" >> /etc/dovecot/conf.d/domains/$domain.conf
707+
echo "}" >> /etc/dovecot/conf.d/domains/$domain.conf
708+
# Add domain SSL configuration to exim4
709+
ln -s $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.pem $HESTIA/ssl/mail/$domain.crt
710+
ln -s $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.key $HESTIA/ssl/mail/$domain.key
711+
fi
705712
echo "" >> /etc/dovecot/conf.d/domains/$domain.conf
706713
echo "local_name mail.$domain {" >> /etc/dovecot/conf.d/domains/$domain.conf
707714
echo " ssl_cert = <$HOMEDIR/$user/conf/mail/$domain/ssl/$domain.pem" >> /etc/dovecot/conf.d/domains/$domain.conf
708715
echo " ssl_key = <$HOMEDIR/$user/conf/mail/$domain/ssl/$domain.key" >> /etc/dovecot/conf.d/domains/$domain.conf
709716
echo "}" >> /etc/dovecot/conf.d/domains/$domain.conf
710-
717+
711718
# Add domain SSL configuration to exim4
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
714719
ln -s $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.pem $HESTIA/ssl/mail/mail.$domain.crt
715720
ln -s $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.key $HESTIA/ssl/mail/mail.$domain.key
716721

@@ -725,7 +730,10 @@ add_mail_ssl_config() {
725730

726731
# Delete SSL support for mail domain
727732
del_mail_ssl_config() {
728-
733+
# Do a few checks to prevent accidentally removal of domain.com
734+
mail_check=$(v-list-mail-domain-ssl $user $domain | grep SUBJECT | grep " $domain");
735+
mail_check_alias=$(v-list-mail-domain-ssl $user $domain | grep ALIASES | grep " $domain");
736+
729737
# Remove old mail certificates
730738
rm -f $HOMEDIR/$user/conf/mail/$domain/ssl/*
731739

@@ -739,7 +747,9 @@ del_mail_ssl_config() {
739747

740748
# Remove SSL certificates
741749
rm -f $HOMEDIR/$user/conf/mail/$domain/ssl/*
742-
rm -f $HESTIA/ssl/mail/$domain.crt $HESTIA/ssl/mail/$domain.key
750+
if [ ! -z "$mail_check" ] || [ ! -z "$mail_check_alias" ]; then
751+
rm -f $HESTIA/ssl/mail/$domain.crt $HESTIA/ssl/mail/$domain.key
752+
fi
743753
rm -f $HESTIA/ssl/mail/mail.$domain.crt $HESTIA/ssl/mail/mail.$domain.key
744754
}
745755

install/upgrade/versions/1.4.13.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@
2121
if [[ $(echo "$servername" | grep -o "\." | wc -l) -lt 2 ]] || [[ $servername =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]];; then
2222
UPGRADE_MESSAGE="$UPGRADE_MESSAGE\nWe've noticed that you're using a invalid hostname. Please have a look at the RFC1178 standard (https://datatracker.ietf.org/doc/html/rfc1178) and use a valid one (ex. hostname.domain.tld). You can change the hostname using v-change-sys-hostname and also add a ssl certificate using v-add-letsencypt-host (proper dns A record mandatory). You'll find more informations in our documentation: https://docs.hestiacp.com/admin_docs/web/ssl_certificates.html#how-to-setup-let-s-encrypt-for-the-control-panel"
2323
$HESTIA/bin/v-add-user-notification admin "Invalid Hostname detected" "Warning: We've noticed that you're using a invalid hostname. Please have a look at the <a href="https://datatracker.ietf.org/doc/html/rfc1178" target="_blank">RFC1178 standard</a> and use a valid one (ex. hostname.domain.tld). You can change the hostname using v-change-sys-hostname and also add a ssl certificate using v-add-letsencypt-host (proper dns A record mandatory). You'll find more informations in our <a href="https://docs.hestiacp.com/admin_docs/web/ssl_certificates.html#how-to-setup-let-s-encrypt-for-the-control-panel" target=_"blank">documentation</a>."
24+
fi
25+
26+
# Empty $HESTIA/ssl/mail/ due to bug in #2066
27+
if [ -e "$HESTIA/ssl/mail/" ]; then
28+
rm -fr $HESTIA/ssl/mail/*
2429
fi

0 commit comments

Comments
 (0)