Ver código fonte

hestia: Ability to specify SMTP account for server communication (#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>
Christian Oder 4 anos atrás
pai
commit
878289347e

+ 6 - 0
CHANGELOG.md

@@ -6,6 +6,12 @@ All notable changes to this project will be documented in this file.
 ### Features
 ### Features
 
 
 - Add support for automated testing HestiaCP code
 - Add support for automated testing HestiaCP code
+- Add support for SMTP server for internal email #1988 @Myself5 / #1165
+
+### Bugfixes
+
+- Resolve issue with double ENFORCE_SUBDOMAIN_OWNERSHIP keys in hestia.conf
+- Resolve issue with create new user during install in some cases #2000
 
 
 ## [1.4.7] - Service release 
 ## [1.4.7] - Service release 
 
 

+ 91 - 0
bin/v-add-sys-phpmailer

@@ -0,0 +1,91 @@
+#!/bin/bash
+# info: add PHPMailer functionality to Hestia Control Panel
+# options: [MODE]
+# labels: hestia
+#
+# The function installs PHPMailer for Server sided email communication
+
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
+# Includes
+# shellcheck source=/usr/local/hestia/func/main.sh
+source $HESTIA/func/main.sh
+# shellcheck source=/usr/local/hestia/conf/hestia.conf
+source $HESTIA/conf/hestia.conf
+# shellcheck source=/usr/local/hestia/install/upgrade/upgrade.conf
+source $HESTIA/install/upgrade/upgrade.conf
+
+MODE=$1
+user="admin"
+
+PM_INSTALL_DIR="$HESTIA/web/inc"
+COMPOSER_BIN="$HOMEDIR/$user/.composer/composer"
+
+
+#----------------------------------------------------------#
+#                    Verifications                         #
+#----------------------------------------------------------#
+
+# Checking root permissions
+if [ "x$(id -u)" != 'x0' ]; then
+    echo "ERROR: v-add-sys-phpmailer can be run executed only by root user"
+    exit 10
+fi
+
+# Ensure that $HESTIA (/usr/local/hestia/) and other variables are valid.
+if [ -z "$HESTIA" ]; then
+    HESTIA="/usr/local/hestia"
+fi
+
+if [ -z "$HOMEDIR" ] || [ -z "$HESTIA_INSTALL_DIR" ]; then
+    echo "ERROR: Environment variables not present, installation aborted."
+    exit 2
+fi
+
+# Ensure that Composer is installed for the user before continuing as it is a dependency of the PHPMailer.
+if [ ! -f "$COMPOSER_BIN" ]; then
+    $BIN/v-add-user-composer "$user"
+    if [ $? -ne 0 ]; then
+        $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>.'
+        exit 1
+    fi
+fi
+
+# Perform verification if read-only mode is enabled
+check_hestia_demo_mode
+
+#----------------------------------------------------------#
+#                       Action                             #
+#----------------------------------------------------------#
+
+cd "$PM_INSTALL_DIR"
+rm --recursive --force ${PM_INSTALL_DIR}/vendor
+mkdir -p ${PM_INSTALL_DIR}/vendor
+chown $user: -R ${PM_INSTALL_DIR}/vendor
+
+COMPOSER_HOME="$HOMEDIR/$user/.config/composer" user_exec /usr/bin/php $COMPOSER_BIN --quiet --no-dev install
+
+# Check if installation was successful, if not abort script and throw error message notification and clean-up
+if [ $? -ne 0 ]; then
+    echo "ERROR: PHPMailer installation failed!"
+    echo "Please report this to our development team:"
+    echo "https://github.com/hestiacp/hestiacp/issues"
+    $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>.'
+    # Installation failed, clean up files
+    rm --recursive --force ${PM_INSTALL_DIR}/vendor
+    $BIN/v-change-sys-config-value 'USE_SERVER_SMTP' 'n'
+    $BIN/v-log-action "system" "Error" "Plugins" "PHPMailer installation failed (Version: $pm_v)."
+    exit 1
+fi
+
+# Set permissions
+chown root: -R "${PM_INSTALL_DIR}/vendor"
+
+#----------------------------------------------------------#
+#                       Logging                            #
+#----------------------------------------------------------#
+
+$BIN/v-log-action "system" "Info" "Plugins" "PHPMailer enabled (Version: $pm_v)."
+log_event "$OK" "$ARGUMENTS"

+ 59 - 0
bin/v-add-sys-smtp

@@ -0,0 +1,59 @@
+#!/bin/bash
+# info: Add SMTP Account for logging, notification and internal mail
+# options: DOMAIN PORT SMTP_SECURITY USERNAME PASSWORD EMAIL
+# labels:
+#
+# example: v-add-sys-smtp example.com 587 STARTTLS test@domain.com securepassword test@example.com
+#
+# This function allows configuring a SMTP account for the server to use
+# for logging, notification and warn emails etc.
+
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
+# Argument definition
+domain=$1
+port=$2
+smtp_security=$3
+username=$4
+password=$5
+email=$6
+
+# Includes
+# shellcheck source=/usr/local/hestia/func/main.sh
+source $HESTIA/func/main.sh
+# shellcheck source=/usr/local/hestia/conf/hestia.conf
+source $HESTIA/conf/hestia.conf
+
+#----------------------------------------------------------#
+#                    Verifications                         #
+#----------------------------------------------------------#
+
+check_args '6' "$#" 'DOMAIN PORT SMTP_SECURITY USERNAME PASSWORD EMAIL'
+is_format_valid 'domain' 'port' 'email'
+
+# Perform verification if read-only mode is enabled
+check_hestia_demo_mode
+
+#----------------------------------------------------------#
+#                       Action                             #
+#----------------------------------------------------------#
+
+$BIN/v-change-sys-config-value "USE_SERVER_SMTP" 'true'
+$BIN/v-change-sys-config-value "SERVER_SMTP_HOST" $domain
+$BIN/v-change-sys-config-value "SERVER_SMTP_PORT" $port
+$BIN/v-change-sys-config-value "SERVER_SMTP_SECURITY" $smtp_security
+$BIN/v-change-sys-config-value "SERVER_SMTP_USER" $username
+$BIN/v-change-sys-config-value "SERVER_SMTP_PASSWD" $password
+$BIN/v-change-sys-config-value "SERVER_SMTP_ADDR" $email
+
+#----------------------------------------------------------#
+#                       Hestia                             #
+#----------------------------------------------------------#
+
+# Logging
+$BIN/v-log-action "system" "Info" "Mail" "Server SMTP enabled."
+log_event "$OK" "$ARGUMENTS"
+
+exit

+ 48 - 0
bin/v-delete-sys-smtp

@@ -0,0 +1,48 @@
+#!/bin/bash
+# info: Remove SMTP Account for logging, notification and internal mail
+# options: NONE
+# labels:
+#
+# example: v-delete-sys-smtp
+#
+# This function allows configuring a SMTP account for the server to use
+# for logging, notification and warn emails etc.
+
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
+# Includes
+# shellcheck source=/usr/local/hestia/func/main.sh
+source $HESTIA/func/main.sh
+# shellcheck source=/usr/local/hestia/conf/hestia.conf
+source $HESTIA/conf/hestia.conf
+
+#----------------------------------------------------------#
+#                    Verifications                         #
+#----------------------------------------------------------#
+
+# Perform verification if read-only mode is enabled
+check_hestia_demo_mode
+
+#----------------------------------------------------------#
+#                       Action                             #
+#----------------------------------------------------------#
+
+$BIN/v-change-sys-config-value "USE_SERVER_SMTP" 'false'
+$BIN/v-change-sys-config-value "SERVER_SMTP_HOST" ''
+$BIN/v-change-sys-config-value "SERVER_SMTP_PORT" ''
+$BIN/v-change-sys-config-value "SERVER_SMTP_SECURITY" ''
+$BIN/v-change-sys-config-value "SERVER_SMTP_USER" ''
+$BIN/v-change-sys-config-value "SERVER_SMTP_PASSWD" ''
+$BIN/v-change-sys-config-value "SERVER_SMTP_ADDR" ''
+
+#----------------------------------------------------------#
+#                       Hestia                             #
+#----------------------------------------------------------#
+
+# Logging
+$BIN/v-log-action "system" "Info" "Mail" "Server SMTP disabled."
+log_event "$OK" "$ARGUMENTS"
+
+exit

+ 19 - 1
bin/v-list-sys-config

@@ -89,7 +89,14 @@ json_list() {
         "POLICY_USER_EDIT_DNS_TEMPLATES": "'$POLICY_USER_EDIT_DNS_TEMPLATES'",
         "POLICY_USER_EDIT_DNS_TEMPLATES": "'$POLICY_USER_EDIT_DNS_TEMPLATES'",
         "POLICY_USER_DELETE_LOGS": "'$POLICY_USER_DELETE_LOGS'",
         "POLICY_USER_DELETE_LOGS": "'$POLICY_USER_DELETE_LOGS'",
         "POLICY_USER_VIEW_LOGS": "'$POLICY_USER_VIEW_LOGS'",
         "POLICY_USER_VIEW_LOGS": "'$POLICY_USER_VIEW_LOGS'",
-        "POLICY_USER_CHANGE_THEME": "'$POLICY_USER_CHANGE_THEME'"
+        "POLICY_USER_CHANGE_THEME": "'$POLICY_USER_CHANGE_THEME'",
+        "USE_SERVER_SMTP": "'$USE_SERVER_SMTP'",
+        "SERVER_SMTP_HOST": "'$SERVER_SMTP_HOST'",
+        "SERVER_SMTP_PORT": "'$SERVER_SMTP_PORT'",
+        "SERVER_SMTP_SECURITY": "'$SERVER_SMTP_SECURITY'",
+        "SERVER_SMTP_USER": "'$SERVER_SMTP_USER'",
+        "SERVER_SMTP_PASSWD": "'$SERVER_SMTP_PASSWD'",
+        "SERVER_SMTP_ADDR": "'$SERVER_SMTP_ADDR'"
     }
     }
     }'
     }'
 }
 }
@@ -185,6 +192,17 @@ shell_list() {
 	echo "SMTP Relay User:                   $SMTP_RELAY_USER"
 	echo "SMTP Relay User:                   $SMTP_RELAY_USER"
     fi
     fi
 
 
+    echo "SMTP Server Account enabled:       $USE_SERVER_SMTP"
+
+    if [ ! -z "$USE_SERVER_SMTP" ] && [ "$USE_SERVER_SMTP" != 'false' ]; then
+    echo "SMTP Server Account Host:          $SERVER_SMTP_HOST"
+    echo "SMTP Server Account Port:          $SERVER_SMTP_PORT"
+    echo "SMTP Server Account Security:      $SERVER_SMTP_SECURITY"
+    echo "SMTP Server Account Username:      $SERVER_SMTP_USER"
+    echo "SMTP Server Account Password:      $SERVER_SMTP_PASSWD"
+    echo "SMTP Server Account Address:       $SERVER_SMTP_ADDR"
+    fi
+
     echo "Release Branch:                   $RELEASE_BRANCH"
     echo "Release Branch:                   $RELEASE_BRANCH"
     echo "Debug Mode:                       $DEBUG_MODE"
     echo "Debug Mode:                       $DEBUG_MODE"
     echo "Theme:                            $THEME"
     echo "Theme:                            $THEME"

+ 35 - 0
func/syshealth.sh

@@ -380,7 +380,42 @@ function syshealth_repair_system_config() {
         echo "[ ! ] Adding missing variable to hestia.conf: PHPMYADMIN_KEY ('')"
         echo "[ ! ] Adding missing variable to hestia.conf: PHPMYADMIN_KEY ('')"
         $BIN/v-change-sys-config-value "PHPMYADMIN_KEY" ""
         $BIN/v-change-sys-config-value "PHPMYADMIN_KEY" ""
     fi
     fi
+    # Use SMTP server for hestia internal mail 
+    if [ -z "$USE_SERVER_SMTP" ]; then
+        echo "[ ! ] Adding missing variable to hestia.conf: USE_SERVER_SMTP ('')"
+        $BIN/v-change-sys-config-value "USE_SERVER_SMTP" "false"
+    fi
+
+    if [ -z "$SERVER_SMTP_PORT" ]; then
+        echo "[ ! ] Adding missing variable to hestia.conf: SERVER_SMTP_PORT ('')"
+        $BIN/v-change-sys-config-value "SERVER_SMTP_PORT" ""
+    fi
+
+    if [ -z "$SERVER_SMTP_HOST" ]; then
+        echo "[ ! ] Adding missing variable to hestia.conf: SERVER_SMTP_HOST ('')"
+        $BIN/v-change-sys-config-value "SERVER_SMTP_HOST" ""
+    fi
+
+    if [ -z "$SERVER_SMTP_SECURITY" ]; then
+        echo "[ ! ] Adding missing variable to hestia.conf: SERVER_SMTP_SECURITY ('')"
+        $BIN/v-change-sys-config-value "SERVER_SMTP_SECURITY" ""
+    fi
+
+    if [ -z "$SERVER_SMTP_USER" ]; then
+        echo "[ ! ] Adding missing variable to hestia.conf: SERVER_SMTP_USER ('')"
+        $BIN/v-change-sys-config-value "SERVER_SMTP_USER" ""
+    fi
     
     
+    if [ -z "$SERVER_SMTP_PASSWD" ]; then
+        echo "[ ! ] Adding missing variable to hestia.conf: SERVER_SMTP_PASSWD ('')"
+        $BIN/v-change-sys-config-value "SERVER_SMTP_PASSWD" ""
+    fi
+        
+    if [ -z "$SERVER_SMTP_ADDR" ]; then
+        echo "[ ! ] Adding missing variable to hestia.conf: SERVER_SMTP_ADDR ('')"
+        $BIN/v-change-sys-config-value "SERVER_SMTP_ADDR" ""
+    fi    
+
 }
 }
 
 
 # Repair System Cron Jobs
 # Repair System Cron Jobs

+ 14 - 0
install/hst-install-debian.sh

@@ -1881,6 +1881,20 @@ write_config_value "POLICY_SYSTEM_ENABLE_BACON" "no"
 write_config_value "PLUGIN_APP_INSTALLER" "true"
 write_config_value "PLUGIN_APP_INSTALLER" "true"
 write_config_value "DEBUG_MODE" "no"
 write_config_value "DEBUG_MODE" "no"
 write_config_value "ENFORCE_SUBDOMAIN_OWNERSHIP" "yes"
 write_config_value "ENFORCE_SUBDOMAIN_OWNERSHIP" "yes"
+write_config_value "USE_SERVER_SMTP" "false"
+write_config_value "SERVER_SMTP_PORT" ""
+write_config_value "SERVER_SMTP_HOST" ""
+write_config_value "SERVER_SMTP_SECURITY" ""
+write_config_value "SERVER_SMTP_USER" ""
+write_config_value "SERVER_SMTP_PASSWD" ""
+write_config_value "SERVER_SMTP_ADDR" ""
+
+#----------------------------------------------------------#
+#                  Configure PHPMailer                     #
+#----------------------------------------------------------#
+
+echo "[ * ] Configuring PHPMailer..."
+$HESTIA/bin/v-add-sys-phpmailer quiet
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 #                   Hestia Access Info                     #
 #                   Hestia Access Info                     #

+ 13 - 0
install/hst-install-ubuntu.sh

@@ -1912,6 +1912,19 @@ write_config_value "POLICY_SYSTEM_ENABLE_BACON" "no"
 write_config_value "PLUGIN_APP_INSTALLER" "true"
 write_config_value "PLUGIN_APP_INSTALLER" "true"
 write_config_value "DEBUG_MODE" "no"
 write_config_value "DEBUG_MODE" "no"
 write_config_value "ENFORCE_SUBDOMAIN_OWNERSHIP" "yes"
 write_config_value "ENFORCE_SUBDOMAIN_OWNERSHIP" "yes"
+write_config_value "USE_SERVER_SMTP" "false"
+write_config_value "SERVER_SMTP_PORT" ""
+write_config_value "SERVER_SMTP_HOST" ""
+write_config_value "SERVER_SMTP_SECURITY" ""
+write_config_value "SERVER_SMTP_USER" ""
+write_config_value "SERVER_SMTP_PASSWD" ""
+write_config_value "SERVER_SMTP_ADDR" ""
+#----------------------------------------------------------#
+#                  Configure PHPMailer                     #
+#----------------------------------------------------------#
+
+echo "[ * ] Configuring PHPMailer..."
+$HESTIA/bin/v-add-sys-phpmailer quiet
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 #                   Hestia Access Info                     #
 #                   Hestia Access Info                     #

+ 81 - 0
install/upgrade/manual/configure-server-smtp.sh

@@ -0,0 +1,81 @@
+#!/bin/bash
+# info: setup SMTP Account for server logging
+# options: NONE
+# labels:
+#
+# example: configure-server-smtp.sh
+#
+# This function provides an user-interactive configuration of a SMTP account
+# for the server to use for logging, notification and warn emails etc.
+
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
+# Includes
+# shellcheck source=/usr/local/hestia/func/main.sh
+source $HESTIA/func/main.sh
+# shellcheck source=/usr/local/hestia/conf/hestia.conf
+source $HESTIA/conf/hestia.conf
+
+function setupFiles
+{
+	echo "Use SMTP account for server communication (Y/n): "
+	read use_smtp_prompt
+
+	use_smtp="${use_smtp_prompt:-y}"
+	use_smtp="${use_smtp,,}"
+	if [ "${use_smtp}" == "y" ] ; then
+		use_smtp=true
+
+		echo "Enter SMTP Host:"
+		read -i $SERVER_SMTP_HOST -e smtp_server_host
+		echo "Enter SMTP Port:"
+		read -i $SERVER_SMTP_PORT -e smtp_server_port
+		echo "Enter SMTP Security:"
+		read -i $SERVER_SMTP_SECURITY -e smtp_server_security
+		echo "Enter SMTP Username:"
+		read -i $SERVER_SMTP_USER -e smtp_server_user_name
+		echo "Enter SMTP Password (stored as plaintext):"
+		read -i $SERVER_SMTP_PASSWD -e smtp_server_password
+		echo "Enter SMTP Address:"
+		read -i $SERVER_SMTP_ADDR -e smtp_server_addr
+	else
+		use_smtp=false
+	fi
+
+	echo "Summary:
+	Use SMTP: $use_smtp
+	SMTP Host: $smtp_server_host
+	SMTP Port: $smtp_server_port
+	SMTP Security: $smtp_server_security
+	SMTP Username: $smtp_server_user_name
+	SMTP Password: $smtp_server_password
+	SMTP Address: $smtp_server_addr
+	Are these values correct? (y/N)"
+	read correct_validation
+	correct="${correct_validation:-n}"
+	correct="${correct,,}"
+	if [ "${correct}" != "y" ] ; then
+		echo "Not Proceeding. Restart or Quit (r/Q)?"
+		read restart_quit_prompt
+		restart_quit="${restart_quit_prompt:-q}"
+		restart_quit="${restart_quit,,}"
+		if [ "${restart_quit}" == "r" ] ; then
+			clear
+			setupFiles
+		else
+			exit 3
+		fi
+	else
+		$BIN/v-change-sys-config-value "USE_SERVER_SMTP" "${use_smtp:-}"
+		$BIN/v-change-sys-config-value "SERVER_SMTP_HOST" "${smtp_server_host:-}"
+		$BIN/v-change-sys-config-value "SERVER_SMTP_PORT" "${smtp_server_port:-}"
+		$BIN/v-change-sys-config-value "SERVER_SMTP_SECURITY" "${smtp_server_security:-}"
+		$BIN/v-change-sys-config-value "SERVER_SMTP_USER" "${smtp_server_user_name:-}"
+		$BIN/v-change-sys-config-value "SERVER_SMTP_PASSWD" "${smtp_server_password:-}"
+		$BIN/v-change-sys-config-value "SERVER_SMTP_ADDR" "${smtp_server_addr:-}"
+	fi
+}
+
+setupFiles

+ 3 - 0
install/upgrade/upgrade.conf

@@ -61,3 +61,6 @@ rl_v="1.16.0"
 
 
 # Set version of File manager to update during upgrade if not already installed
 # Set version of File manager to update during upgrade if not already installed
 fm_v="7.6.0"
 fm_v="7.6.0"
+
+# Set version of PHPMailer to update during upgrade if not already installed
+pm_v="6.5.0"

+ 4 - 1
install/upgrade/versions/1.4.8.sh

@@ -6,10 +6,13 @@
 #######                      Place additional commands below.                   #######
 #######                      Place additional commands below.                   #######
 #######################################################################################
 #######################################################################################
 
 
+echo "[ * ] Configuring PHPMailer..."
+$HESTIA/bin/v-add-sys-phpmailer quiet
+
 matches=$(grep -o 'ENFORCE_SUBDOMAIN_OWNERSHIP' $HESTIA/conf/hestia.conf | wc -l);
 matches=$(grep -o 'ENFORCE_SUBDOMAIN_OWNERSHIP' $HESTIA/conf/hestia.conf | wc -l);
 if [ "$matches" > 1 ]; then
 if [ "$matches" > 1 ]; then
 	echo "[ * ] Removing double matches ENFORCE_SUBDOMAIN_OWNERSHIP key"
 	echo "[ * ] Removing double matches ENFORCE_SUBDOMAIN_OWNERSHIP key"
 	source $HESTIA/conf/hestia.conf
 	source $HESTIA/conf/hestia.conf
 	sed -i "/ENFORCE_SUBDOMAIN_OWNERSHIP='$ENFORCE_SUBDOMAIN_OWNERSHIP'/d" $HESTIA/conf/hestia.conf
 	sed -i "/ENFORCE_SUBDOMAIN_OWNERSHIP='$ENFORCE_SUBDOMAIN_OWNERSHIP'/d" $HESTIA/conf/hestia.conf
 	$HESTIA/bin/v-change-sys-config-value "ENFORCE_SUBDOMAIN_OWNERSHIP" "$ENFORCE_SUBDOMAIN_OWNERSHIP"
 	$HESTIA/bin/v-change-sys-config-value "ENFORCE_SUBDOMAIN_OWNERSHIP" "$ENFORCE_SUBDOMAIN_OWNERSHIP"
-fi
+fi

+ 15 - 0
test/test.bats

@@ -1619,6 +1619,21 @@ function validate_database(){
     refute_output
     refute_output
 }
 }
 
 
+#----------------------------------------------------------#
+#                         System                           #
+#----------------------------------------------------------#
+
+@test "System: Set/Enable SMTP account for internal mail" {
+  run v-add-sys-smtp $domain 587 STARTTLS info@$domain 1234-test noreply@$domain
+  assert_success
+  refute_output
+}
+
+@test "System: Disable SMTP account for internal mail" {
+  run v-delete-sys-smtp
+  assert_success
+  refute_output
+}
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 #                         CLEANUP                          #
 #                         CLEANUP                          #

+ 3 - 2
web/add/db/index.php

@@ -89,9 +89,10 @@ if (!empty($_POST['ok'])) {
         $to = $v_db_email;
         $to = $v_db_email;
         $subject = _("Database Credentials");
         $subject = _("Database Credentials");
         $hostname = exec('hostname');
         $hostname = exec('hostname');
-        $from = sprintf(_('MAIL_FROM'),$hostname);
+        $from = "noreply@".$hostname;
+        $from_name = _('Hestia Control Panel');
         $mailtext = sprintf(_('DATABASE_READY'),$user."_".$_POST['v_database'],$user."_".$_POST['v_dbuser'],$_POST['v_password'],$db_admin_link);
         $mailtext = sprintf(_('DATABASE_READY'),$user."_".$_POST['v_database'],$user."_".$_POST['v_dbuser'],$_POST['v_password'],$db_admin_link);
-        send_email($to, $subject, $mailtext, $from);
+        send_email($to, $subject, $mailtext, $from, $from_name);
     }
     }
 
 
     // Flush field values on success
     // Flush field values on success

+ 3 - 2
web/add/mail/index.php

@@ -269,9 +269,10 @@ if (!empty($_POST['ok_acc'])) {
         $to = $v_send_email;
         $to = $v_send_email;
         $subject = _("Email Credentials");
         $subject = _("Email Credentials");
         $hostname = exec('hostname');
         $hostname = exec('hostname');
-        $from = sprintf(_('MAIL_FROM'), $hostname);
+        $from = "noreply@".$hostname;
+        $from_name = _('Hestia Control Panel');
         $mailtext = $v_credentials;
         $mailtext = $v_credentials;
-        send_email($to, $subject, $mailtext, $from);
+        send_email($to, $subject, $mailtext, $from, $from_name);
     }
     }
 
 
     // Flush field values on success
     // Flush field values on success

+ 3 - 2
web/add/user/index.php

@@ -104,7 +104,8 @@ if (!empty($_POST['ok'])) {
         $subject = _("Welcome to Hestia Control Panel");
         $subject = _("Welcome to Hestia Control Panel");
         $hostname = exec('hostname');
         $hostname = exec('hostname');
         unset($output);
         unset($output);
-        $from = sprintf(_('MAIL_FROM'),$hostname);
+        $from = "noreply@".$hostname;
+        $from_name = _('Hestia Control Panel');
 
 
         if (!empty($_POST['v_name'])) {
         if (!empty($_POST['v_name'])) {
             $mailtext = sprintf(_('GREETINGS_GORDON'),$_POST['v_name'])."\r\n";
             $mailtext = sprintf(_('GREETINGS_GORDON'),$_POST['v_name'])."\r\n";
@@ -113,7 +114,7 @@ if (!empty($_POST['ok'])) {
         }
         }
         
         
         $mailtext .= sprintf(_('ACCOUNT_READY'),$_SERVER['HTTP_HOST'],$_POST['v_username'],$_POST['v_password']);
         $mailtext .= sprintf(_('ACCOUNT_READY'),$_SERVER['HTTP_HOST'],$_POST['v_username'],$_POST['v_password']);
-        send_email($to, $subject, $mailtext, $from);
+        send_email($to, $subject, $mailtext, $from, $from_name);
         putenv("LANGUAGE=".detect_user_language());
         putenv("LANGUAGE=".detect_user_language());
     }
     }
 
 

+ 3 - 2
web/add/web/index.php

@@ -381,9 +381,10 @@ if (!empty($_POST['ok'])) {
                     if ((!empty($v_ftp_user_data['v_ftp_email'])) && (empty($_SESSION['error_msg']))) {
                     if ((!empty($v_ftp_user_data['v_ftp_email'])) && (empty($_SESSION['error_msg']))) {
                         $to = $v_ftp_user_data['v_ftp_email'];
                         $to = $v_ftp_user_data['v_ftp_email'];
                         $subject = _("FTP login credentials");
                         $subject = _("FTP login credentials");
-                        $from = sprintf(_('MAIL_FROM'), $v_domain );
+                        $from = "noreply@".$v_domain;
+                        $from_name = _('Hestia Control Panel');
                         $mailtext = sprintf(_('FTP_ACCOUNT_READY'),$v_domain,$user,$v_ftp_user_data['v_ftp_user'],$v_ftp_user_data['v_ftp_password']);
                         $mailtext = sprintf(_('FTP_ACCOUNT_READY'),$v_domain,$user,$v_ftp_user_data['v_ftp_user'],$v_ftp_user_data['v_ftp_password']);
-                        send_email($to, $subject, $mailtext, $from);
+                        send_email($to, $subject, $mailtext, $from, $from_name);
                         unset($v_ftp_email);
                         unset($v_ftp_email);
                     }
                     }
                 } else {
                 } else {

+ 3 - 2
web/edit/mail/index.php

@@ -611,9 +611,10 @@ if ((!empty($_POST['save'])) && (!empty($_GET['domain'])) && (!empty($_GET['acco
         $to = $v_send_email;
         $to = $v_send_email;
         $subject = _("Email Credentials");
         $subject = _("Email Credentials");
         $hostname = exec('hostname');
         $hostname = exec('hostname');
-        $from = sprintf(_('MAIL_FROM'), $hostname);
+        $from = "noreply@".$hostname;
+        $from_name = _('Hestia Control Panel');
         $mailtext = $v_credentials;
         $mailtext = $v_credentials;
-        send_email($to, $subject, $mailtext, $from);
+        send_email($to, $subject, $mailtext, $from, $from_name);
     }
     }
 
 
     // Set success message
     // Set success message

+ 6 - 4
web/edit/web/index.php

@@ -759,9 +759,10 @@ if (!empty($_POST['save'])) {
                         $to = $v_ftp_user_data['v_ftp_email'];
                         $to = $v_ftp_user_data['v_ftp_email'];
                         $subject = _("FTP login credentials");
                         $subject = _("FTP login credentials");
                         $hostname = exec('hostname');
                         $hostname = exec('hostname');
-                        $from = sprintf(_('MAIL_FROM'),$hostname);
+                        $from = "noreply@".$hostname;
+                        $from_name = _('Hestia Control Panel');
                         $mailtext = sprintf(_('FTP_ACCOUNT_READY'),escapeshellarg($_GET['domain']),$user,$v_ftp_username,$v_ftp_user_data['v_ftp_password']);
                         $mailtext = sprintf(_('FTP_ACCOUNT_READY'),escapeshellarg($_GET['domain']),$user,$v_ftp_username,$v_ftp_user_data['v_ftp_password']);
-                        send_email($to, $subject, $mailtext, $from);
+                        send_email($to, $subject, $mailtext, $from, $from_name);
                         unset($v_ftp_email);
                         unset($v_ftp_email);
                     }
                     }
                     unset($output);
                     unset($output);
@@ -833,9 +834,10 @@ if (!empty($_POST['save'])) {
                     $to = $v_ftp_user_data['v_ftp_email'];
                     $to = $v_ftp_user_data['v_ftp_email'];
                     $subject = _("FTP login credentials");
                     $subject = _("FTP login credentials");
                     $hostname = exec('hostname');
                     $hostname = exec('hostname');
-                    $from = _('MAIL_FROM',$hostname);
+                    $from = "noreply@".$hostname;
+                    $from_name = _('Hestia Control Panel');
                     $mailtext = _('FTP_ACCOUNT_READY',escapeshellarg($_GET['domain']),$user,$v_ftp_username_for_emailing,$v_ftp_user_data['v_ftp_password']);
                     $mailtext = _('FTP_ACCOUNT_READY',escapeshellarg($_GET['domain']),$user,$v_ftp_username_for_emailing,$v_ftp_user_data['v_ftp_password']);
-                    send_email($to, $subject, $mailtext, $from);
+                    send_email($to, $subject, $mailtext, $from, $from_name);
                     unset($v_ftp_email);
                     unset($v_ftp_email);
                 }
                 }
                 check_return_code($return_var, $output);
                 check_return_code($return_var, $output);

+ 5 - 0
web/inc/composer.json

@@ -0,0 +1,5 @@
+{
+    "require": {
+        "phpmailer/phpmailer": "^6.5"
+    }
+}

+ 95 - 0
web/inc/composer.lock

@@ -0,0 +1,95 @@
+{
+    "_readme": [
+        "This file locks the dependencies of your project to a known state",
+        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
+        "This file is @generated automatically"
+    ],
+    "content-hash": "90bbf95869b4e88bf0dc5022e708a458",
+    "packages": [
+        {
+            "name": "phpmailer/phpmailer",
+            "version": "v6.5.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/PHPMailer/PHPMailer.git",
+                "reference": "a5b5c43e50b7fba655f793ad27303cd74c57363c"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/a5b5c43e50b7fba655f793ad27303cd74c57363c",
+                "reference": "a5b5c43e50b7fba655f793ad27303cd74c57363c",
+                "shasum": ""
+            },
+            "require": {
+                "ext-ctype": "*",
+                "ext-filter": "*",
+                "ext-hash": "*",
+                "php": ">=5.5.0"
+            },
+            "require-dev": {
+                "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
+                "doctrine/annotations": "^1.2",
+                "phpcompatibility/php-compatibility": "^9.3.5",
+                "roave/security-advisories": "dev-latest",
+                "squizlabs/php_codesniffer": "^3.5.6",
+                "yoast/phpunit-polyfills": "^0.2.0"
+            },
+            "suggest": {
+                "ext-mbstring": "Needed to send email in multibyte encoding charset or decode encoded addresses",
+                "hayageek/oauth2-yahoo": "Needed for Yahoo XOAUTH2 authentication",
+                "league/oauth2-google": "Needed for Google XOAUTH2 authentication",
+                "psr/log": "For optional PSR-3 debug logging",
+                "stevenmaguire/oauth2-microsoft": "Needed for Microsoft XOAUTH2 authentication",
+                "symfony/polyfill-mbstring": "To support UTF-8 if the Mbstring PHP extension is not enabled (^1.2)"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "PHPMailer\\PHPMailer\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "LGPL-2.1-only"
+            ],
+            "authors": [
+                {
+                    "name": "Marcus Bointon",
+                    "email": "phpmailer@synchromedia.co.uk"
+                },
+                {
+                    "name": "Jim Jagielski",
+                    "email": "jimjag@gmail.com"
+                },
+                {
+                    "name": "Andy Prevost",
+                    "email": "codeworxtech@users.sourceforge.net"
+                },
+                {
+                    "name": "Brent R. Matzelle"
+                }
+            ],
+            "description": "PHPMailer is a full-featured email creation and transfer class for PHP",
+            "support": {
+                "issues": "https://github.com/PHPMailer/PHPMailer/issues",
+                "source": "https://github.com/PHPMailer/PHPMailer/tree/v6.5.0"
+            },
+            "funding": [
+                {
+                    "url": "https://github.com/Synchro",
+                    "type": "github"
+                }
+            ],
+            "time": "2021-06-16T14:33:43+00:00"
+        }
+    ],
+    "packages-dev": [],
+    "aliases": [],
+    "minimum-stability": "stable",
+    "stability-flags": [],
+    "prefer-stable": false,
+    "prefer-lowest": false,
+    "platform": [],
+    "platform-dev": [],
+    "plugin-api-version": "2.1.0"
+}

+ 3 - 2
web/inc/mail-wrapper.php

@@ -27,12 +27,13 @@ if (!empty( $data['config']['LANGUAGE'])) {
 }
 }
 
 
 // Define vars
 // Define vars
-$from = 'Hestia Control Panel <noreply@'.gethostname().'>';
+$from = 'noreply@'.gethostname();
+$from_name = _('Hestia Control Panel');
 $to = $argv[3]."\n";
 $to = $argv[3]."\n";
 $subject = $argv[2]."\n";
 $subject = $argv[2]."\n";
 $mailtext = file_get_contents("php://stdin");
 $mailtext = file_get_contents("php://stdin");
 
 
 // Send email
 // Send email
 if ((!empty($to)) && (!empty($subject))) {
 if ((!empty($to)) && (!empty($subject))) {
-    send_email($to,$subject,$mailtext,$from);
+    send_email($to,$subject,$mailtext,$from, $from_name);
 }
 }

+ 35 - 15
web/inc/main.php

@@ -1,5 +1,11 @@
 <?php
 <?php
 
 
+use PHPMailer\PHPMailer\PHPMailer;
+use PHPMailer\PHPMailer\SMTP;
+use PHPMailer\PHPMailer\Exception;
+
+require 'vendor/autoload.php';
+
 session_start();
 session_start();
 
 
 define('HESTIA_CMD', '/usr/bin/sudo /usr/local/hestia/bin/');
 define('HESTIA_CMD', '/usr/bin/sudo /usr/local/hestia/bin/');
@@ -288,21 +294,35 @@ function get_percentage($used,$total) {
     return $percent;
     return $percent;
 }
 }
 
 
-function send_email($to, $subject, $mailtext, $from) {
-    $charset = "utf-8";
-    $to = '<' . $to . '>';
-    $boundary = '--' . md5( uniqid('myboundary') );
-    $priorities = array( '1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)' );
-    $priority = $priorities[2];
-    $ctencoding = '8bit';
-    $sep = chr(13) . chr(10);
-    $disposition = 'inline';
-    $subject = "=?$charset?B?" . base64_encode($subject) . '?=';
-    $header = "From: $from \nX-Priority: $priority\nCC:\n";
-    $header .= "Mime-Version: 1.0\nContent-Type: text/plain; charset=$charset \n";
-    $header .= "Content-Transfer-Encoding: $ctencoding\nX-Mailer: Php/libMailv1.3\n";
-    $message = $mailtext;
-    mail($to, $subject, $message, $header);
+function send_email($to, $subject, $mailtext, $from, $from_name) {
+
+    $mail = new PHPMailer();
+
+    if (isset($_SESSION['USE_SERVER_SMTP']) && $_SESSION['USE_SERVER_SMTP'] == "true") {
+        $from = $_SESSION['SERVER_SMTP_ADDR'];
+
+        $mail->IsSMTP();
+        $mail->Mailer = "smtp";
+        $mail->SMTPDebug  = 0;
+        $mail->SMTPAuth   = TRUE;
+        $mail->SMTPSecure = $_SESSION['SERVER_SMTP_SECURITY'];
+        $mail->Port       = $_SESSION['SERVER_SMTP_PORT'];
+        $mail->Host       = $_SESSION['SERVER_SMTP_HOST'];
+        $mail->Username   = $_SESSION['SERVER_SMTP_USER'];
+        $mail->Password   = $_SESSION['SERVER_SMTP_PASSWD'];
+    }
+
+    $mail->IsHTML(true);
+    $mail->ClearReplyTos();
+    $mail->AddAddress($to, "Hestia Control Panel User");
+    $mail->SetFrom($from, $from_name);
+
+    $mail->Subject = $subject;
+    $content = $mailtext;
+    $mail->AltBody($content);
+    $content = nl2br($content);
+    $mail->MsgHTML($content);
+    $mail->Send();
 }
 }
 
 
 function list_timezones() {
 function list_timezones() {

+ 3 - 2
web/reset/index.php

@@ -34,7 +34,8 @@ if ((!empty($_POST['user'])) && (empty($_POST['code']))) {
             $to = $data[$user]['CONTACT'];
             $to = $data[$user]['CONTACT'];
             $subject = sprintf(_('MAIL_RESET_SUBJECT'),date("Y-m-d H:i:s"));
             $subject = sprintf(_('MAIL_RESET_SUBJECT'),date("Y-m-d H:i:s"));
             $hostname = exec('hostname');
             $hostname = exec('hostname');
-            $from = sprintf(_('MAIL_FROM'),$hostname);
+            $from = "noreply@".$hostname;
+            $from_name = _('Hestia Control Panel');
             if (!empty($name)) {
             if (!empty($name)) {
                 $mailtext = sprintf(_('GREETINGS_GORDON'),$name);
                 $mailtext = sprintf(_('GREETINGS_GORDON'),$name);
             } else {
             } else {
@@ -42,7 +43,7 @@ if ((!empty($_POST['user'])) && (empty($_POST['code']))) {
             }
             }
             if (in_array(str_replace(':'.$_SERVER['SERVER_PORT'],'.conf',$_SERVER['HTTP_HOST']), array_merge(scandir('/etc/nginx/conf.d'),scandir('/etc/nginx/conf.d/domains'),scandir('/etc/apache2/conf.d/domains'),scandir('/etc/apache2/conf.d')))){
             if (in_array(str_replace(':'.$_SERVER['SERVER_PORT'],'.conf',$_SERVER['HTTP_HOST']), array_merge(scandir('/etc/nginx/conf.d'),scandir('/etc/nginx/conf.d/domains'),scandir('/etc/apache2/conf.d/domains'),scandir('/etc/apache2/conf.d')))){
                 $mailtext .= sprintf(_('PASSWORD_RESET_REQUEST'),$_SERVER['HTTP_HOST'],$user,$rkey,$_SERVER['HTTP_HOST'],$user,$rkey);
                 $mailtext .= sprintf(_('PASSWORD_RESET_REQUEST'),$_SERVER['HTTP_HOST'],$user,$rkey,$_SERVER['HTTP_HOST'],$user,$rkey);
-                if (!empty($rkey)) send_email($to, $subject, $mailtext, $from);
+                if (!empty($rkey)) send_email($to, $subject, $mailtext, $from, $from_name);
                 header("Location: /reset/?action=code&user=".$_POST['user']);
                 header("Location: /reset/?action=code&user=".$_POST['user']);
                 exit;
                 exit;
             } else {
             } else {