Public Access
This commit is contained in:
1 parent
8cd913d5b3
commit
b5926633a3
2 files changed
+5
-63
No files matched your search
@@ -26,7 +26,7 @@ import modules.model_updater
|
||||
dossier_media = "/DATA/AppData/MULTI-IA-AETHAS38/RAG/Media"
|
||||
os.makedirs(dossier_media, exist_ok=True)
|
||||
|
||||
# --- NOUVEAUX COMPOSANTS UI (SIDEBAR & PAYPAL) ---
|
||||
# --- WIDGET PAYPAL (RECHARGE DE CRÉDITS) ---
|
||||
def render_paypal_recharge_widget(montant_usd: float = 10.00):
|
||||
client_id = os.getenv("PAYPAL_CLIENT_ID", "test")
|
||||
|
||||
@@ -84,61 +84,12 @@ def render_paypal_recharge_widget(montant_usd: float = 10.00):
|
||||
)
|
||||
return modal_overlay
|
||||
|
||||
def render_sidebar_menu():
|
||||
sidebar_style = Style("""
|
||||
:root { --nav-sidebar-width: 260px; }
|
||||
#nav-app-sidebar {
|
||||
position: fixed; top: 0; left: 0; width: var(--nav-sidebar-width); height: 100vh;
|
||||
background: rgba(17, 17, 17, 0.95); backdrop-filter: blur(5px); border-right: 1px solid #333; overflow-y: auto;
|
||||
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
z-index: 9000; padding: 60px 20px 20px 20px;
|
||||
}
|
||||
#nav-app-sidebar.collapsed { transform: translateX(-100%); }
|
||||
#nav-app-sidebar::-webkit-scrollbar { width: 6px; }
|
||||
#nav-app-sidebar::-webkit-scrollbar-thumb { background: #444; border-radius: 3px; }
|
||||
|
||||
#nav-sidebar-toggle {
|
||||
position: fixed; top: 15px; left: 15px; z-index: 9001;
|
||||
background: rgba(0, 0, 0, 0.5); border: 1px solid #333; color: #fff; font-size: 1.2em;
|
||||
cursor: pointer; padding: 5px 10px; border-radius: 5px;
|
||||
transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
body:has(#nav-app-sidebar:not(.collapsed)) #nav-sidebar-toggle {
|
||||
left: calc(var(--nav-sidebar-width) - 50px);
|
||||
}
|
||||
""")
|
||||
|
||||
sidebar_js = Script("""
|
||||
function toggleNavSidebar() {
|
||||
document.getElementById('nav-app-sidebar').classList.toggle('collapsed');
|
||||
}
|
||||
""")
|
||||
|
||||
toggle_btn = Button("☰ Menu", id="nav-sidebar-toggle", onclick="toggleNavSidebar()")
|
||||
|
||||
sidebar_content = Div(
|
||||
H3("Interface Multi-IA", style="color: #888; font-size: 0.9em; text-transform: uppercase; margin-bottom: 15px;"),
|
||||
Div("Comptabilité (Export)", style="padding: 10px; color: #ddd; cursor: pointer; border-radius: 5px; margin-bottom: 5px; background: #222;", onclick="window.location.href='/admin/export_comptable'"),
|
||||
Div("Gestion RAG", style="padding: 10px; color: #ddd; cursor: pointer; border-radius: 5px; margin-bottom: 5px;", onclick="window.location.href='/admin/rag_modal'"),
|
||||
Hr(style="border-color: #333; margin: 20px 0;"),
|
||||
Button(
|
||||
"Recharger des crédits",
|
||||
onclick="document.getElementById('modal-recharge-paypal').style.display='flex'",
|
||||
style="width: 100%; padding: 10px; background: #00e5ff; color: #000; border: none; border-radius: 6px; font-weight: bold; cursor: pointer;"
|
||||
),
|
||||
id="nav-app-sidebar",
|
||||
cls="collapsed"
|
||||
)
|
||||
|
||||
return Div(sidebar_style, sidebar_js, toggle_btn, sidebar_content)
|
||||
|
||||
# --- 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")
|
||||
|
||||
# --- 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)
|
||||
@@ -150,12 +101,10 @@ class SecurityMiddleware(BaseHTTPMiddleware):
|
||||
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)
|
||||
|
||||
# Exclusion stricte du spam de logs (Silence pour /ping et /favicon)
|
||||
if request.url.path not in ["/ping", "/favicon.ico"]:
|
||||
journaliser_ip(ip, f"Accès à {request.url.path}")
|
||||
|
||||
@@ -205,13 +154,9 @@ def get(session, request):
|
||||
if 'current_chat_id' not in session or not session['current_chat_id']:
|
||||
session['current_chat_id'] = str(uuid.uuid4())
|
||||
|
||||
# Génération de la page principale existante
|
||||
main_page = render_main_page(session['current_chat_id'], utilisateur_nom=session['user'])
|
||||
|
||||
# Génération des nouveaux composants
|
||||
paypal_modal = render_paypal_recharge_widget(10.00)
|
||||
|
||||
# Renvoi combiné (les éléments fixed/absolute s'afficheront par-dessus)
|
||||
return paypal_modal, main_page
|
||||
|
||||
@rt('/chat')
|
||||
@@ -261,7 +206,6 @@ def post(cid: str):
|
||||
if cid_str in h: del h[cid_str]; save_history(h)
|
||||
return render_sidebar()
|
||||
|
||||
# --- NOUVELLE ROUTE WEBHOOK PAYPAL ---
|
||||
@rt('/api/paypal/success')
|
||||
async def post(request):
|
||||
data = await request.json()
|
||||
@@ -269,14 +213,11 @@ async def post(request):
|
||||
log_event("INFO", "FINANCE", f"Recharge PayPal validée - OrderID: {order_id}")
|
||||
return {"status": "success"}
|
||||
|
||||
# --- NOUVELLE ROUTE POUR LE RAG (BOUTON MANUEL) ---
|
||||
@rt('/api/forcer_rag')
|
||||
def post(prompt: str, reponse: str, theme: str):
|
||||
"""Intercepte la demande manuelle, lance l'indexation et renvoie un badge vert."""
|
||||
auto_apprendre_rag(prompt, reponse, theme)
|
||||
return Span("✅ Indexé", cls="msg-action-btn", style="background-color: #4caf50; color: white; border: none; cursor: default;")
|
||||
|
||||
# --- NOUVELLES ROUTES POUR L'UPLOAD MODAL DU RAG ---
|
||||
@rt('/admin/rag_modal')
|
||||
def get(session):
|
||||
if session.get('user', '') != 'xavier':
|
||||
@@ -315,7 +256,6 @@ async def post(request, session):
|
||||
|
||||
from modules.export_utils import generer_export_comptable
|
||||
|
||||
# --- NOUVELLE ROUTE POUR L'EXPORT COMPTABLE EXCEL ---
|
||||
@rt('/admin/export_comptable')
|
||||
def get(session):
|
||||
if session.get('user', '') != 'xavier':
|
||||
|
||||
Reference in new issue
Block a user