From 3e66ade7ea8a99638c068b2f877bc18bfe7fbe17 Mon Sep 17 00:00:00 2001 From: "AFTECH.RO" <38830718+aftechro@users.noreply.github.com> Date: Tue, 2 Jan 2024 23:42:00 +0000 Subject: [PATCH 1/3] Update settings_backup.php Backup and restore from the backup menu. Add backups folder into the uploads, so the backup path will be uploads/backups https://www.veed.io/view/5bc75a75-9af6-4fc4-a462-6a161c8b9c23?panel=share --- settings_backup.php | 225 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 204 insertions(+), 21 deletions(-) diff --git a/settings_backup.php b/settings_backup.php index 7c42002b8..2cd8013c7 100644 --- a/settings_backup.php +++ b/settings_backup.php @@ -1,37 +1,220 @@ -
-
-

Download Database

+$backupFolder = 'uploads/backups/'; +$backups = array_diff(scandir($backupFolder), array('..', '.')); + +// Database connection +$mysqli = mysqli_connect($dbhost, $dbusername, $dbpassword, $database) or die('Database Connection Failed'); +$conn = new mysqli($dbhost, $dbusername, $dbpassword, $database); + +// Handle backup action +if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST['backup'])) { + // Create a backup + $backupFileName = date("d-m-Y_H-i-s") . ".sql"; + $backupPath = $backupFolder . $backupFileName; + + // Run mysqldump command to include table content + $escapedBackupPath = escapeshellarg($backupPath); + $command = "mysqldump --complete-insert --skip-comments -h $dbhost -u $dbusername -p$dbpassword $database > $escapedBackupPath"; + exec($command); + + // Refresh backup list after creating a new backup + $backups = array_diff(scandir($backupFolder), array('..', '.')); +} + +// Handle restore action +if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST['proceed-restore'])) { + $selectedBackup = $_POST['proceed-restore']; + + $sqlFile = $backupFolder . $selectedBackup; + $sqlContent = file_get_contents($sqlFile); + + // Remove comments and split into separate queries + $sqlQueries = preg_split('/;(?=(?:[^\'"]*[\'"][^\'"]*[\'"])*[^\'"]*$)/', $sqlContent); + + foreach ($sqlQueries as $query) { + $query = trim($query); + if (!empty($query)) { + // Execute each query separately using $conn + $result = $conn->query($query); + + // Check for execution success + if ($result === false) { + die("Error executing query: " . $conn->error); + } + } + } + + // Display success message + echo ''; +} + +// Handle delete action +if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST['delete'])) { + $selectedBackup = $_POST['delete']; + + // Validate the selectedBackup variable to prevent directory traversal + if (in_array($selectedBackup, $backups)) { + unlink($backupFolder . $selectedBackup); + } +} + + + +// Handle delete selected action +if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST['delete-selected'])) { + // Implement delete selected logic here + if (isset($_POST['selectedBackups'])) { + foreach ($_POST['selectedBackups'] as $selectedBackup) { + unlink($backupFolder . $selectedBackup); + } + } +} + +// Reverse the order of backups to display the latest on top +$backups = array_reverse(array_diff(scandir($backupFolder), array('..', '.'))); + +// Function to format file size in human-readable format +function formatBytes($bytes, $decimals = 2) +{ + $size = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + + $factor = floor((strlen($bytes) - 1) / 3); + + return sprintf("%.{$decimals}f", $bytes / (1024 ** $factor)) . ' ' . @$size[$factor]; +} + + +?> + + + +
+
+
+
+

Backup Database

+
+
+
+ + +
+
+
-
-

Download
+ +
+
+
+

Backup Master Encryption Key

+
+
+
+ +
+
+
+ +
+ +
+
+
+
+
+ +
-

Backup Master Encryption Key

+

Backup Manager

-
-
- -
-
-
- + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + + +
SelectBackup NameFile SizeActionsDownload
+ + + Download
+ +
-
+
+ + From e11e996f69813809c993cfb4629c36af38703673 Mon Sep 17 00:00:00 2001 From: "AFTECH.RO" <38830718+aftechro@users.noreply.github.com> Date: Wed, 3 Jan 2024 09:50:23 +0000 Subject: [PATCH 2/3] Update settings_backup.php create backups folder in /uploads folder if not exists create backups and restore --- settings_backup.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/settings_backup.php b/settings_backup.php index 2cd8013c7..163748c3b 100644 --- a/settings_backup.php +++ b/settings_backup.php @@ -4,7 +4,24 @@ require_once "inc_all_settings.php"; + $backupFolder = 'uploads/backups/'; + +// Check if the uploads folder exists, if not, create it +$uploadsFolder = 'uploads/'; +if (!file_exists($uploadsFolder) || !is_dir($uploadsFolder)) { + if (!mkdir($uploadsFolder, 0777, true)) { + die('Failed to create uploads folder'); + } +} + +// Check if the backup folder exists inside uploads, if not, create it +if (!file_exists($backupFolder) || !is_dir($backupFolder)) { + if (!mkdir($backupFolder, 0777, true)) { + die('Failed to create backup folder'); + } +} + $backups = array_diff(scandir($backupFolder), array('..', '.')); // Database connection From edf1e9efb7183990836d7019ab736ad1fa259cdb Mon Sep 17 00:00:00 2001 From: "AFTECH.RO" <38830718+aftechro@users.noreply.github.com> Date: Wed, 3 Jan 2024 09:52:03 +0000 Subject: [PATCH 3/3] Delete settings_backup.php --- settings_backup.php | 237 -------------------------------------------- 1 file changed, 237 deletions(-) delete mode 100644 settings_backup.php diff --git a/settings_backup.php b/settings_backup.php deleted file mode 100644 index 163748c3b..000000000 --- a/settings_backup.php +++ /dev/null @@ -1,237 +0,0 @@ - $escapedBackupPath"; - exec($command); - - // Refresh backup list after creating a new backup - $backups = array_diff(scandir($backupFolder), array('..', '.')); -} - -// Handle restore action -if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST['proceed-restore'])) { - $selectedBackup = $_POST['proceed-restore']; - - $sqlFile = $backupFolder . $selectedBackup; - $sqlContent = file_get_contents($sqlFile); - - // Remove comments and split into separate queries - $sqlQueries = preg_split('/;(?=(?:[^\'"]*[\'"][^\'"]*[\'"])*[^\'"]*$)/', $sqlContent); - - foreach ($sqlQueries as $query) { - $query = trim($query); - if (!empty($query)) { - // Execute each query separately using $conn - $result = $conn->query($query); - - // Check for execution success - if ($result === false) { - die("Error executing query: " . $conn->error); - } - } - } - - // Display success message - echo ''; -} - -// Handle delete action -if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST['delete'])) { - $selectedBackup = $_POST['delete']; - - // Validate the selectedBackup variable to prevent directory traversal - if (in_array($selectedBackup, $backups)) { - unlink($backupFolder . $selectedBackup); - } -} - - - -// Handle delete selected action -if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST['delete-selected'])) { - // Implement delete selected logic here - if (isset($_POST['selectedBackups'])) { - foreach ($_POST['selectedBackups'] as $selectedBackup) { - unlink($backupFolder . $selectedBackup); - } - } -} - -// Reverse the order of backups to display the latest on top -$backups = array_reverse(array_diff(scandir($backupFolder), array('..', '.'))); - -// Function to format file size in human-readable format -function formatBytes($bytes, $decimals = 2) -{ - $size = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; - - $factor = floor((strlen($bytes) - 1) / 3); - - return sprintf("%.{$decimals}f", $bytes / (1024 ** $factor)) . ' ' . @$size[$factor]; -} - - -?> - - - -
-
-
-
-

Backup Database

-
-
-
- - -
-
-
-
- -
-
-
-

Backup Master Encryption Key

-
-
-
- -
-
-
- -
- -
-
-
-
-
-
-
- - - -
-
-

Backup Manager

-
-
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SelectBackup NameFile SizeActionsDownload
- - - Download
- -
-
-
- - - -