Skip to content

Commit b3f7597

Browse files
author
Kristan Kenney
committed
Merge branch 'staging/features' into staging/v1.2.0-release
2 parents 49fdc88 + ac81abf commit b3f7597

32 files changed

+653
-261
lines changed

bin/v-add-cron-hestia-autoupdate

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/bin/bash
22
# info: add cron job for hestia autoupdates
3-
# options: NONE
3+
# options: MODE
44
#
5-
# The function adds cronjob for hestia autoupdate.
5+
# The function adds cronjob for hestia autoupdate from apt or git.
66

77

88
#----------------------------------------------------------#
@@ -11,6 +11,7 @@
1111

1212
# Argument definition
1313
user=admin
14+
mode=$1
1415

1516
# Includes
1617
source $HESTIA/func/main.sh
@@ -24,8 +25,9 @@ source $HESTIA/conf/hestia.conf
2425
is_system_enabled "$CRON_SYSTEM" 'CRON_SYSTEM'
2526
is_package_full 'CRON_JOBS'
2627
get_next_cronjob
27-
check_cron=$(grep 'v-update-sys-hestia-all' $USER_DATA/cron.conf)
28-
if [ ! -z "$check_cron" ]; then
28+
check_cron_apt=$(grep 'v-update-sys-hestia-all' $USER_DATA/cron.conf)
29+
check_cron_git=$(grep 'v-update-sys-hestia-git' $USER_DATA/cron.conf)
30+
if [ ! -z "$check_cron_apt" ] || [ ! -z "$check_cron_git" ]; then
2931
exit
3032
fi
3133

@@ -42,13 +44,27 @@ time_n_date=$(date +'%T %F')
4244
time=$(echo "$time_n_date" |cut -f 1 -d \ )
4345
date=$(echo "$time_n_date" |cut -f 2 -d \ )
4446

47+
# Remove existing cron job
48+
$BIN/v-delete-cron-hestia-autoupdate
49+
4550
# Define time somewhere at night
46-
min=$(generate_password '012345' '2')
47-
hour=$(generate_password '1234567' '1')
48-
day='*'
49-
month='*'
50-
wday='*'
51-
command='sudo /usr/local/hestia/bin/v-update-sys-hestia-all'
51+
if [ -z "$mode" ] || [ "$mode" = "apt" ]; then
52+
min=$(generate_password '012345' '2')
53+
hour=$(generate_password '1234567' '1')
54+
day='*'
55+
month='*'
56+
wday='*'
57+
command='sudo /usr/local/hestia/bin/v-update-sys-hestia-all'
58+
fi
59+
60+
if [ "$mode" = "git" ]; then
61+
min='0'
62+
hour='0'
63+
day='*'
64+
month='*'
65+
wday='*'
66+
command='sudo /usr/local/hestia/bin/v-update-sys-hestia-git'
67+
fi
5268

5369
# Concatenating cron string
5470
str="JOB='$job' MIN='$min' HOUR='$hour' DAY='$day' MONTH='$month' WDAY='$wday'"

bin/v-add-sys-filemanager

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/bin/bash
2+
# info: add file manager functionality to Hestia Control Panel
3+
# options: none
4+
#
5+
# The function installs the File Manager on the server
6+
# for access through the Web interface.
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Includes
13+
source $HESTIA/func/main.sh
14+
source $HESTIA/conf/hestia.conf
15+
16+
MODE=$1
17+
user="admin"
18+
19+
FM_INSTALL_DIR="$HESTIA/web/fm"
20+
FM_V="7.4.1"
21+
FM_FILE="filegator_v${FM_V}.zip"
22+
FM_URL="https://github.com/filegator/filegator/releases/download/v${FM_V}/${FM_FILE}"
23+
COMPOSER_BIN="$HOMEDIR/$user/.composer/composer"
24+
25+
26+
#----------------------------------------------------------#
27+
# Verifications #
28+
#----------------------------------------------------------#
29+
30+
# Checking root permissions
31+
if [ "x$(id -u)" != 'x0' ]; then
32+
echo "ERROR: v-add-sys-filemanager can be run executed only by 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, installation aborted."
43+
exit 2
44+
fi
45+
46+
# Ensure that Composer is installed for the user before continuing as it is a dependency of the File Manager.
47+
if [ ! -f "$COMPOSER_BIN" ]; then
48+
$BIN/v-add-user-composer "$user"
49+
if [ $? -ne 0 ]; then
50+
$BIN/v-add-user-notification admin 'Composer installation failed!' '<b>The File Manager will not work without Composer.</b><br><br>Please try running the installer manually from a shell session:<br>v-add-sys-filemanager<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>.'
51+
exit 1
52+
fi
53+
fi
54+
55+
# Ensure PHP 7.3 is installed before continuing
56+
if [ ! -f "/usr/bin/php7.3" ]; then
57+
$BIN/v-add-user-notification admin 'File Manager installation failed!' '<b>Unable to proceed with installation of File Manager.</b><br><br>Package <b>php7.3-cli</b> is missing from your system. Please check your PHP installation and environment settings.'
58+
echo "ERROR: PHP 7.3 not installed on your system, aborting."
59+
exit 1
60+
fi
61+
62+
# Perform verification if read-only mode is enabled
63+
check_hestia_demo_mode
64+
65+
#----------------------------------------------------------#
66+
# Action #
67+
#----------------------------------------------------------#
68+
69+
rm --recursive --force "$FM_INSTALL_DIR"
70+
mkdir -p "$FM_INSTALL_DIR"
71+
cd "$FM_INSTALL_DIR"
72+
73+
[ ! -f "${FM_INSTALL_DIR}/${FM_FILE}" ] && wget "$FM_URL" --quiet -O "${FM_INSTALL_DIR}/${FM_FILE}"
74+
75+
unzip -qq "${FM_INSTALL_DIR}/${FM_FILE}"
76+
mv --force ${FM_INSTALL_DIR}/filegator/* "${FM_INSTALL_DIR}"
77+
rm --recursive --force ${FM_INSTALL_DIR}/filegator
78+
[[ -f "${FM_INSTALL_DIR}/${FM_FILE}" ]] && rm "${FM_INSTALL_DIR}/${FM_FILE}"
79+
80+
cp --recursive --force ${HESTIA_INSTALL_DIR}/filemanager/filegator/* "${FM_INSTALL_DIR}"
81+
82+
chown $user: -R "${FM_INSTALL_DIR}"
83+
84+
COMPOSER_HOME="$HOMEDIR/$user/.config/composer" user_exec /usr/bin/php7.3 $COMPOSER_BIN --quiet --no-dev install
85+
86+
# Check if installation was successful, if not abort script and throw error message notification and clean-up
87+
if [ $? -ne 0 ]; then
88+
echo "ERROR: File Manager installation failed!"
89+
echo "Please report this to our development team:"
90+
echo "https://github.com/hestiacp/hestiacp/issues"
91+
$BIN/v-add-user-notification admin 'File Manager 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>.'
92+
# Installation failed, clean up files
93+
rm --recursive --force ${FM_INSTALL_DIR}
94+
$BIN/v-change-sys-config-value 'FILE_MANAGER' 'false'
95+
exit 1
96+
fi
97+
98+
# Add configuration file
99+
cp -f $HESTIA_INSTALL_DIR/filemanager/filegator/configuration.php $HESTIA/web/fm/configuration.php
100+
101+
102+
# Set permissions
103+
chown root: -R "${FM_INSTALL_DIR}"
104+
chown $user: "${FM_INSTALL_DIR}/private"
105+
chown $user: "${FM_INSTALL_DIR}/private/logs"
106+
chown $user: "${FM_INSTALL_DIR}/repository"
107+
108+
$BIN/v-change-sys-config-value 'FILE_MANAGER' 'true'
109+
110+
if [ "$MODE" != "quiet" ]; then
111+
echo "File Manager is now installed and ready for use."
112+
fi
113+
114+
#----------------------------------------------------------#
115+
# Logging #
116+
#----------------------------------------------------------#
117+
118+
log_history "file manager installed" '' 'admin'
119+
log_event "$OK" "$ARGUMENTS"

bin/v-change-domain-owner

Lines changed: 88 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ if [ -z "$owner" ]; then
3232
check_result $E_NOTEXIST "domain $domain doesn't exist"
3333
fi
3434
if [ "$owner" = "$user" ]; then
35+
echo "ERROR: $domain is already owned by $user."
3536
exit
3637
fi
3738

@@ -43,9 +44,12 @@ check_hestia_demo_mode
4344
# Action #
4445
#----------------------------------------------------------#
4546

47+
echo "Moving $domain from $owner to $user, please wait..."
48+
4649
# WEB domain
4750
web_data=$(grep "DOMAIN='$domain'" $HESTIA/data/users/$owner/web.conf)
4851
if [ ! -z "$web_data" ]; then
52+
echo "[*] Moving web domain..."
4953
$BIN/v-suspend-web-domain $owner $domain >> /dev/null 2>&1
5054
parse_object_kv_list "$web_data"
5155

@@ -95,6 +99,7 @@ fi
9599
# DNS domain
96100
dns_data=$(grep "DOMAIN='$domain'" $HESTIA/data/users/$owner/dns.conf)
97101
if [ ! -z "$dns_data" ]; then
102+
echo "[*] Moving DNS zone and records..."
98103
parse_object_kv_list "$dns_data"
99104

100105
# Change IP
@@ -125,6 +130,14 @@ fi
125130
# MAIL domain
126131
mail_data=$(grep "DOMAIN='$domain'" $HESTIA/data/users/$owner/mail.conf)
127132
if [ ! -z "$mail_data" ]; then
133+
echo "[*] Moving mail domain and accounts..."
134+
135+
parse_object_kv_list "$mail_data"
136+
137+
# Ensure mail configuration directory exists for receiving user
138+
if [ ! -e "$HOMEDIR/$user/conf/mail/$domain/" ]; then
139+
mkdir -p $HOMEDIR/$user/conf/mail/$domain/
140+
fi
128141

129142
# Move config
130143
sed -i "/DOMAIN='$domain'/d" $HESTIA/data/users/$owner/mail.conf
@@ -140,18 +153,63 @@ if [ ! -z "$mail_data" ]; then
140153
$HESTIA/data/users/$user/mail/
141154
fi
142155

156+
# Move SSL certificates
157+
if [ "$SSL" = 'yes' ]; then
158+
# Ensure that SSL directory exists and move certificates
159+
mkdir -p $HESTIA/data/users/$user/ssl/
160+
mkdir -p $HOMEDIR/$user/conf/mail/$domain/ssl/
161+
162+
ssl_crt=$HESTIA/data/users/$owner/ssl/mail.$domain.crt
163+
ssl_key=$HESTIA/data/users/$owner/ssl/mail.$domain.key
164+
ssl_ca=$HESTIA/data/users/$owner/ssl/mail.$domain.ca
165+
ssl_pem=$HESTIA/data/users/$owner/ssl/mail.$domain.pem
166+
mv $ssl_crt $HESTIA/data/users/$user/ssl/
167+
mv $ssl_key $HESTIA/data/users/$user/ssl/
168+
mv $ssl_ca $HESTIA/data/users/$user/ssl/ >> /dev/null 2>&1
169+
mv $ssl_pem $HESTIA/data/users/$user/ssl/ >> /dev/null 2>&1
170+
171+
# Add certificate to user home directory
172+
cp -f $HESTIA/data/users/$user/ssl/mail.$domain.crt $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.crt
173+
cp -f $HESTIA/data/users/$user/ssl/mail.$domain.key $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.key
174+
cp -f $HESTIA/data/users/$user/ssl/mail.$domain.pem $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.pem
175+
if [ -e "$HESTIA/data/users/$user/ssl/mail.$domain.ca" ]; then
176+
cp -f $HESTIA/data/users/$user/ssl/mail.$domain.ca $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.ca
177+
fi
178+
179+
# Add domain SSL configuration to dovecot
180+
if [ -f /etc/dovecot/conf.d/domains/$domain.conf ]; then
181+
rm -f /etc/dovecot/conf.d/domains/$domain.conf
182+
fi
183+
184+
echo "" >> /etc/dovecot/conf.d/domains/$domain.conf
185+
echo "local_name mail.$domain {" >> /etc/dovecot/conf.d/domains/$domain.conf
186+
echo " ssl_cert = <$HOMEDIR/$user/conf/mail/$domain/ssl/$domain.pem" >> /etc/dovecot/conf.d/domains/$domain.conf
187+
echo " ssl_key = <$HOMEDIR/$user/conf/mail/$domain/ssl/$domain.key" >> /etc/dovecot/conf.d/domains/$domain.conf
188+
echo "}" >> /etc/dovecot/conf.d/domains/$domain.conf
189+
190+
# Add domain SSL configuration to exim4
191+
# Cleanup symlinks
192+
find /usr/local/hestia/ssl/mail -xtype l -delete
193+
194+
ln -s -f $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.pem /usr/local/hestia/ssl/mail/mail.$domain.crt
195+
ln -s -f $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.key /usr/local/hestia/ssl/mail/mail.$domain.key
196+
197+
# Set correct permissions on certificates
198+
chmod 750 $HOMEDIR/$user/conf/mail/$domain/ssl
199+
chown -R $MAIL_USER:mail $HOMEDIR/$user/conf/mail/$domain/ssl
200+
chmod 0644 $HOMEDIR/$user/conf/mail/$domain/ssl/*
201+
chown -h $user:mail $HOMEDIR/$user/conf/mail/$domain/ssl/*
202+
chmod -R 0644 /usr/local/hestia/ssl/mail/*
203+
chown -h $user:mail /usr/local/hestia/ssl/mail/*
204+
fi
205+
143206
# Move data
144207
mv $HOMEDIR/$owner/mail/$domain $HOMEDIR/$user/mail/
145208

146209
# Change ownership
147210
find $HOMEDIR/$user/mail/$domain -user $owner \
148211
-exec chown -h $user {} \;
149212

150-
# Rebuild config
151-
$BIN/v-unsuspend-mail-domain $user $domain no >> /dev/null 2>&1
152-
$BIN/v-rebuild-mail-domains $owner no
153-
$BIN/v-rebuild-mail-domains $user
154-
155213
# Checking exim username for later chowning
156214
exim_user="exim";
157215
check_exim_username=$(grep -c '^Debian-exim:' /etc/passwd)
@@ -163,18 +221,43 @@ if [ ! -z "$mail_data" ]; then
163221
find $HOMEDIR/$user/conf/mail/$domain -user root \
164222
-exec chown $exim_user {} \;
165223
fi
224+
225+
# Remove old mail directory from original owner
226+
if [ -e "$HOMEDIR/$owner/mail/$domain" ]; then
227+
rm -rf "$HOMEDIR/$owner/mail/$domain"
228+
fi
229+
230+
# Remove old mail configuration directory from original owner
231+
if [ -e "$HOMEDIR/$owner/conf/mail/$domain" ]; then
232+
rm -rf "$HOMEDIR/$owner/conf/mail/$domain"
233+
fi
234+
if [ -e "$HESTIA/data/users/$owner/mail/$domain.conf" ]; then
235+
rm -f "$HESTIA/data/users/$owner/mail/$domain.conf"
236+
fi
237+
238+
# Rebuild config
239+
$BIN/v-unsuspend-mail-domain $user $domain no >> /dev/null 2>&1
240+
$BIN/v-rebuild-mail-domains $owner no
241+
$BIN/v-rebuild-mail-domains $user
166242
fi
167243

168244
# Update counters
169245
$BIN/v-update-user-counters $owner
170246
$BIN/v-update-user-counters $user
171247

248+
# Send notification to panel
249+
if [ ! -z "$web_data" ] || [ ! -z "$dns_data" ] || [ ! -z "$mail_data" ]; then
250+
$HESTIA/bin/v-add-user-notification "$user" "$domain has been added to your account" ''
251+
fi
172252

173253
#----------------------------------------------------------#
174254
# Hestia #
175255
#----------------------------------------------------------#
176256

177257
# Logging
258+
log_history "moved domain $domain from $owner to $user" '' "admin"
259+
log_history "$domain was added to your account" '' "$user"
260+
log_history "$domain was removed from your account" '' "$owner"
178261
log_event "$OK" "$ARGUMENTS"
179262

180263
exit

bin/v-change-sys-release

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@ if [ -z "$branch" ]; then
3535
echo "Error: no release branch specified."
3636
echo "Usage: v-change-sys-release branchname"
3737
echo ""
38-
echo "Common release branches:"
39-
echo "(*) release: The latest stable release available via APT"
40-
echo "(*) prerelease: Beta/release candidate releases"
41-
echo "(*) master: The latest development code from GitHub"
38+
echo "Release branches:"
39+
echo "- release: the latest stable release"
40+
echo "- beta: beta and release candidate test releases"
41+
echo "- develop: unstable development builds"
42+
echo ""
43+
echo "Integration branches (not tied to a specific release/version):"
44+
echo "- staging/fixes: contains new fixes since the last release."
45+
echo "- staging/features: contains new features since the last release."
4246
echo ""
4347
echo "You can also specify another branch name from the"
4448
echo "GitHub repository to install the code from that branch."
@@ -58,7 +62,7 @@ else
5862

5963
# Set new branch variable
6064
echo "RELEASE_BRANCH='$branch'" >> $HESTIA/conf/hestia.conf
61-
echo "Changed system release to update from branch: $branch"
65+
echo "Updated system to update from Git using branch: $branch"
6266
fi
6367

6468
#----------------------------------------------------------#

bin/v-delete-cron-hestia-autoupdate

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ source $HESTIA/conf/hestia.conf
2222
#----------------------------------------------------------#
2323

2424
is_system_enabled "$CRON_SYSTEM" 'CRON_SYSTEM'
25-
check_cron=$(grep 'v-update-sys-hestia-all' $USER_DATA/cron.conf)
26-
if [ -z "$check_cron" ]; then
27-
exit
28-
fi
25+
check_cron_apt=$(grep 'v-update-sys-hestia-all' $USER_DATA/cron.conf)
26+
check_cron_git=$(grep 'v-update-sys-hestia-git' $USER_DATA/cron.conf)
2927

3028
# Perform verification if read-only mode is enabled
3129
check_hestia_demo_mode
@@ -37,7 +35,13 @@ check_hestia_demo_mode
3735

3836

3937
# Deleting job
40-
job=$(echo $check_cron|tr ' ' "\n"|grep JOB|cut -f 2 -d "'")
38+
if [ ! -z "$check_cron_apt" ]; then
39+
job=$(echo $check_cron_apt|tr ' ' "\n"|grep JOB|cut -f 2 -d "'")
40+
fi
41+
if [ ! -z "$check_cron_git" ]; then
42+
job=$(echo $check_cron_git|tr ' ' "\n"|grep JOB|cut -f 2 -d "'")
43+
fi
44+
4145
sed -i "/JOB='$job' /d" $USER_DATA/cron.conf
4246

4347
# Sorting jobs by id

0 commit comments

Comments
 (0)