46 lines
1.4 KiB
PHP
46 lines
1.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
session_start();
|
|
|
|
// Load config
|
|
$config = require __DIR__ . '/../../config/config.php';
|
|
|
|
// Simple login check (same as index.php)
|
|
$sessionKey = $config['security']['session_key_user'] ?? 'admin_user';
|
|
if (!isset($_SESSION[$sessionKey])) {
|
|
header('Content-Type: application/json');
|
|
echo json_encode(['success' => false, 'message' => 'Not authenticated']);
|
|
exit;
|
|
}
|
|
|
|
$scriptDir = $config['powershell']['script_dir'] ?? __DIR__ . '/../../scripts/powershell';
|
|
$script = $scriptDir . DIRECTORY_SEPARATOR . 'check_environment.ps1';
|
|
$exe = $config['powershell']['exe'] ?? 'powershell';
|
|
$executionPolicy = $config['powershell']['execution_policy'] ?? 'Bypass';
|
|
|
|
if (!file_exists($script)) {
|
|
header('Content-Type: application/json');
|
|
echo json_encode(['success' => false, 'message' => 'Script not found: ' . $script]);
|
|
exit;
|
|
}
|
|
|
|
$cmd = sprintf('%s -NoProfile -NonInteractive -ExecutionPolicy %s -File "%s"', $exe, $executionPolicy, $script);
|
|
|
|
$output = [];
|
|
$returnVar = null;
|
|
exec($cmd . ' 2>&1', $output, $returnVar);
|
|
$json = implode("\n", $output);
|
|
|
|
// Attempt to parse JSON
|
|
$decoded = json_decode($json, true);
|
|
if ($decoded === null) {
|
|
header('Content-Type: application/json');
|
|
echo json_encode(['success' => false, 'message' => 'Invalid JSON output', 'raw' => $json]);
|
|
exit;
|
|
}
|
|
|
|
header('Content-Type: application/json');
|
|
echo json_encode($decoded);
|
|
exit;
|