Forráskód Böngészése

Merge branch 'main' of github.com:kaelthasmanu/SquidStats into dev

Manuel 8 hónapja
szülő
commit
fbdc644246
6 módosított fájl, 64 hozzáadás és 41 törlés
  1. 3 5
      README.md
  2. 3 6
      README_es.md
  3. 1 1
      requirements.txt
  4. 21 2
      routes/admin/helpers.py
  5. 13 10
      routes/admin_routes.py
  6. 23 17
      routes/api_routes.py

+ 3 - 5
README.md

@@ -152,6 +152,9 @@ _A modern tool for parsing and analyzing Squid logs, providing a sleek and user-
   - Total Transmitted Data
   - Total Request
   - And More...
+- **_Quota System_**:
+  - Quota per users
+  - Quota per group
 - **_And More_**
 
 ## <a href="#readme-top"><img align="right" border="0" src="https://github.com/kaelthasmanu/SquidStats/blob/main/assets/up_arrow.png" width="22" ></a>
@@ -676,11 +679,6 @@ sudo rm -rf /opt/squidstats
 - **Interface Improvements** 🎨
   - Report export (PDF, Excel)
 
-- **Security Features** 🔒
-  - User authentication
-  - System audit logs
-  - Automated alerts
-
 - **Optimization and Performance** ⚡
   - Enhanced data caching
   - Historical log compression

+ 3 - 6
README_es.md

@@ -151,7 +151,9 @@ _Una herramienta moderna para analizar logs de Squid, proporcionando un panel el
   - Total de Usuarios
   - Total de Datos Transmitidos
   - Total de Solicitudes
-  - Y Más...
+- **_Sistema de Cuotas_**:
+  - Quota por usuarios
+  - Quota por grupos 
 - **_Y Más_**
 
 ## <a href="#readme-top"><img align="right" border="0" src="https://github.com/kaelthasmanu/SquidStats/blob/main/assets/up_arrow.png" width="22" ></a>
@@ -702,11 +704,6 @@ sudo rm -rf /opt/squidstats
 - **Mejoras de Interfaz** 🎨
   - Exportación de reportes (PDF, Excel)
 
-- **Características de Seguridad** 🔒
-  - Autenticación de usuarios
-  - Logs de auditoría del sistema
-  - Alertas automatizadas
-
 - **Optimización y Rendimiento** ⚡
   - Cache de datos mejorado
   - Compresión de logs históricos

+ 1 - 1
requirements.txt

@@ -10,7 +10,7 @@ psutil==7.2.2
 eventlet==0.40.4
 flask_socketio==5.6.1
 pytz
-requests==2.32.5
+requests==2.33.0
 #icapclient3
 uvicorn==0.41.0
 PyJWT==2.12.1

+ 21 - 2
routes/admin/helpers.py

@@ -92,15 +92,34 @@ def json_error(message: str, status_code: int = 400, *, details: str | None = No
     """
     resp = {"status": "error", "message": message}
     if is_debug() and details:
-        resp["details"] = details
+        # Avoid leaking raw stack traces in debug output too.
+        if "Traceback" in details or "Exception" in details:
+            resp["details"] = "[REDACTED; check logs]"
+        else:
+            resp["details"] = details
     return jsonify(resp), status_code
 
 
+def _sanitize_response_payload(payload: dict) -> dict:
+    """Remove sensitive fields that may expose stack traces or exception info."""
+    if not payload:
+        return {}
+
+    forbidden = {"stack", "stack_trace", "trace", "traceback", "exception", "error"}
+    sanitized = {}
+    for key, value in payload.items():
+        if key.lower() in forbidden:
+            sanitized[key] = "[REDACTED]"
+        else:
+            sanitized[key] = value
+    return sanitized
+
+
 def json_success(message: str, *, extra: dict | None = None):
     """Build a standard JSON success response."""
     resp = {"status": "success", "message": message}
     if extra:
-        resp.update(extra)
+        resp.update(_sanitize_response_payload(extra))
     return jsonify(resp)
 
 

+ 13 - 10
routes/admin_routes.py

@@ -18,6 +18,7 @@ from loguru import logger
 from config import Config
 from database.database import get_session
 from database.models.models import BlacklistDomain
+from routes.admin.helpers import json_error, json_success
 from services.auth.auth_service import AuthService, admin_required, api_auth_required
 from services.auth.user_service import (
     create_user as service_create_user,
@@ -598,11 +599,12 @@ def delete_user(user_id):
 def restart_squid():
     success, message, details = service_restart_squid()
     if success:
-        return jsonify({"status": "success", "message": message})
-    resp = {"status": "error", "message": message}
-    if bool(current_app.debug) and details:
-        resp["details"] = details
-    return jsonify(resp), 500
+        return json_success(message)
+    return json_error(
+        message or "Could not restart squid",
+        500,
+        details=str(details) if details else None,
+    )
 
 
 @admin_bp.route("/api/reload-squid", methods=["POST"])
@@ -610,11 +612,12 @@ def restart_squid():
 def reload_squid():
     success, message, details = service_reload_squid()
     if success:
-        return jsonify({"status": "success", "message": message})
-    resp = {"status": "error", "message": message}
-    if bool(current_app.debug) and details:
-        resp["details"] = details
-    return jsonify(resp), 500
+        return json_success(message)
+    return json_error(
+        message or "Could not reload squid",
+        500,
+        details=str(details) if details else None,
+    )
 
 
 @admin_bp.route("/api/get-tables", methods=["GET"])

+ 23 - 17
routes/api_routes.py

@@ -3,6 +3,7 @@ from loguru import logger
 from werkzeug.exceptions import BadRequest
 
 from database.database import get_session
+from routes.admin.helpers import json_error, json_success
 from services.analytics.auditoria_service import (
     find_by_ip,
     find_by_keyword,
@@ -211,44 +212,49 @@ def api_mark_notifications_read():
 def api_delete_notification(notification_id):
     try:
         delete_notification(notification_id)
-        return jsonify(
-            {"success": True, "unread_count": get_all_notifications()["unread_count"]}
+        return json_success(
+            "Notification deleted",
+            extra={"unread_count": get_all_notifications()["unread_count"]},
         )
     except Exception as e:
-        logger.error(f"Error deleting notification: {e}")
-        return jsonify({"success": False, "error": "Internal server error"}), 500
+        logger.exception("Error deleting notification")
+        return json_error("Internal server error", 500, details=str(e))
 
 
 @api_bp.route("/notifications/delete-all", methods=["DELETE"])
 def api_delete_all_notifications():
     try:
         delete_all_notifications()
-        return jsonify({"success": True, "unread_count": 0})
+        return json_success("All notifications deleted", extra={"unread_count": 0})
     except Exception as e:
-        logger.error(f"Error deleting all notifications: {e}")
-        return jsonify({"success": False, "error": "Internal server error"}), 500
+        logger.exception("Error deleting all notifications")
+        return json_error("Internal server error", 500, details=str(e))
 
 
 @api_bp.route("/restart-squid", methods=["POST"])
 @admin_required
 def api_restart_squid():
     success, message, details = restart_squid()
-    status_code = 200 if success else 500
-    response = {"success": success, "message": message}
-    if details:
-        response["details"] = details
-    return jsonify(response), status_code
+    if success:
+        return json_success(message)
+    return json_error(
+        message or "Could not restart squid",
+        500,
+        details=str(details) if details else None,
+    )
 
 
 @api_bp.route("/reload-squid", methods=["POST"])
 @admin_required
 def api_reload_squid():
     success, message, details = reload_squid()
-    status_code = 200 if success else 500
-    response = {"success": success, "message": message}
-    if details:
-        response["details"] = details
-    return jsonify(response), status_code
+    if success:
+        return json_success(message)
+    return json_error(
+        message or "Could not reload squid",
+        500,
+        details=str(details) if details else None,
+    )
 
 
 def validate_required_fields(audit_type, data):