57 lines
1.6 KiB
PHP
57 lines
1.6 KiB
PHP
<?php
|
|
/**
|
|
* GracePress MeshCentral plugin download facade.
|
|
* Generated by scripts/build; do not edit manually.
|
|
*/
|
|
$slug = 'gracepress';
|
|
$manifest = __DIR__ . '/' . $slug . '.json';
|
|
|
|
if (!is_file($manifest)) {
|
|
http_response_code(404);
|
|
header('Content-Type: text/plain; charset=utf-8');
|
|
echo 'Manifest not found';
|
|
exit;
|
|
}
|
|
|
|
$data = json_decode((string) file_get_contents($manifest), true);
|
|
$download = is_array($data) ? (string)($data['download_url'] ?? '') : '';
|
|
$prefix = 'https://christit.com/gracepress/';
|
|
|
|
if ($download === '' || strncmp($download, $prefix, strlen($prefix)) !== 0) {
|
|
http_response_code(404);
|
|
header('Content-Type: text/plain; charset=utf-8');
|
|
echo 'Download not found';
|
|
exit;
|
|
}
|
|
|
|
$zip = basename(parse_url($download, PHP_URL_PATH));
|
|
if (!preg_match('/^[a-zA-Z0-9._-]+\.zip$/', $zip)) {
|
|
http_response_code(404);
|
|
header('Content-Type: text/plain; charset=utf-8');
|
|
echo 'Invalid download';
|
|
exit;
|
|
}
|
|
|
|
$file = __DIR__ . '/' . $zip;
|
|
if (!is_file($file)) {
|
|
http_response_code(404);
|
|
header('Content-Type: text/plain; charset=utf-8');
|
|
echo 'Package not found';
|
|
exit;
|
|
}
|
|
|
|
while (ob_get_level() > 0) {
|
|
ob_end_clean();
|
|
}
|
|
|
|
header('Access-Control-Allow-Origin: *');
|
|
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
|
|
header('Pragma: no-cache');
|
|
header('Content-Type: application/zip');
|
|
header('Content-Disposition: attachment; filename="' . $zip . '"');
|
|
header('Content-Length: ' . filesize($file));
|
|
header('X-GracePress-Download-Url: ' . $download);
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'HEAD') {
|
|
readfile($file);
|
|
} |