Merge branch 'pretzel-3' into 'pretzel'

Added the ability to remove all server files when deleting server

See merge request crafty-controller/crafty-commander!43
This commit is contained in:
Andrew 2021-08-10 01:51:42 +00:00
commit 03ba259024
6 changed files with 103 additions and 6 deletions

View File

@ -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)

View File

@ -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

View File

@ -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))

View File

@ -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)

View File

@ -169,7 +169,7 @@
<small>{{ translate('serverConfig', 'stopBeforeDeleting') }}</small>
{% else %}
<button onclick="send_command(server_id, 'update_executable');" id="update_executable" style="max-width: 7rem;" class="btn btn-warning m-1 flex-grow-1">{{ translate('serverConfig', 'update') }}</button>
<a href="/panel/remove_server?id={{ data['server_stats']['server_id']['server_id'] }}" class="btn btn-sm btn-danger">{{ translate('serverConfig', 'deleteServer') }}</a>
<button onclick="deleteConfirm()" class="btn btn-sm btn-danger">{{ translate('serverConfig', 'deleteServer') }}</button>
{% end %}
</div>
@ -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: '<div align="center"><i class="fas fa-spin fa-spinner"></i> &nbsp; {% raw translate("serverConfig", "bePatientDelete") %} </div>'
});
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: '<div align="center"><i class="fas fa-spin fa-spinner"></i> &nbsp; {% raw translate("serverConfig", "bePatientDeleteFiles") %} </div>'
});
}
}
});
}
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();
}
}
});
}
</script>
{% end %}

View File

@ -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.<br /> 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",