Fix up configuration, add some meta files and utils

This commit is contained in:
2025-09-30 17:46:54 -04:00
parent 69e86523fb
commit 4d83960fc2
12 changed files with 261 additions and 227 deletions

View File

@@ -1,3 +1,2 @@
__pycache__ __pycache__
servers.json servers.json
src/config.py

1
TODO.txt Normal file
View File

@@ -0,0 +1 @@
- make Vona a proper Python project

BIN
cat.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 140 KiB

9
cmd/generate_key.py Normal file
View File

@@ -0,0 +1,9 @@
# Generates a key in the format compatible with Synapse and Vona.
import base64
import os
key = base64.b64encode(os.urandom(32)).decode("utf-8")[:43].replace("/", "_")
key_id = base64.b64encode(os.urandom(32)).decode("utf-8")[:6].replace("/", "_")
print(f"ed25519 {key_id} {key}")

2
requirements.txt Normal file
View File

@@ -0,0 +1,2 @@
flask[async]
nacl

View File

@@ -1,8 +1,8 @@
from config import server_name, users_can_register, room_dir_room, cat, the_funny_number
from flask import Blueprint, jsonify, request, send_file from flask import Blueprint, jsonify, request, send_file
from s2s import send_join from s2s import send_join
import globals import globals
import asyncio import asyncio
import config
import random import random
import os import os
@@ -61,7 +61,7 @@ async def whois(user):
"sessions": [{ "sessions": [{
"connections": [{ "connections": [{
"ip": "127.0.0.1", "ip": "127.0.0.1",
"last_seen": the_funny_number, "last_seen": config.the_funny_number,
"user_agent": f"Vona/{globals.vona_version}" "user_agent": f"Vona/{globals.vona_version}"
}] }]
}] }]
@@ -103,15 +103,15 @@ async def room_member_count(roomId):
return jsonify({ return jsonify({
"chunk": [{ "chunk": [{
"content": { "content": {
"avatar_url": f"mxc://{server_name}/cat", "avatar_url": f"mxc://{config.server_name}/cat",
"displayname": "Vona", "displayname": "Vona",
"membership": "join" "membership": "join"
}, },
"event_id": globals.make_event_id(), "event_id": globals.make_event_id(),
"origin_server_ts": the_funny_number, "origin_server_ts": config.the_funny_number,
"room_id": roomId, "room_id": roomId,
"sender": f"@vona:{server_name}", "sender": f"@vona:{config.server_name}",
"state_key": f"@vona:{server_name}", "state_key": f"@vona:{config.server_name}",
"type": "m.room.member", "type": "m.room.member",
"unsigned": {} "unsigned": {}
}] }]
@@ -122,7 +122,7 @@ async def room_member_count(roomId):
async def whoami(): async def whoami():
return jsonify({ return jsonify({
"device_id": "VVOONNAA", "device_id": "VVOONNAA",
"user_id": f"@vona:{server_name}" "user_id": f"@vona:{config.server_name}"
}) })
@@ -130,14 +130,14 @@ async def whoami():
@client.route("/_matrix/client/v1/register", methods=["POST"]) @client.route("/_matrix/client/v1/register", methods=["POST"])
@client.route("/_matrix/client/r0/register", methods=["POST"]) @client.route("/_matrix/client/r0/register", methods=["POST"])
async def register(): async def register():
if users_can_register: if config.users_can_register:
try: try:
data = request.get_json() data = request.get_json()
if data and "auth" in data: if data and "auth" in data:
return jsonify({ return jsonify({
"user_id": f"@vona:{server_name}", "user_id": f"@vona:{config.server_name}",
"home_server": f"{server_name}", "home_server": f"{config.server_name}",
"access_token": "vona", "access_token": "vona",
"device_id": "VVOONNAA" "device_id": "VVOONNAA"
}) })
@@ -175,7 +175,7 @@ async def login():
return jsonify({ return jsonify({
"access_token": "vona", "access_token": "vona",
"device_id": "VVOONNAA", "device_id": "VVOONNAA",
"user_id": f"@vona:{server_name}" "user_id": f"@vona:{config.server_name}"
}) })
@client.route("/_matrix/client/v3/account/password/email/requestToken", methods=["POST"]) @client.route("/_matrix/client/v3/account/password/email/requestToken", methods=["POST"])
@@ -191,22 +191,22 @@ async def key_upload():
@client.route("/_matrix/client/unstable/room_keys/version", methods=["POST", "GET"]) @client.route("/_matrix/client/unstable/room_keys/version", methods=["POST", "GET"])
async def room_keys(): async def room_keys():
if request.method == "POST": if request.method == "POST":
return jsonify({"version": str(the_funny_number)}) return jsonify({"version": str(config.the_funny_number)})
return jsonify({ return jsonify({
"algorithm": "m.megolm_backup.v1.curve25519-aes-sha2", "algorithm": "m.megolm_backup.v1.curve25519-aes-sha2",
"auth_data": { "auth_data": {
"public_key":"vonaisflazingbastandsemorymafe", "public_key":"vonaisflazingbastandsemorymafe",
"signatures": { "signatures": {
f"@vona:{server_name}": { f"@vona:{config.server_name}": {
# TODO: Make this actually valid # TODO: Make this actually valid
"ed25519:vonaa": "vona" "ed25519:vonaa": "vona"
} }
} }
}, },
"count": the_funny_number, "count": config.the_funny_number,
"etag": "burgerkingfootlettuce", "etag": "burgerkingfootlettuce",
"version": str(the_funny_number) "version": str(config.the_funny_number)
}) })
@@ -329,8 +329,8 @@ async def sync():
"content": { "content": {
"name": "Burger King Foot Lettuce cult" "name": "Burger King Foot Lettuce cult"
}, },
"origin_server_ts": the_funny_number, "origin_server_ts": config.the_funny_number,
"sender": f"@vona:{server_name}", "sender": f"@vona:{config.server_name}",
"state_key": "", "state_key": "",
"type": "m.room.name", "type": "m.room.name",
"event_id": globals.make_event_id(), "event_id": globals.make_event_id(),
@@ -386,9 +386,9 @@ async def user_directory():
return jsonify({ return jsonify({
"limited": False, "limited": False,
"results": [{ "results": [{
"avatar_url": f"mxc://{server_name}/cat", "avatar_url": f"mxc://{config.server_name}/cat",
"display_name": "Vona", "display_name": "Vona",
"user_id": f"@vona:{server_name}" "user_id": f"@vona:{config.server_name}"
}] }]
}) })
@@ -401,7 +401,7 @@ async def devices():
"device_id": "VVOONNAA", "device_id": "VVOONNAA",
"display_name": "Vona", "display_name": "Vona",
"last_seen_ip": "127.0.0.1", "last_seen_ip": "127.0.0.1",
"last_seen_ts": the_funny_number "last_seen_ts": config.the_funny_number
}] }]
}) })
@@ -414,7 +414,7 @@ async def get_device(device):
"device_id": device, "device_id": device,
"display_name": "Vona", "display_name": "Vona",
"last_seen_ip": "127.0.0.1", "last_seen_ip": "127.0.0.1",
"last_seen_ts": the_funny_number "last_seen_ts": config.the_funny_number
}) })
return jsonify({}) return jsonify({})
@@ -424,7 +424,7 @@ async def get_device(device):
async def refresh(): async def refresh():
return jsonify({ return jsonify({
"access_token": "vona", "access_token": "vona",
"expires_in_ms": the_funny_number * 1000, "expires_in_ms": config.the_funny_number * 1000,
"refresh_token": "vona" "refresh_token": "vona"
}) })
@@ -432,20 +432,20 @@ async def refresh():
@client.route("/_matrix/client/unstable/im.nheko.summary/rooms/<roomId>/summary") @client.route("/_matrix/client/unstable/im.nheko.summary/rooms/<roomId>/summary")
@client.route("/_matrix/client/unstable/im.nheko.summary/summary/<roomId>") @client.route("/_matrix/client/unstable/im.nheko.summary/summary/<roomId>")
@client.route("/_matrix/client/v1/room_summary/<roomId>") @client.route("/_matrix/client/v1/room_summary/<roomId>")
def unstable_room_summary(roomId): async def room_summary(roomId):
room = room_dir_room["chunk"][0] room = config.room_dir_room["chunk"][0]
return jsonify({ return jsonify({
"room_id": room["room_id"], "room_id": globals.make_event_id().replace("$", "!"),
"avatar_url": room["avatar_url"], "avatar_url": f"mxc://{config.server_name}/cat",
"guest_can_join": room["guest_can_join"], "guest_can_join": False,
"name": room["name"], "name": "Vona",
"num_joined_members": room["num_joined_members"], "num_joined_members": config.the_funny_number,
"topic": room["topic"], "topic": None,
"world_readable": room["world_readable"], "world_readable": False,
"join_rule": room["join_rule"], "join_rule": "public",
"room_type": room["room_type"], "room_type": "m.room",
"membership": "join", "membership": "join",
"room_version": 2, "room_version": 2
}) })
@@ -454,8 +454,8 @@ def unstable_room_summary(roomId):
async def room_query(room): async def room_query(room):
if request.method == "GET": if request.method == "GET":
return jsonify({ return jsonify({
"room_id": room_dir_room["chunk"][0]["room_id"], "room_id": globals.make_event_id().replace("$", "!"),
"servers": [server_name] "servers": [config.server_name]
}) })
return jsonify({}) return jsonify({})
@@ -464,7 +464,7 @@ async def room_query(room):
async def room_aliases(room): async def room_aliases(room):
return jsonify({ return jsonify({
"aliases": [ "aliases": [
f"#vona:{server_name}" f"#vona:{config.server_name}"
] ]
}) })
@@ -495,7 +495,7 @@ async def search():
"highlights": [], "highlights": [],
"next_batch": "vona", "next_batch": "vona",
"results": [{ "results": [{
"rank": the_funny_number, "rank": config.the_funny_number,
"result": { "result": {
"content": { "content": {
"msgtype": "m.text", "msgtype": "m.text",
@@ -504,9 +504,9 @@ async def search():
"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 &quot;This is the lettuce you eat at Burger King.&quot;. 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 &quot;Oh, I know who that is, hes getting fired&quot;. Mystery solved, by 4chan. Now we can go back to eating our fast food in peace." "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 &quot;This is the lettuce you eat at Burger King.&quot;. 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 &quot;Oh, I know who that is, hes getting fired&quot;. Mystery solved, by 4chan. Now we can go back to eating our fast food in peace."
}, },
"event_id": event, "event_id": event,
"origin_server_ts": the_funny_number, "origin_server_ts": config.the_funny_number,
"room_id": room, "room_id": room,
"sender": f"@vona:{server_name}", "sender": f"@vona:{config.server_name}",
"type": "m.room.message" "type": "m.room.message"
} }
}] }]
@@ -524,7 +524,7 @@ async def search():
@client.route("/_matrix/media/v3/download/<server>/<media>") @client.route("/_matrix/media/v3/download/<server>/<media>")
@client.route("/_matrix/media/r0/download/<server>/<media>") @client.route("/_matrix/media/r0/download/<server>/<media>")
async def media(**kwargs): async def media(**kwargs):
return send_file(cat) return send_file(config.cat)
@client.route("/_matrix/client/v3/register/available") @client.route("/_matrix/client/v3/register/available")
@@ -538,7 +538,7 @@ async def url_preview():
return jsonify({ return jsonify({
"matrix:image:size": 102400, "matrix:image:size": 102400,
"og:description": "look at this cool cat", "og:description": "look at this cool cat",
"og:image": f"mxc://{server_name}/ascERGshawAWawugaAcauga", "og:image": f"mxc://{config.server_name}/ascERGshawAWawugaAcauga",
"og:image:height": 48, "og:image:height": 48,
"og:image:type": "image/jpg", "og:image:type": "image/jpg",
"og:image:width": 48, "og:image:width": 48,
@@ -547,7 +547,7 @@ async def url_preview():
@client.route("/_matrix/client/v1/media/preview_url") @client.route("/_matrix/client/v1/media/preview_url")
async def media_preview(): async def media_preview():
response = send_file(cat) response = send_file(config.cat)
response.headers["Content-Disposition"] = f'inline; filename="cat.jpg"' response.headers["Content-Disposition"] = f'inline; filename="cat.jpg"'
response.headers["Content-Type"] = "image/jpg" response.headers["Content-Type"] = "image/jpg"
return response return response
@@ -556,12 +556,12 @@ async def media_preview():
@client.route("/_matrix/media/r0/upload", methods=["POST"]) @client.route("/_matrix/media/r0/upload", methods=["POST"])
@client.route("/_matrix/media/v1/create", methods=["POST"]) @client.route("/_matrix/media/v1/create", methods=["POST"])
async def upload_media(): async def upload_media():
return jsonify({"content_uri": f"mxc://{server_name}/cat"}) return jsonify({"content_uri": f"mxc://{config.server_name}/cat"})
@client.route("/_matrix/media/v3/config") @client.route("/_matrix/media/v3/config")
async def media_config(): async def media_config():
return jsonify({"m.upload.size": the_funny_number * 69420}) return jsonify({"m.upload.size": config.the_funny_number * 69420})
@client.route("/_matrix/client/v3/profile/<userId>/<key>", methods=["GET", "PUT", "DELETE"]) @client.route("/_matrix/client/v3/profile/<userId>/<key>", methods=["GET", "PUT", "DELETE"])
@@ -569,7 +569,7 @@ async def media_config():
async def profile_keys(userId, key): async def profile_keys(userId, key):
if request.method == "GET": if request.method == "GET":
if key == "avatar_url": if key == "avatar_url":
return jsonify({"avatar_url": f"mxc://{server_name}/cat"}) return jsonify({"avatar_url": f"mxc://{config.server_name}/cat"})
elif key == "displayname": elif key == "displayname":
return jsonify({"displayname": "Vona"}) return jsonify({"displayname": "Vona"})
@@ -584,7 +584,7 @@ async def profile_keys(userId, key):
@client.route("/_matrix/client/r0/profile/<userId>") @client.route("/_matrix/client/r0/profile/<userId>")
async def user_profile(userId): async def user_profile(userId):
return jsonify({ return jsonify({
"avatar_url": f"mxc://{server_name}/cat", "avatar_url": f"mxc://{config.server_name}/cat",
"displayname": "Vona" "displayname": "Vona"
}) })
@@ -601,9 +601,9 @@ async def room_messages(roomId):
"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 &quot;This is the lettuce you eat at Burger King.&quot;. 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 &quot;Oh, I know who that is, hes getting fired&quot;. Mystery solved, by 4chan. Now we can go back to eating our fast food in peace." "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 &quot;This is the lettuce you eat at Burger King.&quot;. 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 &quot;Oh, I know who that is, hes getting fired&quot;. Mystery solved, by 4chan. Now we can go back to eating our fast food in peace."
}, },
"event_id": globals.make_event_id(), "event_id": globals.make_event_id(),
"origin_server_ts": the_funny_number, "origin_server_ts": config.the_funny_number,
"room_id": roomId, "room_id": roomId,
"sender": f"@vona:{server_name}", "sender": f"@vona:{config.server_name}",
"type": "m.room.message" "type": "m.room.message"
}], }],
"end": f"{os.urandom(16).hex()}", "end": f"{os.urandom(16).hex()}",
@@ -620,7 +620,7 @@ async def query_keys():
@client.route("/_matrix/client/v3/createRoom", methods=["POST"]) @client.route("/_matrix/client/v3/createRoom", methods=["POST"])
@client.route("/_matrix/client/r0/createRoom", methods=["POST"]) @client.route("/_matrix/client/r0/createRoom", methods=["POST"])
async def create_room(): async def create_room():
return jsonify({"room_id": room_dir_room["chunk"][0]["room_id"]}) return jsonify({"room_id": globals.make_event_id().replace("$", "!")})
@client.route("/_matrix/client/unstable/uk.half-shot.msc2666/mutual_rooms") @client.route("/_matrix/client/unstable/uk.half-shot.msc2666/mutual_rooms")
@@ -628,7 +628,7 @@ async def create_room():
async def mutual_rooms(): async def mutual_rooms():
return jsonify({ return jsonify({
"joined": [ "joined": [
room_dir_room["chunk"][0]["room_id"] globals.make_event_id().replace("$", "!")
] ]
}) })
@@ -645,4 +645,7 @@ async def presence(user):
@client.route("/_matrix/client/r0/publicRooms", methods=["GET", "POST"]) @client.route("/_matrix/client/r0/publicRooms", methods=["GET", "POST"])
async def room_directory(): async def room_directory():
return jsonify(room_dir_room) return jsonify({
"chunk": [],
"total_room_count_estimate": 0
})

View File

@@ -1,55 +0,0 @@
# Cat picture to use. Must be a JPEG (most camera photos are JPEG already anyway).
cat = "../cat.jpg"
# Your server name.
server_name = "example.org"
# Room directory room/space.
room_dir_room = {
"chunk": [
{
"avatar_url": f"mxc://{server_name}/T2RoTUs3QyZUeT4kOC9NVzs4b",
"guest_can_join": False,
"join_rule": "public",
"name": "A [matrix] space",
"num_joined_members": 43502,
"room_id": f"!QDckPFoubl1NS2leKkpk:{server_name}",
"room_type": "m.space",
"topic": "A [matrix] space topic",
"world_readable": False
}
],
"total_room_count_estimate": 1
}
# Where users should reach out for support.
support = {
"contacts": [
{
"email_address": "admin@i-didnt-change-my-vona-config.invalid",
"matrix_id": "@admin:i-didnt-change-my-vona-config.invalid",
"role": "m.role.admin"
},
{
"email_address": "admin@i-didnt-change-my-vona-config.invalid",
"role": "m.role.security"
}
]
}
# The port to listen on.
port = 5000
# The address to listen on.
addr = "127.0.0.1"
# Whether or not to enable registration.
users_can_register = False
# The funny number.
the_funny_number = 1337
# Your private key for Vona, in the format of:
# ed25519 <key id> <base64 encoded key>
#
signing_key = ""

84
src/config.py Normal file
View File

@@ -0,0 +1,84 @@
import mimetypes
import tomllib
import os
# Default values
addr = "127.0.0.1"
port = 5000
allow_registration = False
the_funny_number = 1337
cat = "/etc/vona/cat.jpg"
server_name = ""
signing_key = ""
_config_path = "/etc/vona/config.toml"
try:
with open(_config_path, "rb") as f:
_config = tomllib.load(f)
except FileNotFoundError:
print(f"[FATL] Configuration file not found at {_config_path}")
os._exit(1)
except PermissionError:
print(f"[FATL] Permission denied when accessing configuration")
os._exit(1)
except tomllib.TOMLDecodeError as e:
print(f"[FATL] Invalid TOML configuration: {e}")
os._exit(1)
if "address" in _config:
addr = _config["address"]
if "allow_registration" in _config:
allow_registration = _config["allow_registration"]
if "server_name" in _config:
server_name = _config["server_name"]
else:
print("[FATL] `server_name` is not in configuration")
os._exit(1)
if "signing_key" in _config:
signing_key = _config["signing_key"]
else:
print(
"[FATL] `signing_key` is not in configuration."
+ " A signing key can be generated using `cmd/generate_key.py`."
)
os._exit(1)
if "cat" in _config:
cat = _config["cat"]
if not os.path.exists(cat):
print(f"[FATL] Cat photo at {cat} does not exist")
os._exit(1)
if "support" in _config:
support = {
"contacts": [{
"role": "m.role.admin"
}]
}
_support = _config["support"]
if "mxid" in _support:
support["contacts"][0]["matrix_id"] = _support["mxid"]
if "email" in _support:
support["contacts"][0]["email_address"] = _support["email"]
else:
print(f"[WARN] No support contacts are defined")
support = {"contacts": []}
print("[INFO] Configuration file was valid")

View File

@@ -1,6 +1,6 @@
from config import server_name, the_funny_number, room_dir_room
from flask import Blueprint, jsonify, request, Response from flask import Blueprint, jsonify, request, Response
import globals import globals
import config
import base64 import base64
import re import re
import os import os
@@ -25,8 +25,8 @@ custom = Blueprint("custom", __name__)
@custom.route("/_synapse/admin/v1/users/<user_id>/override_ratelimit", methods=["GET", "POST", "DELETE"]) @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/protect/<media_id>", methods=["POST"])
@custom.route("/_synapse/admin/v1/media/unprotect/<media_id>", methods=["POST"]) @custom.route("/_synapse/admin/v1/media/unprotect/<media_id>", methods=["POST"])
@custom.route("/_synapse/admin/v1/media/quarantine/<server_name>/<media_id>", methods=["POST"]) @custom.route("/_synapse/admin/v1/media/quarantine/<s>/<media_id>", methods=["POST"])
@custom.route("/_synapse/admin/v1/media/unquarantine/<server_name>/<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/purgeRoom/<roomId>", methods=["POST"])
@custom.route("/_dendrite/admin/refreshDevices/<userId>", methods=["POST"]) @custom.route("/_dendrite/admin/refreshDevices/<userId>", methods=["POST"])
@custom.route("/_dendrite/admin/fulltext/reindex") @custom.route("/_dendrite/admin/fulltext/reindex")
@@ -41,15 +41,15 @@ async def empty_response(**kwargs):
# Synapse # Synapse
@custom.route("/_synapse/admin/v1/server_version") @custom.route("/_synapse/admin/v1/server_version")
def synapse_version(): async def synapse_version():
return jsonify({"server_version": globals.vona_version}) return jsonify({"server_version": globals.vona_version})
@custom.route("/_synapse/admin/v2/users") @custom.route("/_synapse/admin/v2/users")
def synapse_user_list(): async def synapse_user_list():
return jsonify({ return jsonify({
"users": [ "users": [
{ {
"name": f"@vona:{server_name}", "name": f"@vona:{config.server_name}",
"is_guest": 0, "is_guest": 0,
"admin": 0, "admin": 0,
"user_type": "vona", "user_type": "vona",
@@ -57,8 +57,8 @@ def synapse_user_list():
"erased": False, "erased": False,
"shadow_banned": 0, "shadow_banned": 0,
"displayname": "Vona", "displayname": "Vona",
"avatar_url": f"mxc://{server_name}/cat", "avatar_url": f"mxc://{config.server_name}/cat",
"creation_ts": the_funny_number, "creation_ts": config.the_funny_number,
"locked": False "locked": False
} }
], ],
@@ -66,22 +66,42 @@ def synapse_user_list():
}) })
@custom.route("/_synapse/admin/v2/users/<user_id>", methods=["GET", "PUT"]) @custom.route("/_synapse/admin/v2/users/<user_id>", methods=["GET", "PUT"])
def synapse_user_info(user_id): async def synapse_user_info(user_id):
if request.method == "GET": if request.method == "GET":
return jsonify({"name":f"@vona:{server_name}","displayname":"Vona","threepids":[],"avatar_url":f"mxc://{server_name}/cat","is_guest":0,"admin":0,"deactivated":0,"erased":False,"shadow_banned":0,"creation_ts":the_funny_number,"last_seen_ts":the_funny_number,"appservice_id":the_funny_number,"consent_server_notice_sent":the_funny_number,"consent_version":the_funny_number,"consent_ts":the_funny_number,"external_ids":[],"user_type":"vona","locked":False,"suspended":False}) 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 return jsonify({}), 201
@custom.route("/_synapse/admin/v1/whois/<user_id>") @custom.route("/_synapse/admin/v1/whois/<user_id>")
async def synapse_whois(user_id): async def synapse_whois(user_id):
return jsonify({ return jsonify({
"user_id": f"@vona:{server_name}", "user_id": f"@vona:{config.server_name}",
"devices": { "devices": {
"": { "": {
"sessions": [{ "sessions": [{
"connections": [{ "connections": [{
"ip":f"127.0.0.1", "ip":f"127.0.0.1",
"last_seen":the_funny_number, "last_seen":config.the_funny_number,
"user_agent":f"Vona/{globals.vona_version}" "user_agent":f"Vona/{globals.vona_version}"
}] }]
}] }]
@@ -90,41 +110,44 @@ async def synapse_whois(user_id):
}) })
@custom.route("/_synapse/admin/v1/users/<user_id>/joined_rooms") @custom.route("/_synapse/admin/v1/users/<user_id>/joined_rooms")
def synapse_user_joined_rooms(user_id): async def synapse_user_joined_rooms(user_id):
return jsonify({"joined_rooms":[room_dir_room["chunk"][0]["room_id"]],"total":1}) return jsonify({
"joined_rooms": [globals.make_event_id().replace("$", "!")],
"total": 1
})
@custom.route("/_synapse/admin/v1/users/<user_id>/sent_invite_count") @custom.route("/_synapse/admin/v1/users/<user_id>/sent_invite_count")
async def synapse_invite_count(user_id): async def synapse_invite_count(user_id):
return jsonify({"invite_count": the_funny_number}) return jsonify({"invite_count": config.the_funny_number})
@custom.route("/_synapse/admin/v1/users/<user_id>/accountdata") @custom.route("/_synapse/admin/v1/users/<user_id>/accountdata")
def synapse_account_data(user_id): async def synapse_account_data(user_id):
return jsonify({"account_data":{"global":{}}}) return jsonify({"account_data":{"global":{}}})
@custom.route("/_synapse/admin/v1/users/<user_id>/media", methods=["GET", "DELETE"]) @custom.route("/_synapse/admin/v1/users/<user_id>/media", methods=["GET", "DELETE"])
def synapse_account_media(user_id): async def synapse_account_media(user_id):
if request.method == "GET": if request.method == "GET":
return jsonify({"media": [{"created_ts":the_funny_number,"last_access_ts":the_funny_number,"media_id":"cat","media_length":the_funny_number,"media_type":"image/jpeg","quarantined_by":"null","safe_from_quarantine":False,"upload_name":"cat.jpg"}], "total": the_funny_number}) 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": the_funny_number}) return jsonify({"deleted_media": ["cat"], "total": config.the_funny_number})
@custom.route("/_synapse/admin/v1/users/<user_id>/login", methods=["POST"]) @custom.route("/_synapse/admin/v1/users/<user_id>/login", methods=["POST"])
def synapse_account_login(user_id): async def synapse_account_login(user_id):
return jsonify({"access_token": "vona"}) return jsonify({"access_token": "vona"})
@custom.route("/_synapse/admin/v1/users/<user_id>/_allow_cross_signing_replacement_without_uia", methods=["POST"]) @custom.route("/_synapse/admin/v1/users/<user_id>/_allow_cross_signing_replacement_without_uia", methods=["POST"])
def synapse_stupid_mas_bullshit(user_id): async def synapse_stupid_mas_bullshit(user_id):
return jsonify({"updatable_without_uia_before_ms": the_funny_number}) return jsonify({"updatable_without_uia_before_ms": config.the_funny_number})
@custom.route("/_synapse/admin/v2/users/<user_id>/devices", methods=["GET", "POST"]) @custom.route("/_synapse/admin/v2/users/<user_id>/devices", methods=["GET", "POST"])
def synapse_device_list(user_id): async def synapse_device_list(user_id):
if request.method == "GET": if request.method == "GET":
return jsonify({ return jsonify({
"devices": [{ "devices": [{
"device_id": "VVOONNAA", "device_id": "VVOONNAA",
"display_name": "Vona", "display_name": "Vona",
"last_seen_ip": "127.0.0.1", "last_seen_ip": "127.0.0.1",
"last_seen_ts": 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.vona_version}"
}], }],
"total": 1 "total": 1
@@ -139,7 +162,7 @@ async def synapse_device_info(user_id, device_id):
"device_id": "VVOONNAA", "device_id": "VVOONNAA",
"display_name": "Vona", "display_name": "Vona",
"last_seen_ip": "127.0.0.1", "last_seen_ip": "127.0.0.1",
"last_seen_ts": 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.vona_version}"
}) })
@@ -147,7 +170,7 @@ async def synapse_device_info(user_id, device_id):
@custom.route("/_synapse/admin/v1/users/<user_id>/pushers") @custom.route("/_synapse/admin/v1/users/<user_id>/pushers")
async def synapse_pushers(user_id): async def synapse_pushers(user_id):
return jsonify({"pushers": [], "total": the_funny_number}) return jsonify({"pushers": [], "total": config.the_funny_number})
@custom.route("/_synapse/admin/v1/username_available") @custom.route("/_synapse/admin/v1/username_available")
async def synapse_username_available(): async def synapse_username_available():
@@ -156,7 +179,7 @@ async def synapse_username_available():
@custom.route("/_synapse/admin/v1/threepid/<medium>/users/<addr>") @custom.route("/_synapse/admin/v1/threepid/<medium>/users/<addr>")
@custom.route("/_synapse/admin/v1/auth_providers/<provider>/users/<ext>") @custom.route("/_synapse/admin/v1/auth_providers/<provider>/users/<ext>")
async def synapse_threepid(p, a): async def synapse_threepid(p, a):
return jsonify({"user_id": f"@vona:{server_name}"}) return jsonify({"user_id": f"@vona:{config.server_name}"})
@custom.route("/_synapse/admin/v1/<user_id>/redact") @custom.route("/_synapse/admin/v1/<user_id>/redact")
def synapse_redact(user_id): def synapse_redact(user_id):
@@ -179,11 +202,11 @@ async def synapse_register():
@custom.route("/_synapse/admin/v1/join/<roomId>", methods=["POST"]) @custom.route("/_synapse/admin/v1/join/<roomId>", methods=["POST"])
async def synapse_membership_manipulation(roomId): async def synapse_membership_manipulation(roomId):
return jsonify({"room_id": room_dir_room["chunk"][0]["room_id"]}) return jsonify({"room_id": globals.make_event_id().replace("$", "!")})
@custom.route("/_synapse/admin/v1/account_validity/validity", methods=["POST"]) @custom.route("/_synapse/admin/v1/account_validity/validity", methods=["POST"])
async def synapse_account_validity(): async def synapse_account_validity():
return jsonify({"expiration_ts": the_funny_number}) 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", methods=["POST"])
@custom.route("/_synapse/admin/v1/send_server_notice/<txnId>", methods=["PUT"]) @custom.route("/_synapse/admin/v1/send_server_notice/<txnId>", methods=["PUT"])
@@ -196,37 +219,37 @@ async def synapse_purge_event(**kwargs):
return jsonify({"purge_id": os.urandom(16).hex()}) return jsonify({"purge_id": os.urandom(16).hex()})
@custom.route("/_synapse/admin/v1/purge_history_status/<purge_id>") @custom.route("/_synapse/admin/v1/purge_history_status/<purge_id>")
def synapse_purge_status(purge_id): async def synapse_purge_status(purge_id):
return jsonify({"status":"active"}) return jsonify({"status":"active"})
@custom.route("/_synapse/admin/v1/room/<room_id>/media") @custom.route("/_synapse/admin/v1/room/<room_id>/media")
def synapse_room_media(room_id): async def synapse_room_media(room_id):
return jsonify({"local": [f"mxc://{server_name}/cat"], "remote": []}) return jsonify({"local": [f"mxc://{config.server_name}/cat"], "remote": []})
@custom.route("/_synapse/admin/v1/room/<room_id>/media/quarantine", methods=["POST"]) @custom.route("/_synapse/admin/v1/room/<room_id>/media/quarantine", methods=["POST"])
def synapse_quarantine_room_media(room_id): async def synapse_quarantine_room_media(room_id):
return jsonify({"num_quarantined": the_funny_number}) return jsonify({"num_quarantined": config.the_funny_number})
@custom.route("/_synapse/admin/v1/media/<server_name>/delete", methods=["POST"]) @custom.route("/_synapse/admin/v1/media/<s>/delete", methods=["POST"])
@custom.route("/_synapse/admin/v1/media/<server_name>/<media_id>", methods=["DELETE"]) @custom.route("/_synapse/admin/v1/media/<s>/<media_id>", methods=["DELETE"])
@custom.route("/_synapse/admin/v1/media/delete", methods=["POST"]) @custom.route("/_synapse/admin/v1/media/delete", methods=["POST"])
async def synapse_delete_media_from_server(**kwargs): async def synapse_delete_media_from_server(**kwargs):
return jsonify({"deleted_media": ["cat"], "total": the_funny_number}) return jsonify({"deleted_media": ["cat"], "total": config.the_funny_number})
@custom.route("/_synapse/admin/v1/purge_media_cache", methods=["POST"]) @custom.route("/_synapse/admin/v1/purge_media_cache", methods=["POST"])
async def synapse_delete_remote_media(): async def synapse_delete_remote_media():
return jsonify({"deleted": the_funny_number}) return jsonify({"deleted": config.the_funny_number})
@custom.route("/_synapse/admin/v1/statistics/users/media") @custom.route("/_synapse/admin/v1/statistics/users/media")
async def synapse_media_stats(): async def synapse_media_stats():
return jsonify({"users":[{"displayname":"Vona","media_count":the_funny_number,"media_length":the_funny_number,"user_id":f"@vona:{server_name}"}],"total":the_funny_number}) 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") @custom.route("/_synapse/admin/v1/statistics/database/rooms")
async def synapse_room_stats(): async def synapse_room_stats():
return jsonify({ return jsonify({
"rooms": [{ "rooms": [{
"room_id": room_dir_room["chunk"][0]["room_id"], "room_id": globals.make_event_id().replace("$", "!"),
"estimated_size": the_funny_number * 420 "estimated_size": config.the_funny_number * 420
}] }]
}) })
@@ -235,28 +258,30 @@ async def synapse_room_stats():
async def synapse_change_bg_update(): async def synapse_change_bg_update():
return jsonify({"enabled":False}) return jsonify({"enabled":False})
# No documentation on what Synapse actually returns for this API, so a blank dict for now. # 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"]) @custom.route("/_synapse/admin/v1/background_updates/start_job", methods=["POST"])
async def synapse_bg_update_start_job(): async def synapse_bg_update_start_job():
return jsonify({}) return jsonify({})
@custom.route("/_synapse/admin/v1/event_reports") @custom.route("/_synapse/admin/v1/event_reports")
async def synapse_event_reports(): async def synapse_event_reports():
return jsonify({ return jsonify({
"event_reports": [{ "event_reports": [{
"event_id": globals.make_event_id(), "event_id": globals.make_event_id(),
"id": the_funny_number, "id": config.the_funny_number,
"reason": "", "reason": "",
"score": the_funny_number, "score": config.the_funny_number,
"received_ts": the_funny_number, "received_ts": config.the_funny_number,
"room_id": room_dir_room["chunk"][0]["room_id"], "room_id": globals.make_event_id().replace("$", "!"),
"name": room_dir_room["chunk"][0]["name"], "name": "Vona",
"sender": f"@vona:{server_name}", "sender": f"@vona:{config.server_name}",
"user_id": f"@vona:{server_name}" "user_id": f"@vona:{config.server_name}"
}], }],
"total": the_funny_number "total": config.the_funny_number
}) })
@custom.route("/_synapse/admin/v1/event_reports/<report_id>", methods=["GET", "DELETE"]) @custom.route("/_synapse/admin/v1/event_reports/<report_id>", methods=["GET", "DELETE"])
async def synapse_interact_with_reported_event(report_id): async def synapse_interact_with_reported_event(report_id):
if request.method == "GET": if request.method == "GET":
@@ -270,13 +295,13 @@ async def synapse_interact_with_reported_event(report_id):
"format": "org.matrix.custom.html", "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 &quot;This is the lettuce you eat at Burger King.&quot;. 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 &quot;Oh, I know who that is, hes getting fired&quot;. Mystery solved, by 4chan. Now we can go back to eating our fast food in peace." "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 &quot;This is the lettuce you eat at Burger King.&quot;. 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 &quot;Oh, I know who that is, hes getting fired&quot;. Mystery solved, by 4chan. Now we can go back to eating our fast food in peace."
}, },
"depth": the_funny_number, "depth": config.the_funny_number,
"origin": server_name, "origin": config.server_name,
"origin_server_ts": the_funny_number, "origin_server_ts": config.the_funny_number,
"prev_events": [globals.make_event_id()], "prev_events": [globals.make_event_id()],
"prev_state": [], "prev_state": [],
"room_id": room_dir_room["chunk"][0]["room_id"], "room_id": globals.make_event_id().replace("$", "!"),
"sender": f"@vona:{server_name}", "sender": f"@vona:{config.server_name}",
"type": "m.room.message" "type": "m.room.message"
}) })
}) })
@@ -294,9 +319,9 @@ async def synapse_federation_destinations():
async def synapse_destination(destination): async def synapse_destination(destination):
return jsonify({ return jsonify({
"destination": destination, "destination": destination,
"retry_last_ts": the_funny_number, "retry_last_ts": config.the_funny_number,
"retry_interval": the_funny_number, "retry_interval": config.the_funny_number,
"failure_ts": the_funny_number, "failure_ts": config.the_funny_number,
"last_successful_stream_ordering": None "last_successful_stream_ordering": None
}) })
@@ -312,7 +337,7 @@ async def synapse_reg_tokens():
return jsonify({ return jsonify({
"registration_tokens": [{ "registration_tokens": [{
"token": "Vona", "token": "Vona",
"uses_allowed": the_funny_number, "uses_allowed": config.the_funny_number,
"pending": 0, "pending": 0,
"completed": 1, "completed": 1,
"expiry_time": None "expiry_time": None
@@ -326,7 +351,7 @@ async def synapse_reg_token(token):
return jsonify({ return jsonify({
"token": "Vona", "token": "Vona",
"uses_allowed": the_funny_number, "uses_allowed": config.the_funny_number,
"pending": 0, "pending": 0,
"completed": 1, "completed": 1,
"expiry_time": None "expiry_time": None
@@ -336,7 +361,7 @@ async def synapse_reg_token(token):
async def synapse_new_reg_token(): async def synapse_new_reg_token():
return jsonify({ return jsonify({
"token": "Vona", "token": "Vona",
"uses_allowed": the_funny_number, "uses_allowed": config.the_funny_number,
"pending": 0, "pending": 0,
"completed": 1, "completed": 1,
"expiry_time": None "expiry_time": None
@@ -354,7 +379,7 @@ async def synapse_rooms():
async def synapse_room_members(room): async def synapse_room_members(room):
return jsonify({ return jsonify({
"members": [ "members": [
f"@vona:{server_name}" f"@vona:{config.server_name}"
], ],
"total": 1 "total": 1
}) })
@@ -379,11 +404,11 @@ async def synapse_block_room(room):
async def synapse_room_delete(room): async def synapse_room_delete(room):
return jsonify({ return jsonify({
"kicked_users": [ "kicked_users": [
f"@vona:{server_name}" f"@vona:{config.server_name}"
], ],
"failed_to_kick_users": [], "failed_to_kick_users": [],
"local_aliases": [], "local_aliases": [],
"new_room_id": f"!vona:{server_name}" "new_room_id": f"!vona:{config.server_name}"
}) })
@custom.route("/_synapse/admin/v2/rooms/<room_id>", methods=["DELETE"]) @custom.route("/_synapse/admin/v2/rooms/<room_id>", methods=["DELETE"])
@@ -403,20 +428,20 @@ async def synapse_forward_extremities(room):
"count": 1, "count": 1,
"results": [{ "results": [{
"event_id": globals.make_event_id(), "event_id": globals.make_event_id(),
"state_group": the_funny_number, "state_group": config.the_funny_number,
"depth": the_funny_number, "depth": config.the_funny_number,
"received_ts": the_funny_number "received_ts": config.the_funny_number
}] }]
}) })
# Dendrite - https://element-hq.github.io/dendrite/administration/adminapi # Dendrite - https://element-hq.github.io/dendrite/administration/adminapi
@custom.route("/_dendrite/admin/evacuateUser/<userId>", methods=["POST"]) @custom.route("/_dendrite/admin/evacuateUser/<userId>", methods=["POST"])
async def dendrite_evacuate_user(userId): async def dendrite_evacuate_user(userId):
return jsonify({"affected": [room_dir_room["chunk"][0]["room_id"]]}) return jsonify({"affected": [globals.make_event_id().replace("$", "!")]})
@custom.route("/_dendrite/admin/evacuateRoom/<roomId>", methods=["POST"]) @custom.route("/_dendrite/admin/evacuateRoom/<roomId>", methods=["POST"])
async def dendrite_evacuate_room(roomId): async def dendrite_evacuate_room(roomId):
return jsonify({"affected": [f"@vona:{server_name}"]}) return jsonify({"affected": [f"@vona:{config.server_name}"]})
@custom.route("/_dendrite/admin/resetPassword/<userId>", methods=["POST"]) @custom.route("/_dendrite/admin/resetPassword/<userId>", methods=["POST"])
async def dendrite_reset_pswd(userId): async def dendrite_reset_pswd(userId):

View File

@@ -7,7 +7,7 @@ import copy
import json import json
import re import re
vona_version = "1.4.0" vona_version = "1.4.1"
def canonical_json(value): def canonical_json(value):

View File

@@ -14,7 +14,7 @@ from s2s import server
logging.getLogger("werkzeug").disabled = True logging.getLogger("werkzeug").disabled = True
logging.getLogger("flask").disabled = True logging.getLogger("flask").disabled = True
app = Flask(__name__) app = Flask("vona")
app.register_blueprint(identity) app.register_blueprint(identity)
app.register_blueprint(policy) app.register_blueprint(policy)
@@ -30,6 +30,11 @@ async def preflight():
@app.after_request @app.after_request
async def handle_logging(response): async def handle_logging(response):
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
response.headers["Access-Control-Allow-Origin"] = "*"
response.headers["Access-Control-Allow-Headers"] = "*"
response.headers["Access-Control-Allow-Methods"] = "GET, HEAD, POST, PUT, DELETE, OPTIONS"
if request.method == "OPTIONS": if request.method == "OPTIONS":
# Discard logs for OPTIONS # Discard logs for OPTIONS
return response return response
@@ -47,11 +52,6 @@ async def handle_logging(response):
print(f'[{origin}] [{request.remote_addr}] [{datetime.now().strftime("%d/%b/%Y:%H:%M:%S")}] {request.method} {request.full_path} {response.status_code}') print(f'[{origin}] [{request.remote_addr}] [{datetime.now().strftime("%d/%b/%Y:%H:%M:%S")}] {request.method} {request.full_path} {response.status_code}')
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
response.headers["Access-Control-Allow-Origin"] = "*"
response.headers["Access-Control-Allow-Headers"] = "*"
response.headers["Access-Control-Allow-Methods"] = "GET, HEAD, POST, PUT, DELETE, OPTIONS"
return response return response

View File

@@ -6,7 +6,7 @@ import json
import time import time
import os import os
server = Blueprint("server", __name__) server = Blueprint("s2s", __name__)
def send_join(request, roomId) -> dict: def send_join(request, roomId) -> dict:
@@ -355,7 +355,10 @@ async def make_join(roomId, userId):
@server.route("/_matrix/federation/v1/publicRooms", methods=["POST", "GET"]) @server.route("/_matrix/federation/v1/publicRooms", methods=["POST", "GET"])
async def room_directory(): async def room_directory():
return jsonify(room_dir_room) return jsonify({
"chunk": [],
"total_room_count_estimate": 0
})
# https://spec.matrix.org/latest/server-server-api/#transactions # https://spec.matrix.org/latest/server-server-api/#transactions
@@ -475,45 +478,8 @@ def invite_user(data):
@server.route("/_matrix/federation/v1/hierarchy/<roomId>") @server.route("/_matrix/federation/v1/hierarchy/<roomId>")
def space_hierachy(roomId): async def space_hierachy(roomId):
room = room_dir_room["chunk"][0]
return jsonify({ return jsonify({
"children": [{ "errcode": "M_NOT_FOUND",
"avatar_url": room["avatar_url"], "error": "Room does not exist."
"children_state": [{
"content": {"via": [server_name]},
"origin_server_ts": the_funny_number,
"sender": f"@vona:{server_name}",
"state_key": room["room_id"],
"type": "m.space.child"
}],
"guest_can_join": room["guest_can_join"],
"join_rule": room["join_rule"],
"name": room["name"],
"num_joined_members": room["num_joined_members"],
"room_id": room["room_id"],
"room_type": room["room_type"],
"topic": room["topic"],
"world_readable": room["world_readable"]
}],
"inaccessible_children": [],
"room": {
"allowed_room_ids": [],
"avatar_url": room["avatar_url"],
"children_state": [{
"content": {"via": [server_name]},
"origin_server_ts": the_funny_number,
"sender": f"@vona:{server_name}",
"state_key": room["room_id"],
"type": "m.space.child"
}],
"guest_can_join": room["guest_can_join"],
"join_rule": room["join_rule"],
"name": room["name"],
"num_joined_members": room["num_joined_members"],
"room_id": room["room_id"],
"room_type": room["room_type"],
"topic": room["topic"],
"world_readable": room["world_readable"]
}
}) })