Compare commits

...

1 commit

Author SHA1 Message Date
e90dc60643
misc(pterodactyl): added some logging calls 2024-08-09 19:46:17 -04:00

View file

@ -34,6 +34,7 @@ async def establish_websocket_connection(coginstance: Pterodactyl) -> None:
while True: # pylint: disable=too-many-nested-blocks
message = json.loads(await websocket.recv())
logger.verbose("Received message: %s", message)
if message['event'] in ('token expiring', 'token expired'):
logger.info("Received token expiring/expired event. Refreshing token.")
websocket_credentials = await retrieve_websocket_credentials(coginstance)
@ -44,15 +45,17 @@ async def establish_websocket_connection(coginstance: Pterodactyl) -> None:
if message['event'] == 'auth success':
logger.info("WebSocket authentication successful")
if message['event'] == 'console output' and await config.console_channel() is not None:
if message['event'] == 'console output':
content = remove_ansi_escape_codes(message['args'][0])
if await config.mask_ip() is True:
content = mask_ip(content)
logger.verbose("Received console output: %s", content)
if await config.console_channel() is not None:
regex_blacklist: dict = await config.regex_blacklist()
matches = [re.search(regex, message['args'][0]) for regex in regex_blacklist.values()]
if await config.current_status() in ('running', '') and not any(matches):
content = remove_ansi_escape_codes(message['args'][0])
if await config.mask_ip() is True:
content = mask_ip(content)
console_channel = coginstance.bot.get_channel(await config.console_channel())
chat_channel = coginstance.bot.get_channel(await config.chat_channel())
if console_channel is not None:
@ -142,11 +145,11 @@ async def retrieve_websocket_credentials(coginstance: Pterodactyl) -> Optional[d
websocket_credentials['data']['token'][:20]
)
return websocket_credentials
#NOTE - The token is truncated to prevent it from being logged in its entirety, for security reasons
# The token is truncated to prevent it from being logged in its entirety, for security reasons
def remove_ansi_escape_codes(text: str) -> str:
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
#NOTE - https://chat.openai.com/share/d92f9acf-d776-4fd6-a53f-b14ac15dd540
# https://chatgpt.com/share/d92f9acf-d776-4fd6-a53f-b14ac15dd540
return ansi_escape.sub('', text)
async def check_if_server_message(text: str) -> Union[bool, str]: