import vona.globals as globals from datetime import datetime import vona.config as config import threading import logging import os from flask import ( Flask, jsonify, request, redirect, abort, ) from vona.federation import server from vona.custom import custom from vona.identity import identity from vona.appservice import apps from vona.policy import policy from vona.client import client logging.getLogger("werkzeug").disabled = True logging.getLogger("flask").disabled = True app = Flask("vona") app.register_blueprint(identity) app.register_blueprint(policy) app.register_blueprint(client) app.register_blueprint(custom) app.register_blueprint(server) app.register_blueprint(apps) @app.before_request async def validate_json(): if request.method == "OPTIONS": return "", 200 elif request.method in ["PUT", "POST", "PATCH"]: if "media" in request.path: # Don't check media uploads return try: request.get_json(force=True) except Exception: return jsonify({"error": "Content not JSON.", "errcode": "M_NOT_JSON"}), 400 @app.after_request async def handle_logging(response): response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate" response.headers["Access-Control-Allow-Origin"] = "*" response.headers["Access-Control-Allow-Headers"] = "*" response.headers["Access-Control-Allow-Methods"] = "GET, HEAD, POST, PUT, DELETE, OPTIONS" if request.method == "OPTIONS": return response origin = "unknown" try: if "Authorization" in request.headers: if request.headers["Authorization"].split()[0] == "X-Matrix": origin = ( request.headers["Authorization"] .split("origin=")[1] .split(",")[0] ) while '"' in origin: origin = origin.replace('"', "") if origin == config.server_name: return response else: origin = "client" except Exception: pass if request.path.startswith("/.well-known/matrix/"): return response print( f"[{origin}] " + f'[{datetime.now().strftime("%d/%b/%Y:%H:%M:%S")}] ' + request.method + " " + request.full_path.rstrip("?") + " " + str(response.status_code) ) return response # Landing page @app.route("/") async def root(): return redirect("/_matrix/static/", 308) @app.route("/_matrix/static/") async def matrix_static(): return f'
Your Vona server is listening on this port and is ready for messages.
To use this server you\"ll need a Matrix client.
Welcome to the Matrix universe :)