<?php
// Download direto do arquivo de backup
$file = basename($_GET['file'] ?? '');

if (!$file || !preg_match('/^monitorping_backup_[\d_\-]+\.tar\.gz$/', $file)) {
    http_response_code(400); echo 'Arquivo inválido.'; exit;
}

$path = '/opt/backups/monitorping/' . $file;
if (!file_exists($path)) {
    http_response_code(404); echo 'Arquivo não encontrado.'; exit;
}

header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $file . '"');
header('Content-Length: ' . filesize($path));
header('Cache-Control: no-cache');
readfile($path);
exit;
