Add support for displaying prosody version

This only works for authenticated users even in debug mode because
it requires a session with prosody to send the request.

Fixes #66.
This commit is contained in:
Kim Alvefur
2021-03-09 22:08:27 +01:00
committed by Jonas Schäfer
parent 3083c118a3
commit 6de1e5313f
2 changed files with 20 additions and 0 deletions

View File

@@ -101,6 +101,10 @@ async def about() -> str:
extra_versions["babel"] = babel.__version__
extra_versions["wtforms"] = wtforms.__version__
extra_versions["flask-wtf"] = flask_wtf.__version__
try:
extra_versions["Prosody"] = await client.get_server_version()
except quart.exceptions.Unauthorized:
extra_versions["Prosody"] = "unknown"
return await render_template(
"about.html",

View File

@@ -503,6 +503,22 @@ class ProsodyClient:
async with session.post(self._rest_endpoint, data=req) as resp:
return resp.status == 200
@autosession
async def get_server_version(self, session: aiohttp.ClientSession) -> str:
_, domain, _ = split_jid(self.session_address)
req = {
"kind": "iq",
"type": "get",
"version": True,
"to": domain,
}
async with session.post(self._rest_endpoint, data=req) as resp:
try:
return (await resp.json())["version"]["version"]
except:
return "unknown"
@autosession
async def get_user_nickname(
self,