Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
9b6988a029
|
|||
|
2f891508ab
|
|||
|
f23a74de5c
|
|||
|
b71096663c
|
|||
|
1fce4d5ba1
|
|||
|
c1a4de06ce
|
|||
|
1e6c7adb41
|
|||
|
6cc08fcb02
|
|||
|
458d69da84
|
|||
|
8c513ac738
|
|||
|
3ec0f2ab4f
|
|||
|
b5e74af72f
|
|||
|
d2e61a3b07
|
|||
|
24133be98c
|
|||
|
647916b749
|
|||
|
6056268a2e
|
|||
|
b4d2f8e728
|
|||
|
2cb6fd005a
|
|||
|
fe43b77611
|
39
MSCs.md
Normal file
39
MSCs.md
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
# MSCs
|
||||||
|
List of MSCs implemented by Vona.
|
||||||
|
|
||||||
|
Merged MSCs:
|
||||||
|
|
||||||
|
* [MSC971: Groups](https://github.com/matrix-org/matrix-spec-proposals/issues/971)
|
||||||
|
* [MSC1708: .well-known for server name resolution](https://github.com/velikopter/matrix-spec-proposals/blob/edutypes/proposals/1708-well-known-for-federation.md)
|
||||||
|
* [MSC1753: C2S Capabilities API](https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/1753-capabilities.md)
|
||||||
|
* [MSC1794: Federation v2 Invite API](https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/1794-federation-v2-invites.md)
|
||||||
|
* [MSC1802: Better format for send_join and send_leave](https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/1802-standardised-federation-response-format.md)
|
||||||
|
* [MSC1812: Federation Make Membership Room Version](https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/1812-federation-make-membership.md)
|
||||||
|
* [MSC1929: Homeserver Admin Contact and Support page](https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/1929-admin-contact.md)
|
||||||
|
* [MSC2320: Versions information for identity servers](https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/2320-identity-versions.md)
|
||||||
|
* [MSC2659: Application service ping endpoint](https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/2659-appservice-ping.md)
|
||||||
|
* [MSC2713: Remove deprecated Identity Service endpoints](https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/2713-remove-deprecated-identity-endpoints.md)
|
||||||
|
* [MSC3266: Room Summary API](https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/3266-room-summary.md)
|
||||||
|
* [MSC3383: Include destination in X-Matrix Auth Header](https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/3383-fed-auth-destination.md)
|
||||||
|
* [MSC4133: Extended User Profile API](https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/4133-extended-profiles.md)
|
||||||
|
* [MSC4151: Reporting rooms](https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/4151-report-room.md)
|
||||||
|
* [MSC4260: Reporting users](https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/4260-report-user.md)
|
||||||
|
|
||||||
|
|
||||||
|
Non-merged MSCs:
|
||||||
|
|
||||||
|
* [MSC4358: Out-of-room server discovery](https://github.com/matrix-org/matrix-spec-proposals/pull/4358)
|
||||||
|
* [MSC4367: via routes in the published room directory](https://github.com/matrix-org/matrix-spec-proposals/pull/4367)
|
||||||
|
* [MSC4370: Federation endpoint for retrieving current extremities](https://github.com/matrix-org/matrix-spec-proposals/pull/4370)
|
||||||
|
* [MSC4373: Server opt-out of specific EDU types](https://github.com/matrix-org/matrix-spec-proposals/pull/4373)
|
||||||
|
|
||||||
|
|
||||||
|
Room version MSCs:
|
||||||
|
* [MSC1759: Room V2](https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/1759-rooms-v2.md)
|
||||||
|
* [MSC1659: Room V3](https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/1659-event-id-as-hashes.md)
|
||||||
|
* [MSC2002: Room V4](https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/2002-rooms-v4.md)
|
||||||
|
* [MSC2077: Room V5](https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/2077-rooms-v5.md)
|
||||||
|
* [MSC2240: Room V6](https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/2240-rooms-v6.md)
|
||||||
|
* [MSC2998: Room V7](https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/2998-rooms-v7.md)
|
||||||
|
* [MSC3289: Room V8](https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/3289-rooms-v8.md)
|
||||||
|
* [MSC3375: Room V9](https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/3375-room-v9.md)
|
||||||
3
TODO.md
3
TODO.md
@@ -1 +1,2 @@
|
|||||||
Nothing yet...
|
- use `resolvematrix` async instead of sync
|
||||||
|
- implement groups over federation
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
# read __main__.py
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
from flask import Flask, jsonify, request, redirect
|
|
||||||
import vona.globals as globals
|
import vona.globals as globals
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import vona.config as config
|
import vona.config as config
|
||||||
@@ -6,6 +5,14 @@ import threading
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from flask import (
|
||||||
|
Flask,
|
||||||
|
jsonify,
|
||||||
|
request,
|
||||||
|
redirect,
|
||||||
|
abort,
|
||||||
|
)
|
||||||
|
|
||||||
from vona.federation import server
|
from vona.federation import server
|
||||||
from vona.custom import custom
|
from vona.custom import custom
|
||||||
from vona.identity import identity
|
from vona.identity import identity
|
||||||
@@ -37,7 +44,7 @@ async def validate_json():
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
request.get_json(force=True)
|
request.get_json(force=True)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
return jsonify({"error": "Content not JSON.", "errcode": "M_NOT_JSON"}), 400
|
return jsonify({"error": "Content not JSON.", "errcode": "M_NOT_JSON"}), 400
|
||||||
|
|
||||||
|
|
||||||
@@ -74,6 +81,9 @@ async def handle_logging(response):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
if request.path.startswith("/.well-known/matrix/"):
|
||||||
|
return response
|
||||||
|
|
||||||
print(
|
print(
|
||||||
f"[{origin}] " +
|
f"[{origin}] " +
|
||||||
f'[{datetime.now().strftime("%d/%b/%Y:%H:%M:%S")}] ' +
|
f'[{datetime.now().strftime("%d/%b/%Y:%H:%M:%S")}] ' +
|
||||||
@@ -137,7 +147,10 @@ def federation_self_test():
|
|||||||
destination=config.server_name,
|
destination=config.server_name,
|
||||||
)
|
)
|
||||||
|
|
||||||
resp.raise_for_status()
|
if str(resp.status_code).startswith("5") or str(resp.status_code).startswith("4"):
|
||||||
|
print(f"[FATL] Federation self-test failed: status code is not acceptable ({str(resp.status_code)})")
|
||||||
|
os._exit(1)
|
||||||
|
|
||||||
print("[INFO] Federation self-test OK")
|
print("[INFO] Federation self-test OK")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[FATL] Federation self-test failed: {e}")
|
print(f"[FATL] Federation self-test failed: {e}")
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
from flask import Blueprint, jsonify
|
|
||||||
from vona.config import the_funny_number
|
from vona.config import the_funny_number
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
|
from flask import (
|
||||||
|
Blueprint,
|
||||||
|
jsonify,
|
||||||
|
)
|
||||||
|
|
||||||
apps = Blueprint("appservice", __name__)
|
apps = Blueprint("appservice", __name__)
|
||||||
|
|
||||||
# This implements both being a homeserver and
|
# This implements both being a homeserver and
|
||||||
@@ -10,6 +14,7 @@ apps = Blueprint("appservice", __name__)
|
|||||||
# Endpoints invoked by the homeserver are put
|
# Endpoints invoked by the homeserver are put
|
||||||
# lower than ones invoked by the appservice.
|
# lower than ones invoked by the appservice.
|
||||||
|
|
||||||
|
|
||||||
@apps.route("/_matrix/client/v1/appservice/<app>/ping", methods=["POST"])
|
@apps.route("/_matrix/client/v1/appservice/<app>/ping", methods=["POST"])
|
||||||
async def homeserver_ping(app):
|
async def homeserver_ping(app):
|
||||||
# Sleeping here makes it more realistic
|
# Sleeping here makes it more realistic
|
||||||
|
|||||||
@@ -1,12 +1,23 @@
|
|||||||
from flask import Blueprint, jsonify, request, send_file
|
|
||||||
from vona.federation import send_join
|
from vona.federation import send_join
|
||||||
import vona.globals as globals
|
import vona.globals as globals
|
||||||
import vona.config as config
|
import vona.config as config
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import random
|
import random
|
||||||
import os
|
import os
|
||||||
|
|
||||||
client = Blueprint("c2s", __name__)
|
from flask import (
|
||||||
|
Blueprint,
|
||||||
|
jsonify,
|
||||||
|
request,
|
||||||
|
send_file,
|
||||||
|
)
|
||||||
|
|
||||||
|
client = Blueprint("client", __name__)
|
||||||
|
|
||||||
|
from .groups import groups
|
||||||
|
|
||||||
|
client.register_blueprint(groups)
|
||||||
|
|
||||||
|
|
||||||
@client.route("/_matrix/client/v3/account/password", methods=["POST"])
|
@client.route("/_matrix/client/v3/account/password", methods=["POST"])
|
||||||
@@ -22,16 +33,18 @@ client = Blueprint("c2s", __name__)
|
|||||||
@client.route("/_matrix/client/v3/logout", methods=["POST"])
|
@client.route("/_matrix/client/v3/logout", methods=["POST"])
|
||||||
@client.route("/_matrix/client/r0/logout", methods=["POST"])
|
@client.route("/_matrix/client/r0/logout", methods=["POST"])
|
||||||
@client.route("/_matrix/client/v3/rooms/<room>/invite", methods=["POST"])
|
@client.route("/_matrix/client/v3/rooms/<room>/invite", methods=["POST"])
|
||||||
@client.route("/_matrix/client/v3/rooms/<roomId>/leave", methods=["POST"])
|
@client.route("/_matrix/client/v3/rooms/<room>/leave", methods=["POST"])
|
||||||
@client.route("/_matrix/client/r0/rooms/<roomId>/leave", methods=["POST"])
|
@client.route("/_matrix/client/r0/rooms/<room>/leave", methods=["POST"])
|
||||||
@client.route("/_matrix/client/v3/rooms/<roomId>/read_markers", methods=["POST"])
|
@client.route("/_matrix/client/v3/rooms/<room>/read_markers", methods=["POST"])
|
||||||
@client.route("/_matrix/client/r0/rooms/<roomId>/read_markers", methods=["POST"])
|
@client.route("/_matrix/client/r0/rooms/<room>/read_markers", methods=["POST"])
|
||||||
@client.route("/_matrix/client/v3/rooms/<room>/typing/<user>", methods=["PUT"])
|
@client.route("/_matrix/client/v3/rooms/<room>/typing/<user>", methods=["PUT"])
|
||||||
|
@client.route("/_matrix/client/api/v1/rooms/<room>/typing/<user>", methods=["PUT"])
|
||||||
@client.route("/_matrix/client/v3/keys/device_signing/upload", methods=["POST"])
|
@client.route("/_matrix/client/v3/keys/device_signing/upload", methods=["POST"])
|
||||||
@client.route("/_matrix/client/v3/rooms/<room>/receipt/<type>/<event>", methods=["POST"])
|
@client.route("/_matrix/client/v3/rooms/<room>/receipt/<type>/<event>", methods=["POST"])
|
||||||
@client.route("/_matrix/client/v3/users/<user>/report", methods=["POST"])
|
@client.route("/_matrix/client/v3/users/<user>/report", methods=["POST"])
|
||||||
@client.route("/_matrix/client/v3/voip/turnServer")
|
@client.route("/_matrix/client/v3/voip/turnServer")
|
||||||
@client.route("/_matrix/client/r0/voip/turnServer")
|
@client.route("/_matrix/client/r0/voip/turnServer")
|
||||||
|
@client.route("/_matrix/client/api/v1/voip/turnServer")
|
||||||
@client.route("/_matrix/client/v3/rooms/<r>/report/<e>")
|
@client.route("/_matrix/client/v3/rooms/<r>/report/<e>")
|
||||||
@client.route("/_matrix/client/v3/rooms/<r>/report")
|
@client.route("/_matrix/client/v3/rooms/<r>/report")
|
||||||
@client.route("/_matrix/client/v3/users/<u>/report")
|
@client.route("/_matrix/client/v3/users/<u>/report")
|
||||||
@@ -99,9 +112,10 @@ async def lock(user):
|
|||||||
return jsonify({"locked": True})
|
return jsonify({"locked": True})
|
||||||
|
|
||||||
|
|
||||||
@client.route("/_matrix/client/v3/rooms/<roomId>/members")
|
@client.route("/_matrix/client/api/v1/rooms/<room>/members")
|
||||||
@client.route("/_matrix/client/r0/rooms/<roomId>/members")
|
@client.route("/_matrix/client/v3/rooms/<room>/members")
|
||||||
async def room_member_count(roomId):
|
@client.route("/_matrix/client/r0/rooms/<room>/members")
|
||||||
|
async def room_members(room):
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"chunk": [{
|
"chunk": [{
|
||||||
"content": {
|
"content": {
|
||||||
@@ -109,9 +123,9 @@ async def room_member_count(roomId):
|
|||||||
"displayname": "Vona",
|
"displayname": "Vona",
|
||||||
"membership": "join"
|
"membership": "join"
|
||||||
},
|
},
|
||||||
"event_id": globals.make_event_id(),
|
"event_id": globals.make_event_id(seed=room),
|
||||||
"origin_server_ts": config.the_funny_number,
|
"origin_server_ts": config.the_funny_number,
|
||||||
"room_id": roomId,
|
"room_id": room,
|
||||||
"sender": f"@vona:{config.server_name}",
|
"sender": f"@vona:{config.server_name}",
|
||||||
"state_key": f"@vona:{config.server_name}",
|
"state_key": f"@vona:{config.server_name}",
|
||||||
"type": "m.room.member",
|
"type": "m.room.member",
|
||||||
@@ -128,6 +142,7 @@ async def whoami():
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@client.route("/_matrix/client/v2_alpha/register", methods=["POST"])
|
||||||
@client.route("/_matrix/client/v3/register", methods=["POST"])
|
@client.route("/_matrix/client/v3/register", methods=["POST"])
|
||||||
@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"])
|
||||||
@@ -161,6 +176,7 @@ async def register():
|
|||||||
|
|
||||||
@client.route("/_matrix/client/r0/login", methods=["GET", "POST"])
|
@client.route("/_matrix/client/r0/login", methods=["GET", "POST"])
|
||||||
@client.route("/_matrix/client/v3/login", methods=["GET", "POST"])
|
@client.route("/_matrix/client/v3/login", methods=["GET", "POST"])
|
||||||
|
@client.route("/_matrix/client/api/v1/login", methods=["POST"])
|
||||||
async def login():
|
async def login():
|
||||||
if request.method == "GET":
|
if request.method == "GET":
|
||||||
return jsonify({
|
return jsonify({
|
||||||
@@ -231,7 +247,13 @@ async def capabilities():
|
|||||||
"9": "stable",
|
"9": "stable",
|
||||||
"10": "stable",
|
"10": "stable",
|
||||||
"11": "stable",
|
"11": "stable",
|
||||||
"12": "stable"
|
"12": "stable",
|
||||||
|
"org.matrix.msc3757.10": "stable",
|
||||||
|
"org.matrix.msc3757.11": "stable",
|
||||||
|
"org.matrix.hydra.11": "stable",
|
||||||
|
"org.matrix.msc3667": "stable",
|
||||||
|
"org.matrix.msc3787": "stable",
|
||||||
|
"org.matrix.msc4014": "unstable",
|
||||||
},
|
},
|
||||||
"org.matrix.msc3244.room_capabilities": {
|
"org.matrix.msc3244.room_capabilities": {
|
||||||
"knock": {
|
"knock": {
|
||||||
@@ -276,6 +298,7 @@ async def filter(**kwargs):
|
|||||||
return jsonify({"filter_id": "vvvooonnnaaa"})
|
return jsonify({"filter_id": "vvvooonnnaaa"})
|
||||||
|
|
||||||
|
|
||||||
|
@client.route("/_matrix/client/api/v1/join/<room>", methods=["POST"])
|
||||||
@client.route("/_matrix/client/v3/join/<room>", methods=["POST"])
|
@client.route("/_matrix/client/v3/join/<room>", methods=["POST"])
|
||||||
@client.route("/_matrix/client/r0/join/<room>", methods=["POST"])
|
@client.route("/_matrix/client/r0/join/<room>", methods=["POST"])
|
||||||
@client.route("/_matrix/client/v3/rooms/<room>/join", methods=["POST"])
|
@client.route("/_matrix/client/v3/rooms/<room>/join", methods=["POST"])
|
||||||
@@ -284,6 +307,7 @@ async def join(room):
|
|||||||
return jsonify({"room_id": room})
|
return jsonify({"room_id": room})
|
||||||
|
|
||||||
|
|
||||||
|
@client.route("/_matrix/client/api/v1/initialSync")
|
||||||
@client.route("/_matrix/client/v3/initialSync")
|
@client.route("/_matrix/client/v3/initialSync")
|
||||||
@client.route("/_matrix/client/v3/sync")
|
@client.route("/_matrix/client/v3/sync")
|
||||||
@client.route("/_matrix/client/r0/sync")
|
@client.route("/_matrix/client/r0/sync")
|
||||||
@@ -292,39 +316,12 @@ async def sync():
|
|||||||
def get_json():
|
def get_json():
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
async def remove_keys(l, keys_to_remove) -> dict:
|
|
||||||
if not isinstance(l, list):
|
|
||||||
return l
|
|
||||||
|
|
||||||
new_list = []
|
|
||||||
for d in l:
|
|
||||||
if not isinstance(d, dict):
|
|
||||||
new_list.append(d)
|
|
||||||
continue
|
|
||||||
|
|
||||||
new_dict = {}
|
|
||||||
for k, v in d.items():
|
|
||||||
if k in keys_to_remove:
|
|
||||||
continue
|
|
||||||
new_dict[k] = await remove_keys(v, keys_to_remove)
|
|
||||||
new_list.append(new_dict)
|
|
||||||
return new_list
|
|
||||||
|
|
||||||
room = globals.make_event_id().replace("$", "!")
|
room = globals.make_event_id().replace("$", "!")
|
||||||
old_room_state = send_join(
|
room_state = globals.strip_state(
|
||||||
bullshit,
|
send_join(
|
||||||
room
|
bullshit,
|
||||||
)["state"]
|
room
|
||||||
|
)["state"]
|
||||||
room_state = await remove_keys(
|
|
||||||
old_room_state,
|
|
||||||
[
|
|
||||||
"auth_events",
|
|
||||||
"prev_events",
|
|
||||||
"signatures",
|
|
||||||
"hashes",
|
|
||||||
"depth"
|
|
||||||
]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
room_name = {
|
room_name = {
|
||||||
@@ -377,6 +374,78 @@ async def sync():
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@client.route("/_matrix/client/api/v1/rooms/<room>/initialSync")
|
||||||
|
async def room_initsync(room):
|
||||||
|
class bullshit:
|
||||||
|
def get_json():
|
||||||
|
return {}
|
||||||
|
|
||||||
|
room_state = globals.strip_state(
|
||||||
|
send_join(
|
||||||
|
bullshit,
|
||||||
|
room
|
||||||
|
)["state"]
|
||||||
|
)
|
||||||
|
|
||||||
|
for evt in room_state:
|
||||||
|
evt["age"] = config.the_funny_number
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
"membership": "join",
|
||||||
|
"room_id": room,
|
||||||
|
"messages": {
|
||||||
|
"chunk": [
|
||||||
|
{
|
||||||
|
"age": config.the_funny_number,
|
||||||
|
"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."
|
||||||
|
},
|
||||||
|
"event_id": globals.make_event_id(),
|
||||||
|
"origin_server_ts": 1432804485886,
|
||||||
|
"room_id": globals.make_event_id(),
|
||||||
|
"type": "m.room.message",
|
||||||
|
"user_id": f"@vona:{config.server_name}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"state": room_state
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@client.route("/_matrix/client/api/v1/events")
|
||||||
|
async def events():
|
||||||
|
if "timeout" in request.args:
|
||||||
|
try:
|
||||||
|
await asyncio.sleep(int(request.args["timeout"]) / 1000)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
"start": os.urandom(32).hex(),
|
||||||
|
"end": os.urandom(32).hex(),
|
||||||
|
"chunk": [
|
||||||
|
{
|
||||||
|
"age": config.the_funny_number,
|
||||||
|
"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."
|
||||||
|
},
|
||||||
|
"event_id": globals.make_event_id(),
|
||||||
|
"origin_server_ts": 1432804485886,
|
||||||
|
"room_id": globals.make_event_id(),
|
||||||
|
"type": "m.room.message",
|
||||||
|
"user_id": f"@vona:{config.server_name}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@client.route("/_matrix/client/api/v1/rooms/<room>/send/<eventType>/<txnId>", methods=["POST", "PUT"])
|
||||||
@client.route("/_matrix/client/v3/rooms/<room>/send/<eventType>/<txnId>", methods=["POST", "PUT"])
|
@client.route("/_matrix/client/v3/rooms/<room>/send/<eventType>/<txnId>", methods=["POST", "PUT"])
|
||||||
@client.route("/_matrix/client/r0/rooms/<room>/send/<eventType>/<txnId>", methods=["POST", "PUT"])
|
@client.route("/_matrix/client/r0/rooms/<room>/send/<eventType>/<txnId>", methods=["POST", "PUT"])
|
||||||
async def send_message(room, eventType, txnId):
|
async def send_message(room, eventType, txnId):
|
||||||
@@ -431,10 +500,10 @@ async def refresh():
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@client.route("/_matrix/client/unstable/im.nheko.summary/rooms/<roomId>/summary")
|
@client.route("/_matrix/client/unstable/im.nheko.summary/rooms/<room>/summary")
|
||||||
@client.route("/_matrix/client/unstable/im.nheko.summary/summary/<roomId>")
|
@client.route("/_matrix/client/unstable/im.nheko.summary/summary/<room>")
|
||||||
@client.route("/_matrix/client/v1/room_summary/<roomId>")
|
@client.route("/_matrix/client/v1/room_summary/<room>")
|
||||||
async def room_summary(roomId):
|
async def room_summary(room):
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"room_id": globals.make_event_id().replace("$", "!"),
|
"room_id": globals.make_event_id().replace("$", "!"),
|
||||||
"avatar_url": f"mxc://{config.server_name}/cat",
|
"avatar_url": f"mxc://{config.server_name}/cat",
|
||||||
@@ -446,7 +515,7 @@ async def room_summary(roomId):
|
|||||||
"join_rule": "public",
|
"join_rule": "public",
|
||||||
"room_type": "m.room",
|
"room_type": "m.room",
|
||||||
"membership": "join",
|
"membership": "join",
|
||||||
"room_version": globals.room_version_from_id(roomId)
|
"room_version": globals.room_version_from_id(room)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@@ -461,6 +530,7 @@ async def room_query(room):
|
|||||||
|
|
||||||
return jsonify({})
|
return jsonify({})
|
||||||
|
|
||||||
|
|
||||||
@client.route("/_matrix/client/v3/rooms/<room>/aliases")
|
@client.route("/_matrix/client/v3/rooms/<room>/aliases")
|
||||||
async def room_aliases(room):
|
async def room_aliases(room):
|
||||||
return jsonify({
|
return jsonify({
|
||||||
@@ -475,6 +545,7 @@ async def room_aliases(room):
|
|||||||
async def room_visibility(room):
|
async def room_visibility(room):
|
||||||
return jsonify({"visibility": "public"})
|
return jsonify({"visibility": "public"})
|
||||||
|
|
||||||
|
|
||||||
@client.route("/_matrix/client/v3/search", methods=["POST"])
|
@client.route("/_matrix/client/v3/search", methods=["POST"])
|
||||||
async def search():
|
async def search():
|
||||||
room = globals.make_event_id().replace("$", "!")
|
room = globals.make_event_id().replace("$", "!")
|
||||||
@@ -546,13 +617,15 @@ async def url_preview():
|
|||||||
"og:title": "cool cat"
|
"og:title": "cool cat"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@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(config.cat)
|
response = send_file(config.cat)
|
||||||
response.headers["Content-Disposition"] = f'inline; filename="cat.jpg"'
|
response.headers["Content-Disposition"] = 'inline; filename="cat.jpg"'
|
||||||
response.headers["Content-Type"] = "image/jpg"
|
response.headers["Content-Type"] = "image/jpg"
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
@client.route("/_matrix/media/v3/upload", methods=["POST"])
|
@client.route("/_matrix/media/v3/upload", methods=["POST"])
|
||||||
@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"])
|
||||||
@@ -565,9 +638,10 @@ async def media_config():
|
|||||||
return jsonify({"m.upload.size": config.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/api/v1/profile/<user>/<key>", methods=["GET", "PUT", "DELETE"])
|
||||||
@client.route("/_matrix/client/r0/profile/<userId>/<key>", methods=["GET", "PUT", "DELETE"])
|
@client.route("/_matrix/client/v3/profile/<user>/<key>", methods=["GET", "PUT", "DELETE"])
|
||||||
async def profile_keys(userId, key):
|
@client.route("/_matrix/client/r0/profile/<user>/<key>", methods=["GET", "PUT", "DELETE"])
|
||||||
|
async def profile_keys(user, key):
|
||||||
if request.method == "GET":
|
if request.method == "GET":
|
||||||
if key == "avatar_url":
|
if key == "avatar_url":
|
||||||
return jsonify({"avatar_url": f"mxc://{config.server_name}/cat"})
|
return jsonify({"avatar_url": f"mxc://{config.server_name}/cat"})
|
||||||
@@ -581,18 +655,20 @@ async def profile_keys(userId, key):
|
|||||||
|
|
||||||
return jsonify({})
|
return jsonify({})
|
||||||
|
|
||||||
@client.route("/_matrix/client/v3/profile/<userId>")
|
|
||||||
@client.route("/_matrix/client/r0/profile/<userId>")
|
@client.route("/_matrix/client/v3/profile/<user>")
|
||||||
async def user_profile(userId):
|
@client.route("/_matrix/client/r0/profile/<user>")
|
||||||
|
async def user_profile(user):
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"avatar_url": f"mxc://{config.server_name}/cat",
|
"avatar_url": f"mxc://{config.server_name}/cat",
|
||||||
"displayname": "Vona"
|
"displayname": "Vona"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@client.route("/_matrix/client/v3/rooms/<roomId>/messages")
|
@client.route("/_matrix/client/api/v1/rooms/<room>/messages")
|
||||||
@client.route("/_matrix/client/r0/rooms/<roomId>/messages")
|
@client.route("/_matrix/client/v3/rooms/<room>/messages")
|
||||||
async def room_messages(roomId):
|
@client.route("/_matrix/client/r0/rooms/<room>/messages")
|
||||||
|
async def room_messages(room):
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"chunk": [{
|
"chunk": [{
|
||||||
"content": {
|
"content": {
|
||||||
@@ -603,7 +679,7 @@ async def room_messages(roomId):
|
|||||||
},
|
},
|
||||||
"event_id": globals.make_event_id(),
|
"event_id": globals.make_event_id(),
|
||||||
"origin_server_ts": config.the_funny_number,
|
"origin_server_ts": config.the_funny_number,
|
||||||
"room_id": roomId,
|
"room_id": room,
|
||||||
"sender": f"@vona:{config.server_name}",
|
"sender": f"@vona:{config.server_name}",
|
||||||
"type": "m.room.message"
|
"type": "m.room.message"
|
||||||
}],
|
}],
|
||||||
@@ -611,6 +687,7 @@ async def room_messages(roomId):
|
|||||||
"start": f"{os.urandom(16).hex()}"
|
"start": f"{os.urandom(16).hex()}"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@client.route("/_matrix/client/v3/keys/query", methods=["POST"])
|
@client.route("/_matrix/client/v3/keys/query", methods=["POST"])
|
||||||
@client.route("/_matrix/client/r0/keys/query", methods=["POST"])
|
@client.route("/_matrix/client/r0/keys/query", methods=["POST"])
|
||||||
async def query_keys():
|
async def query_keys():
|
||||||
@@ -622,6 +699,7 @@ async def query_keys():
|
|||||||
"user_signing_keys": user
|
"user_signing_keys": user
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@client.route("/_matrix/client/api/v1/createRoom", methods=["POST"])
|
@client.route("/_matrix/client/api/v1/createRoom", methods=["POST"])
|
||||||
@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"])
|
||||||
@@ -639,6 +717,7 @@ async def mutual_rooms():
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@client.route("/_matrix/client/api/v1/presence/<user>/status", methods=["GET", "PUT"])
|
||||||
@client.route("/_matrix/client/r0/presence/<user>/status", methods=["GET", "PUT"])
|
@client.route("/_matrix/client/r0/presence/<user>/status", methods=["GET", "PUT"])
|
||||||
async def presence(user):
|
async def presence(user):
|
||||||
if request.method == "PUT":
|
if request.method == "PUT":
|
||||||
@@ -647,7 +726,20 @@ async def presence(user):
|
|||||||
return jsonify({"presence": "online"})
|
return jsonify({"presence": "online"})
|
||||||
|
|
||||||
|
|
||||||
|
@client.route("/_matrix/client/api/v1/publicRooms", methods=["GET", "POST"])
|
||||||
@client.route("/_matrix/client/v3/publicRooms", methods=["GET", "POST"])
|
@client.route("/_matrix/client/v3/publicRooms", methods=["GET", "POST"])
|
||||||
@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(globals.room_dir)
|
return jsonify(globals.room_dir)
|
||||||
|
|
||||||
|
|
||||||
|
@client.route("/_matrix/client/api/v1/rooms/<room>/state/<evttype>/<key>", methods=["GET", "PUT"])
|
||||||
|
@client.route("/_matrix/client/api/v1/rooms/<room>/state/<evttype>/", methods=["GET", "PUT"])
|
||||||
|
async def state(room, evttype, key=None):
|
||||||
|
if request.method == "GET":
|
||||||
|
return jsonify({
|
||||||
|
"errcode": "M_NOT_FOUND",
|
||||||
|
"error": f"Event with type {evttype} and key {key} not found"
|
||||||
|
}), 404
|
||||||
|
|
||||||
|
return jsonify({"event_id": os.urandom(5).hex()})
|
||||||
|
|||||||
120
vona/client/groups.py
Normal file
120
vona/client/groups.py
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
import vona.globals as globals
|
||||||
|
import vona.config as config
|
||||||
|
import time
|
||||||
|
|
||||||
|
from flask import (
|
||||||
|
Blueprint,
|
||||||
|
jsonify,
|
||||||
|
request,
|
||||||
|
)
|
||||||
|
|
||||||
|
groups = Blueprint("groups", __name__)
|
||||||
|
|
||||||
|
# This implements the C2S API for groups
|
||||||
|
|
||||||
|
|
||||||
|
@groups.route("/_matrix/client/r0/groups/<group>/self/update_publicity", methods=["PUT"])
|
||||||
|
@groups.route("/_matrix/client/r0/groups/<group>/self/accept_invite", methods=["PUT"])
|
||||||
|
@groups.route("/_matrix/client/r0/groups/<group>/self/leave", methods=["PUT"])
|
||||||
|
@groups.route("/_matrix/client/r0/groups/<group>/admin/users/remove/<user>", methods=["PUT"])
|
||||||
|
@groups.route("/_matrix/client/r0/groups/<group>/admin/rooms/<room>", methods=["PUT", "DELETE"])
|
||||||
|
async def empty(**k):
|
||||||
|
return jsonify({})
|
||||||
|
|
||||||
|
|
||||||
|
@groups.route("/_matrix/client/r0/publicised_groups/<user>")
|
||||||
|
@groups.route("/_matrix/client/r0/joined_groups")
|
||||||
|
async def joined_groups(user=None):
|
||||||
|
return jsonify({
|
||||||
|
"groups": [f"+vona:{config.server_name}"]
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@groups.route("/_matrix/client/r0/groups/<group>/summary")
|
||||||
|
async def summary(group):
|
||||||
|
return jsonify({
|
||||||
|
"profile": {
|
||||||
|
"name": "Vona",
|
||||||
|
"short_description": "",
|
||||||
|
"long_description": "",
|
||||||
|
"avatar_url": "",
|
||||||
|
"is_public": 1,
|
||||||
|
"is_openly_joinable": True
|
||||||
|
},
|
||||||
|
"users_section": {
|
||||||
|
"users": [],
|
||||||
|
"roles": {},
|
||||||
|
"total_user_count_estimate": 0
|
||||||
|
},
|
||||||
|
"rooms_section": {
|
||||||
|
"rooms": [],
|
||||||
|
"categories": {},
|
||||||
|
"total_room_count_estimate": 0
|
||||||
|
},
|
||||||
|
"user": {
|
||||||
|
"membership": "join",
|
||||||
|
"is_public": 1,
|
||||||
|
"is_privileged": 1,
|
||||||
|
"is_publicised": True
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@groups.route("/_matrix/client/r0/groups/<group>/rooms")
|
||||||
|
async def rooms(group):
|
||||||
|
return jsonify({
|
||||||
|
"chunk": [],
|
||||||
|
"total_room_count_estimate": 0
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@groups.route("/_matrix/client/r0/groups/<group>/invited_users")
|
||||||
|
async def invited_users(group):
|
||||||
|
return jsonify({
|
||||||
|
"chunk": [],
|
||||||
|
"total_user_count_estimate": 0
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@groups.route("/_matrix/client/r0/groups/<group>/users")
|
||||||
|
async def users(group):
|
||||||
|
return jsonify({
|
||||||
|
"chunk": [
|
||||||
|
{
|
||||||
|
"user_id": f"@vona:{config.server_name}",
|
||||||
|
"displayname": "Vona",
|
||||||
|
"avatar_url": None,
|
||||||
|
"is_public": True,
|
||||||
|
"is_privileged": True,
|
||||||
|
"attestation": globals.sign_json({
|
||||||
|
"group_id": group,
|
||||||
|
"user_id": f"@vona:{config.server_name}",
|
||||||
|
"valid_until_ms": int(str(time.time() * 1000).split(".")[0])
|
||||||
|
})
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"total_user_count_estimate": 1
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@groups.route("/_matrix/client/r0/groups/<group>/profile", methods=["GET", "POST"])
|
||||||
|
async def profile(group):
|
||||||
|
if request.method == "POST":
|
||||||
|
return jsonify({})
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
"name": "Vona",
|
||||||
|
"short_description": "",
|
||||||
|
"long_description": "",
|
||||||
|
"avatar_url": "",
|
||||||
|
"is_public": 1,
|
||||||
|
"is_openly_joinable": True
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@groups.route("/_matrix/client/r0/create_group", methods=["POST"])
|
||||||
|
async def create_group():
|
||||||
|
return jsonify({
|
||||||
|
"group_id": f"+vona:{config.server_name}"
|
||||||
|
})
|
||||||
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import os
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import tomllib
|
import tomllib
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
addr: str = "127.0.0.1"
|
addr: str = "127.0.0.1"
|
||||||
port: int = 5000
|
port: int = 5000
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
from flask import Blueprint
|
from flask import (
|
||||||
|
Blueprint,
|
||||||
|
)
|
||||||
|
|
||||||
custom = Blueprint("custom", __name__)
|
custom = Blueprint("custom", __name__)
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
from flask import Blueprint, jsonify, request
|
|
||||||
import vona.config as config
|
import vona.config as config
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from flask import (
|
||||||
|
Blueprint,
|
||||||
|
jsonify,
|
||||||
|
request,
|
||||||
|
)
|
||||||
|
|
||||||
citadel = Blueprint("citadel", __name__)
|
citadel = Blueprint("citadel", __name__)
|
||||||
|
|
||||||
# These are endpoints made by Thales Citadel
|
# These are endpoints made by Thales Citadel
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
from flask import Blueprint, jsonify
|
|
||||||
import vona.globals as globals
|
import vona.globals as globals
|
||||||
|
from flask import (
|
||||||
|
Blueprint,
|
||||||
|
jsonify,
|
||||||
|
)
|
||||||
|
|
||||||
conduwuit = Blueprint("conduwuit", __name__)
|
conduwuit = Blueprint("conduwuit", __name__)
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
from flask import Blueprint, jsonify
|
|
||||||
import vona.globals as globals
|
import vona.globals as globals
|
||||||
import vona.config as config
|
import vona.config as config
|
||||||
|
from flask import (
|
||||||
|
Blueprint,
|
||||||
|
jsonify,
|
||||||
|
)
|
||||||
|
|
||||||
dendrite = Blueprint("dendrite", __name__)
|
dendrite = Blueprint("dendrite", __name__)
|
||||||
|
|
||||||
# https://element-hq.github.io/dendrite/administration/adminapi
|
# This implements the Dendrite admin API
|
||||||
|
|
||||||
|
|
||||||
@dendrite.route("/_dendrite/admin/purgeRoom/<room>", methods=["POST"])
|
@dendrite.route("/_dendrite/admin/purgeRoom/<room>", methods=["POST"])
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
from flask import Blueprint, request, jsonify
|
|
||||||
from vona.config import the_funny_number
|
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from vona.federation import send_join
|
from vona.federation import send_join
|
||||||
import vona.globals as globals
|
import vona.globals as globals
|
||||||
import vona.config as config
|
import vona.config as config
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from flask import (
|
||||||
|
Blueprint,
|
||||||
|
jsonify,
|
||||||
|
)
|
||||||
|
|
||||||
hammerhead = Blueprint("hammerhead", __name__)
|
hammerhead = Blueprint("hammerhead", __name__)
|
||||||
|
|
||||||
# Hammerhead endpoints. Not documented, but code is at:
|
# Hammerhead endpoints. Not documented, but code is at:
|
||||||
@@ -16,10 +19,15 @@ hammerhead = Blueprint("hammerhead", __name__)
|
|||||||
async def uptime():
|
async def uptime():
|
||||||
return jsonify({"started_at": config.the_funny_number})
|
return jsonify({"started_at": config.the_funny_number})
|
||||||
|
|
||||||
|
|
||||||
@hammerhead.route("/_hammerhead/version")
|
@hammerhead.route("/_hammerhead/version")
|
||||||
async def version():
|
async def version():
|
||||||
return jsonify({"version": globals.version})
|
return jsonify({"version": globals.version})
|
||||||
|
|
||||||
|
@hammerhead.route("/_hammerhead/admin/reload-config")
|
||||||
|
async def reload_config():
|
||||||
|
return jsonify({})
|
||||||
|
|
||||||
|
|
||||||
@hammerhead.route("/_hammerhead/admin/server-info/<server>")
|
@hammerhead.route("/_hammerhead/admin/server-info/<server>")
|
||||||
async def server_info(server):
|
async def server_info(server):
|
||||||
@@ -65,7 +73,14 @@ async def room_state(room):
|
|||||||
key = f"({event["type"]},'{event["state_key"]}')"
|
key = f"({event["type"]},'{event["state_key"]}')"
|
||||||
formatted_state[key] = event
|
formatted_state[key] = event
|
||||||
|
|
||||||
event_id = event["event_id"]
|
if "event_id" in event:
|
||||||
|
event_id = event["event_id"]
|
||||||
|
else:
|
||||||
|
event_id = globals.make_ref_hash(
|
||||||
|
event,
|
||||||
|
int(globals.room_version_from_id(room))
|
||||||
|
)
|
||||||
|
|
||||||
event_cache[event_id] = event
|
event_cache[event_id] = event
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +1,28 @@
|
|||||||
from flask import Blueprint, jsonify, request, Response
|
from vona.federation import send_join
|
||||||
import vona.globals as globals
|
import vona.globals as globals
|
||||||
import vona.config as config
|
import vona.config as config
|
||||||
import base64
|
|
||||||
import re
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from flask import (
|
||||||
|
Blueprint,
|
||||||
|
jsonify,
|
||||||
|
request,
|
||||||
|
)
|
||||||
|
|
||||||
synapse = Blueprint("synapse", __name__)
|
synapse = Blueprint("synapse", __name__)
|
||||||
|
|
||||||
# The absolute giant known as the Synapse admin API.
|
# The absolute giant known as the Synapse admin API.
|
||||||
# Very messy, needs cleaning
|
# TODO: Very messy, needs cleaning
|
||||||
|
|
||||||
|
|
||||||
@synapse.route("/_synapse/admin/v1/suspend/<user_id>", methods=["PUT"])
|
@synapse.route("/_synapse/admin/v1/suspend/<user>", methods=["PUT"])
|
||||||
@synapse.route("/_synapse/admin/v1/deactivate/<user_id>", methods=["POST"])
|
@synapse.route("/_synapse/admin/v1/deactivate/<user>", methods=["POST"])
|
||||||
@synapse.route("/_synapse/admin/v1/reset_password/<user_id>", methods=["POST"])
|
@synapse.route("/_synapse/admin/v1/reset_password/<user>", methods=["POST"])
|
||||||
@synapse.route("/_synapse/admin/v1/users/<user_id>/admin", methods=["PUT"])
|
@synapse.route("/_synapse/admin/v1/users/<user>/admin", methods=["PUT"])
|
||||||
@synapse.route("/_synapse/admin/v2/users/<user_id>/delete_devices", methods=["POST"])
|
@synapse.route("/_synapse/admin/v2/users/<user>/delete_devices", methods=["POST"])
|
||||||
@synapse.route("/_synapse/admin/v1/users/<user_id>/shadow_ban", methods=["DELETE", "POST"])
|
@synapse.route("/_synapse/admin/v1/users/<user>/shadow_ban", methods=["DELETE", "POST"])
|
||||||
@synapse.route("/_synapse/admin/v1/users/<user_id>/override_ratelimit", methods=["GET", "POST", "DELETE"])
|
@synapse.route("/_synapse/admin/v1/users/<user>/override_ratelimit", methods=["GET", "POST", "DELETE"])
|
||||||
@synapse.route("/_synapse/admin/v1/media/protect/<media_id>", methods=["POST"])
|
@synapse.route("/_synapse/admin/v1/media/protect/<media_id>", methods=["POST"])
|
||||||
@synapse.route("/_synapse/admin/v1/media/unprotect/<media_id>", methods=["POST"])
|
@synapse.route("/_synapse/admin/v1/media/unprotect/<media_id>", methods=["POST"])
|
||||||
@synapse.route("/_synapse/admin/v1/media/quarantine/<s>/<media_id>", methods=["POST"])
|
@synapse.route("/_synapse/admin/v1/media/quarantine/<s>/<media_id>", methods=["POST"])
|
||||||
@@ -56,7 +61,7 @@ async def user_list():
|
|||||||
"total": 1
|
"total": 1
|
||||||
})
|
})
|
||||||
|
|
||||||
@synapse.route("/_synapse/admin/v2/users/<user_id>", methods=["GET", "PUT"])
|
@synapse.route("/_synapse/admin/v2/users/<user>", methods=["GET", "PUT"])
|
||||||
async def user_info(user_id):
|
async def user_info(user_id):
|
||||||
if request.method == "GET":
|
if request.method == "GET":
|
||||||
return jsonify({
|
return jsonify({
|
||||||
@@ -83,7 +88,7 @@ async def user_info(user_id):
|
|||||||
|
|
||||||
return jsonify({}), 201
|
return jsonify({}), 201
|
||||||
|
|
||||||
@synapse.route("/_synapse/admin/v1/whois/<user_id>")
|
@synapse.route("/_synapse/admin/v1/whois/<user>")
|
||||||
async def whois(user_id):
|
async def whois(user_id):
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"user_id": f"@vona:{config.server_name}",
|
"user_id": f"@vona:{config.server_name}",
|
||||||
@@ -91,7 +96,7 @@ async def whois(user_id):
|
|||||||
"": {
|
"": {
|
||||||
"sessions": [{
|
"sessions": [{
|
||||||
"connections": [{
|
"connections": [{
|
||||||
"ip":f"127.0.0.1",
|
"ip":"127.0.0.1",
|
||||||
"last_seen":config.the_funny_number,
|
"last_seen":config.the_funny_number,
|
||||||
"user_agent":f"Vona/{globals.version}"
|
"user_agent":f"Vona/{globals.version}"
|
||||||
}]
|
}]
|
||||||
@@ -100,22 +105,22 @@ async def whois(user_id):
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@synapse.route("/_synapse/admin/v1/users/<user_id>/joined_rooms")
|
@synapse.route("/_synapse/admin/v1/users/<user>/joined_rooms")
|
||||||
async def user_joined_rooms(user_id):
|
async def user_joined_rooms(user_id):
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"joined_rooms": [globals.make_event_id().replace("$", "!")],
|
"joined_rooms": [globals.make_event_id().replace("$", "!")],
|
||||||
"total": 1
|
"total": 1
|
||||||
})
|
})
|
||||||
|
|
||||||
@synapse.route("/_synapse/admin/v1/users/<user_id>/sent_invite_count")
|
@synapse.route("/_synapse/admin/v1/users/<user>/sent_invite_count")
|
||||||
async def invite_count(user_id):
|
async def invite_count(user_id):
|
||||||
return jsonify({"invite_count": config.the_funny_number})
|
return jsonify({"invite_count": config.the_funny_number})
|
||||||
|
|
||||||
@synapse.route("/_synapse/admin/v1/users/<user_id>/accountdata")
|
@synapse.route("/_synapse/admin/v1/users/<user>/accountdata")
|
||||||
async def account_data(user_id):
|
async def account_data(user_id):
|
||||||
return jsonify({"account_data":{"global":{}}})
|
return jsonify({"account_data":{"global":{}}})
|
||||||
|
|
||||||
@synapse.route("/_synapse/admin/v1/users/<user_id>/media", methods=["GET", "DELETE"])
|
@synapse.route("/_synapse/admin/v1/users/<user>/media", methods=["GET", "DELETE"])
|
||||||
async def account_media(user_id):
|
async def account_media(user_id):
|
||||||
if request.method == "GET":
|
if request.method == "GET":
|
||||||
return jsonify({
|
return jsonify({
|
||||||
@@ -137,15 +142,15 @@ async def account_media(user_id):
|
|||||||
"total": config.the_funny_number
|
"total": config.the_funny_number
|
||||||
})
|
})
|
||||||
|
|
||||||
@synapse.route("/_synapse/admin/v1/users/<user_id>/login", methods=["POST"])
|
@synapse.route("/_synapse/admin/v1/users/<user>/login", methods=["POST"])
|
||||||
async def account_login(user_id):
|
async def account_login(user_id):
|
||||||
return jsonify({"access_token": "vona"})
|
return jsonify({"access_token": "vona"})
|
||||||
|
|
||||||
@synapse.route("/_synapse/admin/v1/users/<user_id>/_allow_cross_signing_replacement_without_uia", methods=["POST"])
|
@synapse.route("/_synapse/admin/v1/users/<user>/_allow_cross_signing_replacement_without_uia", methods=["POST"])
|
||||||
async def stupid_mas_bullshit(user_id):
|
async def stupid_mas_bullshit(user_id):
|
||||||
return jsonify({"updatable_without_uia_before_ms": config.the_funny_number})
|
return jsonify({"updatable_without_uia_before_ms": config.the_funny_number})
|
||||||
|
|
||||||
@synapse.route("/_synapse/admin/v2/users/<user_id>/devices", methods=["GET", "POST"])
|
@synapse.route("/_synapse/admin/v2/users/<user>/devices", methods=["GET", "POST"])
|
||||||
async def device_list(user_id):
|
async def device_list(user_id):
|
||||||
if request.method == "GET":
|
if request.method == "GET":
|
||||||
return jsonify({
|
return jsonify({
|
||||||
@@ -161,7 +166,7 @@ async def device_list(user_id):
|
|||||||
|
|
||||||
return jsonify({})
|
return jsonify({})
|
||||||
|
|
||||||
@synapse.route("/_synapse/admin/v2/users/<user_id>/devices/<device_id>", methods=["GET", "PUT", "DELETE"])
|
@synapse.route("/_synapse/admin/v2/users/<user>/devices/<device_id>", methods=["GET", "PUT", "DELETE"])
|
||||||
async def device_info(user_id, device_id):
|
async def device_info(user_id, device_id):
|
||||||
if request.method == "GET":
|
if request.method == "GET":
|
||||||
return jsonify({
|
return jsonify({
|
||||||
@@ -174,7 +179,7 @@ async def device_info(user_id, device_id):
|
|||||||
|
|
||||||
return jsonify({})
|
return jsonify({})
|
||||||
|
|
||||||
@synapse.route("/_synapse/admin/v1/users/<user_id>/pushers")
|
@synapse.route("/_synapse/admin/v1/users/<user>/pushers")
|
||||||
async def pushers(user_id):
|
async def pushers(user_id):
|
||||||
return jsonify({"pushers": [], "total": config.the_funny_number})
|
return jsonify({"pushers": [], "total": config.the_funny_number})
|
||||||
|
|
||||||
@@ -187,7 +192,7 @@ async def username_available():
|
|||||||
async def threepid(**kwargs):
|
async def threepid(**kwargs):
|
||||||
return jsonify({"user_id": f"@vona:{config.server_name}"})
|
return jsonify({"user_id": f"@vona:{config.server_name}"})
|
||||||
|
|
||||||
@synapse.route("/_synapse/admin/v1/<user_id>/redact")
|
@synapse.route("/_synapse/admin/v1/<user>/redact")
|
||||||
async def redact(user_id):
|
async def redact(user_id):
|
||||||
return jsonify({"redact_id": os.urandom(16).hex()})
|
return jsonify({"redact_id": os.urandom(16).hex()})
|
||||||
|
|
||||||
@@ -195,7 +200,7 @@ async def redact(user_id):
|
|||||||
async def redact_status(redact_id):
|
async def redact_status(redact_id):
|
||||||
return jsonify({"status":"active","failed_redactions":[]})
|
return jsonify({"status":"active","failed_redactions":[]})
|
||||||
|
|
||||||
@synapse.route("/_synapse/admin/v1/experimental_features/<user_id>", methods=["GET", "PUT"])
|
@synapse.route("/_synapse/admin/v1/experimental_features/<user>", methods=["GET", "PUT"])
|
||||||
async def experimental_features(user_id):
|
async def experimental_features(user_id):
|
||||||
return jsonify({"features": {}})
|
return jsonify({"features": {}})
|
||||||
|
|
||||||
@@ -447,3 +452,38 @@ async def forward_extremities(room):
|
|||||||
"received_ts": config.the_funny_number
|
"received_ts": config.the_funny_number
|
||||||
}]
|
}]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@synapse.route("/_synapse/admin/v1/media/<origin>/<media_id>")
|
||||||
|
async def media_info(origin, media_id):
|
||||||
|
return jsonify({
|
||||||
|
"media_info": {
|
||||||
|
"media_origin": origin,
|
||||||
|
"user_id": None,
|
||||||
|
"media_id": media_id,
|
||||||
|
"media_type": "img/jpeg",
|
||||||
|
"media_length": 67,
|
||||||
|
"upload_name": "cat.jpg",
|
||||||
|
"created_ts": config.the_funny_number,
|
||||||
|
"filesystem_id": os.urandom(3).hex(),
|
||||||
|
"url_cache": None,
|
||||||
|
"last_access_ts": config.the_funny_number,
|
||||||
|
"quarantined_by": None,
|
||||||
|
"authenticated": False,
|
||||||
|
"safe_from_quarantine": None,
|
||||||
|
"sha256": os.urandom(32).hex()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@synapse.route("/_synapse/admin/v1/fetch_event/<evt>")
|
||||||
|
async def fetch_event(evt):
|
||||||
|
class bs:
|
||||||
|
def get_json():
|
||||||
|
return {}
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
"event": send_join(
|
||||||
|
bs,
|
||||||
|
globals.make_event_id(seed=evt).replace("$", "!")
|
||||||
|
)["state"][5]
|
||||||
|
})
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
from flask import Blueprint, request, jsonify
|
|
||||||
from vona.globals import version
|
from vona.globals import version
|
||||||
import vona.config as config
|
import vona.config as config
|
||||||
|
|
||||||
|
from flask import (
|
||||||
|
Blueprint,
|
||||||
|
request,
|
||||||
|
jsonify,
|
||||||
|
)
|
||||||
|
|
||||||
telo = Blueprint("telodendria", __name__)
|
telo = Blueprint("telodendria", __name__)
|
||||||
|
|
||||||
# The telodendria admin API as specified by
|
# The telodendria admin API as specified by
|
||||||
|
|||||||
@@ -1,218 +1,31 @@
|
|||||||
from flask import jsonify, Response, request, send_file, abort, Blueprint
|
import vona.federation.rooms as rooms
|
||||||
import vona.globals as globals
|
import vona.globals as globals
|
||||||
import vona.config as config
|
import vona.config as config
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
import os
|
|
||||||
|
from flask import (
|
||||||
|
jsonify,
|
||||||
|
Response,
|
||||||
|
request,
|
||||||
|
Blueprint,
|
||||||
|
)
|
||||||
|
|
||||||
server = Blueprint("federation", __name__)
|
server = Blueprint("federation", __name__)
|
||||||
|
http = globals.http_client()
|
||||||
|
|
||||||
|
|
||||||
def send_join(request, roomId) -> dict:
|
class bullshit:
|
||||||
event_chain = []
|
def get_json():
|
||||||
event_hashes = []
|
return {}
|
||||||
|
|
||||||
event_ids = [
|
|
||||||
globals.make_event_id(seed=f"1_{roomId}"),
|
|
||||||
globals.make_event_id(seed=f"2_{roomId}"),
|
|
||||||
globals.make_event_id(seed=f"3_{roomId}"),
|
|
||||||
globals.make_event_id(seed=f"4_{roomId}"),
|
|
||||||
globals.make_event_id(seed=f"5_{roomId}"),
|
|
||||||
globals.make_event_id(seed=f"6_{roomId}"),
|
|
||||||
]
|
|
||||||
|
|
||||||
create_event = {
|
def send_join(request, room) -> dict:
|
||||||
"content": {
|
if globals.room_version_from_id(room) in ["1", "2"]:
|
||||||
"m.federate": True,
|
return rooms.v1_v2(request, room)
|
||||||
"creator": f"@vona:{config.server_name}",
|
else:
|
||||||
"room_version": globals.room_version_from_id(roomId)
|
return rooms.v3(request, room)
|
||||||
},
|
|
||||||
"event_id": event_ids[0],
|
|
||||||
"origin_server_ts": 1,
|
|
||||||
"room_id": roomId,
|
|
||||||
"sender": f"@vona:{config.server_name}",
|
|
||||||
"state_key": "",
|
|
||||||
"depth": 1,
|
|
||||||
"type": "m.room.create",
|
|
||||||
"auth_events": [],
|
|
||||||
"prev_events": []
|
|
||||||
}
|
|
||||||
|
|
||||||
screate_event = globals.hash_and_sign_event(create_event)
|
|
||||||
event_chain.append(screate_event)
|
|
||||||
|
|
||||||
our_join = {
|
|
||||||
"content": {
|
|
||||||
"displayname": "Vona",
|
|
||||||
"avatar_url": f"mxc://{config.server_name}/cat",
|
|
||||||
"membership": "join"
|
|
||||||
},
|
|
||||||
"origin_server_ts": 2,
|
|
||||||
"sender": f"@vona:{config.server_name}",
|
|
||||||
"state_key": f"@vona:{config.server_name}",
|
|
||||||
"type": "m.room.member",
|
|
||||||
"event_id": event_ids[1],
|
|
||||||
"room_id": roomId,
|
|
||||||
"depth": 2,
|
|
||||||
"auth_events": [[
|
|
||||||
screate_event["event_id"],
|
|
||||||
screate_event["hashes"]
|
|
||||||
]],
|
|
||||||
"prev_events": [[
|
|
||||||
screate_event["event_id"],
|
|
||||||
screate_event["hashes"]
|
|
||||||
]]
|
|
||||||
}
|
|
||||||
|
|
||||||
sour_join = globals.hash_and_sign_event(our_join)
|
|
||||||
event_chain.append(sour_join)
|
|
||||||
|
|
||||||
pls = {
|
|
||||||
"content": {
|
|
||||||
"users": {
|
|
||||||
f"@vona:{config.server_name}": "100"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"origin_server_ts": 3,
|
|
||||||
"room_id": roomId,
|
|
||||||
"sender": f"@vona:{config.server_name}",
|
|
||||||
"state_key": "",
|
|
||||||
"type": "m.room.power_levels",
|
|
||||||
"event_id": event_ids[2],
|
|
||||||
"depth": 3,
|
|
||||||
"user_id": f"@vona:{config.server_name}",
|
|
||||||
"auth_events": [
|
|
||||||
[
|
|
||||||
screate_event["event_id"],
|
|
||||||
screate_event["hashes"]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
sour_join["event_id"],
|
|
||||||
sour_join["hashes"]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
"prev_events": [[
|
|
||||||
sour_join["event_id"],
|
|
||||||
sour_join["hashes"]
|
|
||||||
]]
|
|
||||||
}
|
|
||||||
|
|
||||||
spls = globals.hash_and_sign_event(pls)
|
|
||||||
event_chain.append(spls)
|
|
||||||
|
|
||||||
join_rule = {
|
|
||||||
"content": {
|
|
||||||
"join_rule": "public"
|
|
||||||
},
|
|
||||||
"origin_server_ts": 4,
|
|
||||||
"sender": f"@vona:{config.server_name}",
|
|
||||||
"state_key": "",
|
|
||||||
"type": "m.room.join_rules",
|
|
||||||
"event_id": event_ids[3],
|
|
||||||
"room_id": roomId,
|
|
||||||
"depth": 4,
|
|
||||||
"auth_events": [
|
|
||||||
[
|
|
||||||
screate_event["event_id"],
|
|
||||||
screate_event["hashes"]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
sour_join["event_id"],
|
|
||||||
sour_join["hashes"]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
spls["event_id"],
|
|
||||||
spls["hashes"]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
"prev_events": [[
|
|
||||||
spls["event_id"],
|
|
||||||
spls["hashes"]
|
|
||||||
]]
|
|
||||||
}
|
|
||||||
|
|
||||||
sjoin_rule = globals.hash_and_sign_event(join_rule)
|
|
||||||
event_chain.append(sjoin_rule)
|
|
||||||
|
|
||||||
guest_access = {
|
|
||||||
"content": {
|
|
||||||
"guest_access": "forbidden"
|
|
||||||
},
|
|
||||||
"origin_server_ts": 5,
|
|
||||||
"depth": 5,
|
|
||||||
"sender": f"@vona:{config.server_name}",
|
|
||||||
"state_key": "",
|
|
||||||
"type": "m.room.guest_access",
|
|
||||||
"event_id": event_ids[4],
|
|
||||||
"room_id": roomId,
|
|
||||||
"auth_events": [
|
|
||||||
[
|
|
||||||
screate_event["event_id"],
|
|
||||||
screate_event["hashes"]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
sour_join["event_id"],
|
|
||||||
sour_join["hashes"]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
spls["event_id"],
|
|
||||||
spls["hashes"]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
"prev_events": [[
|
|
||||||
sjoin_rule["event_id"],
|
|
||||||
sjoin_rule["hashes"]
|
|
||||||
]]
|
|
||||||
}
|
|
||||||
|
|
||||||
sguest_access = globals.hash_and_sign_event(guest_access)
|
|
||||||
event_chain.append(sguest_access)
|
|
||||||
|
|
||||||
history = {
|
|
||||||
"content": {
|
|
||||||
"history_visibility": "shared"
|
|
||||||
},
|
|
||||||
"type": "m.room.history_visibility",
|
|
||||||
"sender": f"@vona:{config.server_name}",
|
|
||||||
"state_key": "",
|
|
||||||
"origin_server_ts": 6,
|
|
||||||
"depth": 6,
|
|
||||||
"event_id": event_ids[5],
|
|
||||||
"room_id": roomId,
|
|
||||||
"auth_events": [
|
|
||||||
[
|
|
||||||
screate_event["event_id"],
|
|
||||||
screate_event["hashes"]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
sour_join["event_id"],
|
|
||||||
sour_join["hashes"]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
spls["event_id"],
|
|
||||||
spls["hashes"]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
"prev_events": [[
|
|
||||||
sguest_access["event_id"],
|
|
||||||
sguest_access["hashes"]
|
|
||||||
]]
|
|
||||||
}
|
|
||||||
|
|
||||||
shistory = globals.hash_and_sign_event(history)
|
|
||||||
event_chain.append(shistory)
|
|
||||||
|
|
||||||
remote_join = request.get_json()
|
|
||||||
|
|
||||||
response = {
|
|
||||||
"auth_chain": event_chain,
|
|
||||||
"event": remote_join,
|
|
||||||
"members_omitted": False,
|
|
||||||
"servers_in_room": [config.server_name],
|
|
||||||
"state": event_chain
|
|
||||||
}
|
|
||||||
|
|
||||||
return response
|
|
||||||
|
|
||||||
|
|
||||||
@server.route("/_matrix/federation/v1/version")
|
@server.route("/_matrix/federation/v1/version")
|
||||||
@@ -274,35 +87,43 @@ async def thumbnail_media(media_id):
|
|||||||
"error": "Cat is too cute to thumbnail"
|
"error": "Cat is too cute to thumbnail"
|
||||||
}), 418
|
}), 418
|
||||||
|
|
||||||
@server.route("/_matrix/federation/v1/send_join/<roomId>/<eventId>", methods=["PUT"])
|
|
||||||
async def send_join_v1(roomId, eventId):
|
|
||||||
return jsonify([200, send_join(request, roomId)])
|
|
||||||
|
|
||||||
@server.route("/_matrix/federation/v2/send_join/<roomId>/<eventId>", methods=["PUT"])
|
@server.route("/_matrix/federation/v1/send_join/<room>/<eventId>", methods=["PUT"])
|
||||||
async def send_join_v2(roomId, eventId):
|
async def send_join_v1(room, eventId):
|
||||||
return jsonify(send_join(request, roomId))
|
if globals.room_version_from_id(room) not in ["1", "2"]:
|
||||||
|
return jsonify({
|
||||||
|
"errcode": "M_INCOMPATIBLE_ROOM_VERSION",
|
||||||
|
"error": "This room is not v1 or v2."
|
||||||
|
}), 400
|
||||||
|
|
||||||
@server.route("/_matrix/federation/v1/make_join/<roomId>/<userId>")
|
return jsonify([200, send_join(request, room)])
|
||||||
async def make_join(roomId, userId):
|
|
||||||
def not_invited():
|
|
||||||
|
@server.route("/_matrix/federation/v2/send_join/<room>/<eventId>", methods=["PUT"])
|
||||||
|
async def send_join_v2(room, eventId):
|
||||||
|
return jsonify(send_join(request, room))
|
||||||
|
|
||||||
|
|
||||||
|
@server.route("/_matrix/federation/v1/make_join/<room>/<user>")
|
||||||
|
async def make_join(room, user):
|
||||||
|
if ":" in room:
|
||||||
|
if room.split(":")[1] != config.server_name:
|
||||||
|
return jsonify({
|
||||||
|
"errcode": "M_FORBIDDEN",
|
||||||
|
"error": "You are not invited to this room."
|
||||||
|
}), 403
|
||||||
|
else:
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"errcode": "M_FORBIDDEN",
|
"errcode": "M_FORBIDDEN",
|
||||||
"error": "You are not invited to this room."
|
"error": "You are not invited to this room."
|
||||||
}), 403
|
}), 403
|
||||||
|
|
||||||
try:
|
|
||||||
if roomId.split(":")[1] != config.server_name:
|
|
||||||
return not_invited()
|
|
||||||
except:
|
|
||||||
return not_invited()
|
|
||||||
|
|
||||||
class bullshit:
|
room_ver = globals.room_version_from_id(room)
|
||||||
def get_json():
|
|
||||||
return {}
|
|
||||||
|
|
||||||
state = send_join(
|
state = send_join(
|
||||||
request=bullshit,
|
request=bullshit,
|
||||||
roomId=roomId
|
room=room
|
||||||
)["state"]
|
)["state"]
|
||||||
|
|
||||||
join = {
|
join = {
|
||||||
@@ -312,36 +133,50 @@ async def make_join(roomId, userId):
|
|||||||
},
|
},
|
||||||
"origin": config.server_name,
|
"origin": config.server_name,
|
||||||
"origin_server_ts": 7,
|
"origin_server_ts": 7,
|
||||||
"room_id": roomId,
|
"room_id": room,
|
||||||
"sender": userId,
|
"sender": user,
|
||||||
"state_key": userId,
|
"state_key": user,
|
||||||
"type": "m.room.member",
|
"type": "m.room.member",
|
||||||
"depth": 7
|
"depth": 7
|
||||||
}
|
}
|
||||||
|
|
||||||
join["auth_events"] = [
|
if room_ver in ["1", "2"]:
|
||||||
[
|
join["event_id"] = globals.make_event_id(seed=f"{user}+{room}")
|
||||||
state[0]["event_id"],
|
|
||||||
state[0]["hashes"]
|
join["auth_events"] = [
|
||||||
],
|
[
|
||||||
[
|
state[0]["event_id"],
|
||||||
state[2]["event_id"],
|
state[0]["hashes"]
|
||||||
state[2]["hashes"]
|
],
|
||||||
],
|
[
|
||||||
[
|
state[2]["event_id"],
|
||||||
state[3]["event_id"],
|
state[2]["hashes"]
|
||||||
state[3]["hashes"]
|
],
|
||||||
]
|
[
|
||||||
]
|
state[3]["event_id"],
|
||||||
|
state[3]["hashes"]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
join["prev_events"] = [[
|
||||||
|
state[5]["event_id"],
|
||||||
|
state[5]["hashes"]
|
||||||
|
]]
|
||||||
|
else:
|
||||||
|
join["auth_events"] = [
|
||||||
|
globals.make_ref_hash(state[0], int(room_ver)),
|
||||||
|
globals.make_ref_hash(state[2], int(room_ver)),
|
||||||
|
globals.make_ref_hash(state[3], int(room_ver)),
|
||||||
|
]
|
||||||
|
|
||||||
|
join["prev_events"] = [
|
||||||
|
globals.make_ref_hash(state[5], int(room_ver)),
|
||||||
|
]
|
||||||
|
|
||||||
join["prev_events"] = [[
|
|
||||||
state[5]["event_id"],
|
|
||||||
state[5]["hashes"]
|
|
||||||
]]
|
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"event": globals.hash_and_sign_event(join),
|
"event": globals.hash_and_sign_event(join),
|
||||||
"room_version": globals.room_version_from_id(roomId)
|
"room_version": room_ver
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@@ -415,15 +250,8 @@ async def user_keys():
|
|||||||
|
|
||||||
@server.route("/_matrix/federation/v2/invite/<room>/<txnId>", methods=["PUT"])
|
@server.route("/_matrix/federation/v2/invite/<room>/<txnId>", methods=["PUT"])
|
||||||
async def invite_user_v2(room, txnId):
|
async def invite_user_v2(room, txnId):
|
||||||
return invite_user(request.data)
|
invite_data = request.json
|
||||||
|
|
||||||
|
|
||||||
@server.route("/_matrix/federation/v1/invite/<room>/<txnId>", methods=["PUT"])
|
|
||||||
async def invite_user_v1(room, txnId):
|
|
||||||
return [200, invite_user(request.json)]
|
|
||||||
|
|
||||||
|
|
||||||
def invite_user(invite_data):
|
|
||||||
if "event" in invite_data:
|
if "event" in invite_data:
|
||||||
if "room_version" in invite_data:
|
if "room_version" in invite_data:
|
||||||
if invite_data["room_version"] not in ["1", "2"]:
|
if invite_data["room_version"] not in ["1", "2"]:
|
||||||
@@ -436,7 +264,6 @@ def invite_user(invite_data):
|
|||||||
event = invite_data.get("event", {})
|
event = invite_data.get("event", {})
|
||||||
content = event.get("content", {})
|
content = event.get("content", {})
|
||||||
|
|
||||||
# NOTE to crispycat: I know you loooooove this syntax
|
|
||||||
if (
|
if (
|
||||||
"content" in event
|
"content" in event
|
||||||
and "membership" in content
|
and "membership" in content
|
||||||
@@ -446,7 +273,7 @@ def invite_user(invite_data):
|
|||||||
and event["state_key"] == f"@vona:{config.server_name}"
|
and event["state_key"] == f"@vona:{config.server_name}"
|
||||||
):
|
):
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"event": globals.sign_json_without_discard(invite_data["event"]),
|
"event": globals.sign_json_without_discard(event),
|
||||||
"room_version": invite_data["room_version"]
|
"room_version": invite_data["room_version"]
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -457,8 +284,33 @@ def invite_user(invite_data):
|
|||||||
}), 403
|
}), 403
|
||||||
|
|
||||||
|
|
||||||
@server.route("/_matrix/federation/v1/hierarchy/<roomId>")
|
@server.route("/_matrix/federation/v1/invite/<room>/<txnId>", methods=["PUT"])
|
||||||
async def space_hierachy(roomId):
|
async def invite_user_v1(room, txnId):
|
||||||
|
event = request.json
|
||||||
|
content = event.get("content", {})
|
||||||
|
|
||||||
|
if (
|
||||||
|
"content" in event
|
||||||
|
and "membership" in content
|
||||||
|
and "state_key" in event
|
||||||
|
and "room_id" in event
|
||||||
|
and content["membership"] == "invite"
|
||||||
|
and event["state_key"] == f"@vona:{config.server_name}"
|
||||||
|
and "event_id" in event
|
||||||
|
and ":" in event["event_id"]
|
||||||
|
):
|
||||||
|
return jsonify({
|
||||||
|
"event": globals.sign_json_without_discard(event)
|
||||||
|
})
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
"errcode": "M_FORBIDDEN",
|
||||||
|
"error": "Invalid invitation PDU"
|
||||||
|
}), 403
|
||||||
|
|
||||||
|
|
||||||
|
@server.route("/_matrix/federation/v1/hierarchy/<room>")
|
||||||
|
async def space_hierachy(room):
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"errcode": "M_NOT_FOUND",
|
"errcode": "M_NOT_FOUND",
|
||||||
"error": "Room does not exist."
|
"error": "Room does not exist."
|
||||||
@@ -476,12 +328,108 @@ async def discover_common_rooms():
|
|||||||
async def backfill(room):
|
async def backfill(room):
|
||||||
# TODO: burger king foot lettuce
|
# TODO: burger king foot lettuce
|
||||||
|
|
||||||
class bullshit:
|
|
||||||
def get_json():
|
|
||||||
return {}
|
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"origin": config.server_name,
|
"origin": config.server_name,
|
||||||
"origin_server_ts": int(str(time.time() * 1000).split(".")[0]),
|
"origin_server_ts": int(str(time.time() * 1000).split(".")[0]),
|
||||||
"pdus": send_join(bullshit, room)["state"]
|
"pdus": send_join(bullshit, room)["state"]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@server.route("/_matrix/federation/unstable/org.matrix.msc4370/extremities/<room>")
|
||||||
|
@server.route("/_matrix/federation/v1/extremities/<room>")
|
||||||
|
async def extremities(room):
|
||||||
|
if ":" in room:
|
||||||
|
if room.split(":")[1] != config.server_name:
|
||||||
|
return jsonify({
|
||||||
|
"errcode": "M_NOT_FOUND",
|
||||||
|
"error": f"Room is unknown to this server"
|
||||||
|
}), 404
|
||||||
|
|
||||||
|
room_ver = globals.room_version_from_id(room)
|
||||||
|
|
||||||
|
if room_ver in ["1", "2"]:
|
||||||
|
event_id = globals.make_event_id(seed=f"6_{room}")
|
||||||
|
else:
|
||||||
|
event_id = globals.make_ref_hash(
|
||||||
|
send_join(bullshit, room)["state"][5],
|
||||||
|
int(room_ver)
|
||||||
|
)
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
"prev_events": [event_id]
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@server.route("/_matrix/federation/v1/state_ids/<room>")
|
||||||
|
async def state_ids(room):
|
||||||
|
if (
|
||||||
|
"event_id" in request.args
|
||||||
|
and request.args["event_id"].strip() != ""
|
||||||
|
):
|
||||||
|
evt = request.args["event_id"]
|
||||||
|
def explode():
|
||||||
|
return jsonify({
|
||||||
|
"errcode": "M_NOT_FOUND",
|
||||||
|
"error": f"Could not find event {evt}"
|
||||||
|
}), 404
|
||||||
|
|
||||||
|
|
||||||
|
if ":" not in evt:
|
||||||
|
return explode()
|
||||||
|
if ":" in room:
|
||||||
|
if room.split(":")[1] != config.server_name:
|
||||||
|
return explode()
|
||||||
|
else:
|
||||||
|
return explode()
|
||||||
|
|
||||||
|
server_name = evt.split(":")[1]
|
||||||
|
|
||||||
|
if server_name == config.server_name:
|
||||||
|
state = send_join(bullshit, room)["state"]
|
||||||
|
event_ids = []
|
||||||
|
|
||||||
|
for event in state:
|
||||||
|
if "event_id" in event:
|
||||||
|
event_ids.append(event["event_id"])
|
||||||
|
else:
|
||||||
|
event_ids.append(
|
||||||
|
globals.make_ref_hash(event)
|
||||||
|
)
|
||||||
|
|
||||||
|
if evt in event_ids:
|
||||||
|
return jsonify({
|
||||||
|
"auth_chain_ids": [event_ids],
|
||||||
|
"pdu_ids": [event_ids]
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
return explode()
|
||||||
|
|
||||||
|
try:
|
||||||
|
resp = http.get(
|
||||||
|
path=request.full_path,
|
||||||
|
destination=server_name,
|
||||||
|
)
|
||||||
|
|
||||||
|
if resp.status_code != 200:
|
||||||
|
raise
|
||||||
|
|
||||||
|
return jsonify(resp.json())
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return explode()
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
"errcode": "M_MISSING_PARAM",
|
||||||
|
"error": "Query parameter 'event_id' was not specified"
|
||||||
|
}), 400
|
||||||
|
|
||||||
|
|
||||||
|
@server.route("/_matrix/federation/unstable/io.fsky.vel/edutypes")
|
||||||
|
@server.route("/_matrix/federation/v1/edutypes")
|
||||||
|
async def edutypes():
|
||||||
|
return jsonify({
|
||||||
|
"m.presence": False,
|
||||||
|
"m.receipt": False,
|
||||||
|
"m.typing": False,
|
||||||
|
})
|
||||||
|
|||||||
284
vona/federation/rooms.py
Normal file
284
vona/federation/rooms.py
Normal file
@@ -0,0 +1,284 @@
|
|||||||
|
import vona.globals as globals
|
||||||
|
import vona.config as config
|
||||||
|
|
||||||
|
# This file is responsible for creating Matrix rooms.
|
||||||
|
|
||||||
|
# Room V1/V2
|
||||||
|
def v1_v2(request, room) -> dict:
|
||||||
|
event_chain = []
|
||||||
|
|
||||||
|
event_ids = [
|
||||||
|
globals.make_event_id(seed=f"1_{room}"),
|
||||||
|
globals.make_event_id(seed=f"2_{room}"),
|
||||||
|
globals.make_event_id(seed=f"3_{room}"),
|
||||||
|
globals.make_event_id(seed=f"4_{room}"),
|
||||||
|
globals.make_event_id(seed=f"5_{room}"),
|
||||||
|
globals.make_event_id(seed=f"6_{room}"),
|
||||||
|
]
|
||||||
|
|
||||||
|
create_event = {
|
||||||
|
"content": {
|
||||||
|
"m.federate": True,
|
||||||
|
"creator": f"@vona:{config.server_name}",
|
||||||
|
"room_version": globals.room_version_from_id(room)
|
||||||
|
},
|
||||||
|
"event_id": event_ids[0],
|
||||||
|
"origin_server_ts": 1,
|
||||||
|
"room_id": room,
|
||||||
|
"sender": f"@vona:{config.server_name}",
|
||||||
|
"state_key": "",
|
||||||
|
"depth": 1,
|
||||||
|
"type": "m.room.create",
|
||||||
|
"auth_events": [],
|
||||||
|
"prev_events": []
|
||||||
|
}
|
||||||
|
|
||||||
|
screate_event = globals.hash_and_sign_event(create_event)
|
||||||
|
event_chain.append(screate_event)
|
||||||
|
|
||||||
|
our_join = {
|
||||||
|
"content": {
|
||||||
|
"displayname": "Vona",
|
||||||
|
"avatar_url": f"mxc://{config.server_name}/cat",
|
||||||
|
"membership": "join"
|
||||||
|
},
|
||||||
|
"origin_server_ts": 2,
|
||||||
|
"sender": f"@vona:{config.server_name}",
|
||||||
|
"state_key": f"@vona:{config.server_name}",
|
||||||
|
"type": "m.room.member",
|
||||||
|
"event_id": event_ids[1],
|
||||||
|
"room_id": room,
|
||||||
|
"depth": 2,
|
||||||
|
"auth_events": [[
|
||||||
|
screate_event["event_id"],
|
||||||
|
screate_event["hashes"]
|
||||||
|
]],
|
||||||
|
"prev_events": [[
|
||||||
|
screate_event["event_id"],
|
||||||
|
screate_event["hashes"]
|
||||||
|
]]
|
||||||
|
}
|
||||||
|
|
||||||
|
sour_join = globals.hash_and_sign_event(our_join)
|
||||||
|
event_chain.append(sour_join)
|
||||||
|
|
||||||
|
pls = {
|
||||||
|
"content": {
|
||||||
|
"users": {
|
||||||
|
f"@vona:{config.server_name}": "100"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"origin_server_ts": 3,
|
||||||
|
"room_id": room,
|
||||||
|
"sender": f"@vona:{config.server_name}",
|
||||||
|
"state_key": "",
|
||||||
|
"type": "m.room.power_levels",
|
||||||
|
"event_id": event_ids[2],
|
||||||
|
"depth": 3,
|
||||||
|
"user_id": f"@vona:{config.server_name}",
|
||||||
|
"auth_events": [
|
||||||
|
[
|
||||||
|
screate_event["event_id"],
|
||||||
|
screate_event["hashes"]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
sour_join["event_id"],
|
||||||
|
sour_join["hashes"]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"prev_events": [[
|
||||||
|
sour_join["event_id"],
|
||||||
|
sour_join["hashes"]
|
||||||
|
]]
|
||||||
|
}
|
||||||
|
|
||||||
|
spls = globals.hash_and_sign_event(pls)
|
||||||
|
event_chain.append(spls)
|
||||||
|
|
||||||
|
join_rule = {
|
||||||
|
"content": {
|
||||||
|
"join_rule": "public"
|
||||||
|
},
|
||||||
|
"origin_server_ts": 4,
|
||||||
|
"sender": f"@vona:{config.server_name}",
|
||||||
|
"state_key": "",
|
||||||
|
"type": "m.room.join_rules",
|
||||||
|
"event_id": event_ids[3],
|
||||||
|
"room_id": room,
|
||||||
|
"depth": 4,
|
||||||
|
"auth_events": [
|
||||||
|
[
|
||||||
|
screate_event["event_id"],
|
||||||
|
screate_event["hashes"]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
sour_join["event_id"],
|
||||||
|
sour_join["hashes"]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
spls["event_id"],
|
||||||
|
spls["hashes"]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"prev_events": [[
|
||||||
|
spls["event_id"],
|
||||||
|
spls["hashes"]
|
||||||
|
]]
|
||||||
|
}
|
||||||
|
|
||||||
|
sjoin_rule = globals.hash_and_sign_event(join_rule)
|
||||||
|
event_chain.append(sjoin_rule)
|
||||||
|
|
||||||
|
guest_access = {
|
||||||
|
"content": {
|
||||||
|
"guest_access": "forbidden"
|
||||||
|
},
|
||||||
|
"origin_server_ts": 5,
|
||||||
|
"depth": 5,
|
||||||
|
"sender": f"@vona:{config.server_name}",
|
||||||
|
"state_key": "",
|
||||||
|
"type": "m.room.guest_access",
|
||||||
|
"event_id": event_ids[4],
|
||||||
|
"room_id": room,
|
||||||
|
"auth_events": [
|
||||||
|
[
|
||||||
|
screate_event["event_id"],
|
||||||
|
screate_event["hashes"]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
sour_join["event_id"],
|
||||||
|
sour_join["hashes"]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
spls["event_id"],
|
||||||
|
spls["hashes"]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"prev_events": [[
|
||||||
|
sjoin_rule["event_id"],
|
||||||
|
sjoin_rule["hashes"]
|
||||||
|
]]
|
||||||
|
}
|
||||||
|
|
||||||
|
sguest_access = globals.hash_and_sign_event(guest_access)
|
||||||
|
event_chain.append(sguest_access)
|
||||||
|
|
||||||
|
history = {
|
||||||
|
"content": {
|
||||||
|
"history_visibility": "shared"
|
||||||
|
},
|
||||||
|
"type": "m.room.history_visibility",
|
||||||
|
"sender": f"@vona:{config.server_name}",
|
||||||
|
"state_key": "",
|
||||||
|
"origin_server_ts": 6,
|
||||||
|
"depth": 6,
|
||||||
|
"event_id": event_ids[5],
|
||||||
|
"room_id": room,
|
||||||
|
"auth_events": [
|
||||||
|
[
|
||||||
|
screate_event["event_id"],
|
||||||
|
screate_event["hashes"]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
sour_join["event_id"],
|
||||||
|
sour_join["hashes"]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
spls["event_id"],
|
||||||
|
spls["hashes"]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"prev_events": [[
|
||||||
|
sguest_access["event_id"],
|
||||||
|
sguest_access["hashes"]
|
||||||
|
]]
|
||||||
|
}
|
||||||
|
|
||||||
|
shistory = globals.hash_and_sign_event(history)
|
||||||
|
event_chain.append(shistory)
|
||||||
|
|
||||||
|
remote_join = request.get_json()
|
||||||
|
|
||||||
|
response = {
|
||||||
|
"auth_chain": event_chain,
|
||||||
|
"event": remote_join,
|
||||||
|
"members_omitted": False,
|
||||||
|
"servers_in_room": [config.server_name],
|
||||||
|
"state": event_chain
|
||||||
|
}
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
# Room V3 to V9
|
||||||
|
def v3(request, room) -> dict:
|
||||||
|
initial_response = v1_v2(request, room)
|
||||||
|
state = list(initial_response["state"])
|
||||||
|
ver = int(globals.room_version_from_id(room))
|
||||||
|
events = {}
|
||||||
|
hash_map = {}
|
||||||
|
|
||||||
|
for event in state:
|
||||||
|
events[event["type"]] = event
|
||||||
|
del event["event_id"]
|
||||||
|
del event["hashes"]
|
||||||
|
del event["signatures"]
|
||||||
|
|
||||||
|
# m.room.create doesn't have prev_events or auth_events
|
||||||
|
events["m.room.create"] = globals.hash_and_sign_event(events["m.room.create"])
|
||||||
|
hash_map["m.room.create"] = globals.make_ref_hash(events["m.room.create"], ver)
|
||||||
|
|
||||||
|
events["m.room.member"]["auth_events"] = [hash_map["m.room.create"]]
|
||||||
|
events["m.room.member"]["prev_events"] = [hash_map["m.room.create"]]
|
||||||
|
events["m.room.member"] = globals.hash_and_sign_event(events["m.room.member"])
|
||||||
|
hash_map["m.room.member"] = globals.make_ref_hash(events["m.room.member"], ver)
|
||||||
|
|
||||||
|
events["m.room.power_levels"]["auth_events"] = [
|
||||||
|
hash_map["m.room.create"],
|
||||||
|
hash_map["m.room.member"],
|
||||||
|
]
|
||||||
|
events["m.room.power_levels"]["prev_events"] = [hash_map["m.room.member"]]
|
||||||
|
events["m.room.power_levels"] = globals.hash_and_sign_event(events["m.room.power_levels"])
|
||||||
|
hash_map["m.room.power_levels"] = globals.make_ref_hash(events["m.room.power_levels"], ver)
|
||||||
|
|
||||||
|
events["m.room.join_rules"]["auth_events"] = [
|
||||||
|
hash_map["m.room.create"],
|
||||||
|
hash_map["m.room.member"],
|
||||||
|
hash_map["m.room.power_levels"],
|
||||||
|
]
|
||||||
|
events["m.room.join_rules"]["prev_events"] = [hash_map["m.room.power_levels"]]
|
||||||
|
events["m.room.join_rules"] = globals.hash_and_sign_event(events["m.room.join_rules"])
|
||||||
|
hash_map["m.room.join_rules"] = globals.make_ref_hash(events["m.room.join_rules"], ver)
|
||||||
|
|
||||||
|
events["m.room.guest_access"]["auth_events"] = [
|
||||||
|
hash_map["m.room.create"],
|
||||||
|
hash_map["m.room.member"],
|
||||||
|
hash_map["m.room.power_levels"],
|
||||||
|
]
|
||||||
|
events["m.room.guest_access"]["prev_events"] = [hash_map["m.room.join_rules"]]
|
||||||
|
events["m.room.guest_access"] = globals.hash_and_sign_event(events["m.room.guest_access"])
|
||||||
|
hash_map["m.room.guest_access"] = globals.make_ref_hash(events["m.room.guest_access"], ver)
|
||||||
|
|
||||||
|
events["m.room.history_visibility"]["auth_events"] = [
|
||||||
|
hash_map["m.room.create"],
|
||||||
|
hash_map["m.room.member"],
|
||||||
|
hash_map["m.room.power_levels"],
|
||||||
|
]
|
||||||
|
events["m.room.history_visibility"]["prev_events"] = [hash_map["m.room.guest_access"]]
|
||||||
|
events["m.room.history_visibility"] = globals.hash_and_sign_event(events["m.room.history_visibility"])
|
||||||
|
|
||||||
|
new_state = []
|
||||||
|
|
||||||
|
for event in events:
|
||||||
|
new_state.append(events[event])
|
||||||
|
|
||||||
|
|
||||||
|
resp = {
|
||||||
|
"auth_chain": new_state,
|
||||||
|
"event": initial_response["event"],
|
||||||
|
"members_omitted": False,
|
||||||
|
"servers_in_room": [config.server_name],
|
||||||
|
"state": new_state
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp
|
||||||
@@ -7,11 +7,10 @@ import hashlib
|
|||||||
import base64
|
import base64
|
||||||
import random
|
import random
|
||||||
import httpx
|
import httpx
|
||||||
import copy
|
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
|
|
||||||
version = "1.4.4"
|
version = "1.5.0"
|
||||||
|
|
||||||
|
|
||||||
def canonical_json(value):
|
def canonical_json(value):
|
||||||
@@ -169,7 +168,10 @@ def make_auth_header(
|
|||||||
return authorization_headers[0].decode("utf-8")
|
return authorization_headers[0].decode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
def redact_event(event):
|
def redact_event(
|
||||||
|
event: dict,
|
||||||
|
for_event_id: bool = False,
|
||||||
|
):
|
||||||
# Returns a redacted event as per
|
# Returns a redacted event as per
|
||||||
# the algorithm for v1/v2 rooms.
|
# the algorithm for v1/v2 rooms.
|
||||||
|
|
||||||
@@ -181,7 +183,6 @@ def redact_event(event):
|
|||||||
"state_key",
|
"state_key",
|
||||||
"content",
|
"content",
|
||||||
"hashes",
|
"hashes",
|
||||||
"signatures",
|
|
||||||
"depth",
|
"depth",
|
||||||
"prev_events",
|
"prev_events",
|
||||||
"prev_state",
|
"prev_state",
|
||||||
@@ -191,6 +192,9 @@ def redact_event(event):
|
|||||||
"membership",
|
"membership",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if not for_event_id:
|
||||||
|
allowed_keys.append("signatures")
|
||||||
|
|
||||||
redacted_event = {k: v for k, v in event.items() if k in allowed_keys}
|
redacted_event = {k: v for k, v in event.items() if k in allowed_keys}
|
||||||
|
|
||||||
if "type" in redacted_event and "content" in redacted_event:
|
if "type" in redacted_event and "content" in redacted_event:
|
||||||
@@ -236,30 +240,51 @@ def hash_and_sign_event(event_object):
|
|||||||
return event_object
|
return event_object
|
||||||
|
|
||||||
|
|
||||||
def room_version_from_id(room_id):
|
def make_ref_hash(
|
||||||
room_id_no_sigil = room_id.replace("!", "")
|
event: dict,
|
||||||
|
room_ver: int = 3,
|
||||||
|
):
|
||||||
|
stripped = redact_event(event, True)
|
||||||
|
evt_bytes = canonical_json(stripped)
|
||||||
|
|
||||||
|
evt_hash = base64.b64encode(
|
||||||
|
hashlib.sha256(evt_bytes).digest()
|
||||||
|
).decode("utf-8").rstrip("=")
|
||||||
|
|
||||||
|
if room_ver > 3:
|
||||||
|
while "+" in evt_hash:
|
||||||
|
evt_hash = evt_hash.replace("+", "-")
|
||||||
|
while "/" in evt_hash:
|
||||||
|
evt_hash = evt_hash.replace("/", "_")
|
||||||
|
|
||||||
|
return "$" + evt_hash
|
||||||
|
|
||||||
|
|
||||||
|
def room_version_from_id(room):
|
||||||
|
room_id_no_sigil = (
|
||||||
|
room
|
||||||
|
.replace("!", "")
|
||||||
|
.replace(f":{config.server_name}", "")
|
||||||
|
)
|
||||||
hexadecimal_room_id = bytes(room_id_no_sigil, "utf-8").hex()
|
hexadecimal_room_id = bytes(room_id_no_sigil, "utf-8").hex()
|
||||||
|
|
||||||
if "1" not in hexadecimal_room_id and "2" not in hexadecimal_room_id:
|
versions = [str(i) for i in range(1, 10)]
|
||||||
# NOTE: v2 if impossible from room ID alone
|
|
||||||
|
if not any(ver in hexadecimal_room_id for ver in versions):
|
||||||
hexadecimal_room_id = "2" + hexadecimal_room_id[1:]
|
hexadecimal_room_id = "2" + hexadecimal_room_id[1:]
|
||||||
|
|
||||||
def remove_chars(s):
|
def remove_chars(s):
|
||||||
return re.sub("[^12]", "", s)
|
return re.sub(f"[^{''.join(versions)}]", "", s)
|
||||||
|
|
||||||
nums = remove_chars(hexadecimal_room_id)
|
nums = remove_chars(hexadecimal_room_id)
|
||||||
|
|
||||||
def most_common_character(s):
|
def most_common_character(s):
|
||||||
s = s.replace(" ", "").lower()
|
s = s.replace(" ", "").lower()
|
||||||
|
|
||||||
counts = Counter(s)
|
counts = Counter(s)
|
||||||
|
|
||||||
most_common = counts.most_common(1)
|
most_common = counts.most_common(1)
|
||||||
|
return most_common[0] if most_common else ("2",)
|
||||||
|
|
||||||
return most_common[0] if most_common else None
|
return str(most_common_character(nums)[0])
|
||||||
|
|
||||||
return most_common_character(nums)[0]
|
|
||||||
|
|
||||||
|
|
||||||
room_dir = {
|
room_dir = {
|
||||||
@@ -312,6 +337,7 @@ class http_client:
|
|||||||
method="PUT",
|
method="PUT",
|
||||||
destination=destination,
|
destination=destination,
|
||||||
path=path,
|
path=path,
|
||||||
|
content=json,
|
||||||
)
|
)
|
||||||
|
|
||||||
headers["Host"] = resolved.host_header
|
headers["Host"] = resolved.host_header
|
||||||
@@ -320,7 +346,7 @@ class http_client:
|
|||||||
f"{resolved.base_url}{path}",
|
f"{resolved.base_url}{path}",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
extensions={"sni_hostname": resolved.sni},
|
extensions={"sni_hostname": resolved.sni},
|
||||||
json=json
|
json=json,
|
||||||
)
|
)
|
||||||
|
|
||||||
def get(
|
def get(
|
||||||
@@ -344,5 +370,32 @@ class http_client:
|
|||||||
return self.http.get(
|
return self.http.get(
|
||||||
f"{resolved.base_url}{path}",
|
f"{resolved.base_url}{path}",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
extensions={"sni_hostname": resolved.sni}
|
extensions={"sni_hostname": resolved.sni},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def strip_state(l) -> list:
|
||||||
|
if not isinstance(l, list):
|
||||||
|
return l
|
||||||
|
|
||||||
|
keys_to_remove = [
|
||||||
|
"auth_events",
|
||||||
|
"prev_events",
|
||||||
|
"signatures",
|
||||||
|
"hashes",
|
||||||
|
"depth"
|
||||||
|
]
|
||||||
|
|
||||||
|
new_list = []
|
||||||
|
for d in l:
|
||||||
|
if not isinstance(d, dict):
|
||||||
|
new_list.append(d)
|
||||||
|
continue
|
||||||
|
|
||||||
|
new_dict = {}
|
||||||
|
for k, v in d.items():
|
||||||
|
if k in keys_to_remove:
|
||||||
|
continue
|
||||||
|
new_dict[k] = strip_state(v)
|
||||||
|
new_list.append(new_dict)
|
||||||
|
return new_list
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
from flask import Blueprint, jsonify, request
|
|
||||||
from vona.config import server_name, the_funny_number
|
from vona.config import server_name, the_funny_number
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from flask import (
|
||||||
|
Blueprint,
|
||||||
|
jsonify,
|
||||||
|
request,
|
||||||
|
)
|
||||||
|
|
||||||
identity = Blueprint("identity", __name__)
|
identity = Blueprint("identity", __name__)
|
||||||
|
|
||||||
# This implements being an identity server.
|
# This implements being an identity server.
|
||||||
@@ -128,11 +133,11 @@ async def invite():
|
|||||||
"public_keys": [
|
"public_keys": [
|
||||||
{
|
{
|
||||||
"key_validity_url": f"https://{server_name}/_matrix/identity/v2/pubkey/isvalid",
|
"key_validity_url": f"https://{server_name}/_matrix/identity/v2/pubkey/isvalid",
|
||||||
"public_key":"ohyeah"
|
"public_key": "ohyeah"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key_validity_url": f"https://{server_name}/_matrix/identity/v2/pubkey/ephemeral/isvalid",
|
"key_validity_url": f"https://{server_name}/_matrix/identity/v2/pubkey/ephemeral/isvalid",
|
||||||
"public_key":"thisssssss"
|
"public_key": "burgerkingfootlettuce"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"token": "vona"
|
"token": "vona"
|
||||||
@@ -143,10 +148,10 @@ async def invite():
|
|||||||
@identity.route("/_matrix/identity/v2/sign-ed25519", methods=["POST"])
|
@identity.route("/_matrix/identity/v2/sign-ed25519", methods=["POST"])
|
||||||
async def invite_signing():
|
async def invite_signing():
|
||||||
required_keys = {"mxid", "private_key", "token"}
|
required_keys = {"mxid", "private_key", "token"}
|
||||||
d = data.get_json()
|
d = request.data.get_json()
|
||||||
|
|
||||||
if set(d.keys()) == required_keys:
|
if set(d.keys()) == required_keys:
|
||||||
return jsonify(sign_json(d))
|
return jsonify(globals.sign_json(d))
|
||||||
else:
|
else:
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"errcode": "M_UNRECOGNIZED",
|
"errcode": "M_UNRECOGNIZED",
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
from flask import jsonify, Blueprint, request
|
from flask import (
|
||||||
|
jsonify,
|
||||||
|
Blueprint,
|
||||||
|
request,
|
||||||
|
)
|
||||||
|
|
||||||
policy = Blueprint("policy", __name__)
|
policy = Blueprint("policy", __name__)
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
print("Available utils:")
|
print("Available utils:")
|
||||||
|
|
||||||
a = [
|
a = [
|
||||||
"makekey",
|
"makekey - Generate a signing key",
|
||||||
"joinroom"
|
"joinroom - Join a remote room",
|
||||||
|
"roomwithver - Brute-force a room with a specific room version",
|
||||||
]
|
]
|
||||||
|
|
||||||
for t in a:
|
for t in a:
|
||||||
print(f"\t{t}")
|
print(f"\t{t}")
|
||||||
|
|
||||||
print("")
|
print("")
|
||||||
|
|||||||
@@ -1,10 +1,37 @@
|
|||||||
from resolvematrix import ServerResolver
|
|
||||||
import urllib.parse, time, json, httpx
|
|
||||||
import vona.globals as globals
|
import vona.globals as globals
|
||||||
import vona.config as config
|
import vona.config as config
|
||||||
|
|
||||||
|
import urllib.parse
|
||||||
|
import time
|
||||||
|
import json
|
||||||
|
import httpx
|
||||||
|
|
||||||
|
|
||||||
http_client = globals.http_client()
|
http_client = globals.http_client()
|
||||||
|
|
||||||
|
versions = [
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
"3",
|
||||||
|
"4",
|
||||||
|
"5",
|
||||||
|
"6",
|
||||||
|
"7",
|
||||||
|
"8",
|
||||||
|
"9",
|
||||||
|
"10",
|
||||||
|
"11",
|
||||||
|
"12",
|
||||||
|
"org.matrix.msc3757.10",
|
||||||
|
"org.matrix.msc3757.11",
|
||||||
|
"org.matrix.hydra.11",
|
||||||
|
"org.matrix.msc3667",
|
||||||
|
"org.matrix.msc3787",
|
||||||
|
"org.matrix.msc4014",
|
||||||
|
]
|
||||||
|
|
||||||
|
verparams = "&".join(f"ver={ver}" for ver in versions)
|
||||||
|
|
||||||
|
|
||||||
def get_user_input(prompt):
|
def get_user_input(prompt):
|
||||||
try:
|
try:
|
||||||
@@ -28,13 +55,11 @@ except Exception as e:
|
|||||||
print(f"Error reading server names: {e}")
|
print(f"Error reading server names: {e}")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
resolver = ServerResolver(client=http_client)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print("\nSending make_join request..")
|
print("\nSending make_join request..")
|
||||||
|
|
||||||
make_join_response = http_client.get(
|
make_join_response = http_client.get(
|
||||||
path=f"/_matrix/federation/v1/make_join/{room_id}/%40{username}%3A{config.server_name}?ver=1&ver=2&ver=3&ver=4&ver=5&ver=6&ver=7&ver=8&ver=9&ver=10&ver=11&ver=12",
|
path=f"/_matrix/federation/v1/make_join/{room_id}/%40{username}%3A{config.server_name}?{verparams}",
|
||||||
destination=server_name,
|
destination=server_name,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -57,6 +82,16 @@ if make_join.get("room_version", "1") in ["1", "2"]:
|
|||||||
# NOTE: if we always make it opaque than Synapse will 500 lmao
|
# NOTE: if we always make it opaque than Synapse will 500 lmao
|
||||||
join_event["event_id"] = globals.make_event_id()
|
join_event["event_id"] = globals.make_event_id()
|
||||||
|
|
||||||
|
elif make_join.get("room_version", "1") == "org.matrix.msc4014":
|
||||||
|
# dendrite dislikes this :p
|
||||||
|
join_event["sender_key"] = globals.pubkey()
|
||||||
|
|
||||||
|
join_event["content"]["mxid_mapping"] = globals.sign_json({
|
||||||
|
"sender_key": globals.pubkey(),
|
||||||
|
"user_id": f"@{username}:{config.server_name}"
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
timestamp = input("\nTimestamp (leave blank for now):\n\t")
|
timestamp = input("\nTimestamp (leave blank for now):\n\t")
|
||||||
try:
|
try:
|
||||||
join_event["origin_server_ts"] = int(timestamp)
|
join_event["origin_server_ts"] = int(timestamp)
|
||||||
|
|||||||
@@ -1,25 +1,23 @@
|
|||||||
# Generates a key in the format compatible with Synapse and Vona.
|
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
# Generates a key in the format compatible with Synapse and Vona.
|
||||||
|
|
||||||
|
|
||||||
def mkchar() -> str:
|
def mkchar() -> str:
|
||||||
return os.urandom(4).hex()[:1]
|
return os.urandom(4).hex()[:1]
|
||||||
|
|
||||||
|
|
||||||
key = (
|
def random(length):
|
||||||
base64.b64encode(os.urandom(32))
|
return (
|
||||||
.decode("utf-8")[:43]
|
base64.b64encode(os.urandom(length))
|
||||||
.replace("/", mkchar())
|
.decode("utf-8")[:length]
|
||||||
.replace("+", mkchar())
|
.replace("/", mkchar())
|
||||||
)
|
.replace("+", mkchar())
|
||||||
|
)
|
||||||
|
|
||||||
key_id = (
|
|
||||||
base64.b64encode(os.urandom(32))
|
key = random(43)
|
||||||
.decode("utf-8")[:6]
|
key_id = random(6)
|
||||||
.replace("/", mkchar())
|
|
||||||
.replace("+", mkchar())
|
|
||||||
)
|
|
||||||
|
|
||||||
print(f"ed25519 {key_id} {key}")
|
print(f"ed25519 {key_id} {key}")
|
||||||
|
|||||||
21
vona/utils/roomwithver.py
Normal file
21
vona/utils/roomwithver.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import vona.globals as globals
|
||||||
|
import vona.config as config
|
||||||
|
import os
|
||||||
|
|
||||||
|
versions = [str(i) for i in range(1, 10)]
|
||||||
|
desired_ver = input("Desired room version:\n\t")
|
||||||
|
|
||||||
|
if desired_ver not in versions:
|
||||||
|
os._exit(1)
|
||||||
|
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
room_id = os.urandom(8).hex()
|
||||||
|
room_ver = globals.room_version_from_id(room_id)
|
||||||
|
|
||||||
|
if room_ver == desired_ver:
|
||||||
|
print(f"!{room_id}:{config.server_name}")
|
||||||
|
break
|
||||||
|
except:
|
||||||
|
print("")
|
||||||
|
pass
|
||||||
Reference in New Issue
Block a user