2021-09-08 22:01:10 +00:00
|
|
|
import logging
|
|
|
|
|
2022-04-14 02:10:25 +00:00
|
|
|
from app.classes.models.management import HelpersManagement
|
|
|
|
from app.classes.models.servers import HelperServers
|
2021-09-08 22:01:10 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
|
2022-04-14 02:10:25 +00:00
|
|
|
class ManagementController:
|
2022-04-11 05:23:55 +00:00
|
|
|
def __init__(self, management_helper):
|
|
|
|
self.management_helper = management_helper
|
2021-09-08 22:01:10 +00:00
|
|
|
|
2022-03-23 06:06:13 +00:00
|
|
|
# **********************************************************************************
|
2021-09-08 22:01:10 +00:00
|
|
|
# Host_Stats Methods
|
2022-03-23 06:06:13 +00:00
|
|
|
# **********************************************************************************
|
2021-09-08 22:01:10 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_latest_hosts_stats():
|
2022-04-14 02:10:25 +00:00
|
|
|
return HelpersManagement.get_latest_hosts_stats()
|
2021-09-08 22:01:10 +00:00
|
|
|
|
2022-06-20 19:26:21 +00:00
|
|
|
@staticmethod
|
|
|
|
def set_crafty_api_key(key):
|
|
|
|
HelpersManagement.set_secret_api_key(key)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_crafty_api_key():
|
|
|
|
return HelpersManagement.get_secret_api_key()
|
|
|
|
|
2022-03-23 06:06:13 +00:00
|
|
|
# **********************************************************************************
|
2021-09-08 22:01:10 +00:00
|
|
|
# Commands Methods
|
2022-03-23 06:06:13 +00:00
|
|
|
# **********************************************************************************
|
2021-09-08 22:01:10 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_unactioned_commands():
|
2022-04-14 02:10:25 +00:00
|
|
|
return HelpersManagement.get_unactioned_commands()
|
2021-09-08 22:01:10 +00:00
|
|
|
|
2022-04-11 05:23:55 +00:00
|
|
|
def send_command(self, user_id, server_id, remote_ip, command):
|
2022-04-14 02:10:25 +00:00
|
|
|
server_name = HelperServers.get_server_friendly_name(server_id)
|
2021-09-08 22:01:10 +00:00
|
|
|
|
|
|
|
# Example: Admin issued command start_server for server Survival
|
2022-04-11 05:23:55 +00:00
|
|
|
self.management_helper.add_to_audit_log(
|
2022-03-23 02:50:12 +00:00
|
|
|
user_id,
|
|
|
|
f"issued command {command} for server {server_name}",
|
|
|
|
server_id,
|
|
|
|
remote_ip,
|
|
|
|
)
|
2022-04-14 02:10:25 +00:00
|
|
|
HelpersManagement.add_command(server_id, user_id, remote_ip, command)
|
2021-09-08 22:01:10 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def mark_command_complete(command_id=None):
|
2022-04-14 02:10:25 +00:00
|
|
|
return HelpersManagement.mark_command_complete(command_id)
|
2022-01-26 01:45:30 +00:00
|
|
|
|
2022-03-23 06:06:13 +00:00
|
|
|
# **********************************************************************************
|
2021-09-08 22:01:10 +00:00
|
|
|
# Audit_Log Methods
|
2022-03-23 06:06:13 +00:00
|
|
|
# **********************************************************************************
|
2021-09-08 22:01:10 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_actity_log():
|
2022-04-14 02:10:25 +00:00
|
|
|
return HelpersManagement.get_actity_log()
|
2021-09-08 22:01:10 +00:00
|
|
|
|
2022-04-11 05:23:55 +00:00
|
|
|
def add_to_audit_log(self, user_id, log_msg, server_id=None, source_ip=None):
|
|
|
|
return self.management_helper.add_to_audit_log(
|
2022-03-23 02:50:12 +00:00
|
|
|
user_id, log_msg, server_id, source_ip
|
|
|
|
)
|
2021-09-08 22:01:10 +00:00
|
|
|
|
2022-04-11 05:23:55 +00:00
|
|
|
def add_to_audit_log_raw(self, user_name, user_id, server_id, log_msg, source_ip):
|
|
|
|
return self.management_helper.add_to_audit_log_raw(
|
2022-03-23 02:50:12 +00:00
|
|
|
user_name, user_id, server_id, log_msg, source_ip
|
|
|
|
)
|
2021-09-08 22:01:10 +00:00
|
|
|
|
2022-03-23 06:06:13 +00:00
|
|
|
# **********************************************************************************
|
2021-09-08 22:01:10 +00:00
|
|
|
# Schedules Methods
|
2022-03-23 06:06:13 +00:00
|
|
|
# **********************************************************************************
|
2022-03-23 02:50:12 +00:00
|
|
|
@staticmethod
|
|
|
|
def create_scheduled_task(
|
|
|
|
server_id,
|
|
|
|
action,
|
|
|
|
interval,
|
|
|
|
interval_type,
|
|
|
|
start_time,
|
|
|
|
command,
|
|
|
|
comment=None,
|
|
|
|
enabled=True,
|
|
|
|
):
|
2022-04-14 02:10:25 +00:00
|
|
|
return HelpersManagement.create_scheduled_task(
|
2022-03-23 02:50:12 +00:00
|
|
|
server_id,
|
|
|
|
action,
|
|
|
|
interval,
|
|
|
|
interval_type,
|
|
|
|
start_time,
|
|
|
|
command,
|
|
|
|
comment,
|
|
|
|
enabled,
|
|
|
|
)
|
2021-09-08 22:01:10 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def delete_scheduled_task(schedule_id):
|
2022-04-14 02:10:25 +00:00
|
|
|
return HelpersManagement.delete_scheduled_task(schedule_id)
|
2021-09-08 22:01:10 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def update_scheduled_task(schedule_id, updates):
|
2022-04-14 02:10:25 +00:00
|
|
|
return HelpersManagement.update_scheduled_task(schedule_id, updates)
|
2021-09-08 22:01:10 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_scheduled_task(schedule_id):
|
2022-04-14 02:10:25 +00:00
|
|
|
return HelpersManagement.get_scheduled_task(schedule_id)
|
2021-09-08 22:01:10 +00:00
|
|
|
|
2022-01-11 22:24:05 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_scheduled_task_model(schedule_id):
|
2022-04-14 02:10:25 +00:00
|
|
|
return HelpersManagement.get_scheduled_task_model(schedule_id)
|
2022-01-11 22:24:05 +00:00
|
|
|
|
2022-02-26 00:53:38 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_child_schedules(sch_id):
|
2022-04-14 02:10:25 +00:00
|
|
|
return HelpersManagement.get_child_schedules(sch_id)
|
2022-02-26 00:53:38 +00:00
|
|
|
|
2021-09-08 22:01:10 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_schedules_by_server(server_id):
|
2022-04-14 02:10:25 +00:00
|
|
|
return HelpersManagement.get_schedules_by_server(server_id)
|
2021-09-08 22:01:10 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_schedules_all():
|
2022-04-14 02:10:25 +00:00
|
|
|
return HelpersManagement.get_schedules_all()
|
2021-09-08 22:01:10 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_schedules_enabled():
|
2022-04-14 02:10:25 +00:00
|
|
|
return HelpersManagement.get_schedules_enabled()
|
2021-09-08 22:01:10 +00:00
|
|
|
|
2022-03-23 06:06:13 +00:00
|
|
|
# **********************************************************************************
|
2021-09-08 22:01:10 +00:00
|
|
|
# Backups Methods
|
2022-03-23 06:06:13 +00:00
|
|
|
# **********************************************************************************
|
2021-09-08 22:01:10 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_backup_config(server_id):
|
2022-04-14 02:10:25 +00:00
|
|
|
return HelpersManagement.get_backup_config(server_id)
|
2021-09-08 22:01:10 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
def set_backup_config(
|
2022-04-11 05:23:55 +00:00
|
|
|
self,
|
2022-03-23 02:50:12 +00:00
|
|
|
server_id: int,
|
|
|
|
backup_path: str = None,
|
|
|
|
max_backups: int = None,
|
|
|
|
excluded_dirs: list = None,
|
|
|
|
compress: bool = False,
|
2022-06-20 21:16:56 +00:00
|
|
|
shutdown: bool = False
|
2022-03-23 02:50:12 +00:00
|
|
|
):
|
2022-04-11 05:23:55 +00:00
|
|
|
return self.management_helper.set_backup_config(
|
2022-06-20 21:16:56 +00:00
|
|
|
server_id, backup_path, max_backups, excluded_dirs, compress, shutdown
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
2022-03-01 01:02:30 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_excluded_backup_dirs(server_id: int):
|
2022-04-14 02:10:25 +00:00
|
|
|
return HelpersManagement.get_excluded_backup_dirs(server_id)
|
2022-03-01 01:02:30 +00:00
|
|
|
|
2022-04-11 05:23:55 +00:00
|
|
|
def add_excluded_backup_dir(self, server_id: int, dir_to_add: str):
|
|
|
|
self.management_helper.add_excluded_backup_dir(server_id, dir_to_add)
|
2022-03-01 01:02:30 +00:00
|
|
|
|
2022-04-11 05:23:55 +00:00
|
|
|
def del_excluded_backup_dir(self, server_id: int, dir_to_del: str):
|
|
|
|
self.management_helper.del_excluded_backup_dir(server_id, dir_to_del)
|