false, 'error' => 'RateLimitMonitor service not found', 'path_checked' => $rateLimitMonitorPath ]); exit; } } // Requerir autenticación requireAuthentication(); header('Content-Type: application/json; charset=utf-8'); header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: GET'); header('Access-Control-Allow-Headers: Content-Type'); try { $monitor = new RateLimitMonitor(); $action = $_GET['action'] ?? 'current'; switch ($action) { case 'current': // Obtener estadísticas actuales $stats = $monitor->getCurrentStats(); echo json_encode([ 'success' => true, 'data' => $stats, 'timestamp' => time(), 'datetime' => date('Y-m-d H:i:s') ]); break; case 'history': // Obtener historial $type = $_GET['type'] ?? 'app'; $limit = min(100, intval($_GET['limit'] ?? 20)); $history = $monitor->getUsageHistory($type, $limit); echo json_encode([ 'success' => true, 'data' => $history, 'type' => $type, 'count' => count($history) ]); break; case 'cleanup': // Ejecutar limpieza (solo admin) $monitor->cleanup(); echo json_encode([ 'success' => true, 'message' => 'Limpieza completada' ]); break; default: http_response_code(400); echo json_encode([ 'success' => false, 'error' => 'Acción no válida. Use: current, history, cleanup' ]); } } catch (Exception $e) { http_response_code(500); echo json_encode([ 'success' => false, 'error' => $e->getMessage() ]); }