Skip to content

Commit fdd6c9f

Browse files
cmstewjaapmarcus
andauthored
Add SMTP Relay support (hestiacp#1591)
* Initial Smarthost Commit * Made recommended changes * Fixes when to require password * Added checks for user SMTP Relay settings. * Added restore capability * mend * mend * mend * Execute also when password changed When user needs to change password it needs also modify any other settings Next check should still exits as it an requirement * Also update when password has been changed Co-authored-by: Jaap Marcus <9754650+jaapmarcus@users.noreply.github.com>
1 parent 763c4aa commit fdd6c9f

File tree

16 files changed

+678
-46
lines changed

16 files changed

+678
-46
lines changed

bin/v-add-mail-domain-smtp-relay

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/bash
2+
# info: Add mail domain smtp relay support
3+
# options: USER DOMAIN HOST USERNAME PASSWORD [PORT]
4+
# labels: mail
5+
#
6+
# example: v-add-mail-domain-smtp-relay user domain.tld srv.smtprelay.tld uname123 pass12345
7+
#
8+
# This function adds mail domain smtp relay support.
9+
10+
#----------------------------------------------------------#
11+
# Variable&Function #
12+
#----------------------------------------------------------#
13+
14+
# Argument definition
15+
user=$1
16+
domain=$2
17+
host=$3
18+
username=$4
19+
password=$5
20+
port=${6-587}
21+
22+
# Includes
23+
source $HESTIA/func/main.sh
24+
source $HESTIA/conf/hestia.conf
25+
26+
#----------------------------------------------------------#
27+
# Verifications #
28+
#----------------------------------------------------------#
29+
30+
check_args '5' "$#" 'USER DOMAIN HOST USERNAME PASSWORD'
31+
is_format_valid 'port' 'user' 'domain'
32+
is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
33+
is_object_valid 'user' 'USER' "$user"
34+
is_object_unsuspended 'user' 'USER' "$user"
35+
is_object_valid 'mail' 'DOMAIN' "$domain"
36+
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
37+
38+
# Perform verification if read-only mode is enabled
39+
check_hestia_demo_mode
40+
41+
#----------------------------------------------------------#
42+
# Action #
43+
#----------------------------------------------------------#
44+
45+
cat >/etc/exim4/domains/${domain}/smtp_relay.conf << EOL
46+
host:$host
47+
port:$port
48+
user:$username
49+
pass:$password
50+
EOL
51+
52+
#----------------------------------------------------------#
53+
# Hestia #
54+
#----------------------------------------------------------#
55+
56+
# Adding smtp relay values in config
57+
if [ -z "$U_SMTP_RELAY" ]; then
58+
add_object_key 'mail' 'DOMAIN' "$domain" 'U_SMTP_RELAY' 'ACCOUNTS'
59+
add_object_key 'mail' 'DOMAIN' "$domain" 'U_SMTP_RELAY_HOST' 'ACCOUNTS'
60+
add_object_key 'mail' 'DOMAIN' "$domain" 'U_SMTP_RELAY_PORT' 'ACCOUNTS'
61+
add_object_key 'mail' 'DOMAIN' "$domain" 'U_SMTP_RELAY_USERNAME' 'ACCOUNTS'
62+
add_object_key 'mail' 'DOMAIN' "$domain" 'U_SMTP_RELAY_PASSWORD' 'ACCOUNTS'
63+
fi
64+
65+
update_object_value 'mail' 'DOMAIN' "$domain" '$U_SMTP_RELAY' 'true'
66+
update_object_value 'mail' 'DOMAIN' "$domain" '$U_SMTP_RELAY_HOST' "$host"
67+
update_object_value 'mail' 'DOMAIN' "$domain" '$U_SMTP_RELAY_PORT' "$port"
68+
update_object_value 'mail' 'DOMAIN' "$domain" '$U_SMTP_RELAY_USERNAME' "$username"
69+
update_object_value 'mail' 'DOMAIN' "$domain" '$U_SMTP_RELAY_PASSWORD' "$password"
70+
71+
# Logging
72+
log_history "Added domain smtp relay support for $domain"
73+
log_event "$OK" "$ARGUMENTS"
74+
75+
exit

bin/v-add-sys-smtp-relay

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
# info: add system wide smtp relay support
3+
# options: HOST USERNAME PASSWORD [PORT]
4+
# labels: hestia
5+
#
6+
# example: v-add-sys-smtp-relay srv.smtprelay.tld uname123 pass12345
7+
#
8+
# this function adds system wide smtp relay support.
9+
10+
#----------------------------------------------------------#
11+
# Variable&Function #
12+
#----------------------------------------------------------#
13+
14+
# Argument definition
15+
host=$1
16+
username=$2
17+
password=$3
18+
port=${4-587}
19+
20+
# Includes
21+
source $HESTIA/func/main.sh
22+
source $HESTIA/conf/hestia.conf
23+
24+
#----------------------------------------------------------#
25+
# Verifications #
26+
#----------------------------------------------------------#
27+
28+
check_args '3' "$#" 'HOST USERNAME PASSWORD'
29+
is_format_valid 'port'
30+
is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
31+
32+
# Perform verification if read-only mode is enabled
33+
check_hestia_demo_mode
34+
35+
#----------------------------------------------------------#
36+
# Action #
37+
#----------------------------------------------------------#
38+
39+
40+
$BIN/v-change-sys-config-value SMTP_RELAY 'true'
41+
$BIN/v-change-sys-config-value SMTP_RELAY_HOST $host
42+
$BIN/v-change-sys-config-value SMTP_RELAY_PORT $port
43+
$BIN/v-change-sys-config-value SMTP_RELAY_USER $username
44+
45+
cat >/etc/exim4/smtp_relay.conf << EOL
46+
host:$host
47+
port:$port
48+
user:$username
49+
pass:$password
50+
EOL
51+
52+
53+
#----------------------------------------------------------#
54+
# Hestia #
55+
#----------------------------------------------------------#
56+
57+
# Logging
58+
log_history "enabled system wide smtp relay support."
59+
log_event "$OK" "$ARGUMENTS"
60+
61+
exit
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
# info: Remove mail domain smtp relay support
3+
# options: USER DOMAIN
4+
# labels: hestia
5+
#
6+
# example: v-delete-mail-domain-smtp-relay user domain.tld
7+
#
8+
# This function removes mail domain smtp relay support.
9+
10+
#----------------------------------------------------------#
11+
# Variable&Function #
12+
#----------------------------------------------------------#
13+
14+
# Argument definition
15+
user=$1
16+
domain=$2
17+
18+
# Includes
19+
source $HESTIA/func/main.sh
20+
source $HESTIA/conf/hestia.conf
21+
22+
#----------------------------------------------------------#
23+
# Verifications #
24+
#----------------------------------------------------------#
25+
26+
check_args '2' "$#" 'USER DOMAIN'
27+
is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
28+
is_object_valid 'user' 'USER' "$user"
29+
is_object_unsuspended 'user' 'USER' "$user"
30+
is_object_valid 'mail' 'DOMAIN' "$domain"
31+
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
32+
33+
#----------------------------------------------------------#
34+
# Action #
35+
#----------------------------------------------------------#
36+
37+
rm -f /etc/exim4/domains/${domain}/smtp_relay.conf
38+
39+
#----------------------------------------------------------#
40+
# Hestia #
41+
#----------------------------------------------------------#
42+
43+
# Adding smtp relay values in config
44+
if [ -z "$U_SMTP_RELAY" ]; then
45+
add_object_key 'mail' 'DOMAIN' "$domain" 'U_SMTP_RELAY' 'ACCOUNTS'
46+
add_object_key 'mail' 'DOMAIN' "$domain" 'U_SMTP_RELAY_HOST' 'ACCOUNTS'
47+
add_object_key 'mail' 'DOMAIN' "$domain" 'U_SMTP_RELAY_PORT' 'ACCOUNTS'
48+
add_object_key 'mail' 'DOMAIN' "$domain" 'U_SMTP_RELAY_USERNAME' 'ACCOUNTS'
49+
add_object_key 'mail' 'DOMAIN' "$domain" 'U_SMTP_RELAY_PASSWORD' 'ACCOUNTS'
50+
fi
51+
52+
update_object_value 'mail' 'DOMAIN' "$domain" '$U_SMTP_RELAY' 'false'
53+
update_object_value 'mail' 'DOMAIN' "$domain" '$U_SMTP_RELAY_HOST' ''
54+
update_object_value 'mail' 'DOMAIN' "$domain" '$U_SMTP_RELAY_PORT' ''
55+
update_object_value 'mail' 'DOMAIN' "$domain" '$U_SMTP_RELAY_USERNAME' ''
56+
update_object_value 'mail' 'DOMAIN' "$domain" '$U_SMTP_RELAY_PASSWORD' ''
57+
58+
# Logging
59+
log_history "Removed mail domain smtp relay support for $domain"
60+
61+
log_event "$OK" "$ARGUMENTS"
62+
63+
exit

bin/v-delete-sys-smtp-relay

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
# info: disable system wide smtp relay support
3+
# options:
4+
# labels: hestia
5+
#
6+
# example: v-delete-sys-smtp-relay
7+
#
8+
# this function disables system wide smtp relay support.
9+
10+
#----------------------------------------------------------#
11+
# Variable&Function #
12+
#----------------------------------------------------------#
13+
14+
# Includes
15+
source $HESTIA/func/main.sh
16+
source $HESTIA/conf/hestia.conf
17+
18+
#----------------------------------------------------------#
19+
# Verifications #
20+
#----------------------------------------------------------#
21+
22+
# Perform verification if read-only mode is enabled
23+
check_hestia_demo_mode
24+
25+
#----------------------------------------------------------#
26+
# Action #
27+
#----------------------------------------------------------#
28+
29+
30+
$BIN/v-change-sys-config-value SMTP_RELAY false
31+
$BIN/v-change-sys-config-value SMTP_RELAY_HOST ''
32+
$BIN/v-change-sys-config-value SMTP_RELAY_PORT ''
33+
$BIN/v-change-sys-config-value SMTP_RELAY_USER ''
34+
35+
rm -f /etc/exim4/smtp_relay.conf
36+
37+
#----------------------------------------------------------#
38+
# Hestia #
39+
#----------------------------------------------------------#
40+
41+
# Logging
42+
log_history "Disable system wide smtp relay support."
43+
log_event "$OK" "$ARGUMENTS"
44+
45+
exit

bin/v-list-mail-domain

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,41 +38,52 @@ json_list() {
3838
"TIME": "'$TIME'",
3939
"DATE": "'$DATE'",
4040
"WEBMAIL_ALIAS": "'$WEBMAIL_ALIAS.$domain'",
41-
"WEBMAIL":"'$WEBMAIL'"
41+
"WEBMAIL":"'$WEBMAIL'",
42+
"U_SMTP_RELAY":"'$U_SMTP_RELAY'",
43+
"U_SMTP_RELAY_HOST":"'$U_SMTP_RELAY_HOST'",
44+
"U_SMTP_RELAY_PORT":"'$U_SMTP_RELAY_PORT'",
45+
"U_SMTP_RELAY_USERNAME":"'$U_SMTP_RELAY_USERNAME'"
4246
}'
4347
echo '}'
4448
}
4549

4650
# SHELL list function
4751
shell_list() {
48-
echo "DOMAIN: $DOMAIN"
49-
echo "ANTIVIRUS: $ANTIVIRUS"
50-
echo "ANTISPAM: $ANTISPAM"
51-
echo "DKIM: $DKIM"
52-
echo "CATCHALL: $CATCHALL"
53-
echo "ACCOUNTS: $ACCOUNTS"
54-
echo "DISK: $U_DISK"
55-
echo "SSL: $SSL"
56-
echo "LETSENCRYPT: $LETSENCRYPT"
57-
echo "SUSPENDED: $SUSPENDED"
58-
echo "TIME: $TIME"
59-
echo "DATE: $DATE"
60-
echo "WEBMAIL_ALIAS: $WEBMAIL_ALIAS.$domain"
61-
echo "WEBMAIL: $WEBMAIL"
52+
echo "DOMAIN: $DOMAIN"
53+
echo "ANTIVIRUS: $ANTIVIRUS"
54+
echo "ANTISPAM: $ANTISPAM"
55+
echo "DKIM: $DKIM"
56+
echo "CATCHALL: $CATCHALL"
57+
echo "ACCOUNTS: $ACCOUNTS"
58+
echo "DISK: $U_DISK"
59+
echo "SSL: $SSL"
60+
echo "LETSENCRYPT: $LETSENCRYPT"
61+
echo "SUSPENDED: $SUSPENDED"
62+
echo "TIME: $TIME"
63+
echo "DATE: $DATE"
64+
echo "WEBMAIL_ALIAS: $WEBMAIL_ALIAS.$domain"
65+
echo "WEBMAIL: $WEBMAIL"
66+
echo "U_SMTP_RELAY: $U_SMTP_RELAY"
67+
echo "U_SMTP_RELAY_HOST $U_SMTP_RELAY_HOST"
68+
echo "U_SMTP_RELAY_PORT $U_SMTP_RELAY_PORT"
69+
echo "U_SMTP_RELAY_USERNAME $U_SMTP_RELAY_USERNAME"
6270
}
6371

6472
# PLAIN list function
6573
plain_list() {
6674
echo -ne "$DOMAIN\t$ANTIVIRUS\t$ANTISPAM\t$DKIM\t$CATCHALL\t"
67-
echo -e "$ACCOUNTS\t$U_DISK\t$SSL\t$LETSENCRYPT\t$SUSPENDED\t$TIME\t$DATE\t$WEBMAIL_ALIAS.$domain\t$WEBMAIL"
75+
echo -e "$ACCOUNTS\t$U_DISK\t$SSL\t$LETSENCRYPT\t$SUSPENDED\t$TIME\t$DATE\t$WEBMAIL_ALIAS.$domain\t$WEBMAIL\t"
76+
echo -e "$U_SMTP_RELAY\t$U_SMTP_RELAY_HOST\t$U_SMTP_RELAY_PORT\t$U_SMTP_RELAY_USERNAME"
6877
}
6978

7079
# CSV list function
7180
csv_list() {
7281
echo -n "DOMAIN,ANTIVIRUS,ANTISPAM,DKIM,CATCHALL,ACCOUNTS,U_DISK,"
73-
echo "SSL,LETSENCRYPT,SUSPENDED,TIME,DATE,WEBMAIL_ALIAS,WEBMAIL"
74-
echo -n "$DOMAIN,$ANTIVIRUS,$ANTISPAM,$DKIM,$CATCHALL,$ACCOUNTS,$U_DISK"
75-
echo "$SSL,$LETSENCRYPT,$SUSPENDED,$TIME,$DATE,$WEBMAIL_ALIAS.$domain,$WEBMAIL"
82+
echo "SSL,LETSENCRYPT,SUSPENDED,TIME,DATE,WEBMAIL_ALIAS,WEBMAIL,"
83+
echo "U_SMTP_RELAY,U_SMTP_RELAY_HOST,U_SMTP_RELAY_PORT,U_SMTP_RELAY_USERNAME"
84+
echo -n "$DOMAIN,$ANTIVIRUS,$ANTISPAM,$DKIM,$CATCHALL,$ACCOUNTS,$U_DISK,"
85+
echo "$SSL,$LETSENCRYPT,$SUSPENDED,$TIME,$DATE,$WEBMAIL_ALIAS.$domain,$WEBMAIL,"
86+
echo "$U_SMTP_RELAY,$U_SMTP_RELAY_HOST,$U_SMTP_RELAY_PORT,$U_SMTP_RELAY_USERNAME"
7687
}
7788

7889

bin/v-list-sys-config

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ json_list() {
5151
"RELEASE_BRANCH": "'$RELEASE_BRANCH'",
5252
"UPGRADE_SEND_EMAIL": "'$UPGRADE_SEND_EMAIL'",
5353
"UPGRADE_SEND_EMAIL_LOG": "'$UPGRADE_SEND_EMAIL_LOG'",
54+
"SMTP_RELAY": "'$SMTP_RELAY'",
55+
"SMTP_RELAY_HOST": "'$SMTP_RELAY_HOST'",
56+
"SMTP_RELAY_PORT": "'$SMTP_RELAY_PORT'",
57+
"SMTP_RELAY_USER": "'$SMTP_RELAY_USER'",
5458
"DEMO_MODE": "'$DEMO_MODE'",
5559
"THEME": "'$THEME'",
5660
"LANGUAGE": "'$LANGUAGE'",
@@ -146,6 +150,13 @@ shell_list() {
146150
if [ ! -z "$FILE_MANAGER" ]; then
147151
echo "File Manager enabled: $FILE_MANAGER"
148152
fi
153+
if [ ! -z "$SMTP_RELAY" ] && [ "$SMTP_RELAY" != 'false' ]; then
154+
echo "SMTP Relay enabled: $SMTP_RELAY"
155+
echo "SMTP Relay Server: $SMTP_RELAY_HOST"
156+
echo "SMTP Relay Port: $SMTP_RELAY_PORT"
157+
echo "SMTP Relay User: $SMTP_RELAY_USER"
158+
fi
159+
149160
echo "Release Branch: $RELEASE_BRANCH"
150161
echo "Theme: $THEME"
151162
echo "Updates: Notify by email: $UPGRADE_SEND_EMAIL"
@@ -161,6 +172,7 @@ plain_list() {
161172
echo -ne "$DNS_SYSTEM\t$DNS_CLUSTER\t$STATS_SYSTEM\t$BACKUP_SYSTEM\t"
162173
echo -ne "$CRON_SYSTEM\t$DISK_QUOTA\t$FIREWALL_SYSTEM\t$FIREWALL_EXTENSION\t"
163174
echo -ne "$FILE_MANAGER\t$REPOSITORY\t$VERSION\t$DEMO_MODE\t$RELEASE_BRANCH\t"
175+
echo -ne "$SMTP_RELAY_HOST\t$SMTP_RELAY_PORT\t$SMTP_RELAY_USER\t"
164176
echo -ne "$UPGRADE_SEND_EMAIL\t$UPGRADE_SEND_EMAIL_LOG\t$THEME\t$LANGUAGE\t$BACKUP_GZIP\t"
165177
echo -e "$BACKUP\t$WEBMAIL_ALIAS\t$DB_PMA_URL\t$DB_PGA_URL"
166178
}
@@ -176,6 +188,7 @@ csv_list() {
176188
echo -n "'CRON_SYSTEM','DISK_QUOTA','FIREWALL_SYSTEM',"
177189
echo -n "'FIREWALL_EXTENSION','FILE_MANAGER','REPOSITORY',"
178190
echo -n "'VERSION','DEMO_MODE','RELEASE_BRANCH',"
191+
echo -n "'SMTP_RELAY','SMTP_RELAY_HOST','SMTP_RELAY_PORT','SMTP_RELAY_USER',"
179192
echo -n "'UPGRADE_SEND_EMAIL','UPGRADE_SEND_EMAIL_LOG',"
180193
echo -n "'THEME', 'LANGUAGE','BACKUP_GZIP','BACKUP','WEBMAIL_ALIAS',"
181194
echo -n "'DB_PMA_ALIAS','DB_PGA_ALIAS'"
@@ -187,6 +200,7 @@ csv_list() {
187200
echo -n "'$DNS_CLUSTER','$STATS_SYSTEM','$BACKUP_SYSTEM','$CRON_SYSTEM',"
188201
echo -n "'$DISK_QUOTA','$FIREWALL_SYSTEM','$FIREWALL_EXTENSION','$FILE_MANAGER',"
189202
echo -n "'$REPOSITORY', '$VERSION','$DEMO_MODE','$RELEASE_BRANCH',"
203+
echo -n "'$SMTP_RELAY','$SMTP_RELAY_HOST','$SMTP_RELAY_PORT','$SMTP_RELAY_USER',"
190204
echo -n "'$UPGRADE_SEND_EMAIL','$UPGRADE_SEND_EMAIL_LOG','$THEME','$LANGUAGE',"
191205
echo -n "'$BACKUP_GZIP','$BACKUP','$WEBMAIL_ALIAS','$DB_PMA_URL','$DB_PGA_URL'"
192206
echo

func/rebuild.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,11 @@ rebuild_mail_domain_conf() {
556556
cp $USER_DATA/mail/$domain.pem \
557557
$HOMEDIR/$user/conf/mail/$domain/dkim.pem
558558
fi
559+
560+
# Rebuild SMTP Relay configuration
561+
if [ "$U_SMTP_RELAY" = 'true' ]; then
562+
$BIN/v-add-mail-domain-smtp-relay $user $domain "$U_SMTP_RELAY_HOST" "$U_SMTP_RELAY_USERNAME" "$U_SMTP_RELAY_PASSWORD" "$U_SMTP_RELAY_PORT"
563+
fi
559564

560565
# Removing configuration files if domain is suspended
561566
if [ "$SUSPENDED" = 'yes' ]; then

0 commit comments

Comments
 (0)