Update app.py
This commit is contained in:
@@ -59,9 +59,19 @@ class Config:
|
|||||||
# ============================================================
|
# ============================================================
|
||||||
|
|
||||||
log_level = logging.DEBUG if os.getenv("DEBUG", "false").lower() == "true" else logging.INFO
|
log_level = logging.DEBUG if os.getenv("DEBUG", "false").lower() == "true" else logging.INFO
|
||||||
logging.basicConfig(level=log_level)
|
|
||||||
|
|
||||||
|
logging.basicConfig(
|
||||||
|
level=log_level,
|
||||||
|
format="%(message)s"
|
||||||
|
)
|
||||||
|
|
||||||
|
# 🔇 HTTP Noise entfernen
|
||||||
logging.getLogger("werkzeug").setLevel(logging.ERROR)
|
logging.getLogger("werkzeug").setLevel(logging.ERROR)
|
||||||
|
logging.getLogger("urllib3").setLevel(logging.WARNING)
|
||||||
|
|
||||||
|
# 🔇 Gunicorn Access Logs entfernen
|
||||||
|
logging.getLogger("gunicorn.access").setLevel(logging.WARNING)
|
||||||
|
|
||||||
logger = logging.getLogger("matrix-interceptor")
|
logger = logging.getLogger("matrix-interceptor")
|
||||||
|
|
||||||
def now_iso():
|
def now_iso():
|
||||||
@@ -73,7 +83,7 @@ def log_event(event: str, **kwargs):
|
|||||||
logger.info(f"{base} {details}")
|
logger.info(f"{base} {details}")
|
||||||
|
|
||||||
def debug_log(title, data):
|
def debug_log(title, data):
|
||||||
if config.debug:
|
if os.getenv("DEBUG", "false").lower() == "true":
|
||||||
logger.debug(f"{title}: {json.dumps(data, default=str)}")
|
logger.debug(f"{title}: {json.dumps(data, default=str)}")
|
||||||
|
|
||||||
# ============================================================
|
# ============================================================
|
||||||
@@ -96,7 +106,7 @@ RATE_LIMIT = defaultdict(list)
|
|||||||
METRICS = defaultdict(int)
|
METRICS = defaultdict(int)
|
||||||
|
|
||||||
CACHE_FILE = "/app/cache/known_users.json"
|
CACHE_FILE = "/app/cache/known_users.json"
|
||||||
CACHE_DIRTY = False
|
CACHE_DIRTY = True
|
||||||
|
|
||||||
# ============================================================
|
# ============================================================
|
||||||
# CACHE HANDLING
|
# CACHE HANDLING
|
||||||
@@ -382,19 +392,32 @@ def invite(room_id, event_id):
|
|||||||
|
|
||||||
if domain in config.domain_whitelist:
|
if domain in config.domain_whitelist:
|
||||||
remember_user(sender)
|
remember_user(sender)
|
||||||
return forward_request(
|
METRICS["invite_allowed"] += 1
|
||||||
|
return forward_request(...)
|
||||||
"PUT",
|
"PUT",
|
||||||
f"{config.tuwunel_url}/_matrix/federation/v2/invite/{room_id}/{event_id}",
|
f"{config.tuwunel_url}/_matrix/federation/v2/invite/{room_id}/{event_id}",
|
||||||
request.headers,
|
request.headers,
|
||||||
payload
|
payload
|
||||||
)
|
)
|
||||||
|
|
||||||
if config.block_external_dms and is_external(sender):
|
is_dm = is_likely_dm_event(event)
|
||||||
|
|
||||||
|
if config.block_external_dms and is_dm and is_external(sender):
|
||||||
|
|
||||||
if not is_known_user(sender):
|
if not is_known_user(sender):
|
||||||
|
|
||||||
|
# 🔥 fallback fix
|
||||||
if is_user_in_local_rooms(sender):
|
if is_user_in_local_rooms(sender):
|
||||||
remember_user(sender)
|
remember_user(sender)
|
||||||
|
METRICS["invite_allowed"] += 1
|
||||||
|
|
||||||
|
return forward_request(
|
||||||
|
"PUT",
|
||||||
|
f"{config.tuwunel_url}/_matrix/federation/v2/invite/{room_id}/{event_id}",
|
||||||
|
request.headers,
|
||||||
|
payload
|
||||||
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
METRICS["invite_blocked"] += 1
|
METRICS["invite_blocked"] += 1
|
||||||
log_event(
|
log_event(
|
||||||
|
|||||||
Reference in New Issue
Block a user