Cleaned up the 404 and 500 so they work... also added the replay system cause someone triggerd it.

This commit is contained in:
ZKWolf 2023-12-18 02:35:41 +01:00
parent 471f8922d9
commit 9a74a592a9

View File

@ -1,3 +1,5 @@
import werkzeug.exceptions
from flask_definitions import *
@ -21,9 +23,28 @@ def catalog_get(game_version_unsanitized):
@app.errorhandler(404)
def debug_404(e):
check_for_game_client("soft")
logger.graylog_logger(level="error", handler="404-handler", message=f"Path: {sanitize_input(request.path)} Endpoint: {sanitize_input(request.endpoint)}")
print(e)
user_ip = check_for_game_client("remote")
try:
if request.json:
response_json = sanitize_input(request.json)
else:
response_json = "None"
except werkzeug.exceptions.UnsupportedMediaType:
response_json = "None"
if request.path:
response_path = sanitize_input(request.path)
else:
response_path = "None"
if request.endpoint:
response_endpoint = sanitize_input(request.endpoint)
else:
response_endpoint = "None"
logger.graylog_logger(level="error", handler="404-handler", message=f"<Path: {response_path}> "
f"<Endpoint: {response_endpoint}>"
f"<Methode: {sanitize_input(request.method)}>"
f"<JSON: {response_json}>"
f"<IP: {user_ip}>")
return jsonify({"message": "Endpoint not found"}), 404
@ -31,15 +52,79 @@ def debug_404(e):
def debug_500(e):
check_for_game_client("soft")
if request.path:
path = sanitize_input(request.path)
response_path = sanitize_input(request.path)
else:
path = "None"
response_path = "None"
if request.endpoint:
endpoint = sanitize_input(request.endpoint)
response_endpoint = sanitize_input(request.endpoint)
else:
endpoint = "None"
response_endpoint = "None"
if not e:
e = "None"
logger.graylog_logger(level="error", handler="500-handler", message=f"Path: {path} Endpoint: {endpoint}, Error: {e}")
try:
if request.json:
response_json = sanitize_input(request.json)
else:
response_json = "None"
except werkzeug.exceptions.UnsupportedMediaType:
response_json = "None"
response_method = request.method
user_ip = check_for_game_client("remote")
logger.graylog_logger(level="error", handler="500-handler", message=f"<Path: {response_path}> "
f"<Endpoint: {response_endpoint}>"
f"<Methode: {response_method}>"
f"<JSON: {response_json}>"
f"<IP: {user_ip}>"
f"<Error: {e}>")
print(e)
return jsonify({"message": "Internal Server Error"}), 500
@app.route("/replay", methods=["GET", "POST", "PUT", "DELETE"])
def replay():
# Probably the not implemented replay game function. Who triggerd this?!?!?! 2023-12-17 19:24:20
check_for_game_client("strict")
session_cookie = request.cookies.get("bhvrSession")
userid = session_manager.get_user_id(session_cookie)
try:
if request.method == "GET":
return jsonify({"status": "success"})
elif request.method == "POST":
# This gets called on launch of EMCEE Replay System
# POST https://api.zkwolf.com//replay?app=TheExit&version=1933146466&cl=0&friendlyName=Arena&meta=te-18f25613-36778-ue4-374f864b HTTP/1.1
# {
# "users": [
# "765611991694444485"
# ]
# }
app = request.args["app"]
version = request.args["version"]
cl = request.args["cl"]
friendly_name = request.args["friendlyName"]
meta = request.args["meta"]
users = request.json["users"][0]
logger.graylog_logger(level="info", handler="replay", message=f"New Replay: "
f"Users: {users}, "
f"App: {app}, "
f"Version: {version}, "
f"CL: {cl}, "
f"Friendly_name: {friendly_name}, "
f"Meta: {meta}")
return jsonify({"status": "success"})
elif request.method == "PUT":
return jsonify({"status": "success"})
elif request.method == "DELETE":
return jsonify({"status": "success"})
except TimeoutError:
return jsonify({"status": "error"})
except Exception as e:
logger.graylog_logger(level="error", handler="replay", message=e)
@app.route("/nice ports,/Trinity.txt.bak", methods=["GET"])
def trinity():
# For NMAP Scans
abort(404)