From 60785500b9dc1870c044f8a4d06bcb66f1c9600f Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Thu, 19 Jan 2023 11:47:07 -0500 Subject: [PATCH] Remove commands table --- .../controllers/management_controller.py | 7 --- app/classes/models/management.py | 43 ------------------- app/migrations/20230119_command_drop.py | 35 +++++++++++++++ 3 files changed, 35 insertions(+), 50 deletions(-) create mode 100644 app/migrations/20230119_command_drop.py diff --git a/app/classes/controllers/management_controller.py b/app/classes/controllers/management_controller.py index 5caaa48a..0dab0023 100644 --- a/app/classes/controllers/management_controller.py +++ b/app/classes/controllers/management_controller.py @@ -30,9 +30,6 @@ class ManagementController: # ********************************************************************************** # Commands Methods # ********************************************************************************** - @staticmethod - def get_unactioned_commands(): - return HelpersManagement.get_unactioned_commands() def send_command(self, user_id, server_id, remote_ip, command): server_name = HelperServers.get_server_friendly_name(server_id) @@ -51,10 +48,6 @@ class ManagementController: def queue_command(self, command_data): self.command_queue.put(command_data) - @staticmethod - def mark_command_complete(command_id=None): - return HelpersManagement.mark_command_complete(command_id) - # ********************************************************************************** # Audit_Log Methods # ********************************************************************************** diff --git a/app/classes/models/management.py b/app/classes/models/management.py index 4e85c6d5..ff7387af 100644 --- a/app/classes/models/management.py +++ b/app/classes/models/management.py @@ -68,22 +68,6 @@ class HostStats(BaseModel): table_name = "host_stats" -# ********************************************************************************** -# Commands Class -# ********************************************************************************** -class Commands(BaseModel): - command_id = AutoField() - created = DateTimeField(default=datetime.datetime.now) - server_id = ForeignKeyField(Servers, backref="server", index=True) - user = ForeignKeyField(Users, backref="user", index=True) - source_ip = CharField(default="127.0.0.1") - command = CharField(default="") - executed = BooleanField(default=False) - - class Meta: - table_name = "commands" - - # ********************************************************************************** # Webhooks Class # ********************************************************************************** @@ -150,33 +134,6 @@ class HelpersManagement: query = HostStats.select().order_by(HostStats.id.desc()).get() return model_to_dict(query) - # ********************************************************************************** - # Commands Methods - # ********************************************************************************** - @staticmethod - def add_command(server_id, user_id, remote_ip, command): - Commands.insert( - { - Commands.server_id: server_id, - Commands.user: user_id, - Commands.source_ip: remote_ip, - Commands.command: command, - } - ).execute() - - @staticmethod - def get_unactioned_commands(): - query = Commands.select().where(Commands.executed == 0) - return query - - @staticmethod - def mark_command_complete(command_id=None): - if command_id is not None: - logger.debug(f"Marking Command {command_id} completed") - Commands.update({Commands.executed: True}).where( - Commands.command_id == command_id - ).execute() - # ********************************************************************************** # Audit_Log Methods # ********************************************************************************** diff --git a/app/migrations/20230119_command_drop.py b/app/migrations/20230119_command_drop.py new file mode 100644 index 00000000..e66f5a25 --- /dev/null +++ b/app/migrations/20230119_command_drop.py @@ -0,0 +1,35 @@ +# Generated by database migrator +import datetime +from peewee import * +from app.classes.models.users import Users +from app.classes.models.servers import Servers + + +def migrate(migrator, database, **kwargs): + migrator.drop_table("commands") + """ + Write your migrations here. + """ + + +def rollback(migrator, database, **kwargs): + db = database + + class Commands(Model): + command_id = AutoField() + created = DateTimeField(default=datetime.datetime.now) + server_id = ForeignKeyField(Servers, backref="server", index=True) + user = ForeignKeyField(Users, backref="user", index=True) + source_ip = CharField(default="127.0.0.1") + command = CharField(default="") + executed = BooleanField(default=False) + + class Meta: + table_name = "user_crafty" + database = db + + migrator.create_table(Commands) + + """ + Write your rollback migrations here. + """