diff --git a/pterodactyl/config.py b/pterodactyl/config.py index a116375..fec0336 100644 --- a/pterodactyl/config.py +++ b/pterodactyl/config.py @@ -22,4 +22,5 @@ def register_config(config_obj: Config) -> None: shutdown_msg='Server stopped!', join_msg='Welcome to the server! 👋', leave_msg='Goodbye! 👋', + mask_ip=True, ) diff --git a/pterodactyl/pterodactyl.py b/pterodactyl/pterodactyl.py index b099c39..0c6ad27 100644 --- a/pterodactyl/pterodactyl.py +++ b/pterodactyl/pterodactyl.py @@ -303,3 +303,12 @@ class Pterodactyl(commands.Cog): return await ctx.send(f"Leave message is currently set to: {message}") await config.leave_msg.set(message) await ctx.send(f"Leave message set to: {message}") + + @pterodactyl_config.command(name = "ip") + async def pterodactyl_config_mask_ip(self, ctx: commands.Context, mask: bool = None) -> None: + """Mask the IP addresses of users in console messages.""" + if mask is None: + mask = await config.mask_ip() + return await ctx.send(f"IP masking is currently set to {mask}") + await config.mask_ip.set(mask) + await ctx.send(f"IP masking set to {mask}") diff --git a/pterodactyl/websocket.py b/pterodactyl/websocket.py index 5f8e159..95625ae 100644 --- a/pterodactyl/websocket.py +++ b/pterodactyl/websocket.py @@ -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)