Skip to content

Commit

Permalink
[Feature] Add v-dump-site (#3808)
Browse files Browse the repository at this point in the history
  • Loading branch information
hudokkow committed Jul 21, 2023
1 parent 7199ed3 commit 0de4bf7
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
67 changes: 67 additions & 0 deletions bin/v-dump-site
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash
# info: Dumps the files of a site into a zip archive
# options: USER DOMAIN [TYPE]
#
# example: v-dump-site user domain
# example: v-dump-site user domain full
#
# Dumps site files in /backup/user.domain.timestamp.zip

#----------------------------------------------------------#
# Variables & Functions #
#----------------------------------------------------------#

# Argument definition
user=$1
domain=$2
type=$3

# Includes
# shellcheck source=/etc/hestiacp/hestia.conf
source /etc/hestiacp/hestia.conf
# shellcheck source=/usr/local/hestia/func/main.sh
source $HESTIA/func/main.sh
# load config file
source_conf "$HESTIA/conf/hestia.conf"

check_args '2' "$#" 'USER DOMAIN'
is_format_valid 'user' 'domain'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_object_valid 'web' 'DOMAIN' "$domain"

# Perform verification if read-only mode is enabled
check_hestia_demo_mode

#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#

# Create timestamp in Y-M-D_h-m-s format
timestamp=$(date +'%G-%m-%d_%H-%M-%S')

# echo filename for use in the php
echo "$user.$domain.$timestamp.zip"

if [ "$type" = "full" ]; then
cd /home/$user/web/$domain/
else
cd /home/$user/web/$domain/public_html/
fi

zip -rq $BACKUP/$user.$domain.$timestamp.zip .

if [[ -f "$BACKUP/$user.$domain.$timestamp.zip" ]]; then
echo "$BACKUP/$user.$domain.$timestamp.zip"
echo "rm $BACKUP/$user.$domain.$timestamp.zip" | at now + 1 hour
fi

#----------------------------------------------------------#
# Hestia #
#----------------------------------------------------------#

# Logging
log_event "$OK" "$ARGUMENTS"

exit

18 changes: 18 additions & 0 deletions web/download/site/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
use function Hestiacp\quoteshellarg\quoteshellarg;

ob_start();
include $_SERVER["DOCUMENT_ROOT"] . "/inc/main.php";

// Check token
verify_csrf($_GET);

$site = quoteshellarg($_GET["site"]);

exec(HESTIA_CMD . "v-dump-site " . $user . " " . $site . " full", $output, $return_var);

if ($return_var == 0) {
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=" . $output[0]);
header("X-Accel-Redirect: " . $output[1]);
}
10 changes: 10 additions & 0 deletions web/templates/pages/list_web.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,16 @@ class="units-table-row-action-link"
<span class="u-hide-desktop"><?= _("Edit Domain") ?></span>
</a>
</li>
<li class="units-table-row-action" data-key-action="href">
<a
class="units-table-row-action-link"
href="/download/site/?site=<?=$key?>&token=<?= $_SESSION['token'] ?>"
title="<?= _("Download Site") ?>"
>
<i class="fas fa-download icon-orange"></i>
<span class="u-hide-desktop"><?= _("Download Site") ?></span>
</a>
</li>
<?php } ?>
<li class="units-table-row-action shortcut-l" data-key-action="href">
<a
Expand Down

0 comments on commit 0de4bf7

Please sign in to comment.