Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /SHAdd0WTAka_Zen-Ai-Pentest /api /routes /v1 /stats.py
| """ | |
| Statistics and Analytics Routes | |
| """ | |
| from datetime import datetime, timedelta | |
| from typing import Any | |
| from fastapi import APIRouter, Depends, HTTPException | |
| from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer | |
| router = APIRouter(prefix="/stats", tags=["Statistics"]) | |
| security = HTTPBearer() | |
| # Import verify_token from auth module | |
| try: | |
| from .auth import verify_token | |
| except ImportError: | |
| from api.auth_simple import verify_token as legacy_verify_token | |
| async def verify_token( | |
| credentials: HTTPAuthorizationCredentials = Depends(security), | |
| ): | |
| user = legacy_verify_token(credentials.credentials) | |
| if not user: | |
| raise HTTPException(status_code=401, detail="Invalid token") | |
| return user | |
| def get_severity_color(severity: str) -> str: | |
| """Get color code for severity level""" | |
| colors = { | |
| "critical": "#dc2626", | |
| "high": "#ea580c", | |
| "medium": "#ca8a04", | |
| "low": "#16a34a", | |
| "info": "#2563eb", | |
| } | |
| return colors.get(severity.lower(), "#6b7280") | |
| async def get_stats_overview(user: Any = Depends(verify_token)): | |
| """Get overview statistics""" | |
| # In production, query the database for real stats | |
| return { | |
| "total_scans": 0, | |
| "active_scans": 0, | |
| "completed_scans": 0, | |
| "failed_scans": 0, | |
| "total_findings": 0, | |
| "critical_findings": 0, | |
| "high_findings": 0, | |
| "medium_findings": 0, | |
| "low_findings": 0, | |
| "generated_at": datetime.now().isoformat(), | |
| } | |
| async def get_stats_trends(days: int = 30, user: Any = Depends(verify_token)): | |
| """Get scan trends over time""" | |
| # Generate sample trend data | |
| trends = [] | |
| for i in range(days): | |
| date = datetime.now() - timedelta(days=i) | |
| trends.append({"date": date.strftime("%Y-%m-%d"), "scans": 0, "findings": 0}) | |
| return {"trends": list(reversed(trends))} | |
| async def get_severity_distribution(user: Any = Depends(verify_token)): | |
| """Get findings by severity""" | |
| return { | |
| "distribution": [ | |
| { | |
| "severity": "critical", | |
| "count": 0, | |
| "color": get_severity_color("critical"), | |
| }, | |
| { | |
| "severity": "high", | |
| "count": 0, | |
| "color": get_severity_color("high"), | |
| }, | |
| { | |
| "severity": "medium", | |
| "count": 0, | |
| "color": get_severity_color("medium"), | |
| }, | |
| { | |
| "severity": "low", | |
| "count": 0, | |
| "color": get_severity_color("low"), | |
| }, | |
| { | |
| "severity": "info", | |
| "count": 0, | |
| "color": get_severity_color("info"), | |
| }, | |
| ] | |
| } | |
| async def get_tool_usage_stats(user: Any = Depends(verify_token)): | |
| """Get tool usage statistics""" | |
| return { | |
| "tool_usage": [ | |
| {"tool": "nmap", "executions": 0, "avg_duration": 0}, | |
| {"tool": "sqlmap", "executions": 0, "avg_duration": 0}, | |
| {"tool": "nikto", "executions": 0, "avg_duration": 0}, | |
| ] | |
| } | |
Xet Storage Details
- Size:
- 3.28 kB
- Xet hash:
- b2e95de03445190cadaac93a872b2629d9816460b599f19a743ba65fedbc57f6
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.