Skip to content

Commit 0de4bf7

Browse files
authored
[Feature] Add v-dump-site (hestiacp#3808)
1 parent 7199ed3 commit 0de4bf7

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

bin/v-dump-site

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
# info: Dumps the files of a site into a zip archive
3+
# options: USER DOMAIN [TYPE]
4+
#
5+
# example: v-dump-site user domain
6+
# example: v-dump-site user domain full
7+
#
8+
# Dumps site files in /backup/user.domain.timestamp.zip
9+
10+
#----------------------------------------------------------#
11+
# Variables & Functions #
12+
#----------------------------------------------------------#
13+
14+
# Argument definition
15+
user=$1
16+
domain=$2
17+
type=$3
18+
19+
# Includes
20+
# shellcheck source=/etc/hestiacp/hestia.conf
21+
source /etc/hestiacp/hestia.conf
22+
# shellcheck source=/usr/local/hestia/func/main.sh
23+
source $HESTIA/func/main.sh
24+
# load config file
25+
source_conf "$HESTIA/conf/hestia.conf"
26+
27+
check_args '2' "$#" 'USER DOMAIN'
28+
is_format_valid 'user' 'domain'
29+
is_object_valid 'user' 'USER' "$user"
30+
is_object_unsuspended 'user' 'USER' "$user"
31+
is_object_valid 'web' 'DOMAIN' "$domain"
32+
33+
# Perform verification if read-only mode is enabled
34+
check_hestia_demo_mode
35+
36+
#----------------------------------------------------------#
37+
# Action #
38+
#----------------------------------------------------------#
39+
40+
# Create timestamp in Y-M-D_h-m-s format
41+
timestamp=$(date +'%G-%m-%d_%H-%M-%S')
42+
43+
# echo filename for use in the php
44+
echo "$user.$domain.$timestamp.zip"
45+
46+
if [ "$type" = "full" ]; then
47+
cd /home/$user/web/$domain/
48+
else
49+
cd /home/$user/web/$domain/public_html/
50+
fi
51+
52+
zip -rq $BACKUP/$user.$domain.$timestamp.zip .
53+
54+
if [[ -f "$BACKUP/$user.$domain.$timestamp.zip" ]]; then
55+
echo "$BACKUP/$user.$domain.$timestamp.zip"
56+
echo "rm $BACKUP/$user.$domain.$timestamp.zip" | at now + 1 hour
57+
fi
58+
59+
#----------------------------------------------------------#
60+
# Hestia #
61+
#----------------------------------------------------------#
62+
63+
# Logging
64+
log_event "$OK" "$ARGUMENTS"
65+
66+
exit
67+

web/download/site/index.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
use function Hestiacp\quoteshellarg\quoteshellarg;
3+
4+
ob_start();
5+
include $_SERVER["DOCUMENT_ROOT"] . "/inc/main.php";
6+
7+
// Check token
8+
verify_csrf($_GET);
9+
10+
$site = quoteshellarg($_GET["site"]);
11+
12+
exec(HESTIA_CMD . "v-dump-site " . $user . " " . $site . " full", $output, $return_var);
13+
14+
if ($return_var == 0) {
15+
header("Content-type: application/zip");
16+
header("Content-Disposition: attachment; filename=" . $output[0]);
17+
header("X-Accel-Redirect: " . $output[1]);
18+
}

web/templates/pages/list_web.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,16 @@ class="units-table-row-action-link"
259259
<span class="u-hide-desktop"><?= _("Edit Domain") ?></span>
260260
</a>
261261
</li>
262+
<li class="units-table-row-action" data-key-action="href">
263+
<a
264+
class="units-table-row-action-link"
265+
href="/download/site/?site=<?=$key?>&token=<?= $_SESSION['token'] ?>"
266+
title="<?= _("Download Site") ?>"
267+
>
268+
<i class="fas fa-download icon-orange"></i>
269+
<span class="u-hide-desktop"><?= _("Download Site") ?></span>
270+
</a>
271+
</li>
262272
<?php } ?>
263273
<li class="units-table-row-action shortcut-l" data-key-action="href">
264274
<a

0 commit comments

Comments
 (0)