diff --git a/backend/alldebrid.py b/backend/alldebrid.py new file mode 100644 index 0000000..d639e18 --- /dev/null +++ b/backend/alldebrid.py @@ -0,0 +1,40 @@ +import requests +import os + +ALLDEBRID_API_KEY = os.getenv("ALLDEBRID_API_KEY", "mtrQI4h583rHe2ZpvpbC") +NTFY_TOPIC_URL = os.getenv("NTFY_TOPIC_URL", "https://ntfy.lucasroyer.fr/alldebrid") +NTFY_TOKEN = os.getenv("NTFY_TOKEN", "tk_qqi1ayj2a0etxafgicl0h7ww71ofb") # Ton token pour topic protégé + +def check_alldebrid_status(): + # Retourne True si premium actif, False sinon + try: + r = requests.get( + "https://api.alldebrid.com/v4/user", + params={"agent": "ygg-service", "apikey": ALLDEBRID_API_KEY}, + timeout=5 + ) + data = r.json() + return data.get("data", {}).get("user", {}).get("isPremium", False) + except Exception as e: + print("Erreur AllDebrid:", e) + return False + +def send_ntfy(title, message): + # Envoie une notification sur le topic ntfy, avec token si nécessaire + headers = {"Title": title} + if NTFY_TOKEN: + headers["Authorization"] = f"Bearer {NTFY_TOKEN}" + + try: + r = requests.post( + NTFY_TOPIC_URL, + data=message.encode("utf-8"), + headers=headers, + timeout=5 + ) + if r.status_code not in (200, 201): + print(f"❌ Échec notification ({r.status_code}): {r.text}") + else: + print(f"✅ Notification envoyée : {title}") + except Exception as e: + print("Erreur ntfy:", e) \ No newline at end of file diff --git a/backend/routes.py b/backend/routes.py index 6934851..54962e4 100644 --- a/backend/routes.py +++ b/backend/routes.py @@ -5,7 +5,7 @@ import time # Third-party libraries import requests -from flask import render_template, request, redirect, url_for, session, flash, jsonify +from flask import render_template, request, redirect, url_for, session, flash, jsonify, make_response from flask_login import login_user, logout_user, login_required, current_user from werkzeug.security import check_password_hash @@ -13,6 +13,7 @@ from werkzeug.security import check_password_hash from . import db from backend.models import User, LoginIP from backend.utils import format_size, calculate_age +from backend.alldebrid import check_alldebrid_status, send_ntfy MAX_ATTEMPTS = 5 BLOCK_TIME = timedelta(minutes=15) @@ -56,6 +57,15 @@ def init_app(app): db.session.commit() login_user(user) session['user'] = user.username + + # --- Vérification AllDebrid --- + print("Vérification en cours") + premium = check_alldebrid_status() + session['alldebrid_active'] = premium + if not premium: # notifier seulement si le compte n’est plus premium + print("Envoi notif") + send_ntfy("AllDebrid non premium", "Tentative avortée sur ygg-service !") + return redirect(url_for("dashboard")) else: ip_record.count += 1 @@ -78,8 +88,11 @@ def init_app(app): @app.route('/logout') @login_required def logout(): - logout_user() - return redirect(url_for('login')) + logout_user() # Déconnecte Flask-Login + session.clear() # Efface toutes les clés de session + resp = make_response(redirect(url_for('login'))) + resp.set_cookie('session', '', expires=0) # supprime le cookie de session + return resp @app.route('/search') @login_required diff --git a/frontend/static/css/style.css b/frontend/static/css/style.css index cf490a1..dcfcc47 100644 --- a/frontend/static/css/style.css +++ b/frontend/static/css/style.css @@ -11,7 +11,7 @@ body { header { color: #00ff41; text-shadow: 0 0 10px #00ff41; - margin-bottom: 50px; + margin-bottom: 20px; text-align: center; } @@ -38,6 +38,11 @@ td { font-weight: bold; } +.second-header { + font-weight: bold; + margin-bottom: 20px; +} + #results-table td:nth-child(2), #results-table td:nth-child(3), #results-table td:nth-child(4), diff --git a/frontend/templates/base.html b/frontend/templates/base.html index ff83d85..8b33e11 100644 --- a/frontend/templates/base.html +++ b/frontend/templates/base.html @@ -33,6 +33,18 @@ {% endif %} + {% if session.alldebrid_active is defined %} + {% if session.alldebrid_active %} +
+ ✅ Service fonctionnel +
+ {% else %} +
+ ⚠️ Service en panne, je répare ! +
+ {% endif %} + {% endif %} +
{% block content %}{% endblock %}