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: '