zmiany w acl

This commit is contained in:
Mateusz Gruszczyński 2025-05-13 08:33:10 +02:00
parent 748b4e47a2
commit 8d29328103

13
app.py
View File

@ -76,8 +76,10 @@ def get_real_ip():
return request.remote_addr return request.remote_addr
def is_allowed_ip(remote_ip, allowed_hosts_str): def is_allowed_ip(remote_ip, allowed_hosts_str):
if remote_ip in ("127.0.0.1", "::1"):
return True
if os.path.exists("emergency_access.txt"): if os.path.exists("emergency_access.txt"):
return True return True
@ -93,7 +95,6 @@ def is_allowed_ip(remote_ip, allowed_hosts_str):
except Exception: except Exception:
continue continue
# Log reverse DNS dla IP odwiedzającego
try: try:
hostname = socket.gethostbyaddr(remote_ip)[0] hostname = socket.gethostbyaddr(remote_ip)[0]
app.logger.info(f"Odwiedzający IP: {remote_ip}, host: {hostname}") app.logger.info(f"Odwiedzający IP: {remote_ip}, host: {hostname}")
@ -102,11 +103,19 @@ def is_allowed_ip(remote_ip, allowed_hosts_str):
return remote_ip in allowed_ips return remote_ip in allowed_ips
# Dodaj filtr Markdown pozwala na zagnieżdżanie linków i obrazków w opisie # Dodaj filtr Markdown pozwala na zagnieżdżanie linków i obrazków w opisie
@app.template_filter('markdown') @app.template_filter('markdown')
def markdown_filter(text): def markdown_filter(text):
return Markup(md.markdown(text)) return Markup(md.markdown(text))
@app.context_processor
def inject_ip_allowed():
settings = GlobalSettings.query.first()
allowed_hosts_str = settings.allowed_login_hosts if settings and settings.allowed_login_hosts else ""
client_ip = get_real_ip()
return {'is_ip_allowed': is_allowed_ip(client_ip, allowed_hosts_str)}
# TRASY PUBLICZNE # TRASY PUBLICZNE
@app.route('/') @app.route('/')