diff options
Diffstat (limited to 'includes/refresh')
-rw-r--r-- | includes/refresh/assets.inc | 86 | ||||
-rw-r--r-- | includes/refresh/backup.inc | 95 | ||||
-rw-r--r-- | includes/refresh/cleanup.inc | 24 |
3 files changed, 0 insertions, 205 deletions
diff --git a/includes/refresh/assets.inc b/includes/refresh/assets.inc deleted file mode 100644 index b27840a..0000000 --- a/includes/refresh/assets.inc +++ /dev/null @@ -1,86 +0,0 @@ -<?php - -global $app; - -if (!file_exists("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/avatars")) mkdir("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/avatars"); -if (!file_exists("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/banners")) mkdir("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/banners"); -if (!file_exists("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/heads")) mkdir("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/heads"); -if (!file_exists("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/bodies")) mkdir("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/bodies"); - -function downloadAssets($system, $path = null) { - if (!isset($path)) { - $path = $system; - } - - $general = json_decode(file_get_contents("./data/$path/general.json"), true); - - if (isset($general["avatar_url"])) { - $id = preg_replace("/^([\da-f]{8})-([\da-f]{4})-([\da-f]{4})-([\da-f]{4})-([\da-f]{12})$/", "$1$2$3$4$5", $general["uuid"]); - echo(" /avatars/$id.webp\n"); - file_put_contents("/tmp/img." . pathinfo($general['avatar_url'], PATHINFO_EXTENSION), file_get_contents($general['avatar_url'])); - exec("convert -resize 512x512 \"" . "/tmp/img." . pathinfo($general['avatar_url'], PATHINFO_EXTENSION) . "\" " . $_SERVER['DOCUMENT_ROOT'] . "/assets/avatars/" . $id . ".webp"); - unlink("/tmp/img." . pathinfo($general['avatar_url'], PATHINFO_EXTENSION)); - } - - if (isset($general["banner"])) { - $id = preg_replace("/^([\da-f]{8})-([\da-f]{4})-([\da-f]{4})-([\da-f]{4})-([\da-f]{12})$/", "$1$2$3$4$5", $general["uuid"]); - echo(" /banners/$id.webp\n"); - file_put_contents("/tmp/img." . pathinfo($general['banner'], PATHINFO_EXTENSION), file_get_contents($general['banner'])); - exec("convert -resize 2048x2048 \"" . "/tmp/img." . pathinfo($general['banner'], PATHINFO_EXTENSION) ."\" " . $_SERVER['DOCUMENT_ROOT'] . "/assets/banners/" . $id . ".webp"); - unlink("/tmp/img." . pathinfo($general['banner'], PATHINFO_EXTENSION)); - } - - $members = json_decode(file_get_contents("./data/$path/members.json"), true); - - foreach ($members as $member) { - $id = preg_replace("/^([\da-f]{8})-([\da-f]{4})-([\da-f]{4})-([\da-f]{4})-([\da-f]{12})$/", "$1$2$3$4$5", $general["uuid"]) . preg_replace("/^([\da-f]{8})-([\da-f]{4})-([\da-f]{4})-([\da-f]{4})-([\da-f]{12})$/", "$1$2$3$4$5", $member["uuid"]); - - if (isset($member["avatar_url"])) { - echo(" /avatars/$id.webp\n"); - file_put_contents("/tmp/img." . pathinfo($member['avatar_url'], PATHINFO_EXTENSION), file_get_contents($member['avatar_url'])); - exec("convert -resize 512x512 \"" . "/tmp/img." . pathinfo($member['avatar_url'], PATHINFO_EXTENSION) . "\" " . $_SERVER['DOCUMENT_ROOT'] . "/assets/avatars/" . $id . ".webp"); - unlink("/tmp/img." . pathinfo($member['avatar_url'], PATHINFO_EXTENSION)); - } - - echo(" /banners/$id.webp\n"); - - if (isset($member["banner"])) { - file_put_contents("/tmp/img." . pathinfo($member['banner'], PATHINFO_EXTENSION), file_get_contents($member['banner'])); - exec("convert -resize 2048x2048 \"" . "/tmp/img." . pathinfo($member['banner'], PATHINFO_EXTENSION) . "\" " . $_SERVER['DOCUMENT_ROOT'] . "/assets/banners/" . $id . ".webp"); - unlink("/tmp/img." . pathinfo($member['banner'], PATHINFO_EXTENSION)); - } else { - $img = imagecreate(2048, 1024); - - if (isset($member["color"])) { - imagecolorallocate($img, hexdec(substr($member["color"], 0, 2)) / 2, hexdec(substr($member["color"], 2, 2)) / 2, hexdec(substr($member["color"], 4, 2)) / 2); - } else { - imagecolorallocate($img, 0, 0, 0); - } - - imagejpeg($img, "/tmp/img.jpeg", 100); - imagedestroy($img); - exec("convert -resize 2048x2048 \"/tmp/img.jpeg\" " . $_SERVER['DOCUMENT_ROOT'] . "/assets/banners/" . $id . ".webp"); - unlink("/tmp/img.jpeg"); - } - - if (file_exists("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/uploads/pt-" . $member["name"] . ".png")) { - $url = "" . $_SERVER['DOCUMENT_ROOT'] . "/assets/uploads/pt-" . $member["name"] . ".png"; - } else { - $url = "" . $_SERVER['DOCUMENT_ROOT'] . "/assets/uploads/pt.png"; - } - echo(" /heads/$id.png\n"); - exec("convert \"" . $url . "\" " . $_SERVER['DOCUMENT_ROOT'] . "/assets/heads/" . $id . ".png"); - - if (file_exists("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/ponies/" . $member["id"] . ".png")) { - echo(" /bodies/$id.png\n"); - exec("convert \"" . "" . $_SERVER['DOCUMENT_ROOT'] . "/assets/ponies/" . $member["id"] . ".png" . "\" " . $_SERVER['DOCUMENT_ROOT'] . "/assets/bodies/" . $id . ".png"); - } - } -} - -downloadAssets("gdapd"); -downloadAssets("ynmuc"); - -if (isset($app["other"]) && isset($app["other"]["id"]) && isset($app["other"]["token"])) { - downloadAssets($app["other"]["id"], "other"); -}
\ No newline at end of file diff --git a/includes/refresh/backup.inc b/includes/refresh/backup.inc deleted file mode 100644 index bed4637..0000000 --- a/includes/refresh/backup.inc +++ /dev/null @@ -1,95 +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($_SERVER['DOCUMENT_ROOT'] . "/includes/data/backup.ponieskey")) { - echo(" Creating encryption key...\n"); - $key = openssl_random_pseudo_bytes(512); - $iv = openssl_random_pseudo_bytes(16); - file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/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($_SERVER['DOCUMENT_ROOT'] . "/includes/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($_SERVER['DOCUMENT_ROOT'] . "/includes/data/backup.poniesbackup", $encrypted); -@mkdir($_SERVER['DOCUMENT_ROOT'] . "/includes/data/encrypted"); - -$id = str_replace(":", "-", date('c')); -copy($_SERVER['DOCUMENT_ROOT'] . "/includes/data/backup.poniesbackup", $_SERVER['DOCUMENT_ROOT'] . "/includes/data/encrypted/" . $id . ".poniesbackup"); - -echo(" Uploading to servers...\n"); - -echo(" zephyrheights... upload\n"); -exec("scp -P 2222 " . $_SERVER['DOCUMENT_ROOT'] . "/includes/data/encrypted/" . $id . ".poniesbackup root@zephyrheights.equestria.dev:/opt/ponies"); - -if (file_exists("/opt/ponies")) { - echo(" bridlewood... copy\n"); - copy($_SERVER['DOCUMENT_ROOT'] . "/includes/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($_SERVER['DOCUMENT_ROOT'] . "/includes/data/encrypted/" . $id . ".poniesbackup");
\ No newline at end of file diff --git a/includes/refresh/cleanup.inc b/includes/refresh/cleanup.inc deleted file mode 100644 index 39ec41a..0000000 --- a/includes/refresh/cleanup.inc +++ /dev/null @@ -1,24 +0,0 @@ -<?php - -$screens = array_values(array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/includes/data/computers/screens"), function ($i) { - return !str_starts_with($i, "."); -})); - -$computers = array_values(array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/includes/data/computers/metadata"), function ($i) { - return !str_starts_with($i, "."); -})); - -foreach ($screens as $screen) { - $delete = true; - $id = explode(".", explode("-", $screen)[2])[0]; - - foreach ($computers as $file) { - $computer = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/computers/metadata/" . $file), true); - - foreach ($computer["screens"] as $sel) { - if ($sel["id"] === $id) $delete = false; - } - } - - if ($delete) unlink($_SERVER['DOCUMENT_ROOT'] . "/includes/data/computers/screens/" . $screen); -}
\ No newline at end of file |