Skip to content

Commit a0821ae

Browse files
authored
Merge pull request hestiacp#4349 from Anuril/fix-v-sys-add-snappymail
Fixes handling of snappymail
2 parents 0ef322d + bd3b8cf commit a0821ae

File tree

3 files changed

+107
-10
lines changed

3 files changed

+107
-10
lines changed

bin/v-add-sys-snappymail

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,26 @@ if [ "$UPDATE" == "no" ]; then
9292
exit 2
9393
fi
9494

95-
# Get current version
96-
9795
key=$(openssl rand -hex 4)
98-
96+
suffix=$(openssl rand -hex 4)
9997
admin_account="admin_$key"
10098
admin_password=$(generate_password)
10199

102100
echo "Username: admin_$key" > ~/.snappymail
103101
echo "Password: $admin_password" >> ~/.snappymail
104-
echo "Secret key: admin_$key" >> ~/.snappymail
102+
echo "Admin Panel key: admin_$suffix" >> ~/.snappymail
105103

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

108108
mv ./data $SM_CONFIG_DIR/
109109
ln -s $SM_CONFIG_DIR/data/ ./data
110110

111+
# Create cache folder and set permissions
112+
mkdir -p "$SM_CONFIG_DIR/data/_data_/_default_/cache/"
113+
chown -R www-data:www-data ./data
114+
111115
if [ -f '/usr/bin/mariadb' ]; then
112116
mariadb -e "CREATE DATABASE snappymail" 2>&1
113117
r=$(generate_password)
@@ -119,11 +123,14 @@ if [ "$UPDATE" == "no" ]; then
119123
mysql -e "GRANT ALL ON snappymail.*
120124
TO snappymail@localhost IDENTIFIED BY '$r'"
121125
fi
122-
php -f $HESTIA_COMMON_DIR/snappymail/install.php "admin_$key" "$admin_password" "$r" "$BACKEND_PORT"
123-
124-
chown -R www-data:www-data ./data
126+
# Temporarily set the permissions to www-data
125127
chown -R www-data:www-data $SM_CONFIG_DIR/
128+
php -f $HESTIA_COMMON_DIR/snappymail/install.php "admin_$key" "admin_$suffix" "$admin_password" "$r" "$BACKEND_PORT"
129+
130+
# Set the permissions back to hestiamail
131+
chown -R hestiamail:www-data $SM_CONFIG_DIR/
126132

133+
# Remove the downloaded file
127134
rm ${SM_INSTALL_DIR}/${SM_FILE}
128135
# Add robots.txt
129136
echo "User-agent: *" > $SM_INSTALL_DIR/robots.txt

bin/v-delete-sys-snappymail

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/bash
2+
# info: Delete SnappyMail webmail client
3+
# options: None
4+
#
5+
# This function removes the SnappyMail webmail client.
6+
7+
#----------------------------------------------------------#
8+
# Variables & Functions #
9+
#----------------------------------------------------------#
10+
11+
# Includes
12+
# shellcheck source=/etc/hestiacp/hestia.conf
13+
source /etc/hestiacp/hestia.conf
14+
# shellcheck source=/usr/local/hestia/func/main.sh
15+
source $HESTIA/func/main.sh
16+
# load config file
17+
source_conf "$HESTIA/conf/hestia.conf"
18+
# upgrade config file
19+
source "$HESTIA/install/upgrade/upgrade.conf"
20+
21+
# Folder paths
22+
SM_INSTALL_DIR="/var/lib/snappymail"
23+
SM_CONFIG_DIR="/etc/snappymail"
24+
SM_LOG="/var/log/snappymail"
25+
26+
#----------------------------------------------------------#
27+
# Verifications #
28+
#----------------------------------------------------------#
29+
30+
# Checking root permissions
31+
if [ "x$(id -u)" != 'x0' ]; then
32+
echo "ERROR: v-delete-sys-snappymail can only be executed by the root user"
33+
exit 10
34+
fi
35+
36+
# Ensure that $HESTIA (/usr/local/hestia/) and other variables are valid.
37+
if [ -z "$HESTIA" ]; then
38+
HESTIA="/usr/local/hestia"
39+
fi
40+
41+
if [ -z "$HOMEDIR" ] || [ -z "$HESTIA_INSTALL_DIR" ]; then
42+
echo "ERROR: Environment variables not present, uninstallation aborted."
43+
exit 2
44+
fi
45+
46+
if [ -z "$(echo "$DB_SYSTEM" | grep -w 'mysql')" ]; then
47+
echo "ERROR: Mysql not available. Uninstallation aborted"
48+
exit 2
49+
fi
50+
51+
# Get current version
52+
if [ -f "/var/lib/snappymail/data/VERSION" ]; then
53+
version=$(cat /var/lib/snappymail/data/VERSION)
54+
else
55+
echo "Error: SnappyMail is not installed"
56+
exit 2
57+
fi
58+
59+
# Perform verification if read-only mode is enabled
60+
check_hestia_demo_mode
61+
62+
#----------------------------------------------------------#
63+
# Action #
64+
#----------------------------------------------------------#
65+
66+
rm -f -r $SM_INSTALL_DIR
67+
rm -f -r $SM_CONFIG_DIR
68+
rm ~/.snappymail
69+
70+
if [ -f '/usr/bin/mariadb' ]; then
71+
mariadb -e "DROP DATABASE snappymail" 2>&1
72+
mariadb -e "DROP USER snappymail@localhost"
73+
else
74+
mysql -e "DROP DATABASE snappymail" 2>&1
75+
mysql -e "DROP USER snappymail@localhost"
76+
fi
77+
# Updating hestia.conf
78+
if [ -z "$(echo "$WEBMAIL_SYSTEM" | grep -w 'snappymail')" ]; then
79+
# remove snappymail from webmail list and make sure the string doesn't start with a comma
80+
$BIN/v-change-sys-config-value 'WEBMAIL_SYSTEM' "$(echo "$WEBMAIL_SYSTEM" | sed "s/snappymail//g" | sed 's/^,//g')"
81+
fi
82+
83+
#----------------------------------------------------------#
84+
# Hestia #
85+
#----------------------------------------------------------#
86+
87+
$BIN/v-log-action "system" "Info" "Plugins" "SnappyMail removed (Version: $version)."
88+
89+
log_event "$OK" "$ARGUMENTS"

install/common/snappymail/install.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@
77

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

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

2122
// Plugins
2223
$oConfig->Set("plugins", "enable", "On");

0 commit comments

Comments
 (0)