summaryrefslogtreecommitdiff
path: root/includes/backup.inc
diff options
context:
space:
mode:
authorRaindropsSys <contact@minteck.org>2023-03-12 19:16:53 +0100
committerRaindropsSys <contact@minteck.org>2023-03-12 19:16:53 +0100
commiteb89b15c0f044673c1206a418a21d0baba1a675e (patch)
tree39ac31a576d8b8392cbd9baf8d67621bf2cefa86 /includes/backup.inc
parent5385f0ed8fbb4325203a222a75e6700ffb519349 (diff)
downloadpluralconnect-eb89b15c0f044673c1206a418a21d0baba1a675e.tar.gz
pluralconnect-eb89b15c0f044673c1206a418a21d0baba1a675e.tar.bz2
pluralconnect-eb89b15c0f044673c1206a418a21d0baba1a675e.zip
Updated 104 files, added 3 files, deleted 4 files and renamed 36 files (automated)
Diffstat (limited to 'includes/backup.inc')
-rw-r--r--includes/backup.inc102
1 files changed, 0 insertions, 102 deletions
diff --git a/includes/backup.inc b/includes/backup.inc
deleted file mode 100644
index 6196389..0000000
--- a/includes/backup.inc
+++ /dev/null
@@ -1,102 +0,0 @@
-<?php
-
-echo(" Scanning...\n");
-$root = array_filter(scandir("data"), function ($i) {
- return !str_starts_with($i, ".");
-});
-$files = [];
-$data = [
- "date" => date('c'),
- "files" => []
-];
-
-foreach ($root as $file) {
- if ($file === "backup.poniesbackup" || $file === "backup.ponieskey" || $file === "encrypted" || str_ends_with($file, ".poniesbackup")) continue;
- echo(" /$file\n");
-
- if (is_dir("data/$file")) {
- foreach (array_filter(scandir("data/$file"), function ($i) {
- return !str_starts_with($i, ".");
- }) as $dirfile) {
- if ($dirfile === "backup.poniesbackup" || $dirfile === "backup.ponieskey" || $dirfile === "encrypted" || str_ends_with($dirfile, ".poniesbackup")) continue;
-
- echo(" /$dirfile/$file\n");
- $files[] = [
- "dir" => $file,
- "file" => $dirfile
- ];
- }
- } else {
- echo(" /$file\n");
- $files[] = [
- "dir" => "",
- "file" => $file
- ];
- }
-}
-
-echo(" Reading files...\n");
-foreach ($files as $file) {
- echo(" /$file[dir]/$file[file]\n");
- $file["mime"] = mime_content_type("data/$file[dir]/$file[file]");
- $file["checksum"] = [
- sha1_file("data/$file[dir]/$file[file]"),
- md5_file("data/$file[dir]/$file[file]")
- ];
- $file["content"] = base64_encode(file_get_contents("data/$file[dir]/$file[file]"));
-
- $data["files"][] = $file;
-}
-
-function pkcs7_pad($data, $size) {
- $length = $size - strlen($data) % $size;
- return $data . str_repeat(chr($length), $length);
-}
-
-if (!file_exists("./data/backup.ponieskey")) {
- echo(" Creating encryption key...\n");
- $key = openssl_random_pseudo_bytes(512);
- $iv = openssl_random_pseudo_bytes(16);
- file_put_contents("./data/backup.ponieskey", base64_encode(json_encode([
- "iv" => bin2hex($iv),
- "key" => bin2hex($key)
- ])));
-} else {
- echo(" Reading encryption key...\n");
- $key_raw = json_decode(base64_decode(file_get_contents("./data/backup.ponieskey")), true);
- $key = hex2bin($key_raw["key"]);
- $iv = hex2bin($key_raw["iv"]);
-}
-
-echo(" Encrypting...\n");
-$payload = json_encode($data);
-$encrypted = openssl_encrypt(pkcs7_pad($payload, 16), 'AES-256-CBC', $key, OPENSSL_RAW_DATA, $iv);
-
-echo(" Writing backup...\n");
-file_put_contents("./data/backup.poniesbackup", $encrypted);
-@mkdir("./data/encrypted");
-
-$id = str_replace(":", "-", date('c'));
-copy("./data/backup.poniesbackup", "./data/encrypted/" . $id . ".poniesbackup");
-
-echo(" Uploading to servers...\n");
-
-echo(" zephyrheights... upload\n");
-exec("scp ./data/encrypted/" . $id . ".poniesbackup root@zephyrheights.equestria.dev:/opt/ponies");
-echo(" zephyrheights... cleaning up\n");
-exec('ssh root@zephyrheights.equestria.dev bash /opt/clean.sh');
-
-echo(" canterlot... upload\n");
-exec("scp ./data/encrypted/" . $id . ".poniesbackup root@canterlot.equestria.dev:/opt/ponies");
-echo(" canterlot... cleaning up\n");
-exec('ssh root@canterlot.equestria.dev bash /opt/clean.sh');
-
-if (file_exists("/opt/ponies")) {
- echo(" bridlewood... copy\n");
- copy("./data/encrypted/" . $id . ".poniesbackup", "/opt/ponies/" . $id . ".poniesbackup");
- echo(" bridlewood... cleaning up\n");
- exec('bash -c "cd /opt/ponies; ls -tp | grep -v \'/$\' | tail -n +20 | xargs -I {} rm -- {}"');
-}
-
-echo(" Cleaning up...\n");
-unlink("./data/encrypted/" . $id . ".poniesbackup"); \ No newline at end of file