From 8c793cec9d85612e0b5242eb52d6a669a1fc5893 Mon Sep 17 00:00:00 2001 From: jakani24 Date: Sat, 8 Jun 2024 17:27:36 +0200 Subject: [PATCH] adding automatic backups --- .../secure_zone/php/create_log_backup.php | 64 +++++++++++++++++++ .../system/secure_zone/php/welcome.php | 4 +- 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 src/server/cyberhex-code/system/secure_zone/php/create_log_backup.php diff --git a/src/server/cyberhex-code/system/secure_zone/php/create_log_backup.php b/src/server/cyberhex-code/system/secure_zone/php/create_log_backup.php new file mode 100644 index 0000000..f41c122 --- /dev/null +++ b/src/server/cyberhex-code/system/secure_zone/php/create_log_backup.php @@ -0,0 +1,64 @@ +prepare($sql); + + $stmt->execute(); + $result = $stmt->get_result(); + + fwrite ($fp,"Entry id;Loglevel;Logtext;Machine id;Machine Location;Time & date\n"); + //now add entrys + while ($row = $result->fetch_assoc()) { + fwrite($fp,$row["id"] . ';'); + fwrite($fp,$row["loglevel"] . ';'); + fwrite($fp,$row["logtext"] . ';'); + fwrite($fp,$row["machine_id"] . ';'); + fwrite($fp,$row["machine_location"] . ';'); + fwrite($fp,$row["time"] . ";\n"); + } + fclose($fp); + $stmt->close(); + $conn->close(); + +} + +function create_dashboard_backup($conn){ + //create a filename + $filename="dashboard_export_".date('Y-m-d H:i:s').".csv"; + + $fp=fopen("/var/www/html/backup/$filename","w"); + //do all the logic here and write into file + // Query log entries for the export file + $sql = "SELECT * FROM machines,vir_notify WHERE machine_name=machine_id ORDER BY vir_notify.id DESC"; + $stmt = $conn->prepare($sql); + + $stmt->execute(); + $result = $stmt->get_result(); + + fwrite ($fp,"Entry id;Machine id;Machine Location;Path;Hash;Action taken\n"); + //now add entrys + while ($row = $result->fetch_assoc()) { + fwrite($fp,$row["id"] . ';'); + fwrite($fp,$row["machine_id"] . ';'); + fwrite($fp,$row["machine_location"] . ';'); + fwrite($fp,$row["path"] . ';'); + fwrite($fp,$row["hash"] . ';'); + fwrite($fp,$row["action"] . ";\n"); + } + + fclose($fp); + $stmt->close(); + $conn->close(); + +} + +?> \ No newline at end of file diff --git a/src/server/cyberhex-code/system/secure_zone/php/welcome.php b/src/server/cyberhex-code/system/secure_zone/php/welcome.php index 675c321..4901092 100644 --- a/src/server/cyberhex-code/system/secure_zone/php/welcome.php +++ b/src/server/cyberhex-code/system/secure_zone/php/welcome.php @@ -19,7 +19,7 @@ $hash = htmlspecialchars(isset($_GET["hash"]) ? $_GET["hash"] : ""); $action = htmlspecialchars(isset($_GET["action"]) ? $_GET["action"] : ""); $machine_location = htmlspecialchars(isset($_GET["machine_location"]) ? $_GET["machine_location"] : ""); $filter_query = "&hash=$hash&path=$path&machine_id=$machine_id&action=$action&machine_location=$machine_location"; - +include "create_log_backup.php"; ?> @@ -56,6 +56,7 @@ $filter_query = "&hash=$hash&path=$path&machine_id=$machine_id&action=$action&ma if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } + create_dashboard_backup($conn); $sql = "DELETE FROM vir_notify WHERE id = ?"; $stmt = $conn->prepare($sql); $stmt->bind_param("i", $id); @@ -78,6 +79,7 @@ $filter_query = "&hash=$hash&path=$path&machine_id=$machine_id&action=$action&ma if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } + create_dashboard_backup($conn); $sql = "DELETE FROM vir_notify"; $stmt = $conn->prepare($sql); // Execute the statement