465 lines
18 KiB
Python
465 lines
18 KiB
Python
from flask import Blueprint, jsonify, request, Response
|
|
import vona.globals as globals
|
|
import vona.config as config
|
|
import base64
|
|
import re
|
|
import os
|
|
|
|
custom = Blueprint("custom", __name__)
|
|
|
|
# This implements custom endpoints
|
|
# used by other homeserver
|
|
# implementations. They do not start
|
|
# with /_matrix/
|
|
|
|
# This should be split into more
|
|
# files eventually.
|
|
|
|
|
|
@custom.route("/_synapse/admin/v1/suspend/<user_id>", methods=["PUT"])
|
|
@custom.route("/_synapse/admin/v1/deactivate/<user_id>", methods=["POST"])
|
|
@custom.route("/_synapse/admin/v1/reset_password/<user_id>", methods=["POST"])
|
|
@custom.route("/_synapse/admin/v1/users/<user_id>/admin", methods=["PUT"])
|
|
@custom.route("/_synapse/admin/v2/users/<user_id>/delete_devices", methods=["POST"])
|
|
@custom.route("/_synapse/admin/v1/users/<user_id>/shadow_ban", methods=["DELETE", "POST"])
|
|
@custom.route("/_synapse/admin/v1/users/<user_id>/override_ratelimit", methods=["GET", "POST", "DELETE"])
|
|
@custom.route("/_synapse/admin/v1/media/protect/<media_id>", methods=["POST"])
|
|
@custom.route("/_synapse/admin/v1/media/unprotect/<media_id>", methods=["POST"])
|
|
@custom.route("/_synapse/admin/v1/media/quarantine/<s>/<media_id>", methods=["POST"])
|
|
@custom.route("/_synapse/admin/v1/media/unquarantine/<s>/<media_id>", methods=["POST"])
|
|
@custom.route("/_dendrite/admin/purgeRoom/<roomId>", methods=["POST"])
|
|
@custom.route("/_dendrite/admin/refreshDevices/<userId>", methods=["POST"])
|
|
@custom.route("/_dendrite/admin/fulltext/reindex")
|
|
@custom.route("/_synapse/admin/v1/federation/destinations/<destination>/reset_connection", methods=["POST"])
|
|
@custom.route("/_synapse/admin/v1/rooms/<room>")
|
|
@custom.route("/_synapse/admin/v1/rooms/<room_id>/timestamp_to_event")
|
|
@custom.route("/_synapse/admin/v2/rooms/delete_status/<delete_id>")
|
|
@custom.route("/_synapse/admin/v1/rooms/<room_id_or_alias>/make_room_admin", methods=["POST"])
|
|
async def empty_response(**kwargs):
|
|
return jsonify({})
|
|
|
|
|
|
# Synapse
|
|
@custom.route("/_synapse/admin/v1/server_version")
|
|
async def synapse_version():
|
|
return jsonify({"server_version": globals.vona_version})
|
|
|
|
@custom.route("/_synapse/admin/v2/users")
|
|
async def synapse_user_list():
|
|
return jsonify({
|
|
"users": [
|
|
{
|
|
"name": f"@vona:{config.server_name}",
|
|
"is_guest": 0,
|
|
"admin": 0,
|
|
"user_type": "vona",
|
|
"deactivated": 0,
|
|
"erased": False,
|
|
"shadow_banned": 0,
|
|
"displayname": "Vona",
|
|
"avatar_url": f"mxc://{config.server_name}/cat",
|
|
"creation_ts": config.the_funny_number,
|
|
"locked": False
|
|
}
|
|
],
|
|
"total": 1
|
|
})
|
|
|
|
@custom.route("/_synapse/admin/v2/users/<user_id>", methods=["GET", "PUT"])
|
|
async def synapse_user_info(user_id):
|
|
if request.method == "GET":
|
|
return jsonify({
|
|
"name": f"@vona:{config.server_name}",
|
|
"displayname": "Vona",
|
|
"threepids": [],
|
|
"avatar_url": f"mxc://{config.server_name}/cat",
|
|
"is_guest": 0,
|
|
"admin": 0,
|
|
"deactivated": 0,
|
|
"erased": False,
|
|
"shadow_banned": 0,
|
|
"creation_ts": config.the_funny_number,
|
|
"last_seen_ts": config.the_funny_number,
|
|
"appservice_id": config.the_funny_number,
|
|
"consent_server_notice_sent":config.the_funny_number,
|
|
"consent_version": config.the_funny_number,
|
|
"consent_ts": config.the_funny_number,
|
|
"external_ids": [],
|
|
"user_type": "vona",
|
|
"locked": False,
|
|
"suspended": False
|
|
})
|
|
|
|
return jsonify({}), 201
|
|
|
|
@custom.route("/_synapse/admin/v1/whois/<user_id>")
|
|
async def synapse_whois(user_id):
|
|
return jsonify({
|
|
"user_id": f"@vona:{config.server_name}",
|
|
"devices": {
|
|
"": {
|
|
"sessions": [{
|
|
"connections": [{
|
|
"ip":f"127.0.0.1",
|
|
"last_seen":config.the_funny_number,
|
|
"user_agent":f"Vona/{globals.vona_version}"
|
|
}]
|
|
}]
|
|
}
|
|
}
|
|
})
|
|
|
|
@custom.route("/_synapse/admin/v1/users/<user_id>/joined_rooms")
|
|
async def synapse_user_joined_rooms(user_id):
|
|
return jsonify({
|
|
"joined_rooms": [globals.make_event_id().replace("$", "!")],
|
|
"total": 1
|
|
})
|
|
|
|
@custom.route("/_synapse/admin/v1/users/<user_id>/sent_invite_count")
|
|
async def synapse_invite_count(user_id):
|
|
return jsonify({"invite_count": config.the_funny_number})
|
|
|
|
@custom.route("/_synapse/admin/v1/users/<user_id>/accountdata")
|
|
async def synapse_account_data(user_id):
|
|
return jsonify({"account_data":{"global":{}}})
|
|
|
|
@custom.route("/_synapse/admin/v1/users/<user_id>/media", methods=["GET", "DELETE"])
|
|
async def synapse_account_media(user_id):
|
|
if request.method == "GET":
|
|
return jsonify({"media": [{"created_ts":config.the_funny_number,"last_access_ts":config.the_funny_number,"media_id":"cat","media_length":config.the_funny_number,"media_type":"image/jpeg","quarantined_by":"null","safe_from_quarantine":False,"upload_name":"cat.jpg"}], "total": config.the_funny_number})
|
|
|
|
return jsonify({"deleted_media": ["cat"], "total": config.the_funny_number})
|
|
|
|
@custom.route("/_synapse/admin/v1/users/<user_id>/login", methods=["POST"])
|
|
async def synapse_account_login(user_id):
|
|
return jsonify({"access_token": "vona"})
|
|
|
|
@custom.route("/_synapse/admin/v1/users/<user_id>/_allow_cross_signing_replacement_without_uia", methods=["POST"])
|
|
async def synapse_stupid_mas_bullshit(user_id):
|
|
return jsonify({"updatable_without_uia_before_ms": config.the_funny_number})
|
|
|
|
@custom.route("/_synapse/admin/v2/users/<user_id>/devices", methods=["GET", "POST"])
|
|
async def synapse_device_list(user_id):
|
|
if request.method == "GET":
|
|
return jsonify({
|
|
"devices": [{
|
|
"device_id": "VVOONNAA",
|
|
"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}"
|
|
}],
|
|
"total": 1
|
|
})
|
|
|
|
return jsonify({})
|
|
|
|
@custom.route("/_synapse/admin/v2/users/<user_id>/devices/<device_id>", methods=["GET", "PUT", "DELETE"])
|
|
async def synapse_device_info(user_id, device_id):
|
|
if request.method == "GET":
|
|
return jsonify({
|
|
"device_id": "VVOONNAA",
|
|
"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}"
|
|
})
|
|
|
|
return jsonify({})
|
|
|
|
@custom.route("/_synapse/admin/v1/users/<user_id>/pushers")
|
|
async def synapse_pushers(user_id):
|
|
return jsonify({"pushers": [], "total": config.the_funny_number})
|
|
|
|
@custom.route("/_synapse/admin/v1/username_available")
|
|
async def synapse_username_available():
|
|
return jsonify({"available": True})
|
|
|
|
@custom.route("/_synapse/admin/v1/threepid/<medium>/users/<addr>")
|
|
@custom.route("/_synapse/admin/v1/auth_providers/<provider>/users/<ext>")
|
|
async def synapse_threepid(p, a):
|
|
return jsonify({"user_id": f"@vona:{config.server_name}"})
|
|
|
|
@custom.route("/_synapse/admin/v1/<user_id>/redact")
|
|
def synapse_redact(user_id):
|
|
return jsonify({"redact_id": os.urandom(16).hex()})
|
|
|
|
@custom.route("/_synapse/admin/v1/user/redact_status/<redact_id>")
|
|
async def synapse_redact_status(redact_id):
|
|
return jsonify({"status":"active","failed_redactions":[]})
|
|
|
|
@custom.route("/_synapse/admin/v1/experimental_features/<user_id>", methods=["GET", "PUT"])
|
|
async def synapse_experimental_features(user_id):
|
|
return jsonify({"features": {}})
|
|
|
|
@custom.route("/_synapse/admin/v1/register", methods=["GET", "POST"])
|
|
async def synapse_register():
|
|
if request.method == "GET":
|
|
return jsonify({"nonce": os.urandom(16).hex()})
|
|
|
|
return jsonify({"access_token": "vona"})
|
|
|
|
@custom.route("/_synapse/admin/v1/join/<roomId>", methods=["POST"])
|
|
async def synapse_membership_manipulation(roomId):
|
|
return jsonify({"room_id": globals.make_event_id().replace("$", "!")})
|
|
|
|
@custom.route("/_synapse/admin/v1/account_validity/validity", methods=["POST"])
|
|
async def synapse_account_validity():
|
|
return jsonify({"expiration_ts": config.the_funny_number})
|
|
|
|
@custom.route("/_synapse/admin/v1/send_server_notice", methods=["POST"])
|
|
@custom.route("/_synapse/admin/v1/send_server_notice/<txnId>", methods=["PUT"])
|
|
async def synapse_server_notice(**kwargs):
|
|
return jsonify({"event_id": globals.make_event_id()})
|
|
|
|
@custom.route("/_synapse/admin/v1/purge_history/<room_id>/<event_id>", methods=["POST"])
|
|
@custom.route("/_synapse/admin/v1/purge_history/<room_id>", methods=["POST"])
|
|
async def synapse_purge_event(**kwargs):
|
|
return jsonify({"purge_id": os.urandom(16).hex()})
|
|
|
|
@custom.route("/_synapse/admin/v1/purge_history_status/<purge_id>")
|
|
async def synapse_purge_status(purge_id):
|
|
return jsonify({"status":"active"})
|
|
|
|
@custom.route("/_synapse/admin/v1/room/<room_id>/media")
|
|
async def synapse_room_media(room_id):
|
|
return jsonify({"local": [f"mxc://{config.server_name}/cat"], "remote": []})
|
|
|
|
@custom.route("/_synapse/admin/v1/room/<room_id>/media/quarantine", methods=["POST"])
|
|
async def synapse_quarantine_room_media(room_id):
|
|
return jsonify({"num_quarantined": config.the_funny_number})
|
|
|
|
@custom.route("/_synapse/admin/v1/media/<s>/delete", methods=["POST"])
|
|
@custom.route("/_synapse/admin/v1/media/<s>/<media_id>", methods=["DELETE"])
|
|
@custom.route("/_synapse/admin/v1/media/delete", methods=["POST"])
|
|
async def synapse_delete_media_from_server(**kwargs):
|
|
return jsonify({"deleted_media": ["cat"], "total": config.the_funny_number})
|
|
|
|
@custom.route("/_synapse/admin/v1/purge_media_cache", methods=["POST"])
|
|
async def synapse_delete_remote_media():
|
|
return jsonify({"deleted": config.the_funny_number})
|
|
|
|
@custom.route("/_synapse/admin/v1/statistics/users/media")
|
|
async def synapse_media_stats():
|
|
return jsonify({"users":[{"displayname":"Vona","media_count":config.the_funny_number,"media_length":config.the_funny_number,"user_id":f"@vona:{config.server_name}"}],"total":config.the_funny_number})
|
|
|
|
@custom.route("/_synapse/admin/v1/statistics/database/rooms")
|
|
async def synapse_room_stats():
|
|
return jsonify({
|
|
"rooms": [{
|
|
"room_id": globals.make_event_id().replace("$", "!"),
|
|
"estimated_size": config.the_funny_number * 420
|
|
}]
|
|
})
|
|
|
|
@custom.route("/_synapse/admin/v1/background_updates/enabled", methods=["POST", "GET"])
|
|
@custom.route("/_synapse/admin/v1/background_updates/status")
|
|
async def synapse_change_bg_update():
|
|
return jsonify({"enabled":False})
|
|
|
|
# No documentation on what Synapse actually returns for this API, so a blank dict for now
|
|
@custom.route("/_synapse/admin/v1/background_updates/start_job", methods=["POST"])
|
|
async def synapse_bg_update_start_job():
|
|
return jsonify({})
|
|
|
|
|
|
@custom.route("/_synapse/admin/v1/event_reports")
|
|
async def synapse_event_reports():
|
|
return jsonify({
|
|
"event_reports": [{
|
|
"event_id": globals.make_event_id(),
|
|
"id": config.the_funny_number,
|
|
"reason": "",
|
|
"score": config.the_funny_number,
|
|
"received_ts": config.the_funny_number,
|
|
"room_id": globals.make_event_id().replace("$", "!"),
|
|
"name": "Vona",
|
|
"sender": f"@vona:{config.server_name}",
|
|
"user_id": f"@vona:{config.server_name}"
|
|
}],
|
|
"total": config.the_funny_number
|
|
})
|
|
|
|
|
|
@custom.route("/_synapse/admin/v1/event_reports/<report_id>", methods=["GET", "DELETE"])
|
|
async def synapse_interact_with_reported_event(report_id):
|
|
if request.method == "GET":
|
|
return jsonify({
|
|
"event_id": globals.make_event_id(),
|
|
"event_json": globals.hash_and_sign_event({
|
|
"auth_events": [],
|
|
"content": {
|
|
"msgtype": "m.text",
|
|
"body": "Number 15: Burger King Foot Lettuce.\nThe last thing you'd want in your Burger King burger is someones foot fungus, but as it turns out, that might be what you get. A 4channer uploaded a photo, anonymously to the site showcasing his feet in a plastic bin of lettuce with the statement \"This is the lettuce you eat at Burger King.\". Admittedly, he had shoes on, but thats even worse. The post went live at 11:38 PM on July 16 and a mere 20 minutes later the Burger King in question was alerted to the rogue employee. At least, I hope hes rogue. How did it happen? Well, the BK employee hadn't removed the EXIF data from the uploaded photo, which suggested that the culprit was somewhere in Mayfield Heights, Ohio. This was at 11:47. 3 minutes later, at 11:50, the Burger King branch was posted with wishes of happy unemployment. 5 minutes later, the news station was contacted by another 4channer, and 3 minutes later at 11:58 a link was posted: BK's tell us about us online forum. The foot photo, otherwise known as Exhibit A, was attached. Cleveland Seen Magazine contacted the BK in question and the next day when questioned, the breakfast shift manager said \"Oh, I know who that is, hes getting fired\". Mystery solved, by 4chan. Now we can go back to eating our fast food in peace.",
|
|
"format": "org.matrix.custom.html",
|
|
"formatted_body": "Number 15: Burger King Foot Lettuce.<br />The last thing you'd want in your Burger King burger is someones foot fungus, but as it turns out, that might be what you get. A 4channer uploaded a photo, anonymously to the site showcasing his feet in a plastic bin of lettuce with the statement "This is the lettuce you eat at Burger King.". Admittedly, he had shoes on, but thats even worse. The post went live at 11:38 PM on July 16 and a mere 20 minutes later the Burger King in question was alerted to the rogue employee. At least, I hope hes rogue. How did it happen? Well, the BK employee hadn't removed the EXIF data from the uploaded photo, which suggested that the culprit was somewhere in Mayfield Heights, Ohio. This was at 11:47. 3 minutes later, at 11:50, the Burger King branch was posted with wishes of happy unemployment. 5 minutes later, the news station was contacted by another 4channer, and 3 minutes later at 11:58 a link was posted: BK's tell us about us online forum. The foot photo, otherwise known as Exhibit A, was attached. Cleveland Seen Magazine contacted the BK in question and the next day when questioned, the breakfast shift manager said "Oh, I know who that is, hes getting fired". Mystery solved, by 4chan. Now we can go back to eating our fast food in peace."
|
|
},
|
|
"depth": config.the_funny_number,
|
|
"origin": config.server_name,
|
|
"origin_server_ts": config.the_funny_number,
|
|
"prev_events": [globals.make_event_id()],
|
|
"prev_state": [],
|
|
"room_id": globals.make_event_id().replace("$", "!"),
|
|
"sender": f"@vona:{config.server_name}",
|
|
"type": "m.room.message"
|
|
})
|
|
})
|
|
|
|
return jsonify({})
|
|
|
|
@custom.route("/_synapse/admin/v1/federation/destinations")
|
|
async def synapse_federation_destinations():
|
|
return jsonify({
|
|
"destinations": [{}],
|
|
"total": 0
|
|
})
|
|
|
|
@custom.route("/_synapse/admin/v1/federation/destinations/<destination>")
|
|
async def synapse_destination(destination):
|
|
return jsonify({
|
|
"destination": destination,
|
|
"retry_last_ts": config.the_funny_number,
|
|
"retry_interval": config.the_funny_number,
|
|
"failure_ts": config.the_funny_number,
|
|
"last_successful_stream_ordering": None
|
|
})
|
|
|
|
@custom.route("/_synapse/admin/v1/federation/destinations/<destination>/rooms")
|
|
async def synapse_destination_rooms(destination):
|
|
return jsonify({
|
|
"rooms": [],
|
|
"total": 0
|
|
})
|
|
|
|
@custom.route("/_synapse/admin/v1/registration_tokens")
|
|
async def synapse_reg_tokens():
|
|
return jsonify({
|
|
"registration_tokens": [{
|
|
"token": "Vona",
|
|
"uses_allowed": config.the_funny_number,
|
|
"pending": 0,
|
|
"completed": 1,
|
|
"expiry_time": None
|
|
}]
|
|
})
|
|
|
|
@custom.route("/_synapse/admin/v1/registration_tokens/<token>", methods=["GET", "PUT", "DELETE"])
|
|
async def synapse_reg_token(token):
|
|
if request.method == "DELETE":
|
|
return jsonify({})
|
|
|
|
return jsonify({
|
|
"token": "Vona",
|
|
"uses_allowed": config.the_funny_number,
|
|
"pending": 0,
|
|
"completed": 1,
|
|
"expiry_time": None
|
|
})
|
|
|
|
@custom.route("/_synapse/admin/v1/registration_tokens/new", methods=["POST"])
|
|
async def synapse_new_reg_token():
|
|
return jsonify({
|
|
"token": "Vona",
|
|
"uses_allowed": config.the_funny_number,
|
|
"pending": 0,
|
|
"completed": 1,
|
|
"expiry_time": None
|
|
})
|
|
|
|
@custom.route("/_synapse/admin/v1/rooms")
|
|
async def synapse_rooms():
|
|
return jsonify({
|
|
"rooms": [],
|
|
"offset": 0,
|
|
"total_rooms": 0
|
|
})
|
|
|
|
@custom.route("/_synapse/admin/v1/rooms/<room_id>/members")
|
|
async def synapse_room_members(room):
|
|
return jsonify({
|
|
"members": [
|
|
f"@vona:{config.server_name}"
|
|
],
|
|
"total": 1
|
|
})
|
|
|
|
@custom.route("/_synapse/admin/v1/rooms/<room_id>/state")
|
|
async def synapse_room_state(room):
|
|
return jsonify({"state": []})
|
|
|
|
@custom.route("/_synapse/admin/v1/rooms/<room_id>/state")
|
|
async def synapse_room_messages(room):
|
|
return jsonify({
|
|
"chunk": [],
|
|
"end": "vona",
|
|
"start": "vona"
|
|
})
|
|
|
|
@custom.route("/_synapse/admin/v1/rooms/<room_id>/block", methods=["GET", "PUT"])
|
|
async def synapse_block_room(room):
|
|
return jsonify({"block": False})
|
|
|
|
@custom.route("/_synapse/admin/v1/rooms/<room_id>", methods=["DELETE"])
|
|
async def synapse_room_delete(room):
|
|
return jsonify({
|
|
"kicked_users": [
|
|
f"@vona:{config.server_name}"
|
|
],
|
|
"failed_to_kick_users": [],
|
|
"local_aliases": [],
|
|
"new_room_id": f"!vona:{config.server_name}"
|
|
})
|
|
|
|
@custom.route("/_synapse/admin/v2/rooms/<room_id>", methods=["DELETE"])
|
|
async def synapse_room_delete_v2(room):
|
|
return jsonify({"delete_id": "vona"})
|
|
|
|
@custom.route("/_synapse/admin/v2/rooms/<room_id>/delete_status")
|
|
async def synapse_room_delete_status(room):
|
|
return jsonify({"results": []})
|
|
|
|
@custom.route("/_synapse/admin/v1/rooms/<room_id_or_alias>/forward_extremities", methods=["GET"])
|
|
async def synapse_forward_extremities(room):
|
|
if request.method == "DELETE":
|
|
return jsonify({"deleted": 0})
|
|
|
|
return jsonify({
|
|
"count": 1,
|
|
"results": [{
|
|
"event_id": globals.make_event_id(),
|
|
"state_group": config.the_funny_number,
|
|
"depth": config.the_funny_number,
|
|
"received_ts": config.the_funny_number
|
|
}]
|
|
})
|
|
|
|
# Dendrite - https://element-hq.github.io/dendrite/administration/adminapi
|
|
@custom.route("/_dendrite/admin/evacuateUser/<userId>", methods=["POST"])
|
|
async def dendrite_evacuate_user(userId):
|
|
return jsonify({"affected": [globals.make_event_id().replace("$", "!")]})
|
|
|
|
@custom.route("/_dendrite/admin/evacuateRoom/<roomId>", methods=["POST"])
|
|
async def dendrite_evacuate_room(roomId):
|
|
return jsonify({"affected": [f"@vona:{config.server_name}"]})
|
|
|
|
@custom.route("/_dendrite/admin/resetPassword/<userId>", methods=["POST"])
|
|
async def dendrite_reset_pswd(userId):
|
|
return jsonify({"password_updated": True})
|
|
|
|
# Conduwuit/Tuwunel/Continuwuity
|
|
@custom.route("/_continuwuity/local_user_count")
|
|
@custom.route("/_conduwuit/local_user_count")
|
|
@custom.route("/_tuwunel/local_user_count")
|
|
async def conduwuit_user_count():
|
|
return jsonify({"count": 1})
|
|
|
|
@custom.route("/_continuwuity/server_version")
|
|
@custom.route("/_conduwuit/server_version")
|
|
@custom.route("/_tuwunel/server_version")
|
|
async def conduwuit_server_version():
|
|
return jsonify({
|
|
"name": "Vona",
|
|
"version":globals.vona_version
|
|
})
|