dynmap-honeypot/dynmap_honeypot/main.py

491 lines
19 KiB
Python
Raw Normal View History

2024-09-07 19:35:40 +00:00
from typing import Optional
from fastapi import Body, FastAPI, Request
from loguru import logger
from discord_webhook import DiscordEmbed, DiscordWebhook
from os import getenv
app = FastAPI()
webhook_url = getenv("DYNMAP_WEBHOOK", None)
if webhook_url:
webhook = DiscordWebhook(url=webhook_url)
else:
webhook = None
@app.post("/up/sendmessage")
async def message_endpoint(request: Request, name: str = Body(str), message: str = Body(str)):
ip = request.headers['X-Forwarded-For']
if webhook:
embed = DiscordEmbed(
title="message received",
description="```" + (f"{name}: " if name != "" else "") + str(message) + "```",
)
embed.add_embed_field(name="address", value=ip)
webhook.add_embed(embed)
response = webhook.execute()
logger.info(f"new message from {ip}: [{name}] {message}")
return {"error": "none"}
@app.get("/up/configuration")
async def configuration_endpoint(request: Request):
ip = request.headers['X-Forwarded-For']
if webhook:
embed = DiscordEmbed(title="received configuration request")
embed.add_embed_field(name="address", value=ip)
response = webhook.execute()
# default configuration
# TODO: move to a separate file
return {
"updaterate": 2000.0,
"chatlengthlimit": 256,
"components": [
{
"spawnlabel": "Spawn",
"spawnbedhidebydefault": True,
"spawnbedformat": "%name%'s bed",
"worldborderlabel": "Border",
"spawnbedremoveonplayerleave": True,
"showworldborder": True,
"type": "markers",
"showlabel": False,
"offlineicon": "offlineuser",
"showspawnbeds": False,
"showofflineplayers": False,
"spawnbedicon": "bed",
"offlinehidebydefault": True,
"offlinelabel": "Offline",
"enablesigns": False,
"default-sign-set": "markers",
"spawnicon": "world",
"offlineminzoom": 0,
"spawnbedminzoom": 0,
"showspawn": True,
"spawnbedlabel": "Spawn Beds",
"maxofflinetime": 30,
},
{"allowurlname": False, "type": "chat"},
{"focuschatballoons": False, "type": "chatballoon"},
{
"showplayerfaces": True,
"sendbutton": False,
"type": "chatbox",
"messagettl": 5,
},
{
"hidebydefault": False,
"showplayerhealth": True,
"showplayerbody": False,
"showplayerfaces": True,
"largeplayerfaces": False,
"label": "Players",
"type": "playermarkers",
"smallplayerfaces": False,
"layerprio": 0,
},
{"type": "link"},
{"showdigitalclock": True, "showweather": True, "type": "timeofdayclock"},
{
"show-mcr": False,
"label": "Location",
"type": "coord",
"show-chunk": False,
"hidey": False,
},
],
"worlds": [
{
"sealevel": 63,
"protected": False,
"maps": [
{
"nightandday": False,
"shader": "stdtexture",
"compassview": "S",
"prefix": "flat",
"tilescale": 0,
"icon": None,
"scale": 4,
"azimuth": 270.0,
"type": "HDMapType",
"title": "Flat",
"backgroundday": None,
"protected": False,
"mapzoomout": 5,
"perspective": "iso_S_90_lowres",
"worldtomap": [
4.0,
0.0,
-2.4492935982947064e-16,
-2.4492935982947064e-16,
0.0,
-4.0,
0.0,
1.0,
0.0,
],
"inclination": 90.0,
"image-format": "jpg",
"lighting": "shadows",
"bigmap": True,
"maptoworld": [
0.25,
-1.5308084989341915e-17,
0.0,
0.0,
0.0,
1.0,
-1.5308084989341915e-17,
-0.25,
0.0,
],
"background": None,
"boostzoom": 0,
"name": "flat",
"backgroundnight": None,
"mapzoomin": 1,
},
{
"nightandday": False,
"shader": "stdtexture",
"compassview": "SE",
"prefix": "t",
"tilescale": 0,
"icon": None,
"scale": 16,
"azimuth": 225.0,
"type": "HDMapType",
"title": "Surface",
"backgroundday": None,
"protected": False,
"mapzoomout": 7,
"perspective": "iso_SE_30_hires",
"worldtomap": [
11.31370849898476,
0.0,
-11.313708498984761,
-5.6568542494923815,
13.856406460551018,
-5.656854249492381,
5.551115123125782e-17,
0.9999999999999997,
5.551115123125782e-17,
],
"inclination": 30.0,
"image-format": "jpg",
"lighting": "shadows",
"bigmap": True,
"maptoworld": [
0.044194173824159216,
-0.08838834764831843,
1.2247448713915894,
0.0,
0.0,
1.0000000000000004,
-0.04419417382415922,
-0.08838834764831842,
1.2247448713915892,
],
"background": None,
"boostzoom": 0,
"name": "surface",
"backgroundnight": None,
"mapzoomin": 1,
},
{
"nightandday": False,
"shader": "cave",
"compassview": "SE",
"prefix": "ct",
"tilescale": 0,
"icon": None,
"scale": 4,
"azimuth": 225.0,
"type": "HDMapType",
"title": "Cave",
"backgroundday": None,
"protected": False,
"mapzoomout": 5,
"perspective": "iso_SE_60_lowres",
"worldtomap": [
2.82842712474619,
0.0,
-2.8284271247461903,
-2.4494897427831783,
1.9999999999999998,
-2.449489742783178,
-4.8074067159589095e-17,
0.9999999999999999,
-4.8074067159589095e-17,
],
"inclination": 60.0,
"image-format": "jpg",
"lighting": "default",
"bigmap": True,
"maptoworld": [
0.17677669529663687,
-0.2041241452319315,
0.408248290463863,
0.0,
-1.3877787807814457e-17,
1.0000000000000002,
-0.1767766952966369,
-0.20412414523193148,
0.40824829046386296,
],
"background": None,
"boostzoom": 0,
"name": "cave",
"backgroundnight": None,
"mapzoomin": 3,
},
],
"extrazoomout": 2,
"center": {"x": 8.0, "y": -64.0, "z": 8.0},
"name": "world",
"title": "world",
"worldheight": 320,
},
{
"sealevel": 63,
"protected": False,
"maps": [
{
"nightandday": False,
"shader": "stdtexture",
"compassview": "S",
"prefix": "flat",
"tilescale": 0,
"icon": None,
"scale": 4,
"azimuth": 270.0,
"type": "HDMapType",
"title": "Flat",
"backgroundday": None,
"protected": False,
"mapzoomout": 5,
"perspective": "iso_S_90_lowres",
"worldtomap": [
4.0,
0.0,
-2.4492935982947064e-16,
-2.4492935982947064e-16,
0.0,
-4.0,
0.0,
1.0,
0.0,
],
"inclination": 90.0,
"image-format": "jpg",
"lighting": "nethershadows",
"bigmap": True,
"maptoworld": [
0.25,
-1.5308084989341915e-17,
0.0,
0.0,
0.0,
1.0,
-1.5308084989341915e-17,
-0.25,
0.0,
],
"background": "#300806",
"boostzoom": 0,
"name": "flat",
"backgroundnight": None,
"mapzoomin": 1,
},
{
"nightandday": False,
"shader": "stdtexture",
"compassview": "SE",
"prefix": "nt",
"tilescale": 0,
"icon": None,
"scale": 16,
"azimuth": 225.0,
"type": "HDMapType",
"title": "Surface",
"backgroundday": None,
"protected": False,
"mapzoomout": 7,
"perspective": "iso_SE_30_hires",
"worldtomap": [
11.31370849898476,
0.0,
-11.313708498984761,
-5.6568542494923815,
13.856406460551018,
-5.656854249492381,
5.551115123125782e-17,
0.9999999999999997,
5.551115123125782e-17,
],
"inclination": 30.0,
"image-format": "jpg",
"lighting": "nethershadows",
"bigmap": True,
"maptoworld": [
0.044194173824159216,
-0.08838834764831843,
1.2247448713915894,
0.0,
0.0,
1.0000000000000004,
-0.04419417382415922,
-0.08838834764831842,
1.2247448713915892,
],
"background": "#300806",
"boostzoom": 0,
"name": "nether",
"backgroundnight": None,
"mapzoomin": 1,
},
],
"extrazoomout": 2,
"center": {"x": 0.0, "y": 66.0, "z": 0.0},
"name": "world_nether",
"title": "world_nether",
"worldheight": 256,
},
{
"sealevel": 63,
"protected": False,
"maps": [
{
"nightandday": False,
"shader": "stdtexture",
"compassview": "S",
"prefix": "flat",
"tilescale": 0,
"icon": None,
"scale": 4,
"azimuth": 270.0,
"type": "HDMapType",
"title": "Flat",
"backgroundday": None,
"protected": False,
"mapzoomout": 5,
"perspective": "iso_S_90_lowres",
"worldtomap": [
4.0,
0.0,
-2.4492935982947064e-16,
-2.4492935982947064e-16,
0.0,
-4.0,
0.0,
1.0,
0.0,
],
"inclination": 90.0,
"image-format": "jpg",
"lighting": "brightnight",
"bigmap": True,
"maptoworld": [
0.25,
-1.5308084989341915e-17,
0.0,
0.0,
0.0,
1.0,
-1.5308084989341915e-17,
-0.25,
0.0,
],
"background": None,
"boostzoom": 0,
"name": "flat",
"backgroundnight": None,
"mapzoomin": 1,
},
{
"nightandday": False,
"shader": "stdtexture",
"compassview": "SE",
"prefix": "st",
"tilescale": 0,
"icon": None,
"scale": 16,
"azimuth": 225.0,
"type": "HDMapType",
"title": "Surface",
"backgroundday": None,
"protected": False,
"mapzoomout": 7,
"perspective": "iso_SE_30_hires",
"worldtomap": [
11.31370849898476,
0.0,
-11.313708498984761,
-5.6568542494923815,
13.856406460551018,
-5.656854249492381,
5.551115123125782e-17,
0.9999999999999997,
5.551115123125782e-17,
],
"inclination": 30.0,
"image-format": "jpg",
"lighting": "brightnight",
"bigmap": True,
"maptoworld": [
0.044194173824159216,
-0.08838834764831843,
1.2247448713915894,
0.0,
0.0,
1.0000000000000004,
-0.04419417382415922,
-0.08838834764831842,
1.2247448713915892,
],
"background": None,
"boostzoom": 0,
"name": "the_end",
"backgroundnight": None,
"mapzoomin": 1,
},
],
"extrazoomout": 2,
"center": {"x": 0.0, "y": 64.0, "z": 0.0},
"name": "world_the_end",
"title": "world_the_end",
"worldheight": 256,
},
],
"confighash": -845210049,
"spammessage": "You may only chat once every %interval% seconds.",
"defaultmap": "flat",
"msg-chatrequireslogin": "Chat Requires Login",
"msg-hiddennamejoin": "Player joined",
"title": "A Minecraft Server",
"grayplayerswhenhidden": True,
"quitmessage": "%playername% quit",
"defaultzoom": 0,
"allowwebchat": True,
"allowchat": True,
"sidebaropened": "False",
"webchat-interval": 5.0,
"msg-chatnotallowed": "You are not permitted to send chat messages",
"loggedin": False,
"coreversion": "3.7-SNAPSHOT-949",
"joinmessage": "%playername% joined",
"webchat-requires-login": False,
"showlayercontrol": "True",
"login-enabled": False,
"maxcount": 20,
"dynmapversion": "3.7-SNAPSHOT-948",
"msg-maptypes": "Map Types",
"cyrillic": False,
"msg-hiddennamequit": "Player quit",
"msg-players": "Players",
"webprefix": "[WEB] ",
"showplayerfacesinmenu": True,
"defaultworld": "world",
}