feat(pterodactyl): added masking of IP addresses in the console output
Some checks failed
Actions / Lint Code (Ruff & Pylint) (pull_request) Failing after 21s
Actions / Build Documentation (MkDocs) (pull_request) Successful in 24s

This commit is contained in:
SeaswimmerTheFsh 2024-03-01 22:38:49 -05:00
parent fb177ff8ad
commit 306148ea69
Signed by: cswimr
GPG key ID: B8953EC01E5C4063
3 changed files with 19 additions and 0 deletions

View file

@ -47,6 +47,8 @@ async def establish_websocket_connection(coginstance: Pterodactyl) -> None:
if json.loads(message)['event'] == 'console output' and await config.console_channel() is not None:
if await config.current_status() in ('running', 'offline', ''):
content = remove_ansi_escape_codes(json.loads(message)['args'][0])
if await config.mask_ip() is True:
content = mask_ip(content)
channel = coginstance.bot.get_channel(await config.console_channel())
if channel is not None:
@ -250,3 +252,10 @@ async def generate_achievement_embed(username: str, achievement: str, challenge:
embed.set_author(name=username, icon_url='https://seafsh.cc/u/j3AzqQ.png')
embed.timestamp = discord.utils.utcnow()
return embed
def mask_ip(string: str) -> str:
def mask_ip(match):
ip = match.group(0)
masked_ip = '.'.join('*' * len(octet) for octet in ip.split('.'))
return masked_ip
return re.sub(r'\b(?:\d{1,3}\.){3}\d{1,3}\b', mask_ip, string)