Files
2026-11-04 07:55:51 +00:00

50 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/common.php';
/**
* Update-Prüfung der Apps und der Chrome-Erweiterung: GET ?platform=android|windows|chrome liefert die aktuell veröffentlichte Version,
* mit &download=1 die Installationsdatei. Die Quelle ist die Plugin-Webseite (Zugangsschlüssel bleibt auf dem Server).
*/
api_require_method('GET');
api_require_staff();
$platform = (string) ($_GET['platform'] ?? '');
if (!in_array($platform, ['android', 'windows', 'chrome'], true)) api_error(400, 'bad_platform', 'Unbekannte Plattform.');
$info = app_publisher_info($platform);
if (!$info) api_json(['available' => false, 'platform' => $platform]);
if (($_GET['download'] ?? '') !== '1') {
api_json([
'available' => true,
'platform' => $platform,
'version' => (string) $info['version'],
'sha256' => (string) $info['sha256'],
'size' => (int) $info['size'],
'notes' => (string) ($info['notes'] ?? ''),
'publishedAt' => (string) ($info['modified_at'] ?? ''),
]);
}
@set_time_limit(0);
while (ob_get_level() > 0) { @ob_end_clean(); }
header('Content-Type: ' . $info['mime']);
header('Content-Disposition: attachment; filename="' . $info['filename'] . '"');
if ((int) $info['size'] > 0) header('Content-Length: ' . (int) $info['size']);
header('X-Content-Type-Options: nosniff');
header('X-DeskHub-SHA256: ' . $info['sha256']);
header('Cache-Control: private, no-store');
$url = app_publisher_endpoint($platform, true);
$headers = function_exists('catalog_access_headers') ? catalog_access_headers($url) : [];
if (function_exists('curl_init')) {
$ch = curl_init($url);
curl_setopt_array($ch, [CURLOPT_FOLLOWLOCATION => false, CURLOPT_CONNECTTIMEOUT => 8, CURLOPT_TIMEOUT => 0, CURLOPT_HTTPHEADER => $headers, CURLOPT_RETURNTRANSFER => false, CURLOPT_WRITEFUNCTION => static function ($curl, $chunk) { echo $chunk; return strlen($chunk); }]);
curl_exec($ch);
curl_close($ch);
} else {
$remote = @fopen($url, 'rb', false, stream_context_create(['http' => ['timeout' => 0, 'header' => implode("\r\n", $headers)]]));
if ($remote) { fpassthru($remote); fclose($remote); }
}