summaryrefslogtreecommitdiff
path: root/includes/refresh.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/refresh.php')
-rw-r--r--includes/refresh.php101
1 files changed, 0 insertions, 101 deletions
diff --git a/includes/refresh.php b/includes/refresh.php
deleted file mode 100644
index cac1fb1..0000000
--- a/includes/refresh.php
+++ /dev/null
@@ -1,101 +0,0 @@
-<?php
-
-$_SERVER['DOCUMENT_ROOT'] = "..";
-
-$app = json_decode(file_get_contents("./app.json"), true);
-@mkdir("./data");
-
-
-$version = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/version.json"), true);
-
-$ignore = [
- $_SERVER['DOCUMENT_ROOT'] . "/includes/data",
- $_SERVER['DOCUMENT_ROOT'] . "/includes/tokens",
- $_SERVER['DOCUMENT_ROOT'] . "/app",
- $_SERVER['DOCUMENT_ROOT'] . "/assets",
-];
-
-$documents = array_map(function ($i) {
- return [
- "id" => substr($i, 0, -5),
- ...(json_decode(file_get_contents("./data/docs/" . $i), true) ?? [])
- ];
-}, array_filter(scandir("./data/docs"), function ($i) {
- return !str_starts_with($i, ".") && str_ends_with($i, ".json");
-}));
-
-$deletable = array_values(array_filter($documents, function ($i) {
- return str_starts_with(strip_tags($i["contents"]), "/delete");
-}));
-
-foreach ($deletable as $item) {
- if (time() - $item["last"]["date"] > 86400) {
- unlink("./data/docs/" . $item["id"] . ".json");
- }
-}
-
-function rscandir($dir) {
- global $ignore;
- $files = [];
-
- foreach (array_filter(scandir($dir), function ($i) {
- return !str_starts_with($i, ".");
- }) as $file) {
- if (in_array($dir . "/" . $file, $ignore)) continue;
-
- if (is_dir($dir . "/" . $file)) {
- array_push($files, ...rscandir($dir . "/" . $file));
- } else {
- $files[] = $dir . "/" . $file;
- }
- }
-
- return array_unique($files);
-}
-
-function calculateVersionNumber() {
- $files = rscandir($_SERVER['DOCUMENT_ROOT']);
- $hashes = [];
-
- foreach ($files as $file) {
- $hashes[] = md5_file($file);
- }
-
- $hash = md5(implode("", $hashes));
- return [$hash, $hashes];
-}
-
-$versionHash = calculateVersionNumber();
-
-if ($versionHash[0] !== $version["hash"]) {
- $version["hash"] = $versionHash[0];
- $version["timestamp"] = time();
- $version["revision"] = 0;
- $version["list"] = [
- "current" => $versionHash[1],
- "old" => isset($version["list"]) ? $version["list"]["current"] ?? null : null
- ];
- $version["build"]++;
-} else {
- $version["revision"]++;
-}
-
-file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/version.json", json_encode($version));
-
-if (!is_link($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $app["other"]["id"])) {
- link($_SERVER['DOCUMENT_ROOT'] . "/includes/data/other", $_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $app["other"]["id"]);
-}
-
-echo("Backing up...\n");
-
-$lastBackup = (int)trim(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/backup.txt"));
-
-if (time() - $lastBackup >= 3600) {
- require_once "./backup.inc";
- file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/backup.txt", time());
- echo("Backup completed\n");
-} else {
- echo("Backup skipped\n");
-}
-
-echo("Completed.\n"); \ No newline at end of file