Public Access
This commit is contained in:
1 parent
6d509edbb9
commit
a510916247
1 file changed
+15
-14
@@ -23,13 +23,25 @@ import modules.model_updater
|
||||
dossier_media = "/DATA/AppData/MULTI-IA-AETHAS38/RAG/Media"
|
||||
os.makedirs(dossier_media, exist_ok=True)
|
||||
|
||||
# --- MIDDLEWARE DE SÉCURITÉ ---
|
||||
# --- MIDDLEWARE DE SÉCURITÉ & SERVEUR MÉDIA UNIFIÉ ---
|
||||
class SecurityMiddleware(BaseHTTPMiddleware):
|
||||
async def dispatch(self, request, call_next):
|
||||
ip = request.headers.get("X-Forwarded-For", request.client.host).split(",")[0].strip()
|
||||
utilisateur = request.cookies.get("aethas_user", "visiteur")
|
||||
|
||||
# EXCLUSION DE /Media POUR NE PAS BLOQUER L'IMAGE
|
||||
# --- LECTURE EN RAM ULTRA-DIRECTE PAR LE MIDDLEWARE ---
|
||||
if request.url.path.startswith("/Media/"):
|
||||
fname = request.url.path.replace("/Media/", "", 1)
|
||||
chemin = os.path.join(dossier_media, fname)
|
||||
if os.path.exists(chemin):
|
||||
try:
|
||||
with open(chemin, "rb") as f:
|
||||
return Response(content=f.read(), media_type="image/png")
|
||||
except Exception as e:
|
||||
return HTMLResponse(f"Erreur : {e}", status_code=500)
|
||||
return HTMLResponse("Fichier introuvable", status_code=404)
|
||||
|
||||
# EXCLUSION DE /Media POUR NE PAS BLOQUER LE RESTE
|
||||
if not request.url.path.startswith(("/Logo", "/login", "/Media")):
|
||||
if verifier_et_bloquer_vpn(ip, utilisateur):
|
||||
return HTMLResponse("<h1 style='color:red; text-align:center;'>Accès refusé</h1><p style='text-align:center;'>VPN ou Proxy strictement interdit.</p>", status_code=403)
|
||||
@@ -49,18 +61,7 @@ app, rt = fast_app(
|
||||
)
|
||||
|
||||
app.mount("/Logo", StaticFiles(directory="Logo"), name="Logo")
|
||||
|
||||
# --- ROUTE MÉDIA INDESTRUCTIBLE (SYNTAXE FASHTHTML NATIVE) ---
|
||||
@rt('/Media/{fname:path}')
|
||||
def get(fname: str):
|
||||
chemin = os.path.join(dossier_media, fname)
|
||||
if os.path.exists(chemin):
|
||||
try:
|
||||
with open(chemin, "rb") as f:
|
||||
return Response(content=f.read(), media_type="image/png")
|
||||
except Exception as e:
|
||||
return HTMLResponse(f"Erreur lecture RAM : {e}", status_code=500)
|
||||
return HTMLResponse("Fichier introuvable", status_code=404)
|
||||
app.mount("/Media", StaticFiles(directory=dossier_media), name="Media")
|
||||
|
||||
# --- ROUTES D'AUTHENTIFICATION ---
|
||||
@rt('/login')
|
||||
|
||||
Reference in new issue
Block a user