From 9aa2e062e50e2ba966fcebb99cb68b76f05d0bef Mon Sep 17 00:00:00 2001 From: Kierre Date: Mon, 13 Oct 2025 17:55:48 -0400 Subject: [PATCH] Better logging (for the 3rd time), fix devices list over federation --- vona/__main__.py | 31 +++++++++++++++++++++++++++---- vona/federation/__init__.py | 2 +- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/vona/__main__.py b/vona/__main__.py index 9190ffd..970f520 100644 --- a/vona/__main__.py +++ b/vona/__main__.py @@ -49,7 +49,6 @@ async def handle_logging(response): response.headers["Access-Control-Allow-Methods"] = "GET, HEAD, POST, PUT, DELETE, OPTIONS" if request.method == "OPTIONS": - # Discard logs for OPTIONS return response origin = "unknown" @@ -57,13 +56,31 @@ async def handle_logging(response): try: if "Authorization" in request.headers: if request.headers["Authorization"].split()[0] == "X-Matrix": - origin = request.headers["Authorization"].split('origin="')[1].split('"')[0] + origin = ( + request.headers["Authorization"] + .split("origin=")[1] + .split(",")[0] + ) + + while '"' in origin: + origin = origin.replace('"', "") + + if origin == config.server_name: + return response + else: origin = "client" + except: pass - print(f'[{origin}] [{request.remote_addr}] [{datetime.now().strftime("%d/%b/%Y:%H:%M:%S")}] {request.method} {request.full_path} {response.status_code}') + print( + f"[{origin}] " + + f'[{datetime.now().strftime("%d/%b/%Y:%H:%M:%S")}] ' + + request.method + " " + + request.full_path.rstrip("?") + " " + + str(response.status_code) + ) return response @@ -115,7 +132,13 @@ async def client(): def federation_self_test(): try: - resp = globals.http_client.get(f"https://{config.server_name}/.well-known/matrix/server") + auth = globals.make_auth_header(config.server_name, "GET", "/.well-known/matrix/server") + + resp = globals.http_client.get( + f"https://{config.server_name}/.well-known/matrix/server", + headers={"Authorization": auth} + ) + resp.raise_for_status() print("[INFO] Federation self-test OK") except Exception as e: diff --git a/vona/federation/__init__.py b/vona/federation/__init__.py index bc22519..18f1abc 100644 --- a/vona/federation/__init__.py +++ b/vona/federation/__init__.py @@ -404,7 +404,7 @@ async def user_profile(): async def user_devices(user): return jsonify({ "devices": [], - "stream_id": the_funny_number, + "stream_id": config.the_funny_number, "user_id": f"@vona:{config.server_name}" })