diff --git a/app/classes/shared/controller.py b/app/classes/shared/controller.py index 74174e27..ce021d37 100644 --- a/app/classes/shared/controller.py +++ b/app/classes/shared/controller.py @@ -344,7 +344,7 @@ class Controller: return new_id - def remove_server(self, server_id): + def remove_server(self, server_id, files): counter = 0 for s in self.servers_list: @@ -361,7 +361,8 @@ class Controller: if running: self.stop_server(server_id) - + if files: + shutil.rmtree(db_helper.get_server_data_by_id(server_id)['path']) # remove the server from the DB db_helper.remove_server(server_id) diff --git a/app/classes/shared/models.py b/app/classes/shared/models.py index 7f7461d4..5d9924e0 100644 --- a/app/classes/shared/models.py +++ b/app/classes/shared/models.py @@ -347,6 +347,7 @@ class db_shortcuts: def remove_server(server_id): with database.atomic(): Role_Servers.delete().where(Role_Servers.server_id == server_id).execute() + User_Servers.delete().where(User_Servers.server_id == server_id).execute() Servers.delete().where(Servers.server_id == server_id).execute() @staticmethod diff --git a/app/classes/shared/tasks.py b/app/classes/shared/tasks.py index 15789111..20b0ffa4 100644 --- a/app/classes/shared/tasks.py +++ b/app/classes/shared/tasks.py @@ -5,6 +5,7 @@ import time import logging import threading import asyncio +import shutil from app.classes.shared.helpers import helper from app.classes.shared.console import console @@ -112,6 +113,15 @@ class TasksManager: elif command == "update_executable": svr.jar_update() + elif command == "delete_server": + logger.info( + "Removing server from panel for server: {}".format(c['server_id']['server_name'])) + self.controller.remove_server(c['server_id']['server_id'], False) + + elif command == "delete_server_files": + logger.info( + "Removing server and all associated files for server: {}".format(c['server_id']['server_name'])) + self.controller.remove_server(c['server_id']['server_id'], True) db_helper.mark_command_complete(c.get('command_id', None)) diff --git a/app/classes/web/ajax_handler.py b/app/classes/web/ajax_handler.py index 0796527e..700994b6 100644 --- a/app/classes/web/ajax_handler.py +++ b/app/classes/web/ajax_handler.py @@ -210,7 +210,7 @@ class AjaxHandler(BaseHandler): server_id = self.get_argument('id', None) print(server_id) - console.warning("delete {} for server {}".format(file_path, server_id)) + console.warning("delete {} for server {}".format(dir_path, server_id)) if not self.check_server_id(server_id, 'del_dir'): return False else: server_id = bleach.clean(server_id) diff --git a/app/frontend/templates/panel/server_config.html b/app/frontend/templates/panel/server_config.html index 156b3154..f39b91fc 100644 --- a/app/frontend/templates/panel/server_config.html +++ b/app/frontend/templates/panel/server_config.html @@ -169,7 +169,7 @@ {{ translate('serverConfig', 'stopBeforeDeleting') }} {% else %} - {{ translate('serverConfig', 'deleteServer') }} + {% end %} @@ -226,6 +226,80 @@ let server_id = '{{ data['server_stats']['server_id']['server_id'] }}'; }); } + function deleteServer (){ + path = "{{data['server_stats']['server_id']['path']}}"; + name = "{{data['server_stats']['server_id']['server_name']}}"; + bootbox.confirm({ + size: "", + title: "{% raw translate('serverConfig', 'deleteFilesQuestion') %}", + closeButton: false, + message: "{% raw translate('serverConfig', 'deleteFilesQuestionMessage') %}", + buttons: { + confirm: { + label: "{{ translate('serverConfig', 'yesDeleteFiles') }}", + className: 'btn-danger', + }, + cancel: { + label: "{{ translate('serverConfig', 'noDeleteFiles') }}", + className: 'btn-link', + } + }, + callback: function(result) { + if (!result){ + send_command(server_id, 'delete_server'); + setTimeout(function(){ window.location = '/panel/dashboard'; }, 5000); + bootbox.dialog({ + backdrop: true, + closeButton: false, + title: '{% raw translate("serverConfig", "sendingDelete") %}', + message: '
  {% raw translate("serverConfig", "bePatientDelete") %}
' + }); + + return;} + else{ + send_command(server_id, 'delete_server_files'); + setTimeout(function(){ window.location = '/panel/dashboard'; }, 5000); + bootbox.dialog({ + backdrop: true, + closeButton: false, + title: '{% raw translate("serverConfig", "sendingDelete") %}', + message: '
  {% raw translate("serverConfig", "bePatientDeleteFiles") %}
' + }); + } + + } + }); + } + function deleteConfirm (){ + path = "{{data['server_stats']['server_id']['path']}}"; + name = "{{data['server_stats']['server_id']['server_name']}}"; + bootbox.confirm({ + size: "", + title: "{% raw translate('serverConfig', 'deleteServerQuestion') %}", + closeButton: false, + message: "{% raw translate('serverConfig', 'deleteServerQuestionMessage') %}", + buttons: { + confirm: { + label: "{{ translate('serverConfig', 'yesDelete') }}", + className: 'btn-danger', + }, + cancel: { + label: "{{ translate('serverConfig', 'noDelete') }}", + className: 'btn-link', + } + }, + callback: function(result) { + if (!result){ + return; + return;} + else{ + deleteServer(); + } + + } + }); + } + {% end %} \ No newline at end of file diff --git a/app/translations/en_EN.json b/app/translations/en_EN.json index caeb0d6b..1eb6b99f 100644 --- a/app/translations/en_EN.json +++ b/app/translations/en_EN.json @@ -127,7 +127,7 @@ "restart": "Restart", "stop": "Stop", "updating": "Updating..." - }, + }, "serverPlayerManagement": { "players": "Players", "bannedPlayers": "Banned Players", @@ -205,7 +205,18 @@ "exeUpdateURL": "Server Executable Update URL", "update": "Update Executable", "bePatientUpdate": "Please be patient while we update the server. Download times can vary depending upon your internet speeds.
This screen will refresh in a moment", - "sendingRequest": "Sending your request..." + "sendingRequest": "Sending your request...", + "deleteServerQuestion": "Delete Server?", + "deleteServerQuestionMessage": "Are you sure you want to delete this server? After this there is no going back...", + "yesDelete": "Yes, delete", + "noDelete": "No, go back", + "deleteFilesQuestion": "Delete server files from machine?", + "deleteFilesQuestionMessage": "Would you like Crafty to delete all server files from the host machine?", + "yesDeleteFiles": "Yes, delete files", + "noDeleteFiles": "No, just remove from panel", + "sendingDelete": "Deleting Server", + "bePatientDelete": "Please be patient while we remove your server from the Crafty panel. This screen will close in a few moments.", + "bePatientDeleteFiles" : "Please be patient while we remove your server from the Crafty panel and delete all files. This screen will close in a few moments." }, "serverConfigHelp": { "title": "Server Config Area",