From 432421f36241cfe62174f906f079140c7f2b986b Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Mon, 1 Apr 2024 17:02:27 -0400 Subject: [PATCH 1/3] Fix server clones following uuid migration --- .../web/routes/api/servers/server/action.py | 45 +++++++++---------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/app/classes/web/routes/api/servers/server/action.py b/app/classes/web/routes/api/servers/server/action.py index 01ce45c4..7de2697d 100644 --- a/app/classes/web/routes/api/servers/server/action.py +++ b/app/classes/web/routes/api/servers/server/action.py @@ -67,20 +67,29 @@ class ApiServersServerActionHandler(BaseApiHandler): name_counter += 1 new_server_name = server_data.get("server_name") + f" (Copy {name_counter})" - new_server_id = self.controller.servers.create_server( - new_server_name, - None, - "", - None, - server_data.get("executable"), - None, - server_data.get("stop_command"), - server_data.get("type"), - user_id, - server_data.get("server_port"), + new_server_id = self.helper.create_uuid() + new_server_path = os.path.join(self.helper.servers_dir, new_server_id) + new_backup_path = os.path.join(self.helper.backup_path, new_server_id) + new_server_command = str(server_data.get("execution_command")).replace( + server_id, new_server_id + ) + new_server_log_path = server_data.get("log_path").replace( + server_id, new_server_id ) - new_server_path = os.path.join(self.helper.servers_dir, new_server_id) + self.controller.register_server( + new_server_name, + new_server_id, + new_server_path, + new_backup_path, + new_server_command, + server_data.get("executable"), + new_server_log_path, + server_data.get("stop_command"), + server_data.get("server_port"), + user_id, + server_data.get("type"), + ) self.controller.management.add_to_audit_log( user_id, @@ -92,18 +101,6 @@ class ApiServersServerActionHandler(BaseApiHandler): # copy the old server FileHelpers.copy_dir(server_data.get("path"), new_server_path) - # TODO get old server DB data to individual variables - new_server_command = str(server_data.get("execution_command")) - new_server_log_file = str( - self.helper.get_os_understandable_path(server_data.get("log_path")) - ) - - server: Servers = self.controller.servers.get_server_obj(new_server_id) - server.path = new_server_path - server.log_path = new_server_log_file - server.execution_command = new_server_command - self.controller.servers.update_server(server) - for role in self.controller.server_perms.get_server_roles(server_id): mask = self.controller.server_perms.get_permissions_mask( role.role_id, server_id From 4f469f3df1d08692172283bc5a1099f4e8d30e25 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Sat, 6 Apr 2024 16:24:55 -0400 Subject: [PATCH 2/3] Do not allow clone while server is running --- app/classes/web/routes/api/servers/server/action.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/classes/web/routes/api/servers/server/action.py b/app/classes/web/routes/api/servers/server/action.py index 7de2697d..526899b5 100644 --- a/app/classes/web/routes/api/servers/server/action.py +++ b/app/classes/web/routes/api/servers/server/action.py @@ -33,6 +33,17 @@ class ApiServersServerActionHandler(BaseApiHandler): self.controller.crafty_perms.can_create_server(auth_data[4]["user_id"]) or auth_data[4]["superuser"] ): + srv_object = self.controller.servers.get_server_instance_by_id( + server_id + ) + if srv_object.check_running(): + return self.finish_json( + 409, + { + "status": "error", + "error": "Server Running!", + }, + ) self._clone_server(server_id, auth_data[4]["user_id"]) return self.finish_json(200, {"status": "ok"}) return self.finish_json( From b4a962b5a6b964ade91aed75bcfe1e2b001b205d Mon Sep 17 00:00:00 2001 From: Zedifus Date: Sat, 6 Apr 2024 21:39:30 +0100 Subject: [PATCH 3/3] Update changelog !741 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8450118..74695a9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ TBD ### Bug fixes - Fix migrator issue when jumping versions ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/734)) - Fix backend issue causing error when restoring backups in 4.3.x ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/736)) +- Fix backend issue causing error when cloning servers in 4.3.x ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/741)) ### Tweaks - Clean up remaining http handler references ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/733)) - Remove version disclosure on login page ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/737))