From 9520858c22fbc63b7333a90e57b32376d7790798 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Mon, 7 Mar 2022 21:36:23 -0500 Subject: [PATCH 1/4] Fix backup restore --- app/classes/shared/main_controller.py | 8 ++++-- app/classes/web/ajax_handler.py | 41 ++++++++++++++++++--------- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/app/classes/shared/main_controller.py b/app/classes/shared/main_controller.py index 871c0d53..25d21a9e 100644 --- a/app/classes/shared/main_controller.py +++ b/app/classes/shared/main_controller.py @@ -1,5 +1,6 @@ import os import pathlib +from pathlib import Path import shutil import time import logging @@ -513,10 +514,13 @@ class Controller: server_data = self.servers.get_server_data_by_id(old_server_id) old_bu_path = server_data['backup_path'] Server_Perms_Controller.backup_role_swap(old_server_id, new_server_id) - backup_path = helper.validate_traversal(helper.backup_path, old_bu_path) + if not helper.is_os_windows(): + backup_path = helper.validate_traversal(helper.backup_path, old_bu_path) if helper.is_os_windows(): - backup_path = helper.wtol_path(backup_path) + backup_path = helper.validate_traversal(helper.wtol_path(helper.backup_path), helper.wtol_path(old_bu_path)) + backup_path = helper.wtol_path(str(backup_path)) backup_path.replace(' ', '^ ') + backup_path = Path(backup_path) backup_path_components = list(backup_path.parts) backup_path_components[-1] = new_uuid new_bu_path = pathlib.PurePath(os.path.join(*backup_path_components)) diff --git a/app/classes/web/ajax_handler.py b/app/classes/web/ajax_handler.py index eea02283..c103bab7 100644 --- a/app/classes/web/ajax_handler.py +++ b/app/classes/web/ajax_handler.py @@ -337,19 +337,34 @@ class AjaxHandler(BaseHandler): zip_name = bleach.clean(self.get_argument('zip_file', None)) svr_obj = self.controller.servers.get_server_obj(server_id) server_data = self.controller.servers.get_server_data_by_id(server_id) - backup_path = svr_obj.backup_path - if helper.validate_traversal(backup_path, zip_name): - tempDir = helper.unzip_backup_archive(backup_path, zip_name) - new_server = self.controller.import_zip_server(svr_obj.server_name, - tempDir, - server_data['executable'], - '1', '2', - server_data['server_port']) - new_server_id = new_server - new_server = self.controller.get_server_data(new_server) - self.controller.rename_backup_dir(server_id, new_server_id, new_server['server_uuid']) - self.controller.remove_server(server_id, True) - self.redirect('/panel/dashboard') + if server_data['type'] == 'minecraft-java': + backup_path = svr_obj.backup_path + if helper.validate_traversal(backup_path, zip_name): + tempDir = helper.unzip_backup_archive(backup_path, zip_name) + new_server = self.controller.import_zip_server(svr_obj.server_name, + tempDir, + server_data['executable'], + '1', '2', + server_data['server_port']) + new_server_id = new_server + new_server = self.controller.get_server_data(new_server) + self.controller.rename_backup_dir(server_id, new_server_id, new_server['server_uuid']) + self.controller.remove_server(server_id, True) + self.redirect('/panel/dashboard') + + else: + backup_path = svr_obj.backup_path + if helper.validate_traversal(backup_path, zip_name): + tempDir = helper.unzip_backup_archive(backup_path, zip_name) + new_server = self.controller.import_bedrock_zip_server(svr_obj.server_name, + tempDir, + server_data['executable'], + server_data['server_port']) + new_server_id = new_server + new_server = self.controller.get_server_data(new_server) + self.controller.rename_backup_dir(server_id, new_server_id, new_server['server_uuid']) + self.controller.remove_server(server_id, True) + self.redirect('/panel/dashboard') elif page == "unzip_server": path = self.get_argument('path', None) From 244beed1e4e35612d7d307378d446a713d489879 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Mon, 7 Mar 2022 21:46:42 -0500 Subject: [PATCH 2/4] Fix restore message not showing up immediately --- app/frontend/templates/panel/server_backup.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/frontend/templates/panel/server_backup.html b/app/frontend/templates/panel/server_backup.html index e2498a05..b641cb3b 100644 --- a/app/frontend/templates/panel/server_backup.html +++ b/app/frontend/templates/panel/server_backup.html @@ -253,6 +253,10 @@ const server_id = new URLSearchParams(document.location.search).get('id') function restore_backup(filename, id){ var token = getCookie("_xsrf") + var dialog = bootbox.dialog({ + message: ' {{ translate('serverBackups', 'restoring', data['lang']) }}', + closeButton: false + }); console.log('Sending Command to restore backup: ' + filename) $.ajax({ @@ -264,10 +268,6 @@ const server_id = new URLSearchParams(document.location.search).get('id') id: id }, success: function(data) { - var dialog = bootbox.dialog({ - message: ' {{ translate('serverBackups', 'restoring', data['lang']) }}', - closeButton: false - }); setTimeout(function(){ location.href=('/panel/dashboard'); }, 15000); From abdefc3e434ab1c3cab1208d18c1e3950db73719 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Mon, 7 Mar 2022 21:48:06 -0500 Subject: [PATCH 3/4] Ensure stats schedule is removed on server start --- app/classes/shared/server.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/classes/shared/server.py b/app/classes/shared/server.py index 6a7d4e16..bfee265d 100644 --- a/app/classes/shared/server.py +++ b/app/classes/shared/server.py @@ -178,7 +178,11 @@ class Server: #Register an shedule for polling server stats when running logger.info(f"Polling server statistics {self.name} every {5} seconds") console.info(f"Polling server statistics {self.name} every {5} seconds") - self.server_scheduler.add_job(self.realtime_stats, 'interval', seconds=5, id="stats_"+str(self.server_id)) + try: + self.server_scheduler.add_job(self.realtime_stats, 'interval', seconds=5, id="stats_"+str(self.server_id)) + except: + self.server_scheduler.remove_job('stats_'+str(self.server_id)) + self.server_scheduler.add_job(self.realtime_stats, 'interval', seconds=5, id="stats_"+str(self.server_id)) def setup_server_run_command(self): @@ -514,6 +518,7 @@ class Server: proc.kill() # kill the main process we are after logger.info('Sending SIGKILL to parent') + self.server_scheduler.remove_job("stats_"+str(self.server_id)) self.process.kill() def get_start_time(self): From 73027370057a0718756c02beebc1d83f2db843ba Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Mon, 7 Mar 2022 21:48:37 -0500 Subject: [PATCH 4/4] Fix 'server_id' not defined bug in download file --- app/frontend/templates/panel/server_files.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/frontend/templates/panel/server_files.html b/app/frontend/templates/panel/server_files.html index bff0fa29..225f5ba6 100644 --- a/app/frontend/templates/panel/server_files.html +++ b/app/frontend/templates/panel/server_files.html @@ -849,7 +849,7 @@ function downloadFileE(event) { path = event.target.parentElement.getAttribute('data-path'); name = event.target.parentElement.getAttribute('data-name'); - window.location.href = `/panel/download_file?id=${server_id}&path=${path}&name=${name}`; + window.location.href = `/panel/download_file?id=${serverId}&path=${path}&name=${name}`; } function renameItemE(event) {