Skip to content

Commit e81a475

Browse files
author
Kristan Kenney
committed
Add additional checks to v-*-webmail scripts
* Verify that IMAP_SYSTEM is available when deleting webmail configuration files * Verify that WEBMAIL_ALIAS is set in hestia.conf prior to manipulating webmail & DNS configuration
1 parent b31f50e commit e81a475

File tree

2 files changed

+46
-36
lines changed

2 files changed

+46
-36
lines changed

bin/v-add-webmail

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,39 +55,44 @@ is_object_unsuspended 'mail' 'DOMAIN' "$domain"
5555
# Action #
5656
#----------------------------------------------------------#
5757

58-
# Ensure DNS record exists if Hestia is hosting DNS zones
59-
if [ ! -z "$DNS_SYSTEM" ]; then
60-
dns_domain=$($BIN/v-list-dns-domains $user | grep $domain | cut -d' ' -f1)
61-
webmail_record=$($BIN/v-list-dns-records $user $domain | grep -i $WEBMAIL_ALIAS | cut -d' ' -f1)
62-
63-
if [ "$dns_domain" = "$domain" ]; then
64-
if [ -z "$webmail_record" ]; then
65-
$BIN/v-add-dns-record $user $domain $WEBMAIL_ALIAS A $ip
66-
else
67-
$BIN/v-delete-dns-record $user $domain $webmail_record
68-
$BIN/v-add-dns-record $user $domain $WEBMAIL_ALIAS A $ip
58+
# Verify that webmail alias variable exists
59+
if [ ! -z "$WEBMAIL_ALIAS" ]; then
60+
# Ensure DNS record exists if Hestia is hosting DNS zones
61+
if [ ! -z "$DNS_SYSTEM" ]; then
62+
dns_domain=$($BIN/v-list-dns-domains $user | grep $domain | cut -d' ' -f1)
63+
webmail_record=$($BIN/v-list-dns-records $user $domain | grep -i $WEBMAIL_ALIAS | cut -d' ' -f1)
64+
65+
if [ "$dns_domain" = "$domain" ]; then
66+
if [ -z "$webmail_record" ]; then
67+
$BIN/v-add-dns-record $user $domain $WEBMAIL_ALIAS A $ip
68+
else
69+
$BIN/v-delete-dns-record $user $domain $webmail_record
70+
$BIN/v-add-dns-record $user $domain $WEBMAIL_ALIAS A $ip
71+
fi
6972
fi
7073
fi
71-
fi
7274

73-
# Add webmail configuration to mail domain
74-
WEBMAIL_TEMPLATE="default"
75-
if [ "$WEB_SYSTEM" = "nginx" ]; then
76-
WEBMAIL_TEMPLATE="web_system"
77-
fi
78-
add_webmail_config "$WEB_SYSTEM" "${WEBMAIL_TEMPLATE}.tpl"
75+
# Add webmail configuration to mail domain
76+
WEBMAIL_TEMPLATE="default"
77+
if [ "$WEB_SYSTEM" = "nginx" ]; then
78+
WEBMAIL_TEMPLATE="web_system"
79+
fi
80+
add_webmail_config "$WEB_SYSTEM" "${WEBMAIL_TEMPLATE}.tpl"
7981

80-
if [ ! -z "$PROXY_SYSTEM" ]; then
81-
add_webmail_config "$PROXY_SYSTEM" "default.tpl"
82-
fi
82+
if [ ! -z "$PROXY_SYSTEM" ]; then
83+
add_webmail_config "$PROXY_SYSTEM" "default.tpl"
84+
fi
8385

84-
# Enable SSL for webmail if available
85-
if [ -f $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.crt ] || [ "$SSL" = 'yes' ]; then
86-
add_webmail_config "$WEB_SYSTEM" "${WEBMAIL_TEMPLATE}.stpl"
86+
# Enable SSL for webmail if available
87+
if [ -f $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.crt ] || [ "$SSL" = 'yes' ]; then
88+
add_webmail_config "$WEB_SYSTEM" "${WEBMAIL_TEMPLATE}.stpl"
8789

88-
if [ ! -z "$PROXY_SYSTEM" ]; then
89-
add_webmail_config "$PROXY_SYSTEM" "default.stpl"
90+
if [ ! -z "$PROXY_SYSTEM" ]; then
91+
add_webmail_config "$PROXY_SYSTEM" "default.stpl"
92+
fi
9093
fi
94+
else
95+
echo "Error: WEBMAIL_ALIAS is not defined in hestia.conf"
9196
fi
9297

9398
#----------------------------------------------------------#

bin/v-delete-webmail

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ check_args '2' "$#" 'USER DOMAIN [RESTART]'
3030
is_format_valid 'user' 'domain'
3131
is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
3232
is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
33+
is_system_enabled "$IMAP_SYSTEM" 'IMAP_SYSTEM'
3334
is_object_valid 'user' 'USER' "$user"
3435
is_object_unsuspended 'user' 'USER' "$user"
3536
is_object_valid 'mail' 'DOMAIN' "$domain"
@@ -39,20 +40,24 @@ is_object_unsuspended 'mail' 'DOMAIN' "$domain"
3940
# Action #
4041
#----------------------------------------------------------#
4142

42-
# Delete webmail configuration
43-
del_webmail_config
44-
del_webmail_ssl_config
43+
if [ ! -z "$WEBMAIL_ALIAS" ]; then
44+
# Delete webmail configuration
45+
del_webmail_config
46+
del_webmail_ssl_config
4547

46-
# Ensure that corresponding DNS records are removed
47-
if [ ! -z "$DNS_SYSTEM" ]; then
48-
dns_domain=$($BIN/v-list-dns-domains $user | grep $domain | cut -d' ' -f1)
49-
webmail_record=$($BIN/v-list-dns-records $user $domain | grep -i $WEBMAIL_ALIAS | cut -d' ' -f1)
48+
# Ensure that corresponding DNS records are removed
49+
if [ ! -z "$DNS_SYSTEM" ]; then
50+
dns_domain=$($BIN/v-list-dns-domains $user | grep $domain | cut -d' ' -f1)
51+
webmail_record=$($BIN/v-list-dns-records $user $domain | grep -i $WEBMAIL_ALIAS | cut -d' ' -f1)
5052

51-
if [ "$dns_domain" = "$domain" ]; then
52-
if [ ! -z "$webmail_record" ]; then
53-
$BIN/v-delete-dns-record $user $domain $webmail_record
53+
if [ "$dns_domain" = "$domain" ]; then
54+
if [ ! -z "$webmail_record" ]; then
55+
$BIN/v-delete-dns-record $user $domain $webmail_record
56+
fi
5457
fi
5558
fi
59+
else
60+
echo "Error: WEBMAIL_ALIAS is not defined in hestia.conf."
5661
fi
5762

5863
#----------------------------------------------------------#

0 commit comments

Comments
 (0)