<?php
require __DIR__ . '/../config.php';
require __DIR__ . '/auth.php';
requireLogin();

$cmd = 'fastfetch --logo none';
//$cmd = '/var/www/html/skripts_webseite/fastfetch.sh';
//$cmd = 'cat /var/www/html/Metrics/Fastfetch/Fastfetch.txt';


exec($cmd . ' 2>&1', $out, $code);

$text = implode("\n", $out);

/* ANSI Escape Codes entfernen */
$text = preg_replace('/\x1B\[[0-9;]*[A-Za-z]/', '', $text);

header('Content-Type: application/json');
echo json_encode([
    'code' => $code,
    'output' => trim($text),
    'ts' => date('H:i:s'),
]);
