Skip to content

Commit

Permalink
Merge pull request hestiacp#4349 from Anuril/fix-v-sys-add-snappymail
Browse files Browse the repository at this point in the history
Fixes handling of snappymail
  • Loading branch information
jaapmarcus authored Apr 4, 2024
2 parents 0ef322d + bd3b8cf commit a0821ae
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 10 deletions.
21 changes: 14 additions & 7 deletions bin/v-add-sys-snappymail
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,26 @@ if [ "$UPDATE" == "no" ]; then
exit 2
fi

# Get current version

key=$(openssl rand -hex 4)

suffix=$(openssl rand -hex 4)
admin_account="admin_$key"
admin_password=$(generate_password)

echo "Username: admin_$key" > ~/.snappymail
echo "Password: $admin_password" >> ~/.snappymail
echo "Secret key: admin_$key" >> ~/.snappymail
echo "Admin Panel key: admin_$suffix" >> ~/.snappymail

tar -xzf ${SM_INSTALL_DIR}/${SM_FILE}
# Get current version
version=$(cat ./data/VERSION)

mv ./data $SM_CONFIG_DIR/
ln -s $SM_CONFIG_DIR/data/ ./data

# Create cache folder and set permissions
mkdir -p "$SM_CONFIG_DIR/data/_data_/_default_/cache/"
chown -R www-data:www-data ./data

if [ -f '/usr/bin/mariadb' ]; then
mariadb -e "CREATE DATABASE snappymail" 2>&1
r=$(generate_password)
Expand All @@ -119,11 +123,14 @@ if [ "$UPDATE" == "no" ]; then
mysql -e "GRANT ALL ON snappymail.*
TO snappymail@localhost IDENTIFIED BY '$r'"
fi
php -f $HESTIA_COMMON_DIR/snappymail/install.php "admin_$key" "$admin_password" "$r" "$BACKEND_PORT"

chown -R www-data:www-data ./data
# Temporarily set the permissions to www-data
chown -R www-data:www-data $SM_CONFIG_DIR/
php -f $HESTIA_COMMON_DIR/snappymail/install.php "admin_$key" "admin_$suffix" "$admin_password" "$r" "$BACKEND_PORT"

# Set the permissions back to hestiamail
chown -R hestiamail:www-data $SM_CONFIG_DIR/

# Remove the downloaded file
rm ${SM_INSTALL_DIR}/${SM_FILE}
# Add robots.txt
echo "User-agent: *" > $SM_INSTALL_DIR/robots.txt
Expand Down
89 changes: 89 additions & 0 deletions bin/v-delete-sys-snappymail
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/bin/bash
# info: Delete SnappyMail webmail client
# options: None
#
# This function removes the SnappyMail webmail client.

#----------------------------------------------------------#
# Variables & Functions #
#----------------------------------------------------------#

# Includes
# shellcheck source=/etc/hestiacp/hestia.conf
source /etc/hestiacp/hestia.conf
# shellcheck source=/usr/local/hestia/func/main.sh
source $HESTIA/func/main.sh
# load config file
source_conf "$HESTIA/conf/hestia.conf"
# upgrade config file
source "$HESTIA/install/upgrade/upgrade.conf"

# Folder paths
SM_INSTALL_DIR="/var/lib/snappymail"
SM_CONFIG_DIR="/etc/snappymail"
SM_LOG="/var/log/snappymail"

#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#

# Checking root permissions
if [ "x$(id -u)" != 'x0' ]; then
echo "ERROR: v-delete-sys-snappymail can only be executed by the 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, uninstallation aborted."
exit 2
fi

if [ -z "$(echo "$DB_SYSTEM" | grep -w 'mysql')" ]; then
echo "ERROR: Mysql not available. Uninstallation aborted"
exit 2
fi

# Get current version
if [ -f "/var/lib/snappymail/data/VERSION" ]; then
version=$(cat /var/lib/snappymail/data/VERSION)
else
echo "Error: SnappyMail is not installed"
exit 2
fi

# Perform verification if read-only mode is enabled
check_hestia_demo_mode

#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#

rm -f -r $SM_INSTALL_DIR
rm -f -r $SM_CONFIG_DIR
rm ~/.snappymail

if [ -f '/usr/bin/mariadb' ]; then
mariadb -e "DROP DATABASE snappymail" 2>&1
mariadb -e "DROP USER snappymail@localhost"
else
mysql -e "DROP DATABASE snappymail" 2>&1
mysql -e "DROP USER snappymail@localhost"
fi
# Updating hestia.conf
if [ -z "$(echo "$WEBMAIL_SYSTEM" | grep -w 'snappymail')" ]; then
# remove snappymail from webmail list and make sure the string doesn't start with a comma
$BIN/v-change-sys-config-value 'WEBMAIL_SYSTEM' "$(echo "$WEBMAIL_SYSTEM" | sed "s/snappymail//g" | sed 's/^,//g')"
fi

#----------------------------------------------------------#
# Hestia #
#----------------------------------------------------------#

$BIN/v-log-action "system" "Info" "Plugins" "SnappyMail removed (Version: $version)."

log_event "$OK" "$ARGUMENTS"
7 changes: 4 additions & 3 deletions install/common/snappymail/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@

// Change default login data / key
$oConfig->Set("security", "admin_login", $argv[1]);
$oConfig->Set("security", "admin_panel_key", $argv[1]);
$oConfig->SetPassword($argv[2]);
$oConfig->Set("security", "admin_panel_key", $argv[2]);
$newPassword = new \SnappyMail\SensitiveString($argv[3]);
$oConfig->SetPassword($newPassword);

// Allow Contacts to be saved in database
$oConfig->Set("contacts", "enable", "On");
$oConfig->Set("contacts", "allow_sync", "On");
$oConfig->Set("contacts", "type", "mysql");
$oConfig->Set("contacts", "pdo_dsn", "mysql:host=127.0.0.1;port=3306;dbname=snappymail");
$oConfig->Set("contacts", "pdo_user", "snappymail");
$oConfig->Set("contacts", "pdo_password", $argv[3]);
$oConfig->Set("contacts", "pdo_password", $argv[4]);

// Plugins
$oConfig->Set("plugins", "enable", "On");
Expand Down

0 comments on commit a0821ae

Please sign in to comment.