Update app.py

This commit is contained in:
gru 2025-05-12 23:10:04 +02:00
parent 3dfe67a9ea
commit 0d378fa514

8
app.py
View File

@ -113,20 +113,18 @@ def zbiorka(zbiorka_id):
return render_template('zbiorka.html', zbiorka=zb) return render_template('zbiorka.html', zbiorka=zb)
def get_real_ip(): def get_real_ip():
# Sprawdź, czy żądanie pochodzi przez Cloudflare # Cloudflare
if "CF-Connecting-IP" in request.headers: if "CF-Connecting-IP" in request.headers:
return request.headers.get("CF-Connecting-IP") return request.headers.get("CF-Connecting-IP")
# Następnie sprawdź nagłówek X-Real-IP # Nginx proxy (Nginx Proxy Manager / standard reverse proxy)
elif "X-Real-IP" in request.headers: elif "X-Real-IP" in request.headers:
return request.headers.get("X-Real-IP") return request.headers.get("X-Real-IP")
# Jeśli jest nagłówek X-Forwarded-For, pobierz pierwszy adres na liście
elif "X-Forwarded-For" in request.headers: elif "X-Forwarded-For" in request.headers:
forwarded_for = request.headers.get("X-Forwarded-For").split(",") forwarded_for = request.headers.get("X-Forwarded-For").split(",")
return forwarded_for[0].strip() return forwarded_for[0].strip()
# W przeciwnym wypadku użyj standardowego remote_addr # Fallback
return request.remote_addr return request.remote_addr
# TRASY LOGOWANIA I REJESTRACJI # TRASY LOGOWANIA I REJESTRACJI
@app.route('/login', methods=['GET', 'POST']) @app.route('/login', methods=['GET', 'POST'])