Fix logging and versioning

This commit is contained in:
2025-10-05 20:04:57 -04:00
parent 9985fb48a8
commit 470d4cc4d9
8 changed files with 34 additions and 35 deletions

View File

@@ -62,7 +62,7 @@ async def root():
@app.route("/_matrix/static/")
async def matrix_static():
return f'<!DOCTYPE html><html lang="en"><head><title>Vona {globals.vona_version} is running</title><style>body {{font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;max-width: 40em;margin: auto;text-align: center;}}h1,p {{margin: 1.5em;}}hr {{border: none;background-color: #ccc;color: #ccc;height: 1px;width: 7em;margin-top: 4em;}}.logo {{display: block;width: 12em;height: auto;margin: 4em auto;}}</style></head><body><img src="https://matrix.org/images/matrix-logo.svg" class="logo"><h1>It works! Vona {globals.vona_version} is running</h1><p>Your Vona server is listening on this port and is ready for messages.</p><p>To use this server you\"ll need <a href="https://matrix.org/ecosystem/clients/" target="_blank"rel="noopener noreferrer">a Matrix client</a>.</p><p>Welcome to the Matrix universe :)</p><hr><p><small><a href="https://natribu.org/en/" target="_blank" rel="noopener noreferrer">matrix.org</a></small></p></body></html>'
return f'<!DOCTYPE html><html lang="en"><head><title>Vona {globals.version} is running</title><style>body {{font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;max-width: 40em;margin: auto;text-align: center;}}h1,p {{margin: 1.5em;}}hr {{border: none;background-color: #ccc;color: #ccc;height: 1px;width: 7em;margin-top: 4em;}}.logo {{display: block;width: 12em;height: auto;margin: 4em auto;}}</style></head><body><img src="https://matrix.org/images/matrix-logo.svg" class="logo"><h1>It works! Vona {globals.version} is running</h1><p>Your Vona server is listening on this port and is ready for messages.</p><p>To use this server you\"ll need <a href="https://matrix.org/ecosystem/clients/" target="_blank"rel="noopener noreferrer">a Matrix client</a>.</p><p>Welcome to the Matrix universe :)</p><hr><p><small><a href="https://natribu.org/en/" target="_blank" rel="noopener noreferrer">matrix.org</a></small></p></body></html>'
# Error handlers

View File

@@ -64,7 +64,7 @@ async def whois(user):
"connections": [{
"ip": "127.0.0.1",
"last_seen": config.the_funny_number,
"user_agent": f"Vona/{globals.vona_version}"
"user_agent": f"Vona/{globals.version}"
}]
}]
}

View File

@@ -30,31 +30,31 @@ def _load_toml(path: Path) -> dict:
with path.open("rb") as f:
return tomllib.load(f)
except FileNotFoundError:
_fatal(f"[FATL] Configuration file not found at {path}")
_fatal(f"Configuration file not found at {path}")
except PermissionError:
_fatal(f"[FATL] Permission denied when accessing configuration {path}")
_fatal(f"Permission denied when accessing configuration {path}")
except tomllib.TOMLDecodeError as e:
_fatal(f"[FATL] Invalid TOML configuration: {e}")
_fatal(f"Invalid TOML configuration: {e}")
def _read_signing_key_from_path(path_value) -> str | None:
p = Path(path_value)
if not p.exists():
_fatal(f"[FATL] signing_key_path {p} does not exist")
_fatal(f"signing_key_path {p} does not exist")
try:
return p.read_text(encoding="utf-8").strip()
except Exception as e:
_fatal(f"[FATL] Failed to read signing_key_path {p}: {e}")
_fatal(f"Failed to read signing_key_path {p}: {e}")
def _validate_cat_path(cat_path: str) -> Path:
p = Path(cat_path)
if not p.exists():
_fatal(f"[FATL] Cat photo at {p} does not exist")
_fatal(f"Cat photo at {p} does not exist")
mtype, _ = mimetypes.guess_type(str(p))
if mtype is None or not mtype.startswith("image/"):
_warn(f"[WARN] Cat file {p} does not look like an image (mimetype={mtype})")
_warn(f"Cat file {p} does not look like an image (mimetype={mtype})")
return p
@@ -69,9 +69,7 @@ def _apply_config(cfg: dict) -> None:
try:
port = int(cfg["port"])
except (TypeError, ValueError):
_warn(
f"[WARN] Invalid port in config: {cfg.get('port')}; using default {port}"
)
_warn(f"Invalid port in config: {cfg.get('port')}; using default {port}")
if "allow_registration" in cfg:
allow_registration = bool(cfg["allow_registration"])
@@ -79,12 +77,10 @@ def _apply_config(cfg: dict) -> None:
if "server_name" in cfg:
server_name = str(cfg["server_name"])
else:
_fatal("[FATL] `server_name` is not in configuration")
_fatal("`server_name` is not in configuration")
if "signing_key" in cfg and "signing_key_path" in cfg:
_warn(
"[WARN] Both `signing_key` and `signing_key_path` present. Using `signing_key`."
)
_warn("Both `signing_key` and `signing_key_path` present. Using `signing_key`.")
if "signing_key" in cfg:
signing_key = str(cfg["signing_key"]).strip()
@@ -94,7 +90,7 @@ def _apply_config(cfg: dict) -> None:
signing_key = sk
else:
_fatal(
"[FATL] `signing_key` is not in configuration. "
"`signing_key` is not in configuration. "
"A signing key can be generated using `cmd/generate_key.py`."
)
@@ -115,7 +111,7 @@ def _apply_config(cfg: dict) -> None:
if len(contact) > 1:
support_obj["contacts"].append(contact)
else:
_warn("[WARN] No support contacts are defined")
_warn("No support contacts are defined")
support = support_obj
print("[INFO] Configuration file was valid")

View File

@@ -1 +1 @@
import vona.config
import vona.config

View File

@@ -42,7 +42,7 @@ async def empty_response(**kwargs):
# Synapse
@custom.route("/_synapse/admin/v1/server_version")
async def synapse_version():
return jsonify({"server_version": globals.vona_version})
return jsonify({"server_version": globals.version})
@custom.route("/_synapse/admin/v2/users")
async def synapse_user_list():
@@ -102,7 +102,7 @@ async def synapse_whois(user_id):
"connections": [{
"ip":f"127.0.0.1",
"last_seen":config.the_funny_number,
"user_agent":f"Vona/{globals.vona_version}"
"user_agent":f"Vona/{globals.version}"
}]
}]
}
@@ -148,7 +148,7 @@ async def synapse_device_list(user_id):
"display_name": "Vona",
"last_seen_ip": "127.0.0.1",
"last_seen_ts": config.the_funny_number,
"last_seen_user_agent": f"Vona/{globals.vona_version}"
"last_seen_user_agent": f"Vona/{globals.version}"
}],
"total": 1
})
@@ -163,7 +163,7 @@ async def synapse_device_info(user_id, device_id):
"display_name": "Vona",
"last_seen_ip": "127.0.0.1",
"last_seen_ts": config.the_funny_number,
"last_seen_user_agent": f"Vona/{globals.vona_version}"
"last_seen_user_agent": f"Vona/{globals.version}"
})
return jsonify({})
@@ -460,5 +460,5 @@ async def conduwuit_user_count():
async def conduwuit_server_version():
return jsonify({
"name": "Vona",
"version":globals.vona_version
"version":globals.version
})

View File

@@ -228,7 +228,7 @@ def send_join(request, roomId) -> dict:
async def version():
return jsonify({
"server": {
"version": globals.vona_version,
"version": globals.version,
"name": "Vona"
}
})

View File

@@ -1,4 +1,3 @@
from importlib.metadata import version
import vona.config as config
import nacl.signing
import hashlib
@@ -8,7 +7,7 @@ import copy
import json
import re
vona_version = version("vona")
version = "1.4.1"
def canonical_json(value):