Browse Source

[Feature] Add v-dump-site (#3808)

h.udo 2 years ago
parent
commit
0de4bf7a1c
3 changed files with 95 additions and 0 deletions
  1. 67 0
      bin/v-dump-site
  2. 18 0
      web/download/site/index.php
  3. 10 0
      web/templates/pages/list_web.php

+ 67 - 0
bin/v-dump-site

@@ -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 - 0
web/download/site/index.php

@@ -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 - 0
web/templates/pages/list_web.php

@@ -259,6 +259,16 @@
 										<span class="u-hide-desktop"><?= _("Edit Domain") ?></span>
 										<span class="u-hide-desktop"><?= _("Edit Domain") ?></span>
 									</a>
 									</a>
 								</li>
 								</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 } ?>
 							<?php } ?>
 							<li class="units-table-row-action shortcut-l" data-key-action="href">
 							<li class="units-table-row-action shortcut-l" data-key-action="href">
 								<a
 								<a