|
| 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" |
0 commit comments