mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Added option to remove server files on delete.
Added confirmation for server delete.
This commit is contained in:
parent
e62b24fdb8
commit
8db46d6ab6
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
@ -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))
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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('serverTerm', 'deleteFilesQuestion') %}",
|
||||
closeButton: false,
|
||||
message: "{% raw translate('serverTerm', 'deleteFilesQuestionMessage') %}",
|
||||
buttons: {
|
||||
confirm: {
|
||||
label: "{{ translate('serverTerm', 'yesDeleteFiles') }}",
|
||||
className: 'btn-danger',
|
||||
},
|
||||
cancel: {
|
||||
label: "{{ translate('serverTerm', '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", "sendingRequest") %}',
|
||||
message: '<div align="center"><i class="fas fa-spin fa-spinner"></i> {% raw translate("serverConfig", "bePatientUpdate") %} </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", "sendingRequest") %}',
|
||||
message: '<div align="center"><i class="fas fa-spin fa-spinner"></i> {% raw translate("serverConfig", "bePatientUpdate") %} </div>'
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
function deleteConfirm (){
|
||||
path = "{{data['server_stats']['server_id']['path']}}";
|
||||
name = "{{data['server_stats']['server_id']['server_name']}}";
|
||||
bootbox.confirm({
|
||||
size: "",
|
||||
title: "{% raw translate('serverTerm', 'deleteServerQuestion') %}",
|
||||
closeButton: false,
|
||||
message: "{% raw translate('serverTerm', 'deleteServerQuestionMessage') %}",
|
||||
buttons: {
|
||||
confirm: {
|
||||
label: "{{ translate('serverTerm', 'yesDelete') }}",
|
||||
className: 'btn-danger',
|
||||
},
|
||||
cancel: {
|
||||
label: "{{ translate('serverTerm', 'noDelete') }}",
|
||||
className: 'btn-link',
|
||||
}
|
||||
},
|
||||
callback: function(result) {
|
||||
if (!result){
|
||||
return;
|
||||
return;}
|
||||
else{
|
||||
deleteServer();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
{% end %}
|
@ -126,7 +126,15 @@
|
||||
"start": "Start",
|
||||
"restart": "Restart",
|
||||
"stop": "Stop",
|
||||
"updating": "Updating..."
|
||||
"updating": "Updating...",
|
||||
"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"
|
||||
},
|
||||
"serverPlayerManagement": {
|
||||
"players": "Players",
|
||||
|
Loading…
Reference in New Issue
Block a user