38 lines
1.1 KiB
PHP
38 lines
1.1 KiB
PHP
<?php
|
|
include('include/headscript.php');
|
|
$db = DBHandlerSelect::getInstance();
|
|
$pdo = $db->getConnection();
|
|
$logDir = __DIR__ . '/logs/api/';
|
|
|
|
$iddatadb = (int)($_GET['iddatadb'] ?? 0);
|
|
if ($iddatadb <= 0) {
|
|
http_response_code(400);
|
|
exit('iddatadb mancante');
|
|
}
|
|
|
|
$stmt = $pdo->prepare("SELECT log_file, commessaweb FROM datadb WHERE iddatadb = :id LIMIT 1");
|
|
$stmt->execute(['id' => $iddatadb]);
|
|
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (!$row || empty($row['log_file'])) {
|
|
http_response_code(404);
|
|
exit('Nessun log per questa commessa');
|
|
}
|
|
|
|
// solo basename: niente path traversal
|
|
$path = $logDir . basename($row['log_file']);
|
|
if (!is_file($path)) {
|
|
http_response_code(404);
|
|
exit('File di log non trovato: ' . basename($row['log_file']));
|
|
}
|
|
|
|
while (ob_get_level() > 0) {
|
|
ob_end_clean();
|
|
}
|
|
$label = preg_replace('/[^A-Za-z0-9_\-]/', '_', (string)($row['commessaweb'] ?: $iddatadb));
|
|
header('Content-Type: text/plain; charset=utf-8');
|
|
header('Content-Disposition: attachment; filename="log_' . $label . '_' . $iddatadb . '.log"');
|
|
header('Content-Length: ' . filesize($path));
|
|
readfile($path);
|
|
exit;
|