<?php
require_once __DIR__ . '/../../config.php';
require_once __DIR__ . '/auth.php';
function_admin_login_erfordern();

$cmd = 'fastfetch --logo none';
//$cmd = '/var/www/wecker/skripts_webseite/fastfetch.sh';
//$cmd = 'cat /var/www/wecker/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'),
]);
