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;