All alldebrid premium check

This commit is contained in:
2025-11-11 20:00:08 +01:00
parent b4b75f9545
commit 9435225c8c
4 changed files with 74 additions and 4 deletions

40
backend/alldebrid.py Normal file
View File

@@ -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)

View File

@@ -5,7 +5,7 @@ import time
# Third-party libraries # Third-party libraries
import requests 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 flask_login import login_user, logout_user, login_required, current_user
from werkzeug.security import check_password_hash from werkzeug.security import check_password_hash
@@ -13,6 +13,7 @@ from werkzeug.security import check_password_hash
from . import db from . import db
from backend.models import User, LoginIP from backend.models import User, LoginIP
from backend.utils import format_size, calculate_age from backend.utils import format_size, calculate_age
from backend.alldebrid import check_alldebrid_status, send_ntfy
MAX_ATTEMPTS = 5 MAX_ATTEMPTS = 5
BLOCK_TIME = timedelta(minutes=15) BLOCK_TIME = timedelta(minutes=15)
@@ -56,6 +57,15 @@ def init_app(app):
db.session.commit() db.session.commit()
login_user(user) login_user(user)
session['user'] = user.username 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 nest plus premium
print("Envoi notif")
send_ntfy("AllDebrid non premium", "Tentative avortée sur ygg-service !")
return redirect(url_for("dashboard")) return redirect(url_for("dashboard"))
else: else:
ip_record.count += 1 ip_record.count += 1
@@ -78,8 +88,11 @@ def init_app(app):
@app.route('/logout') @app.route('/logout')
@login_required @login_required
def logout(): def logout():
logout_user() logout_user() # Déconnecte Flask-Login
return redirect(url_for('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') @app.route('/search')
@login_required @login_required

View File

@@ -11,7 +11,7 @@ body {
header { header {
color: #00ff41; color: #00ff41;
text-shadow: 0 0 10px #00ff41; text-shadow: 0 0 10px #00ff41;
margin-bottom: 50px; margin-bottom: 20px;
text-align: center; text-align: center;
} }
@@ -38,6 +38,11 @@ td {
font-weight: bold; font-weight: bold;
} }
.second-header {
font-weight: bold;
margin-bottom: 20px;
}
#results-table td:nth-child(2), #results-table td:nth-child(2),
#results-table td:nth-child(3), #results-table td:nth-child(3),
#results-table td:nth-child(4), #results-table td:nth-child(4),

View File

@@ -33,6 +33,18 @@
{% endif %} {% endif %}
</header> </header>
{% if session.alldebrid_active is defined %}
{% if session.alldebrid_active %}
<div class="second-header">
✅ Service fonctionnel
</div>
{% else %}
<div class="second-header">
⚠️ Service en panne, je répare !
</div>
{% endif %}
{% endif %}
<main> <main>
{% block content %}{% endblock %} {% block content %}{% endblock %}
</main> </main>