Better logging (for the 3rd time), fix devices list over federation
This commit is contained in:
@@ -49,7 +49,6 @@ async def handle_logging(response):
|
|||||||
response.headers["Access-Control-Allow-Methods"] = "GET, HEAD, POST, PUT, DELETE, OPTIONS"
|
response.headers["Access-Control-Allow-Methods"] = "GET, HEAD, POST, PUT, DELETE, OPTIONS"
|
||||||
|
|
||||||
if request.method == "OPTIONS":
|
if request.method == "OPTIONS":
|
||||||
# Discard logs for OPTIONS
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
origin = "unknown"
|
origin = "unknown"
|
||||||
@@ -57,13 +56,31 @@ async def handle_logging(response):
|
|||||||
try:
|
try:
|
||||||
if "Authorization" in request.headers:
|
if "Authorization" in request.headers:
|
||||||
if request.headers["Authorization"].split()[0] == "X-Matrix":
|
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:
|
else:
|
||||||
origin = "client"
|
origin = "client"
|
||||||
|
|
||||||
except:
|
except:
|
||||||
pass
|
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
|
return response
|
||||||
|
|
||||||
@@ -115,7 +132,13 @@ async def client():
|
|||||||
|
|
||||||
def federation_self_test():
|
def federation_self_test():
|
||||||
try:
|
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()
|
resp.raise_for_status()
|
||||||
print("[INFO] Federation self-test OK")
|
print("[INFO] Federation self-test OK")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -404,7 +404,7 @@ async def user_profile():
|
|||||||
async def user_devices(user):
|
async def user_devices(user):
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"devices": [],
|
"devices": [],
|
||||||
"stream_id": the_funny_number,
|
"stream_id": config.the_funny_number,
|
||||||
"user_id": f"@vona:{config.server_name}"
|
"user_id": f"@vona:{config.server_name}"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user