maybe it'll fix it

This commit is contained in:
magmaus3 2024-11-30 19:09:31 +01:00
parent 8a96679771
commit 91bfa94208
Signed by: magmaus3
GPG key ID: 84BC6F564FD017BE
4 changed files with 12 additions and 4 deletions

View file

@ -12,8 +12,16 @@ else:
webhook = None webhook = None
@app.post("/up/sendmessage") @app.post("/up/sendmessage")
async def message_endpoint(request: Request, name: str = Body(str), message: str = Body(str)): # async def message_endpoint(request: Request, name: str = Body(str), message: str = Body(str)):
ip = request.headers['X-Forwarded-For'] async def message_endpoint(request: Request):
ip = request.headers['X-Forwarded-For'] if 'X-Forwarded-For' in request.headers else request.client.host
try:
data = await request.json()
name = data["name"] if "name" in data else "<none>"
message = data["message"] if "message" in data else "<none>"
except:
logger.info(f"{ip}: invalid body: {request._body}")
return {"error": "invalid body"}
if webhook: if webhook:
embed = DiscordEmbed( embed = DiscordEmbed(
title="message received", title="message received",
@ -29,9 +37,9 @@ async def message_endpoint(request: Request, name: str = Body(str), message: str
@app.get("/up/configuration") @app.get("/up/configuration")
async def configuration_endpoint(request: Request): async def configuration_endpoint(request: Request):
ip = request.headers['X-Forwarded-For'] ip = request.headers['X-Forwarded-For'] if 'X-Forwarded-For' in request.headers else request.client.host
if webhook: if webhook:
embed = DiscordEmbed(title="received configuration request") embed = DiscordEmbed(title="received configuration request", description=f"address: {ip}")
embed.add_embed_field(name="address", value=ip) embed.add_embed_field(name="address", value=ip)
response = webhook.execute() response = webhook.execute()