Skip to content

Commit 242df31

Browse files
authored
Merge pull request hestiacp#2862 from jaapmarcus/fix/include-custom-nginx
Fix hestiacp#1834 Include extra config when restoring backups
2 parents bd59888 + 8afd031 commit 242df31

File tree

3 files changed

+97
-14
lines changed

3 files changed

+97
-14
lines changed

bin/v-restore-user

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,13 @@ if [ "$web" != 'no' ] && [ -n "$WEB_SYSTEM" ]; then
291291
if [ -n "$check_backend_tpl" ]; then
292292
BACKEND='default'
293293
fi
294+
295+
if [ -n "$CUSTOM_DOCROOT" ]; then
296+
CUSTOM_DOCROOT=$(echo "$CUSTOM_DOCROOT" | sed -e "s|/home/${old_user}/web/|/home/${user}/web/")
297+
fi
298+
if [ -n "$CUSTOM_PHPROOT" ]; then
299+
CUSTOM_PHPROOT=$(echo "$CUSTOM_PHPROOT" | sed -e "s|/home/${old_user}/web/|/home/${user}/web/")
300+
fi
294301

295302
# Converting FTP users
296303
if [ -n "$FTP_USER" ]; then
@@ -335,8 +342,25 @@ if [ "$web" != 'no' ] && [ -n "$WEB_SYSTEM" ]; then
335342
$BIN/v-add-web-domain-backend $user $domain $BACKEND
336343
fi
337344
fi
338-
339-
# Rebuilding vhost
345+
346+
# Restoring custom user config
347+
# Except certificates, .conf files
348+
if [ ! -d "$HOMEDIR/$user/conf/web/$domain/" ]; then
349+
mkdir -p $HOMEDIR/$user/conf/web/$domain/
350+
fi
351+
for file in $tmpdir/web/$domain/conf/*; do
352+
if [[ "$file" == *.ca ]] || [[ "$file" == *.crt ]] || [[ "$file" == *.key ]] || [[ "$file" == *.pem ]] || [[ "$file" == *.conf ]]; then
353+
continue;
354+
fi
355+
if grep "fastcgi_pass" file; then
356+
# Do not allow to run php under a different user
357+
continue;
358+
fi
359+
filename=$(basename $file)
360+
cp -f "$file" "$HOMEDIR/$user/conf/web/$domain/$filename"
361+
done
362+
363+
# Rebuilding vhost to prevent user overwrite default config changes not ideal
340364
rebuild_web_domain_conf
341365

342366
# Restoring web domain data

func/domain.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,11 @@ prepare_web_domain_values() {
230230

231231
# Add web config
232232
add_web_config() {
233-
mkdir -p "$HOMEDIR/$user/conf/web/$domain"
233+
# Check if folder already exists
234+
if [ ! -d "$HOMEDIR/$user/conf/web/$domain" ]; then
235+
mkdir -p "$HOMEDIR/$user/conf/web/$domain/"
236+
fi
237+
234238
conf="$HOMEDIR/$user/conf/web/$domain/$1.conf"
235239
if [[ "$2" =~ stpl$ ]]; then
236240
conf="$HOMEDIR/$user/conf/web/$domain/$1.ssl.conf"

test/restore.bats

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ function validate_web_domain() {
4242
local domain=$2
4343
local webproof=$3
4444
local webpath=${4}
45+
local valwebpath=${5}
4546

4647
refute [ -z "$user" ]
4748
refute [ -z "$domain" ]
@@ -57,15 +58,16 @@ function validate_web_domain() {
5758
SSL=$(get_object_value 'web' 'DOMAIN' "$domain" '$SSL')
5859
domain_ip=$(get_real_ip "$domain_ip")
5960

60-
if [ ! -z $webpath ]; then
61-
domain_docroot=$(get_object_value 'web' 'DOMAIN' "$domain" '$CUSTOM_DOCROOT')
62-
if [ -n "$domain_docroot" ] && [ -d "$domain_docroot" ]; then
63-
assert_file_exist "${domain_docroot}/${webpath}"
64-
else
65-
assert_file_exist "${HOMEDIR}/${user}/web/${domain}/public_html/${webpath}"
61+
if [ -z $valwebpath ]; then
62+
if [ ! -z $webpath ]; then
63+
domain_docroot=$(get_object_value 'web' 'DOMAIN' "$domain" '$CUSTOM_DOCROOT')
64+
if [ -n "$domain_docroot" ] && [ -d "$domain_docroot" ]; then
65+
assert_file_exist "${domain_docroot}/${webpath}"
66+
else
67+
assert_file_exist "${HOMEDIR}/${user}/web/${domain}/public_html/${webpath}"
68+
fi
6669
fi
6770
fi
68-
6971
# Test HTTP
7072
run curl --location --silent --show-error --insecure --resolve "${domain}:80:${domain_ip}" "http://${domain}/${webpath}"
7173
assert_success
@@ -101,18 +103,24 @@ function validate_web_domain() {
101103
# - hestia111_db
102104
# cron:
103105
# - 1: /bin/true
104-
# Hestia 1.3.1 archive contains (As zstd format)
106+
# Hestia 1.7.0 archive contains (As zstd format)
105107
# user: hestia131
106108
# web:
107109
# - test.hestia.com (+SSL self-signed)
110+
# FTP Account
111+
# Awstats enabled
108112
# dns:
109113
# - test.hestia.com
110114
# mail:
111115
# - test.hestia.com
116+
# Ratelimit: 10
112117
# mail acc:
113118
# - testaccount@test.hestia.com
119+
# Alias: info@test.hestiacp.com
120+
# Ratelimit: 20
121+
# - support@test.hestia.com
114122
# db:
115-
# - hestia131_db
123+
# - hestia170_db
116124
# cron:
117125
# - 1: /bin/true
118126
# Vesta 0.9.8-23 archive contains:
@@ -275,7 +283,7 @@ function validate_web_domain() {
275283

276284
mkdir -p /backup
277285

278-
local archive_name="hestia131.2020-12-12"
286+
local archive_name="hestia170.2022-08-23"
279287
run wget --quiet --tries=3 --timeout=15 --read-timeout=15 --waitretry=3 --no-dns-cache "https://hestiacp.com/testing/data/${archive_name}.tar" -O "/backup/${archive_name}.tar"
280288
assert_success
281289

@@ -290,6 +298,24 @@ function validate_web_domain() {
290298
validate_web_domain $userbk $domain 'Hello Hestia'
291299
}
292300

301+
@test "Restore[3]: From Hestia [WEB] FTP" {
302+
local domain="test.hestia.com"
303+
assert_file_contains /etc/passwd "$userbk_test"
304+
assert_file_contains /etc/passwd "/home/$userbk/web/$domain"
305+
}
306+
307+
@test "Restore[3]: From Hestia [WEB] Awstats" {
308+
local domain="test.hestia.com"
309+
assert_file_exist /home/$userbk/conf/web/$domain/awstats.conf
310+
}
311+
312+
@test "Restore[3]: From Hestia [WEB] Custom rule" {
313+
# check if custom rule is still working
314+
local domain="test.hestia.com"
315+
validate_web_domain $userbk $domain 'hestia-yes' '/hestia/hestia' 'no'
316+
}
317+
318+
293319
@test "Restore[3]: From Hestia [DNS]" {
294320
local domain="test.hestia.com"
295321

@@ -312,6 +338,11 @@ function validate_web_domain() {
312338

313339
run v-list-mail-account $userbk $domain testaccount
314340
assert_success
341+
# Check if alias is created
342+
assert_file_contains /etc/exim4/domains/$domain/aliases "testaccount@$domain"
343+
# Check if expected rate limits are set
344+
assert_file_contains /etc/exim4/domains/$domain/limits "testaccount@$domain:20"
345+
assert_file_contains /etc/exim4/domains/$domain/limits "support@$domain:10"
315346
}
316347

317348
@test "Restore[3]: From Hestia [DB]" {
@@ -324,6 +355,7 @@ function validate_web_domain() {
324355
assert_success
325356
}
326357

358+
327359
@test "Restore[3]: From Hestia Cleanup" {
328360
run v-delete-user $userbk
329361
assert_success
@@ -344,7 +376,7 @@ function validate_web_domain() {
344376

345377
mkdir -p /backup
346378

347-
local archive_name="hestia131.2020-12-12"
379+
local archive_name="hestia170.2022-08-23"
348380
run wget --quiet --tries=3 --timeout=15 --read-timeout=15 --waitretry=3 --no-dns-cache "https://hestiacp.com/testing/data/${archive_name}.tar" -O "/backup/${archive_name}.tar"
349381
assert_success
350382

@@ -359,6 +391,24 @@ function validate_web_domain() {
359391
validate_web_domain $userbk $domain 'Hello Hestia'
360392
}
361393

394+
@test "Restore[4]: From Hestia [WEB] FTP" {
395+
local domain="test.hestia.com"
396+
assert_file_contains /etc/passwd "$userbk_test"
397+
assert_file_contains /etc/passwd "/home/$userbk/web/$domain"
398+
}
399+
400+
@test "Restore[4]: From Hestia [WEB] Awstats" {
401+
local domain="test.hestia.com"
402+
assert_file_exist /home/$userbk/conf/web/$domain/awstats.conf
403+
}
404+
405+
@test "Restore[4]: From Hestia [WEB] Custom rule" {
406+
# check if custom rule is still working
407+
local domain="test.hestia.com"
408+
validate_web_domain $userbk $domain 'hestia-yes' '/hestia/hestia' 'no'
409+
}
410+
411+
362412
@test "Restore[4]: From Hestia [DNS]" {
363413
local domain="test.hestia.com"
364414

@@ -381,6 +431,11 @@ function validate_web_domain() {
381431

382432
run v-list-mail-account $userbk $domain testaccount
383433
assert_success
434+
# Check if alias is created
435+
assert_file_contains /etc/exim4/domains/$domain/aliases "testaccount@$domain"
436+
# Check if expected rate limits are set
437+
assert_file_contains /etc/exim4/domains/$domain/limits "testaccount@$domain:20"
438+
assert_file_contains /etc/exim4/domains/$domain/limits "support@$domain:10"
384439
}
385440

386441
@test "Restore[4]: From Hestia [DB]" {

0 commit comments

Comments
 (0)