diff --git a/vona/client/__init__.py b/vona/client/__init__.py index ab56273..07a8f44 100644 --- a/vona/client/__init__.py +++ b/vona/client/__init__.py @@ -7,6 +7,7 @@ import random import os from .groups import groups +from .admin import admin from flask import ( Blueprint, @@ -18,6 +19,7 @@ from flask import ( client = Blueprint("client", __name__) client.register_blueprint(groups) +client.register_blueprint(admin) @client.route("/_matrix/client/v3/account/password", methods=["POST"]) @@ -66,52 +68,6 @@ async def spec_versions(): }) -@client.route("/_matrix/client/v3/admin/whois/") -@client.route("/_matrix/client/r0/admin/whois/") -async def whois(user): - if user.startswith("@"): - return jsonify({ - "devices": { - "": { - "sessions": [{ - "connections": [{ - "ip": "127.0.0.1", - "last_seen": config.the_funny_number, - "user_agent": f"Vona/{globals.version}" - }] - }] - } - }, - "user_id": user - }) - - return jsonify({ - "errcode": "M_INVALID_PARAM", - "error": "Expected UserID string to start with '@'" - }) - -@client.route("/_matrix/client/unstable/uk.timedout.msc4323/admin/suspend/", methods=["GET", "PUT"]) -@client.route("/_matrix/client/v1/admin/suspend/", methods=["GET", "PUT"]) -async def suspend(user): - if request.method == "PUT": - req = request.get_json() - if req and "suspended" in req: - return jsonify({"suspended": req["suspended"]}) - - return jsonify({"suspended": True}) - - -@client.route("/_matrix/client/unstable/uk.timedout.msc4323/admin/lock/", methods=["GET", "PUT"]) -@client.route("/_matrix/client/v1/admin/lock/", methods=["GET", "PUT"]) -async def lock(user): - if request.method == "PUT": - req = request.get_json() - if req and "locked" in req: - return jsonify({"locked": req["locked"]}) - - return jsonify({"locked": True}) - - @client.route("/_matrix/client/api/v1/rooms//members") @client.route("/_matrix/client/v3/rooms//members") @client.route("/_matrix/client/r0/rooms//members") diff --git a/vona/client/admin.py b/vona/client/admin.py new file mode 100644 index 0000000..de621ef --- /dev/null +++ b/vona/client/admin.py @@ -0,0 +1,59 @@ +import vona.globals as globals +import vona.config as config + +from flask import ( + Blueprint, + jsonify, + request, +) + +admin = Blueprint("admin", __name__) + +# This implements misc standard admin APIs. + + +@admin.route("/_matrix/client/v3/admin/whois/") +@admin.route("/_matrix/client/r0/admin/whois/") +async def whois(user): + if user.startswith("@"): + return jsonify({ + "devices": { + "": { + "sessions": [{ + "connections": [{ + "ip": "127.0.0.1", + "last_seen": config.the_funny_number, + "user_agent": f"Vona/{globals.version}" + }] + }] + } + }, + "user_id": user + }) + + return jsonify({ + "errcode": "M_INVALID_PARAM", + "error": "Expected UserID string to start with '@'" + }) + + +@admin.route("/_matrix/client/unstable/uk.timedout.msc4323/admin/suspend/", methods=["GET", "PUT"]) +@admin.route("/_matrix/client/v1/admin/suspend/", methods=["GET", "PUT"]) +async def suspend(user): + if request.method == "PUT": + req = request.get_json() + if req and "suspended" in req: + return jsonify({"suspended": req["suspended"]}) + + return jsonify({"suspended": True}) + + +@admin.route("/_matrix/client/unstable/uk.timedout.msc4323/admin/lock/", methods=["GET", "PUT"]) +@admin.route("/_matrix/client/v1/admin/lock/", methods=["GET", "PUT"]) +async def lock(user): + if request.method == "PUT": + req = request.get_json() + if req and "locked" in req: + return jsonify({"locked": req["locked"]}) + + return jsonify({"locked": True})