Fix logging and versioning
This commit is contained in:
@@ -1,18 +1,22 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "vona"
|
name = "vona"
|
||||||
version = "1.4.1"
|
|
||||||
description = "Flazing bast Matrix homeserver"
|
description = "Flazing bast Matrix homeserver"
|
||||||
authors = [
|
|
||||||
{name = "Kierre",email = "vel@riseup.net"}
|
|
||||||
]
|
|
||||||
license = {text = "Velicense"}
|
license = {text = "Velicense"}
|
||||||
requires-python = ">=3.13"
|
requires-python = ">=3.12"
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"httpx (>=0.28.1,<0.29.0)",
|
"httpx (>=0.28.1,<0.29.0)",
|
||||||
"pynacl (>=1.6.0,<2.0.0)",
|
"pynacl (>=1.6.0,<2.0.0)",
|
||||||
"flask[async] (>=3.1.2,<4.0.0)",
|
"flask[async] (>=3.1.2,<4.0.0)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
authors = [
|
||||||
|
{ name = "Kierre", email = "vel@riseup.net" }
|
||||||
|
]
|
||||||
|
|
||||||
|
# We put this in the code itself rather than here.
|
||||||
|
version = "0.0.0"
|
||||||
|
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ async def root():
|
|||||||
|
|
||||||
@app.route("/_matrix/static/")
|
@app.route("/_matrix/static/")
|
||||||
async def 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
|
# Error handlers
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ async def whois(user):
|
|||||||
"connections": [{
|
"connections": [{
|
||||||
"ip": "127.0.0.1",
|
"ip": "127.0.0.1",
|
||||||
"last_seen": config.the_funny_number,
|
"last_seen": config.the_funny_number,
|
||||||
"user_agent": f"Vona/{globals.vona_version}"
|
"user_agent": f"Vona/{globals.version}"
|
||||||
}]
|
}]
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,31 +30,31 @@ def _load_toml(path: Path) -> dict:
|
|||||||
with path.open("rb") as f:
|
with path.open("rb") as f:
|
||||||
return tomllib.load(f)
|
return tomllib.load(f)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
_fatal(f"[FATL] Configuration file not found at {path}")
|
_fatal(f"Configuration file not found at {path}")
|
||||||
except PermissionError:
|
except PermissionError:
|
||||||
_fatal(f"[FATL] Permission denied when accessing configuration {path}")
|
_fatal(f"Permission denied when accessing configuration {path}")
|
||||||
except tomllib.TOMLDecodeError as e:
|
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:
|
def _read_signing_key_from_path(path_value) -> str | None:
|
||||||
p = Path(path_value)
|
p = Path(path_value)
|
||||||
if not p.exists():
|
if not p.exists():
|
||||||
_fatal(f"[FATL] signing_key_path {p} does not exist")
|
_fatal(f"signing_key_path {p} does not exist")
|
||||||
try:
|
try:
|
||||||
return p.read_text(encoding="utf-8").strip()
|
return p.read_text(encoding="utf-8").strip()
|
||||||
except Exception as e:
|
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:
|
def _validate_cat_path(cat_path: str) -> Path:
|
||||||
p = Path(cat_path)
|
p = Path(cat_path)
|
||||||
if not p.exists():
|
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))
|
mtype, _ = mimetypes.guess_type(str(p))
|
||||||
if mtype is None or not mtype.startswith("image/"):
|
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
|
return p
|
||||||
|
|
||||||
@@ -69,9 +69,7 @@ def _apply_config(cfg: dict) -> None:
|
|||||||
try:
|
try:
|
||||||
port = int(cfg["port"])
|
port = int(cfg["port"])
|
||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
_warn(
|
_warn(f"Invalid port in config: {cfg.get('port')}; using default {port}")
|
||||||
f"[WARN] Invalid port in config: {cfg.get('port')}; using default {port}"
|
|
||||||
)
|
|
||||||
|
|
||||||
if "allow_registration" in cfg:
|
if "allow_registration" in cfg:
|
||||||
allow_registration = bool(cfg["allow_registration"])
|
allow_registration = bool(cfg["allow_registration"])
|
||||||
@@ -79,12 +77,10 @@ def _apply_config(cfg: dict) -> None:
|
|||||||
if "server_name" in cfg:
|
if "server_name" in cfg:
|
||||||
server_name = str(cfg["server_name"])
|
server_name = str(cfg["server_name"])
|
||||||
else:
|
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:
|
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:
|
if "signing_key" in cfg:
|
||||||
signing_key = str(cfg["signing_key"]).strip()
|
signing_key = str(cfg["signing_key"]).strip()
|
||||||
@@ -94,7 +90,7 @@ def _apply_config(cfg: dict) -> None:
|
|||||||
signing_key = sk
|
signing_key = sk
|
||||||
else:
|
else:
|
||||||
_fatal(
|
_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`."
|
"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:
|
if len(contact) > 1:
|
||||||
support_obj["contacts"].append(contact)
|
support_obj["contacts"].append(contact)
|
||||||
else:
|
else:
|
||||||
_warn("[WARN] No support contacts are defined")
|
_warn("No support contacts are defined")
|
||||||
support = support_obj
|
support = support_obj
|
||||||
|
|
||||||
print("[INFO] Configuration file was valid")
|
print("[INFO] Configuration file was valid")
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ async def empty_response(**kwargs):
|
|||||||
# Synapse
|
# Synapse
|
||||||
@custom.route("/_synapse/admin/v1/server_version")
|
@custom.route("/_synapse/admin/v1/server_version")
|
||||||
async def synapse_version():
|
async def synapse_version():
|
||||||
return jsonify({"server_version": globals.vona_version})
|
return jsonify({"server_version": globals.version})
|
||||||
|
|
||||||
@custom.route("/_synapse/admin/v2/users")
|
@custom.route("/_synapse/admin/v2/users")
|
||||||
async def synapse_user_list():
|
async def synapse_user_list():
|
||||||
@@ -102,7 +102,7 @@ async def synapse_whois(user_id):
|
|||||||
"connections": [{
|
"connections": [{
|
||||||
"ip":f"127.0.0.1",
|
"ip":f"127.0.0.1",
|
||||||
"last_seen":config.the_funny_number,
|
"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",
|
"display_name": "Vona",
|
||||||
"last_seen_ip": "127.0.0.1",
|
"last_seen_ip": "127.0.0.1",
|
||||||
"last_seen_ts": config.the_funny_number,
|
"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
|
"total": 1
|
||||||
})
|
})
|
||||||
@@ -163,7 +163,7 @@ async def synapse_device_info(user_id, device_id):
|
|||||||
"display_name": "Vona",
|
"display_name": "Vona",
|
||||||
"last_seen_ip": "127.0.0.1",
|
"last_seen_ip": "127.0.0.1",
|
||||||
"last_seen_ts": config.the_funny_number,
|
"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({})
|
return jsonify({})
|
||||||
@@ -460,5 +460,5 @@ async def conduwuit_user_count():
|
|||||||
async def conduwuit_server_version():
|
async def conduwuit_server_version():
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"name": "Vona",
|
"name": "Vona",
|
||||||
"version":globals.vona_version
|
"version":globals.version
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ def send_join(request, roomId) -> dict:
|
|||||||
async def version():
|
async def version():
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"server": {
|
"server": {
|
||||||
"version": globals.vona_version,
|
"version": globals.version,
|
||||||
"name": "Vona"
|
"name": "Vona"
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
from importlib.metadata import version
|
|
||||||
import vona.config as config
|
import vona.config as config
|
||||||
import nacl.signing
|
import nacl.signing
|
||||||
import hashlib
|
import hashlib
|
||||||
@@ -8,7 +7,7 @@ import copy
|
|||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
|
|
||||||
vona_version = version("vona")
|
version = "1.4.1"
|
||||||
|
|
||||||
|
|
||||||
def canonical_json(value):
|
def canonical_json(value):
|
||||||
|
|||||||
Reference in New Issue
Block a user