diff options
Diffstat (limited to 'api/pluralkit-integration.php')
-rw-r--r-- | api/pluralkit-integration.php | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/api/pluralkit-integration.php b/api/pluralkit-integration.php index 9b0033d..f0f22d3 100644 --- a/api/pluralkit-integration.php +++ b/api/pluralkit-integration.php @@ -6,6 +6,27 @@ $inputJSON = file_get_contents('php://input'); $input = json_decode($inputJSON, true); $data = $GLOBALS["ColdHazeApp"]["webhook"]; +function random($length = 13): string { + if (function_exists("random_bytes")) { + $bytes = random_bytes(ceil($length / 2)); + } elseif (function_exists("openssl_random_pseudo_bytes")) { + $bytes = openssl_random_pseudo_bytes(ceil($length / 2)); + } else { + throw new Exception("No cryptographically secure random function available"); + } + return substr(bin2hex($bytes), 0, $length); +} + +function createJob($title, $options): void { + $job = [ + "name" => $title, + "options" => $options, + "date" => date('c') + ]; + + file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/data/jobs/" . round(microtime(true) * 1000000) . "-" . random() . ".json", json_encode($job)); +} + if ($user === null) { header("HTTP/1.1 500 Internal Server Error") and die(); } @@ -31,24 +52,18 @@ if ($input['system_id'] === "7d9f543e-f742-40f6-9d07-86c3f2983124") { die(); } -$lastFronter = json_decode(@file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/last.json"), true) ?? ""; +$lastFronter = json_decode(@file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/data/$system/last.json"), true) ?? ""; if ($input["type"] === "CREATE_MEMBER" || $input["type"] === "UPDATE_MEMBER" || $input["type"] === "DELETE_MEMBER") { createJob("PKMembers", [ "system" => $system ]); - createJob("UpdateAssets", [ - "type" => "members" - ]); } if ($input["type"] === "UPDATE_SYSTEM") { createJob("PKSystem", [ "system" => $system ]); - createJob("UpdateAssets", [ - "type" => "system" - ]); } if ($input["type"] === "CREATE_SWITCH" || $input["type"] === "UPDATE_SWITCH" || $input["type"] === "DELETE_SWITCH") { |