Skip to content

Commit 8782893

Browse files
Myself5jaapmarcus
andauthored
hestia: Ability to specify SMTP account for server communication (hestiacp#1988)
* web/inc: Add phpmailer 6.5.0 via composer * hestia: Ability to specify SMTP account for server communication * Use v-setup-server-smtp-account to configure a SMTP account that is used by emails sent from the server. * Minor changes to script Replace y/n with true/false rename script * Include basic tests * Add new vars on update * Update installers with new keys * Update change log Co-authored-by: Jaap Marcus <9754650+jaapmarcus@users.noreply.github.com>
1 parent 011ab1b commit 8782893

23 files changed

+550
-35
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ All notable changes to this project will be documented in this file.
66
### Features
77

88
- Add support for automated testing HestiaCP code
9+
- Add support for SMTP server for internal email #1988 @Myself5 / #1165
10+
11+
### Bugfixes
12+
13+
- Resolve issue with double ENFORCE_SUBDOMAIN_OWNERSHIP keys in hestia.conf
14+
- Resolve issue with create new user during install in some cases #2000
915

1016
## [1.4.7] - Service release
1117

bin/v-add-sys-phpmailer

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
# info: add PHPMailer functionality to Hestia Control Panel
3+
# options: [MODE]
4+
# labels: hestia
5+
#
6+
# The function installs PHPMailer for Server sided email communication
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Includes
13+
# shellcheck source=/usr/local/hestia/func/main.sh
14+
source $HESTIA/func/main.sh
15+
# shellcheck source=/usr/local/hestia/conf/hestia.conf
16+
source $HESTIA/conf/hestia.conf
17+
# shellcheck source=/usr/local/hestia/install/upgrade/upgrade.conf
18+
source $HESTIA/install/upgrade/upgrade.conf
19+
20+
MODE=$1
21+
user="admin"
22+
23+
PM_INSTALL_DIR="$HESTIA/web/inc"
24+
COMPOSER_BIN="$HOMEDIR/$user/.composer/composer"
25+
26+
27+
#----------------------------------------------------------#
28+
# Verifications #
29+
#----------------------------------------------------------#
30+
31+
# Checking root permissions
32+
if [ "x$(id -u)" != 'x0' ]; then
33+
echo "ERROR: v-add-sys-phpmailer can be run executed only by root user"
34+
exit 10
35+
fi
36+
37+
# Ensure that $HESTIA (/usr/local/hestia/) and other variables are valid.
38+
if [ -z "$HESTIA" ]; then
39+
HESTIA="/usr/local/hestia"
40+
fi
41+
42+
if [ -z "$HOMEDIR" ] || [ -z "$HESTIA_INSTALL_DIR" ]; then
43+
echo "ERROR: Environment variables not present, installation aborted."
44+
exit 2
45+
fi
46+
47+
# Ensure that Composer is installed for the user before continuing as it is a dependency of the PHPMailer.
48+
if [ ! -f "$COMPOSER_BIN" ]; then
49+
$BIN/v-add-user-composer "$user"
50+
if [ $? -ne 0 ]; then
51+
$BIN/v-add-user-notification admin 'Composer installation failed!' '<b>PHPMailer will not work without Composer.</b><br><br>Please try running the installer manually from a shell session:<br>v-add-sys-phpmailer<br><br>If this continues, open an issue report on <a href="https://github.com/hestiacp/hestiacp/issues" target="_new"><i class="fab fa-github"></i> GitHub</a>.'
52+
exit 1
53+
fi
54+
fi
55+
56+
# Perform verification if read-only mode is enabled
57+
check_hestia_demo_mode
58+
59+
#----------------------------------------------------------#
60+
# Action #
61+
#----------------------------------------------------------#
62+
63+
cd "$PM_INSTALL_DIR"
64+
rm --recursive --force ${PM_INSTALL_DIR}/vendor
65+
mkdir -p ${PM_INSTALL_DIR}/vendor
66+
chown $user: -R ${PM_INSTALL_DIR}/vendor
67+
68+
COMPOSER_HOME="$HOMEDIR/$user/.config/composer" user_exec /usr/bin/php $COMPOSER_BIN --quiet --no-dev install
69+
70+
# Check if installation was successful, if not abort script and throw error message notification and clean-up
71+
if [ $? -ne 0 ]; then
72+
echo "ERROR: PHPMailer installation failed!"
73+
echo "Please report this to our development team:"
74+
echo "https://github.com/hestiacp/hestiacp/issues"
75+
$BIN/v-add-user-notification admin 'PHPMailer installation failed!' 'Please report this to our development team on <a href="https://github.com/hestiacp/hestiacp/issues" target="_new"><i class="fab fa-github"></i> GitHub</a>.'
76+
# Installation failed, clean up files
77+
rm --recursive --force ${PM_INSTALL_DIR}/vendor
78+
$BIN/v-change-sys-config-value 'USE_SERVER_SMTP' 'n'
79+
$BIN/v-log-action "system" "Error" "Plugins" "PHPMailer installation failed (Version: $pm_v)."
80+
exit 1
81+
fi
82+
83+
# Set permissions
84+
chown root: -R "${PM_INSTALL_DIR}/vendor"
85+
86+
#----------------------------------------------------------#
87+
# Logging #
88+
#----------------------------------------------------------#
89+
90+
$BIN/v-log-action "system" "Info" "Plugins" "PHPMailer enabled (Version: $pm_v)."
91+
log_event "$OK" "$ARGUMENTS"

bin/v-add-sys-smtp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
# info: Add SMTP Account for logging, notification and internal mail
3+
# options: DOMAIN PORT SMTP_SECURITY USERNAME PASSWORD EMAIL
4+
# labels:
5+
#
6+
# example: v-add-sys-smtp example.com 587 STARTTLS test@domain.com securepassword test@example.com
7+
#
8+
# This function allows configuring a SMTP account for the server to use
9+
# for logging, notification and warn emails etc.
10+
11+
#----------------------------------------------------------#
12+
# Variable&Function #
13+
#----------------------------------------------------------#
14+
15+
# Argument definition
16+
domain=$1
17+
port=$2
18+
smtp_security=$3
19+
username=$4
20+
password=$5
21+
email=$6
22+
23+
# Includes
24+
# shellcheck source=/usr/local/hestia/func/main.sh
25+
source $HESTIA/func/main.sh
26+
# shellcheck source=/usr/local/hestia/conf/hestia.conf
27+
source $HESTIA/conf/hestia.conf
28+
29+
#----------------------------------------------------------#
30+
# Verifications #
31+
#----------------------------------------------------------#
32+
33+
check_args '6' "$#" 'DOMAIN PORT SMTP_SECURITY USERNAME PASSWORD EMAIL'
34+
is_format_valid 'domain' 'port' 'email'
35+
36+
# Perform verification if read-only mode is enabled
37+
check_hestia_demo_mode
38+
39+
#----------------------------------------------------------#
40+
# Action #
41+
#----------------------------------------------------------#
42+
43+
$BIN/v-change-sys-config-value "USE_SERVER_SMTP" 'true'
44+
$BIN/v-change-sys-config-value "SERVER_SMTP_HOST" $domain
45+
$BIN/v-change-sys-config-value "SERVER_SMTP_PORT" $port
46+
$BIN/v-change-sys-config-value "SERVER_SMTP_SECURITY" $smtp_security
47+
$BIN/v-change-sys-config-value "SERVER_SMTP_USER" $username
48+
$BIN/v-change-sys-config-value "SERVER_SMTP_PASSWD" $password
49+
$BIN/v-change-sys-config-value "SERVER_SMTP_ADDR" $email
50+
51+
#----------------------------------------------------------#
52+
# Hestia #
53+
#----------------------------------------------------------#
54+
55+
# Logging
56+
$BIN/v-log-action "system" "Info" "Mail" "Server SMTP enabled."
57+
log_event "$OK" "$ARGUMENTS"
58+
59+
exit

bin/v-delete-sys-smtp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
# info: Remove SMTP Account for logging, notification and internal mail
3+
# options: NONE
4+
# labels:
5+
#
6+
# example: v-delete-sys-smtp
7+
#
8+
# This function allows configuring a SMTP account for the server to use
9+
# for logging, notification and warn emails etc.
10+
11+
#----------------------------------------------------------#
12+
# Variable&Function #
13+
#----------------------------------------------------------#
14+
15+
# Includes
16+
# shellcheck source=/usr/local/hestia/func/main.sh
17+
source $HESTIA/func/main.sh
18+
# shellcheck source=/usr/local/hestia/conf/hestia.conf
19+
source $HESTIA/conf/hestia.conf
20+
21+
#----------------------------------------------------------#
22+
# Verifications #
23+
#----------------------------------------------------------#
24+
25+
# Perform verification if read-only mode is enabled
26+
check_hestia_demo_mode
27+
28+
#----------------------------------------------------------#
29+
# Action #
30+
#----------------------------------------------------------#
31+
32+
$BIN/v-change-sys-config-value "USE_SERVER_SMTP" 'false'
33+
$BIN/v-change-sys-config-value "SERVER_SMTP_HOST" ''
34+
$BIN/v-change-sys-config-value "SERVER_SMTP_PORT" ''
35+
$BIN/v-change-sys-config-value "SERVER_SMTP_SECURITY" ''
36+
$BIN/v-change-sys-config-value "SERVER_SMTP_USER" ''
37+
$BIN/v-change-sys-config-value "SERVER_SMTP_PASSWD" ''
38+
$BIN/v-change-sys-config-value "SERVER_SMTP_ADDR" ''
39+
40+
#----------------------------------------------------------#
41+
# Hestia #
42+
#----------------------------------------------------------#
43+
44+
# Logging
45+
$BIN/v-log-action "system" "Info" "Mail" "Server SMTP disabled."
46+
log_event "$OK" "$ARGUMENTS"
47+
48+
exit

bin/v-list-sys-config

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,14 @@ json_list() {
8989
"POLICY_USER_EDIT_DNS_TEMPLATES": "'$POLICY_USER_EDIT_DNS_TEMPLATES'",
9090
"POLICY_USER_DELETE_LOGS": "'$POLICY_USER_DELETE_LOGS'",
9191
"POLICY_USER_VIEW_LOGS": "'$POLICY_USER_VIEW_LOGS'",
92-
"POLICY_USER_CHANGE_THEME": "'$POLICY_USER_CHANGE_THEME'"
92+
"POLICY_USER_CHANGE_THEME": "'$POLICY_USER_CHANGE_THEME'",
93+
"USE_SERVER_SMTP": "'$USE_SERVER_SMTP'",
94+
"SERVER_SMTP_HOST": "'$SERVER_SMTP_HOST'",
95+
"SERVER_SMTP_PORT": "'$SERVER_SMTP_PORT'",
96+
"SERVER_SMTP_SECURITY": "'$SERVER_SMTP_SECURITY'",
97+
"SERVER_SMTP_USER": "'$SERVER_SMTP_USER'",
98+
"SERVER_SMTP_PASSWD": "'$SERVER_SMTP_PASSWD'",
99+
"SERVER_SMTP_ADDR": "'$SERVER_SMTP_ADDR'"
93100
}
94101
}'
95102
}
@@ -185,6 +192,17 @@ shell_list() {
185192
echo "SMTP Relay User: $SMTP_RELAY_USER"
186193
fi
187194

195+
echo "SMTP Server Account enabled: $USE_SERVER_SMTP"
196+
197+
if [ ! -z "$USE_SERVER_SMTP" ] && [ "$USE_SERVER_SMTP" != 'false' ]; then
198+
echo "SMTP Server Account Host: $SERVER_SMTP_HOST"
199+
echo "SMTP Server Account Port: $SERVER_SMTP_PORT"
200+
echo "SMTP Server Account Security: $SERVER_SMTP_SECURITY"
201+
echo "SMTP Server Account Username: $SERVER_SMTP_USER"
202+
echo "SMTP Server Account Password: $SERVER_SMTP_PASSWD"
203+
echo "SMTP Server Account Address: $SERVER_SMTP_ADDR"
204+
fi
205+
188206
echo "Release Branch: $RELEASE_BRANCH"
189207
echo "Debug Mode: $DEBUG_MODE"
190208
echo "Theme: $THEME"

func/syshealth.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,42 @@ function syshealth_repair_system_config() {
380380
echo "[ ! ] Adding missing variable to hestia.conf: PHPMYADMIN_KEY ('')"
381381
$BIN/v-change-sys-config-value "PHPMYADMIN_KEY" ""
382382
fi
383+
# Use SMTP server for hestia internal mail
384+
if [ -z "$USE_SERVER_SMTP" ]; then
385+
echo "[ ! ] Adding missing variable to hestia.conf: USE_SERVER_SMTP ('')"
386+
$BIN/v-change-sys-config-value "USE_SERVER_SMTP" "false"
387+
fi
388+
389+
if [ -z "$SERVER_SMTP_PORT" ]; then
390+
echo "[ ! ] Adding missing variable to hestia.conf: SERVER_SMTP_PORT ('')"
391+
$BIN/v-change-sys-config-value "SERVER_SMTP_PORT" ""
392+
fi
393+
394+
if [ -z "$SERVER_SMTP_HOST" ]; then
395+
echo "[ ! ] Adding missing variable to hestia.conf: SERVER_SMTP_HOST ('')"
396+
$BIN/v-change-sys-config-value "SERVER_SMTP_HOST" ""
397+
fi
398+
399+
if [ -z "$SERVER_SMTP_SECURITY" ]; then
400+
echo "[ ! ] Adding missing variable to hestia.conf: SERVER_SMTP_SECURITY ('')"
401+
$BIN/v-change-sys-config-value "SERVER_SMTP_SECURITY" ""
402+
fi
403+
404+
if [ -z "$SERVER_SMTP_USER" ]; then
405+
echo "[ ! ] Adding missing variable to hestia.conf: SERVER_SMTP_USER ('')"
406+
$BIN/v-change-sys-config-value "SERVER_SMTP_USER" ""
407+
fi
383408

409+
if [ -z "$SERVER_SMTP_PASSWD" ]; then
410+
echo "[ ! ] Adding missing variable to hestia.conf: SERVER_SMTP_PASSWD ('')"
411+
$BIN/v-change-sys-config-value "SERVER_SMTP_PASSWD" ""
412+
fi
413+
414+
if [ -z "$SERVER_SMTP_ADDR" ]; then
415+
echo "[ ! ] Adding missing variable to hestia.conf: SERVER_SMTP_ADDR ('')"
416+
$BIN/v-change-sys-config-value "SERVER_SMTP_ADDR" ""
417+
fi
418+
384419
}
385420

386421
# Repair System Cron Jobs

install/hst-install-debian.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,6 +1881,20 @@ write_config_value "POLICY_SYSTEM_ENABLE_BACON" "no"
18811881
write_config_value "PLUGIN_APP_INSTALLER" "true"
18821882
write_config_value "DEBUG_MODE" "no"
18831883
write_config_value "ENFORCE_SUBDOMAIN_OWNERSHIP" "yes"
1884+
write_config_value "USE_SERVER_SMTP" "false"
1885+
write_config_value "SERVER_SMTP_PORT" ""
1886+
write_config_value "SERVER_SMTP_HOST" ""
1887+
write_config_value "SERVER_SMTP_SECURITY" ""
1888+
write_config_value "SERVER_SMTP_USER" ""
1889+
write_config_value "SERVER_SMTP_PASSWD" ""
1890+
write_config_value "SERVER_SMTP_ADDR" ""
1891+
1892+
#----------------------------------------------------------#
1893+
# Configure PHPMailer #
1894+
#----------------------------------------------------------#
1895+
1896+
echo "[ * ] Configuring PHPMailer..."
1897+
$HESTIA/bin/v-add-sys-phpmailer quiet
18841898

18851899
#----------------------------------------------------------#
18861900
# Hestia Access Info #

install/hst-install-ubuntu.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,6 +1912,19 @@ write_config_value "POLICY_SYSTEM_ENABLE_BACON" "no"
19121912
write_config_value "PLUGIN_APP_INSTALLER" "true"
19131913
write_config_value "DEBUG_MODE" "no"
19141914
write_config_value "ENFORCE_SUBDOMAIN_OWNERSHIP" "yes"
1915+
write_config_value "USE_SERVER_SMTP" "false"
1916+
write_config_value "SERVER_SMTP_PORT" ""
1917+
write_config_value "SERVER_SMTP_HOST" ""
1918+
write_config_value "SERVER_SMTP_SECURITY" ""
1919+
write_config_value "SERVER_SMTP_USER" ""
1920+
write_config_value "SERVER_SMTP_PASSWD" ""
1921+
write_config_value "SERVER_SMTP_ADDR" ""
1922+
#----------------------------------------------------------#
1923+
# Configure PHPMailer #
1924+
#----------------------------------------------------------#
1925+
1926+
echo "[ * ] Configuring PHPMailer..."
1927+
$HESTIA/bin/v-add-sys-phpmailer quiet
19151928

19161929
#----------------------------------------------------------#
19171930
# Hestia Access Info #

0 commit comments

Comments
 (0)