| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- declare(strict_types=1);
- // POST api/v1/heartbeat.php
- // Instance status report. The response doubles as a cheap update check, so a
- // cron heartbeat is enough to keep the dashboard current and to learn about a
- // pending update in one request.
- //
- // JSON body: version, php_version, disk_free, pending_migrations, last_backup_at
- require_once __DIR__ . "/../../includes/api.php";
- require_once __DIR__ . "/../../includes/releases.php";
- manageApiRequireMethod("POST");
- $instance = manageApiAuthenticate();
- $body = manageApiReadJsonBody();
- $report = [
- "version" => trim((string) ($body["version"] ?? "")),
- "php_version" => trim((string) ($body["php_version"] ?? "")),
- "disk_free" => (int) ($body["disk_free"] ?? 0),
- "pending_migrations" => max(0, (int) ($body["pending_migrations"] ?? 0)),
- ];
- manageInstanceTouch($instance["id"], $report);
- if (isset($body["last_backup_at"])) {
- try {
- manageInstanceUpdate($instance["id"], [
- "last_backup_at" => trim((string) $body["last_backup_at"]),
- ]);
- } catch (Throwable $exception) {
- manageLogError("Heartbeat backup timestamp update failed", [
- "instance" => $instance["id"],
- "error" => $exception->getMessage(),
- ]);
- }
- }
- $latest = manageReleaseLatestVersion();
- $updateAvailable = false;
- if ($latest !== "" && $report["version"] !== "") {
- $updateAvailable = version_compare(
- ltrim($latest, "vV"),
- ltrim($report["version"], "vV"),
- ">",
- );
- }
- manageApiSendJson(200, [
- "success" => true,
- "instance" => $instance["id"],
- "latest" => $latest,
- "update_available" => $updateAvailable,
- "server_time" => date(DATE_ATOM),
- ]);
|