Skip to content

Commit 2d190af

Browse files
Update all non-major dependencies (hestiacp#4158)
* Update all non-major dependencies * Add v-generate-password-hash to ignore list * Run npm format again --------- Co-authored-by: Jaap Marcus <9754650+jaapmarcus@users.noreply.github.com>
1 parent 7a09373 commit 2d190af

15 files changed

+214
-219
lines changed

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
# Bats seems to break Prettier
1818
*.bats
1919

20+
# Bin folder
21+
/bin/v-generate-password-hash
22+
2023
# Exclude bats submodules if present
2124
/test/test_helper/*
2225

bin/v-add-backup-host

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ if [ "$type" = 'sftp' ]; then
246246
case $rc in
247247
$E_CONNECT) echo "Error: can't login to sftp $user@$host" ;;
248248
$E_FTP) echo "Error: can't create temp folder on the sftp host" ;;
249-
*) echo "Error Unable to connect via sftp.";;
249+
*) echo "Error Unable to connect via sftp." ;;
250250
esac
251251
log_event "$rc" "$ARGUMENTS"
252252
exit "$rc"

bin/v-add-sys-quota

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if ! find "/lib/modules/$(uname -r)" -type f -name '*quota_v*.ko*' | grep -q '.*
3232
fi
3333

3434
# Checking quota package
35-
if ! type -P quota &>/dev/null; then
35+
if ! type -P quota &> /dev/null; then
3636
if [ -f "/etc/redhat-release" ]; then
3737
dnf -y install quota > /dev/null 2>&1
3838
else

bin/v-change-sys-hostname

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -37,58 +37,58 @@ check_hestia_demo_mode
3737

3838
current_hostname="$(hostname)"
3939
if [[ "$current_hostname" == "$domain" ]]; then
40-
echo "Current hostname \"$current_hostname\" is the same as the new one you want to use"
41-
echo "I'm not going to change it"
42-
exit
40+
echo "Current hostname \"$current_hostname\" is the same as the new one you want to use"
41+
echo "I'm not going to change it"
42+
exit
4343
fi
4444

4545
hostname "$domain"
4646
if [ -d "/etc/sysconfig" ]; then
47-
# RHEL/CentOS/Amazon
48-
touch /etc/sysconfig/network
49-
if [ -z "$(grep HOSTNAME /etc/sysconfig/network)" ]; then
50-
echo "HOSTNAME='$domain'" >>/etc/sysconfig/network
51-
else
52-
sed -i "s/HOSTNAME=.*/HOSTNAME='$domain'/" /etc/sysconfig/network
53-
fi
47+
# RHEL/CentOS/Amazon
48+
touch /etc/sysconfig/network
49+
if [ -z "$(grep HOSTNAME /etc/sysconfig/network)" ]; then
50+
echo "HOSTNAME='$domain'" >> /etc/sysconfig/network
51+
else
52+
sed -i "s/HOSTNAME=.*/HOSTNAME='$domain'/" /etc/sysconfig/network
53+
fi
5454
else
55-
# Debian/Ubuntu
56-
hostnamectl set-hostname "$domain"
57-
echo "$domain" >/etc/hostname
55+
# Debian/Ubuntu
56+
hostnamectl set-hostname "$domain"
57+
echo "$domain" > /etc/hostname
5858
fi
5959

6060
# Update webmail's password plugin configuration
6161
if [ -d /etc/roundcube/ ]; then
62-
sed -i "/password_hestia_host/c\$rcmail_config['password_hestia_host'] = '$domain';" /etc/roundcube/plugins/password/config.inc.php
62+
sed -i "/password_hestia_host/c\$rcmail_config['password_hestia_host'] = '$domain';" /etc/roundcube/plugins/password/config.inc.php
6363
fi
6464
if [ -d /etc/rainloop/ ]; then
65-
sed -i "/hestia_host/c\hestia_host = \"$domain\"" /etc/rainloop/data/_data_/_default_/configs/plugin-hestia-change-password.ini
65+
sed -i "/hestia_host/c\hestia_host = \"$domain\"" /etc/rainloop/data/_data_/_default_/configs/plugin-hestia-change-password.ini
6666
fi
6767
if [ -d /etc/snappymail/ ]; then
68-
sed -i "/\"hestia_host\":/c\\\"hestia_host\": \"$domain\"," /etc/snappymail/data/_data_/_default_/configs/plugin-change-password.json
68+
sed -i "/\"hestia_host\":/c\\\"hestia_host\": \"$domain\"," /etc/snappymail/data/_data_/_default_/configs/plugin-change-password.json
6969
fi
7070

7171
# Update /etc/hosts
7272
if [ -f /etc/hosts ]; then
73-
if grep -q -E "^127\.0\.0\.1\s{1,}${current_hostname}$" /etc/hosts; then
74-
sed -i -E "s/127\.0\.0\.1\s{1,}${current_hostname}/127\.0\.0\.1 ${domain}/" /etc/hosts
75-
else
76-
echo "127.0.0.1 $domain" >>/etc/hosts
77-
fi
78-
# Check whether hostname entries are duplicated and remove all but the last one
79-
ndup_hosts="$(grep -c -E "^127\.0\.0\.1\s{1,}${domain}$" /etc/hosts)"
80-
if [[ "${ndup_hosts}" -gt "1" ]]; then
81-
nlines_to_del="$((ndup_hosts - 1))"
82-
lines_to_del="$(grep -n -E "^127\.0\.0\.1\s{1,}${domain}$" /etc/hosts | head -n${nlines_to_del} | awk -F ':' '{print $1}')"
83-
for i in $lines_to_del; do
84-
if [[ -z $list_lines ]]; then
85-
list_lines="${i}d"
86-
else
87-
list_lines+=";${i}d"
88-
fi
89-
done
90-
sed -i "${list_lines}" /etc/hosts
91-
fi
73+
if grep -q -E "^127\.0\.0\.1\s{1,}${current_hostname}$" /etc/hosts; then
74+
sed -i -E "s/127\.0\.0\.1\s{1,}${current_hostname}/127\.0\.0\.1 ${domain}/" /etc/hosts
75+
else
76+
echo "127.0.0.1 $domain" >> /etc/hosts
77+
fi
78+
# Check whether hostname entries are duplicated and remove all but the last one
79+
ndup_hosts="$(grep -c -E "^127\.0\.0\.1\s{1,}${domain}$" /etc/hosts)"
80+
if [[ "${ndup_hosts}" -gt "1" ]]; then
81+
nlines_to_del="$((ndup_hosts - 1))"
82+
lines_to_del="$(grep -n -E "^127\.0\.0\.1\s{1,}${domain}$" /etc/hosts | head -n${nlines_to_del} | awk -F ':' '{print $1}')"
83+
for i in $lines_to_del; do
84+
if [[ -z $list_lines ]]; then
85+
list_lines="${i}d"
86+
else
87+
list_lines+=";${i}d"
88+
fi
89+
done
90+
sed -i "${list_lines}" /etc/hosts
91+
fi
9292
fi
9393

9494
#----------------------------------------------------------#

bin/v-delete-sys-quota

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ if [ -n "$(echo $opt | grep $fnd)" ]; then
4242
fi
4343

4444
# Disabling group and user quota
45-
if quotaon="$(type -P quotaon 2>/dev/null)" && quotaoff="$(type -P quotaoff 2>/dev/null)"; then
46-
if "${quotaon}" -pa | grep " $mnt " | grep 'user\|group' | grep -q 'is on' &>/dev/null; then
45+
if quotaon="$(type -P quotaon 2> /dev/null)" && quotaoff="$(type -P quotaoff 2> /dev/null)"; then
46+
if "${quotaon}" -pa | grep " $mnt " | grep 'user\|group' | grep -q 'is on' &> /dev/null; then
4747
"$quotaoff" "$mnt"
4848
fi
4949
fi
@@ -55,10 +55,10 @@ done
5555

5656
# Deleting cron job and forcequotacheck
5757
if [[ -f "/etc/cron.daily/quotacheck" ]]; then
58-
rm -f "/etc/cron.daily/quotacheck"
58+
rm -f "/etc/cron.daily/quotacheck"
5959
fi
6060
if [[ -f "/forcequotacheck" ]]; then
61-
rm -f "/forcequotacheck"
61+
rm -f "/forcequotacheck"
6262
fi
6363

6464
# Updating hestia.conf value

bin/v-dump-site

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,3 @@ fi
6767
log_event "$OK" "$ARGUMENTS"
6868

6969
exit
70-

bin/v-export-rrd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ elif [ "$timespan" = "yearly" ]; then
133133
start=$(date -d "1 year ago" +%s)
134134
step=172800
135135
elif [ "$timespan" = "biennially" ]; then
136-
start=$(date -d "2 year ago" +%s)
137-
step=345600
136+
start=$(date -d "2 year ago" +%s)
137+
step=345600
138138
elif [ "$timespan" = "triennially" ]; then
139-
start=$(date -d "3 year ago" +%s)
140-
step=518400
139+
start=$(date -d "3 year ago" +%s)
140+
step=518400
141141
else
142142
start=$(date -d "1 day ago" +%s)
143143
# every 5min

bin/v-import-cpanel

Lines changed: 60 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ fi
107107
# Extract cPanel package name
108108
cpanel_package_name=$(cat ./cp/$new_user | grep 'PLAN=' | cut -f2 -d'=')
109109
if /usr/local/hestia/bin/v-list-user-packages | grep -qw "$cpanel_package_name"; then
110-
hestia_package="$cpanel_package_name"
111-
echo "Package $hestia_package will be used for the user."
110+
hestia_package="$cpanel_package_name"
111+
echo "Package $hestia_package will be used for the user."
112112
else
113-
hestia_package="default" # Replace "default" with your default Hestia package name
114-
echo "Default package $hestia_package will be used for the user."
113+
hestia_package="default" # Replace "default" with your default Hestia package name
114+
echo "Default package $hestia_package will be used for the user."
115115
fi
116116

117117
# Create a new user
@@ -258,18 +258,18 @@ CPANEL_PHP_VERSION=$(echo $CPANEL_PHP_VERSION | grep -oP '(?<=php)\d+')
258258
HESTIA_PHP_VERSION="PHP-${CPANEL_PHP_VERSION:0:1}_${CPANEL_PHP_VERSION:1}"
259259

260260
if $BIN/v-list-web-templates-backend | grep -qw "$HESTIA_PHP_VERSION"; then
261-
echo "Setting PHP version to $HESTIA_PHP_VERSION for $main_domain1 under user $new_user"
262-
$BIN/v-change-web-domain-backend-tpl $new_user $main_domain1 $HESTIA_PHP_VERSION
263-
if [ $? -ne 0 ]; then
264-
echo "Failed to set PHP version for $main_domain1"
265-
exit 1
266-
else
267-
echo "PHP version for $main_domain1 set to $HESTIA_PHP_VERSION"
268-
fi
261+
echo "Setting PHP version to $HESTIA_PHP_VERSION for $main_domain1 under user $new_user"
262+
$BIN/v-change-web-domain-backend-tpl $new_user $main_domain1 $HESTIA_PHP_VERSION
263+
if [ $? -ne 0 ]; then
264+
echo "Failed to set PHP version for $main_domain1"
265+
exit 1
266+
else
267+
echo "PHP version for $main_domain1 set to $HESTIA_PHP_VERSION"
268+
fi
269269
else
270-
echo "PHP version $HESTIA_PHP_VERSION is not installed on HestiaCP."
271-
echo "Please install it before trying to set it for a domain."
272-
exit 1
270+
echo "PHP version $HESTIA_PHP_VERSION is not installed on HestiaCP."
271+
echo "Please install it before trying to set it for a domain."
272+
exit 1
273273
fi
274274

275275
##################
@@ -286,12 +286,12 @@ for folder in *; do
286286
echo "Domain: $folder"
287287
cd $folder
288288

289-
mail_account_count=$(find . -maxdepth 1 -mindepth 1 -type d \( ! -name cur ! -name new ! -name tmp \) | wc -l)
290-
if [ "$mail_account_count" -eq 0 ]; then
291-
echo "No mail accounts to restore for domain $folder."
292-
cd ..
293-
continue
294-
fi
289+
mail_account_count=$(find . -maxdepth 1 -mindepth 1 -type d \( ! -name cur ! -name new ! -name tmp \) | wc -l)
290+
if [ "$mail_account_count" -eq 0 ]; then
291+
echo "No mail accounts to restore for domain $folder."
292+
cd ..
293+
continue
294+
fi
295295

296296
for mail_account in *; do
297297
echo "Import mail account: $mail_account@$folder"
@@ -302,40 +302,40 @@ for folder in *; do
302302
chown -R $new_user:mail /home/$new_user/mail/$folder/
303303

304304
# Decompress gzipped emails
305-
decompressed_count=0
306-
for mail_file in $(find /home/$new_user/mail/$folder -type f); do
307-
if file "$mail_file" | grep -q "gzip compressed"; then
308-
original_time=$(stat -c %y "$mail_file" 2>/dev/null)
309-
gunzip -c "$mail_file" > "${mail_file}.decompressed" && mv "${mail_file}.decompressed" "$mail_file"
310-
if [ ! -z "$original_time" ]; then
305+
decompressed_count=0
306+
for mail_file in $(find /home/$new_user/mail/$folder -type f); do
307+
if file "$mail_file" | grep -q "gzip compressed"; then
308+
original_time=$(stat -c %y "$mail_file" 2> /dev/null)
309+
gunzip -c "$mail_file" > "${mail_file}.decompressed" && mv "${mail_file}.decompressed" "$mail_file"
310+
if [ ! -z "$original_time" ]; then
311311
touch -d "$original_time" "$mail_file"
312-
fi
312+
fi
313313
let decompressed_count++
314-
fi
315-
done
314+
fi
315+
done
316+
317+
echo "$decompressed_count emails decompressed for $mail_account@$folder"
316318

317-
echo "$decompressed_count emails decompressed for $mail_account@$folder"
318-
319319
find /home/$new_user/mail/$folder -type f -name 'dovecot*' -delete
320320

321321
# Extract and update password from the shadow file
322322
password_file="../../etc/${folder}/shadow"
323323
if [ -f "$password_file" ]; then
324-
pass_line=$(grep "^$mail_account:" $password_file)
325-
if [ $? -eq 0 ]; then
326-
# Extract the hashed password from the shadow file
327-
pass=$(echo "$pass_line" | awk -F ":" '{print $2}')
328-
newline="${mail_account}:{SHA512-CRYPT}$pass:${new_user}:mail::/home/${new_user}:0"
329-
newline2="ACCOUNT='${mail_account}' ALIAS='' AUTOREPLY='no' FWD='' FWD_ONLY='' MD5='{SHA512-CRYPT}$pass' QUOTA='unlimited' U_DISK='0' SUSPENDED='no' TIME='$time' DATE='$date'"
330-
escaped=$(printf '%s\n' "$newline" | sed -e 's/[\/&]/\\&/g')
331-
escaped2=$(printf '%s\n' "$newline2" | sed -e 's/[\/&]/\\&/g')
332-
sed -i "s/^${mail_account}:.*/$escaped/g" /home/${new_user}/conf/mail/${folder}/passwd
333-
sed -i "s/^ACCOUNT='${mail_account}.*/$escaped2/g" /usr/local/hestia/data/users/${new_user}/mail/${folder}.conf
334-
else
335-
echo "Warning: Password for $mail_account@$folder not found in shadow file."
336-
fi
324+
pass_line=$(grep "^$mail_account:" $password_file)
325+
if [ $? -eq 0 ]; then
326+
# Extract the hashed password from the shadow file
327+
pass=$(echo "$pass_line" | awk -F ":" '{print $2}')
328+
newline="${mail_account}:{SHA512-CRYPT}$pass:${new_user}:mail::/home/${new_user}:0"
329+
newline2="ACCOUNT='${mail_account}' ALIAS='' AUTOREPLY='no' FWD='' FWD_ONLY='' MD5='{SHA512-CRYPT}$pass' QUOTA='unlimited' U_DISK='0' SUSPENDED='no' TIME='$time' DATE='$date'"
330+
escaped=$(printf '%s\n' "$newline" | sed -e 's/[\/&]/\\&/g')
331+
escaped2=$(printf '%s\n' "$newline2" | sed -e 's/[\/&]/\\&/g')
332+
sed -i "s/^${mail_account}:.*/$escaped/g" /home/${new_user}/conf/mail/${folder}/passwd
333+
sed -i "s/^ACCOUNT='${mail_account}.*/$escaped2/g" /usr/local/hestia/data/users/${new_user}/mail/${folder}.conf
334+
else
335+
echo "Warning: Password for $mail_account@$folder not found in shadow file."
336+
fi
337337
else
338-
echo "Warning: Shadow file for $folder not found."
338+
echo "Warning: Shadow file for $folder not found."
339339
fi
340340
done
341341
cd ..
@@ -377,24 +377,23 @@ cd "$CRON_DIR"
377377

378378
CRON_FILE="${new_user}"
379379
if [ -f "$CRON_FILE" ] && [ -s "$CRON_FILE" ]; then
380-
while IFS= read -r cron_job || [ -n "$cron_job" ]; do
381-
[[ "$cron_job" =~ ^(#.*|\s*|MAILTO=.*|SHELL=.*)$ ]] && continue
382-
383-
min=$(echo "$cron_job" | awk '{print $1}')
384-
hour=$(echo "$cron_job" | awk '{print $2}')
385-
day=$(echo "$cron_job" | awk '{print $3}')
386-
month=$(echo "$cron_job" | awk '{print $4}')
387-
dow=$(echo "$cron_job" | awk '{print $5}')
388-
cmd=$(echo "$cron_job" | awk '{for (i=6; i<=NF; i++) printf $i " "; print ""}')
389-
390-
$BIN/v-add-cron-job $new_user "$min" "$hour" "$day" "$month" "$dow" "$cmd"
391-
done < "$CRON_FILE"
392-
echo "Cron jobs restored for user $new_user."
380+
while IFS= read -r cron_job || [ -n "$cron_job" ]; do
381+
[[ "$cron_job" =~ ^(#.*|\s*|MAILTO=.*|SHELL=.*)$ ]] && continue
382+
383+
min=$(echo "$cron_job" | awk '{print $1}')
384+
hour=$(echo "$cron_job" | awk '{print $2}')
385+
day=$(echo "$cron_job" | awk '{print $3}')
386+
month=$(echo "$cron_job" | awk '{print $4}')
387+
dow=$(echo "$cron_job" | awk '{print $5}')
388+
cmd=$(echo "$cron_job" | awk '{for (i=6; i<=NF; i++) printf $i " "; print ""}')
389+
390+
$BIN/v-add-cron-job $new_user "$min" "$hour" "$day" "$month" "$dow" "$cmd"
391+
done < "$CRON_FILE"
392+
echo "Cron jobs restored for user $new_user."
393393
else
394-
echo "No cron jobs file found or it is empty for user $new_user."
394+
echo "No cron jobs file found or it is empty for user $new_user."
395395
fi
396396

397-
398397
rm -rf "$tmpdir"
399398

400399
echo "##############################"

0 commit comments

Comments
 (0)