From 61ac97c02e9aa523a2d9ffb6a31572feec0bc536 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 2 Mar 2022 12:55:49 -0500 Subject: [PATCH] Add unexecuted clear. Add option to compress backups --- app/classes/models/management.py | 6 +++++ app/classes/shared/helpers.py | 2 +- app/classes/shared/main_controller.py | 3 +++ app/classes/web/ajax_handler.py | 5 ++++ .../templates/panel/panel_config.html | 26 +++++++++++++++++++ app/translations/en_EN.json | 4 ++- main.py | 1 + 7 files changed, 45 insertions(+), 2 deletions(-) diff --git a/app/classes/models/management.py b/app/classes/models/management.py index 8cd6e527..49a67fc0 100644 --- a/app/classes/models/management.py +++ b/app/classes/models/management.py @@ -388,6 +388,12 @@ class helpers_management: self.set_backup_config(server_id=server_id, excluded_dirs=excluded_dirs) else: logger.debug(f"Not removing {dir_to_del} from excluded directories - not in the excluded directory list for server ID {server_id}") + + @staticmethod + def clear_unexecuted_commands(): + Commands.update({ + Commands.executed: True + }).where(Commands.executed == False).execute() management_helper = helpers_management() diff --git a/app/classes/shared/helpers.py b/app/classes/shared/helpers.py index c9777346..738ac1a0 100644 --- a/app/classes/shared/helpers.py +++ b/app/classes/shared/helpers.py @@ -481,8 +481,8 @@ class Helpers: data = json.loads(file_data) pid = data.get('pid') started = data.get('started') - console.critical(f"Another Crafty Controller agent seems to be running...\npid: {pid} \nstarted on: {started}") if psutil.pid_exists(pid): + console.critical(f"Another Crafty Controller agent seems to be running...\npid: {pid} \nstarted on: {started}") logger.critical("Found running crafty process. Exiting.") sys.exit(1) else: diff --git a/app/classes/shared/main_controller.py b/app/classes/shared/main_controller.py index 42e77600..b2f82941 100644 --- a/app/classes/shared/main_controller.py +++ b/app/classes/shared/main_controller.py @@ -594,3 +594,6 @@ class Controller: self.servers_list.pop(counter) counter += 1 + @staticmethod + def clear_unexecuted_commands(): + helpers_management.clear_unexecuted_commands() \ No newline at end of file diff --git a/app/classes/web/ajax_handler.py b/app/classes/web/ajax_handler.py index c06e6a78..70678b8c 100644 --- a/app/classes/web/ajax_handler.py +++ b/app/classes/web/ajax_handler.py @@ -306,6 +306,11 @@ class AjaxHandler(BaseHandler): self.controller.users.update_server_order(exec_user['user_id'], bleach.clean(self.get_argument('order'))) return + elif page == "clear_comms": + if exec_user['superuser']: + self.controller.clear_unexecuted_commands() + return + elif page == "kill": if not permissions['Commands'] in user_perms: if not superuser: diff --git a/app/frontend/templates/panel/panel_config.html b/app/frontend/templates/panel/panel_config.html index 957a5e3d..1fadb840 100644 --- a/app/frontend/templates/panel/panel_config.html +++ b/app/frontend/templates/panel/panel_config.html @@ -141,6 +141,21 @@ + {% if data['superuser'] %} +
+
+
+
+

{{ translate('panelConfig', 'adminControls', data['lang']) }}

+
+
+ + +
+
+
+
+ {% end %} @@ -206,6 +221,17 @@ $( document ).ready(function() { message: api_key, }); }); + + $('.clear-comm').click(function () { + var token = getCookie("_xsrf") + $.ajax({ + type: "POST", + headers: {'X-XSRFToken': token}, + url: '/ajax/clear_comm', + success: function (data) { + }, + }); +}) {% end %} \ No newline at end of file diff --git a/app/translations/en_EN.json b/app/translations/en_EN.json index f585b127..7d4f51ad 100644 --- a/app/translations/en_EN.json +++ b/app/translations/en_EN.json @@ -357,7 +357,9 @@ "cancel": "Cancel", "delete": "Delete", "superConfirmTitle": "Enable superuser? Are you sure?", - "superConfirm": "Proceed only if you want this user to have access to EVERYTHING (all user accounts, servers, panel settings, etc.). They can even revoke your superuser rights." + "superConfirm": "Proceed only if you want this user to have access to EVERYTHING (all user accounts, servers, panel settings, etc.). They can even revoke your superuser rights.", + "adminControls": "Admin Controls", + "clearComms": "Clear Un-executed Commands" }, "userConfig": { "pageTitle": "Edit User", diff --git a/main.py b/main.py index e86c5153..b1874422 100644 --- a/main.py +++ b/main.py @@ -150,6 +150,7 @@ if __name__ == '__main__': project_root = os.path.dirname(__file__) controller.set_project_root(project_root) + controller.clear_unexecuted_commands() def sigterm_handler(): print() # for newline