61 lines
2.4 KiB
PHP
61 lines
2.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
require_once __DIR__ . '/inc/lib.php';
|
|
site_require_access();
|
|
|
|
$platform = (string) ($_GET['platform'] ?? '');
|
|
$wanted = (string) ($_GET['version'] ?? '');
|
|
$json = static function (array $data): void {
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
header('Cache-Control: no-store');
|
|
echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
|
exit;
|
|
};
|
|
/** Angaben zu einer Version; für das System-Update (server) mit Signatur des Herausgebers. */
|
|
$describe = static function (string $platform, array $r): array {
|
|
$d = [
|
|
'platform' => $platform,
|
|
'version' => $r['version'],
|
|
'sha256' => $r['sha256'],
|
|
'size' => (int) $r['size'],
|
|
'notes' => $r['notes'],
|
|
'created_at' => $r['created_at'],
|
|
];
|
|
if ($platform === 'server') $d['signature'] = site_sign_update((string) $r['version'], (string) $r['sha256']);
|
|
return $d;
|
|
};
|
|
|
|
// Liste aller Versionen (System-Update: „Bestimmte Version installieren“)
|
|
if (($_GET['list'] ?? '') === '1' && isset(site_app_platforms()[$platform])) {
|
|
$json(['platform' => $platform, 'releases' => array_map(fn($r) => $describe($platform, $r), array_slice(site_app_versions($platform), 0, 20))]);
|
|
}
|
|
|
|
$release = null;
|
|
if ($wanted !== '' && isset(site_app_platforms()[$platform]) && preg_match('/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/', ltrim($wanted, 'vV'))) {
|
|
foreach (site_app_versions($platform) as $r) if ($r['version'] === ltrim($wanted, 'vV')) { $release = $r; break; }
|
|
} elseif ($wanted === '') {
|
|
$release = site_app_release($platform);
|
|
}
|
|
if (!$release) {
|
|
http_response_code(404);
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
exit(json_encode(['error' => 'Kein App-Release vorhanden.']));
|
|
}
|
|
$path = site_storage() . '/apps/' . $platform . '/' . basename((string) $release['file']);
|
|
if (!is_file($path)) {
|
|
http_response_code(404);
|
|
exit;
|
|
}
|
|
if (($_GET['download'] ?? '') !== '1') $json($describe($platform, $release));
|
|
|
|
$kind = site_app_platforms()[$platform];
|
|
$filename = $kind['file'];
|
|
while (ob_get_level() > 0) @ob_end_clean();
|
|
header('Content-Type: ' . $kind['mime']);
|
|
header('Content-Disposition: attachment; filename="' . $filename . '"');
|
|
header('Content-Length: ' . filesize($path));
|
|
header('X-Content-Type-Options: nosniff');
|
|
header('X-DeskHub-SHA256: ' . $release['sha256']);
|
|
header('X-DeskHub-Version: ' . $release['version']);
|
|
readfile($path);
|