From 266e5403745730d964300197cfaca7d40a4ccabe Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 31 Aug 2022 11:59:33 -0400 Subject: [PATCH 01/24] Add bedrock update support --- app/classes/shared/file_helpers.py | 7 ++++++- app/classes/shared/server.py | 32 ++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/app/classes/shared/file_helpers.py b/app/classes/shared/file_helpers.py index 04ec3305..28edbef7 100644 --- a/app/classes/shared/file_helpers.py +++ b/app/classes/shared/file_helpers.py @@ -64,6 +64,11 @@ class FileHelpers: FileHelpers.copy_dir(src_path, dest_path) FileHelpers.del_dirs(src_path) + @staticmethod + def move_dir_exist(src_path, dest_path): + FileHelpers.copy_dir(src_path, dest_path, True) + FileHelpers.del_dirs(src_path) + @staticmethod def move_file(src_path, dest_path): FileHelpers.copy_file(src_path, dest_path) @@ -290,7 +295,7 @@ class FileHelpers: for item in os.listdir(full_root_path): if os.path.isdir(os.path.join(full_root_path, item)): try: - FileHelpers.move_dir( + FileHelpers.move_dir_exist( os.path.join(full_root_path, item), os.path.join(new_dir, item), ) diff --git a/app/classes/shared/server.py b/app/classes/shared/server.py index 0b2c5b96..cee0a8e9 100644 --- a/app/classes/shared/server.py +++ b/app/classes/shared/server.py @@ -9,6 +9,7 @@ import threading import logging.config import subprocess import html +import urllib.request # TZLocal is set as a hidden import on win pipeline from tzlocal import get_localzone @@ -1100,13 +1101,32 @@ class ServerInstance: self.settings["executable"], ) - # copies to backup dir - FileHelpers.copy_file(current_executable, backup_executable) + try: + # copies to backup dir + FileHelpers.copy_file(current_executable, backup_executable) + except FileNotFoundError: + logger.error("Could not create backup of jarfile. File not found.") - # boolean returns true for false for success - downloaded = Helpers.download_file( - self.settings["executable_update_url"], current_executable - ) + if HelperServers.get_server_type_by_id(self.server_id) != "minecraft-bedrock": + # boolean returns true for false for success + downloaded = Helpers.download_file( + self.settings["executable_update_url"], current_executable + ) + else: + print("in download") + # downloads zip from remote url + urllib.request.urlretrieve( + self.settings["executable_update_url"], + os.path.join(self.settings["path"], "bedrock_server.zip"), + ) + unzip_path = os.path.join(self.settings["path"], "bedrock_server.zip") + unzip_path = self.helper.wtol_path(unzip_path) + # unzips archive that was downloaded. + FileHelpers.unzip_file(unzip_path) + # adjusts permissions for execution if os is not windows + if not self.helper.is_os_windows(): + os.chmod(os.path.join(self.settings["path"], "bedrock_server"), 0o0775) + downloaded = True while self.stats_helper.get_server_stats()["updating"]: if downloaded and not self.is_backingup: From 600de2be0c93afdf2c5298c84ec3a664afb2bcc0 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 31 Aug 2022 12:18:52 -0400 Subject: [PATCH 02/24] Fix executable backups Cleanup after ourselves --- app/classes/shared/server.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/classes/shared/server.py b/app/classes/shared/server.py index cee0a8e9..8866b09a 100644 --- a/app/classes/shared/server.py +++ b/app/classes/shared/server.py @@ -1079,22 +1079,23 @@ class ServerInstance: ) # checks if backup directory already exists if os.path.isdir(backup_dir): - backup_executable = os.path.join(backup_dir, "old_server.jar") + backup_executable = os.path.join(backup_dir, self.settings["executable"]) else: logger.info( f"Executable backup directory not found for Server: {self.name}." f" Creating one." ) os.mkdir(backup_dir) - backup_executable = os.path.join(backup_dir, "old_server.jar") + backup_executable = os.path.join(backup_dir, self.settings["executable"]) - if os.path.isfile(backup_executable): - # removes old backup - logger.info(f"Old backup found for server: {self.name}. Removing...") - os.remove(backup_executable) - logger.info(f"Old backup removed for server: {self.name}.") - else: - logger.info(f"No old backups found for server: {self.name}") + if len(os.listdir(backup_dir)) > 0: + # removes old backup + logger.info(f"Old backups found for server: {self.name}. Removing...") + for item in os.listdir(backup_dir): + os.remove(os.path.join(backup_dir, item)) + logger.info(f"Old backups removed for server: {self.name}.") + else: + logger.info(f"No old backups found for server: {self.name}") current_executable = os.path.join( Helpers.get_os_understandable_path(self.settings["path"]), @@ -1113,7 +1114,6 @@ class ServerInstance: self.settings["executable_update_url"], current_executable ) else: - print("in download") # downloads zip from remote url urllib.request.urlretrieve( self.settings["executable_update_url"], @@ -1126,6 +1126,10 @@ class ServerInstance: # adjusts permissions for execution if os is not windows if not self.helper.is_os_windows(): os.chmod(os.path.join(self.settings["path"], "bedrock_server"), 0o0775) + + # we'll delete the zip we downloaded now + + os.remove(os.path.join(self.settings["path"], "bedrock_server.zip")) downloaded = True while self.stats_helper.get_server_stats()["updating"]: From 0f820433f137bcd0aaf248ad824734eabfa517f0 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 31 Aug 2022 12:39:52 -0400 Subject: [PATCH 03/24] Remove log path from config for bedrock --- app/classes/web/panel_handler.py | 13 +++++++------ app/frontend/templates/panel/server_config.html | 3 ++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/classes/web/panel_handler.py b/app/classes/web/panel_handler.py index a8bac6e2..7fa42d77 100644 --- a/app/classes/web/panel_handler.py +++ b/app/classes/web/panel_handler.py @@ -1500,12 +1500,13 @@ class PanelHandler(BaseHandler): if Helpers.is_os_windows(): server_path.replace(" ", "^ ") server_path = Helpers.wtol_path(server_path) - log_path = self.get_argument("log_path", None) - if Helpers.is_os_windows(): - log_path.replace(" ", "^ ") - log_path = Helpers.wtol_path(log_path) - if not self.helper.validate_traversal(server_obj.path, log_path): - log_path = "" + log_path = self.get_argument("log_path", "") + if log_path: + if Helpers.is_os_windows(): + log_path.replace(" ", "^ ") + log_path = Helpers.wtol_path(log_path) + if not self.helper.validate_traversal(server_obj.path, log_path): + log_path = "" executable = self.get_argument("executable", None) execution_command = self.get_argument("execution_command", None) server_ip = self.get_argument("server_ip", None) diff --git a/app/frontend/templates/panel/server_config.html b/app/frontend/templates/panel/server_config.html index e1c38e1e..d19b482d 100644 --- a/app/frontend/templates/panel/server_config.html +++ b/app/frontend/templates/panel/server_config.html @@ -67,7 +67,7 @@ placeholder="{{ translate('serverConfig', 'serverPath', data['lang']) }}" required> - + {% if data['server_stats']['server_type'] != "minecraft-bedrock" %}
+ {% end %}
{% if data['super_user'] %} + {% if data['server_stats']['server_type'] != "minecraft-bedrock" %}
+ {% end %}