diff --git a/app/classes/shared/tasks.py b/app/classes/shared/tasks.py index 5848e005..45c1d088 100644 --- a/app/classes/shared/tasks.py +++ b/app/classes/shared/tasks.py @@ -450,7 +450,6 @@ class TasksManager: # created task a child of itself. if str(job_data.get("parent")) == str(sch_id): job_data["parent"] = None - HelpersManagement.update_scheduled_task(sch_id, job_data) if not ( diff --git a/app/classes/web/panel_handler.py b/app/classes/web/panel_handler.py index fe7b8946..9adec950 100644 --- a/app/classes/web/panel_handler.py +++ b/app/classes/web/panel_handler.py @@ -1652,336 +1652,6 @@ class PanelHandler(BaseHandler): self.redirect("/panel/config_json") - if page == "new_schedule": - server_id = self.check_server_id() - if not server_id: - return - - if ( - not permissions["Schedule"] - in self.controller.server_perms.get_user_id_permissions_list( - exec_user["user_id"], server_id - ) - and not superuser - ): - self.redirect( - "/panel/error?error=Unauthorized access: User not authorized" - ) - return - - difficulty = bleach.clean(self.get_argument("difficulty", None)) - server_obj = self.controller.servers.get_server_obj(server_id) - enabled = bleach.clean(self.get_argument("enabled", "0")) - name = bleach.clean(self.get_argument("name", "")) - if difficulty == "basic": - action = bleach.clean(self.get_argument("action", None)) - interval = bleach.clean(self.get_argument("interval", None)) - interval_type = bleach.clean(self.get_argument("interval_type", None)) - # only check for time if it's number of days - if interval_type == "days": - sch_time = bleach.clean(self.get_argument("time", None)) - if int(interval) > 30: - self.redirect( - "/panel/error?error=Invalid argument." - " Days must be 30 or fewer." - ) - return - if action == "command": - command = self.get_argument("command", None) - elif action == "start": - command = "start_server" - elif action == "stop": - command = "stop_server" - elif action == "restart": - command = "restart_server" - elif action == "backup": - command = "backup_server" - - elif difficulty == "reaction": - interval_type = "reaction" - action = bleach.clean(self.get_argument("action", None)) - delay = bleach.clean(self.get_argument("delay", None)) - parent = bleach.clean(self.get_argument("parent", None)) - if action == "command": - command = self.get_argument("command", None) - elif action == "start": - command = "start_server" - elif action == "stop": - command = "stop_server" - elif action == "restart": - command = "restart_server" - elif action == "backup": - command = "backup_server" - - else: - interval_type = "" - cron_string = bleach.clean(self.get_argument("cron", "")) - if not croniter.is_valid(cron_string): - self.redirect( - "/panel/error?error=INVALID FORMAT: Invalid Cron Format." - ) - return - action = bleach.clean(self.get_argument("action", None)) - if action == "command": - command = self.get_argument("command", None) - elif action == "start": - command = "start_server" - elif action == "stop": - command = "stop_server" - elif action == "restart": - command = "restart_server" - elif action == "backup": - command = "backup_server" - if bleach.clean(self.get_argument("enabled", "0")) == "1": - enabled = True - else: - enabled = False - if bleach.clean(self.get_argument("one_time", "0")) == "1": - one_time = True - else: - one_time = False - - if interval_type == "days": - job_data = { - "name": name, - "server_id": server_id, - "action": action, - "interval_type": interval_type, - "interval": interval, - "command": command, - "start_time": sch_time, - "enabled": enabled, - "one_time": one_time, - "cron_string": "", - "parent": None, - "delay": 0, - } - elif difficulty == "reaction": - job_data = { - "name": name, - "server_id": server_id, - "action": action, - "interval_type": interval_type, - "interval": "", - # We'll base every interval off of a midnight start time. - "start_time": "", - "command": command, - "cron_string": "", - "enabled": enabled, - "one_time": one_time, - "parent": parent, - "delay": delay, - } - elif difficulty == "advanced": - job_data = { - "name": name, - "server_id": server_id, - "action": action, - "interval_type": "", - "interval": "", - # We'll base every interval off of a midnight start time. - "start_time": "", - "command": command, - "cron_string": cron_string, - "enabled": enabled, - "one_time": one_time, - "parent": None, - "delay": 0, - } - else: - job_data = { - "name": name, - "server_id": server_id, - "action": action, - "interval_type": interval_type, - "interval": interval, - "command": command, - "enabled": enabled, - # We'll base every interval off of a midnight start time. - "start_time": "00:00", - "one_time": one_time, - "cron_string": "", - "parent": None, - "delay": 0, - } - - self.tasks_manager.schedule_job(job_data) - - self.controller.management.add_to_audit_log( - exec_user["user_id"], - f"Edited server {server_id}: added scheduled job", - server_id, - self.get_remote_ip(), - ) - self.tasks_manager.reload_schedule_from_db() - self.redirect(f"/panel/server_detail?id={server_id}&subpage=schedules") - - if page == "edit_schedule": - server_id = self.check_server_id() - if not server_id: - return - - if ( - not permissions["Schedule"] - in self.controller.server_perms.get_user_id_permissions_list( - exec_user["user_id"], server_id - ) - and not superuser - ): - self.redirect( - "/panel/error?error=Unauthorized access: User not authorized" - ) - return - - sch_id = self.get_argument("sch_id", None) - if sch_id is None: - self.redirect("/panel/error?error=Invalid Schedule ID") - - difficulty = bleach.clean(self.get_argument("difficulty", None)) - server_obj = self.controller.servers.get_server_obj(server_id) - enabled = bleach.clean(self.get_argument("enabled", "0")) - name = bleach.clean(self.get_argument("name", "")) - if difficulty == "basic": - action = bleach.clean(self.get_argument("action", None)) - interval = bleach.clean(self.get_argument("interval", None)) - interval_type = bleach.clean(self.get_argument("interval_type", None)) - # only check for time if it's number of days - if interval_type == "days": - sch_time = bleach.clean(self.get_argument("time", None)) - if int(interval) > 30: - self.redirect( - "/panel/error?error=Invalid argument." - " Days must be 30 or fewer." - ) - return - if action == "command": - command = self.get_argument("command", None) - elif action == "start": - command = "start_server" - elif action == "stop": - command = "stop_server" - elif action == "restart": - command = "restart_server" - elif action == "backup": - command = "backup_server" - elif difficulty == "reaction": - interval_type = "reaction" - action = bleach.clean(self.get_argument("action", None)) - delay = bleach.clean(self.get_argument("delay", None)) - parent = bleach.clean(self.get_argument("parent", None)) - if action == "command": - command = self.get_argument("command", None) - elif action == "start": - command = "start_server" - elif action == "stop": - command = "stop_server" - elif action == "restart": - command = "restart_server" - elif action == "backup": - command = "backup_server" - parent = bleach.clean(self.get_argument("parent", None)) - else: - interval_type = "" - cron_string = bleach.clean(self.get_argument("cron", "")) - if not croniter.is_valid(cron_string): - self.redirect( - "/panel/error?error=INVALID FORMAT: Invalid Cron Format." - ) - return - action = bleach.clean(self.get_argument("action", None)) - if action == "command": - command = self.get_argument("command", None) - elif action == "start": - command = "start_server" - elif action == "stop": - command = "stop_server" - elif action == "restart": - command = "restart_server" - elif action == "backup": - command = "backup_server" - if bleach.clean(self.get_argument("enabled", "0")) == "1": - enabled = True - else: - enabled = False - if bleach.clean(self.get_argument("one_time", "0")) == "1": - one_time = True - else: - one_time = False - - if interval_type == "days": - job_data = { - "name": name, - "server_id": server_id, - "action": action, - "interval_type": interval_type, - "interval": interval, - "command": command, - "start_time": sch_time, - "enabled": enabled, - "one_time": one_time, - "cron_string": "", - "parent": None, - "delay": 0, - } - elif difficulty == "advanced": - job_data = { - "name": name, - "server_id": server_id, - "action": action, - "interval_type": "", - "interval": "", - # We'll base every interval off of a midnight start time. - "start_time": "", - "command": command, - "cron_string": cron_string, - "delay": "", - "parent": "", - "enabled": enabled, - "one_time": one_time, - } - elif difficulty == "reaction": - job_data = { - "name": name, - "server_id": server_id, - "action": action, - "interval_type": interval_type, - "interval": "", - # We'll base every interval off of a midnight start time. - "start_time": "", - "command": command, - "cron_string": "", - "enabled": enabled, - "one_time": one_time, - "parent": parent, - "delay": delay, - } - else: - job_data = { - "name": name, - "server_id": server_id, - "action": action, - "interval_type": interval_type, - "interval": interval, - "command": command, - "enabled": enabled, - # We'll base every interval off of a midnight start time. - "start_time": "00:00", - "delay": "", - "parent": "", - "one_time": one_time, - "cron_string": "", - } - self.tasks_manager.update_job(sch_id, job_data) - - self.controller.management.add_to_audit_log( - exec_user["user_id"], - f"Edited server {server_id}: updated schedule", - server_id, - self.get_remote_ip(), - ) - self.tasks_manager.reload_schedule_from_db() - self.redirect(f"/panel/server_detail?id={server_id}&subpage=schedules") - elif page == "edit_user": if bleach.clean(self.get_argument("username", None)).lower() == "system": self.redirect( diff --git a/app/classes/web/routes/api/servers/server/tasks/task/index.py b/app/classes/web/routes/api/servers/server/tasks/task/index.py index b046dc17..a9a1f5d9 100644 --- a/app/classes/web/routes/api/servers/server/tasks/task/index.py +++ b/app/classes/web/routes/api/servers/server/tasks/task/index.py @@ -35,6 +35,7 @@ task_patch_schema = { "", ], }, + "name": {"type": "string"}, "start_time": {"type": "string", "pattern": r"\d{1,2}:\d{1,2}"}, "command": {"type": ["string", "null"]}, "one_time": {"type": "boolean", "default": False}, @@ -133,6 +134,7 @@ class ApiServersServerTasksTaskIndexHandler(BaseApiHandler): if str(data.get("parent")) == str(task_id) and data.get("parent") is not None: data["parent"] = None + data["server_id"] = server_id self.tasks_manager.update_job(task_id, data) self.controller.management.add_to_audit_log( diff --git a/app/frontend/templates/panel/server_schedule_edit.html b/app/frontend/templates/panel/server_schedule_edit.html index 298e4cc7..9e535d67 100644 --- a/app/frontend/templates/panel/server_schedule_edit.html +++ b/app/frontend/templates/panel/server_schedule_edit.html @@ -37,15 +37,12 @@
{{schedule.command}}
{{ translate('serverSchedules', 'every', data['lang']) }}
{{schedule.interval}} {{schedule.interval_type}}
{% elif schedule.interval_type == 'reaction' %}