<?php
// get_log.php

header('Content-Type: text/plain; charset=UTF-8');

$logFile = '/var/www/nix.roulaise.net/status/qt-temp/qtw*/temp/build.log';
$lines   = 50;

$command = sprintf(
    'tail -n %d %s 2>&1',
    $lines,
    escapeshellarg($logFile)
);

$output = shell_exec($command);

if ($output === null) {
    http_response_code(500);
    echo "Error: Unable to read log file.\n";
    exit;
}

echo $output;
