Add Hammerhead endpoints
This commit is contained in:
@@ -8,11 +8,13 @@ custom = Blueprint("custom", __name__)
|
|||||||
# with /_matrix/
|
# with /_matrix/
|
||||||
|
|
||||||
|
|
||||||
|
from .hammerhead import hammerhead
|
||||||
from .conduwuit import conduwuit
|
from .conduwuit import conduwuit
|
||||||
from .dendrite import dendrite
|
from .dendrite import dendrite
|
||||||
from .telodendria import telo
|
from .telodendria import telo
|
||||||
from .synapse import synapse
|
from .synapse import synapse
|
||||||
|
|
||||||
|
custom.register_blueprint(hammerhead)
|
||||||
custom.register_blueprint(conduwuit)
|
custom.register_blueprint(conduwuit)
|
||||||
custom.register_blueprint(dendrite)
|
custom.register_blueprint(dendrite)
|
||||||
custom.register_blueprint(synapse)
|
custom.register_blueprint(synapse)
|
||||||
|
|||||||
79
vona/custom/hammerhead.py
Normal file
79
vona/custom/hammerhead.py
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
from flask import Blueprint, request, jsonify
|
||||||
|
from vona.config import the_funny_number
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
from vona.federation import send_join
|
||||||
|
import vona.globals as globals
|
||||||
|
import vona.config as config
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
hammerhead = Blueprint("hammerhead", __name__)
|
||||||
|
|
||||||
|
# Hammerhead endpoints. Not documented, but code is at:
|
||||||
|
# https://codeberg.org/timedout/hammerhead/src/branch/dev/hammerhead/router/routes/hammerhead
|
||||||
|
|
||||||
|
@hammerhead.route("/_hammerhead/uptime")
|
||||||
|
async def uptime():
|
||||||
|
return jsonify({"started_at": config.the_funny_number})
|
||||||
|
|
||||||
|
@hammerhead.route("/_hammerhead/version")
|
||||||
|
async def version():
|
||||||
|
return jsonify({"version": globals.version})
|
||||||
|
|
||||||
|
|
||||||
|
@hammerhead.route("/_hammerhead/admin/server-info/<server>")
|
||||||
|
async def server_info(server):
|
||||||
|
return jsonify({
|
||||||
|
"destination": {
|
||||||
|
"expires": datetime.now(timezone.utc).isoformat(),
|
||||||
|
"host_header": server,
|
||||||
|
"ip_port": [
|
||||||
|
f"{server}:443"
|
||||||
|
],
|
||||||
|
"server_name": server
|
||||||
|
},
|
||||||
|
"keys": globals.sign_json({
|
||||||
|
"old_verify_keys": {},
|
||||||
|
"server_name": server,
|
||||||
|
"valid_until_ts": int(time.time() * 1000 + 604800000),
|
||||||
|
"verify_keys": {
|
||||||
|
f"ed25519:{config.signing_key.split()[1]}": {
|
||||||
|
"key": globals.pubkey()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
"software": {
|
||||||
|
"server": {
|
||||||
|
"version": globals.version,
|
||||||
|
"name": "Vona"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@hammerhead.route("/_hammerhead/admin/rooms/<room>/state-resolver")
|
||||||
|
async def room_state(room):
|
||||||
|
class bullshit:
|
||||||
|
def get_json():
|
||||||
|
return {}
|
||||||
|
|
||||||
|
state = send_join(bullshit, room)["state"]
|
||||||
|
formatted_state = {}
|
||||||
|
event_cache = {}
|
||||||
|
|
||||||
|
for event in state:
|
||||||
|
key = f"{event["type"]}:{event["state_key"]}"
|
||||||
|
formatted_state[key] = event
|
||||||
|
|
||||||
|
event_id = event["event_id"]
|
||||||
|
event_cache[event_id] = event
|
||||||
|
|
||||||
|
del event["event_id"]
|
||||||
|
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
"current_state": formatted_state,
|
||||||
|
"event_cache": event_cache,
|
||||||
|
"room_id": room,
|
||||||
|
"room_version": globals.room_version_from_id(room)
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user