mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Add working schedules.
Add ability to edit schedules. Add new pages for task creation/edit.
This commit is contained in:
parent
5e7d0d64bd
commit
51fcb2adc3
@ -91,6 +91,10 @@ class Management_Controller:
|
|||||||
def get_scheduled_task(schedule_id):
|
def get_scheduled_task(schedule_id):
|
||||||
return management_helper.get_scheduled_task(schedule_id)
|
return management_helper.get_scheduled_task(schedule_id)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_scheduled_task_model(schedule_id):
|
||||||
|
return management_helper.get_scheduled_task_model(schedule_id)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_schedules_by_server(server_id):
|
def get_schedules_by_server(server_id):
|
||||||
return management_helper.get_schedules_by_server(server_id)
|
return management_helper.get_schedules_by_server(server_id)
|
||||||
|
@ -195,15 +195,34 @@ class TasksManager:
|
|||||||
elif job_data['interval_type'] == 'minutes':
|
elif job_data['interval_type'] == 'minutes':
|
||||||
self.scheduler.add_job(management_helper.add_command, 'cron', minute = '*/'+str(job_data['interval']), id=str(sch_id), args=[job_data['server_id'], self.users_controller.get_id_by_name('system'), '127.0.0.1', job_data['command']])
|
self.scheduler.add_job(management_helper.add_command, 'cron', minute = '*/'+str(job_data['interval']), id=str(sch_id), args=[job_data['server_id'], self.users_controller.get_id_by_name('system'), '127.0.0.1', job_data['command']])
|
||||||
elif job_data['interval_type'] == 'days':
|
elif job_data['interval_type'] == 'days':
|
||||||
time = job_data['time'].split(':')
|
time = job_data['start_time'].split(':')
|
||||||
self.scheduler.add_job(management_helper.add_command, 'cron', day = '*/'+str(job_data['interval']), hour = time[0], minute = time[1], id=str(sch_id), args=[job_data['server_id'], self.users_controller.get_id_by_name('system'), '127.0.0.1', job_data['command']], )
|
self.scheduler.add_job(management_helper.add_command, 'cron', day = '*/'+str(job_data['interval']), hour = time[0], minute = time[1], id=str(sch_id), args=[job_data['server_id'], self.users_controller.get_id_by_name('system'), '127.0.0.1', job_data['command']], )
|
||||||
|
|
||||||
def remove_job(self, sch_id):
|
def remove_job(self, sch_id):
|
||||||
management_helper.delete_scheduled_task(sch_id)
|
management_helper.delete_scheduled_task(sch_id)
|
||||||
self.scheduler.remove_job(str(sch_id))
|
self.scheduler.remove_job(str(sch_id))
|
||||||
|
|
||||||
def update_job(self):
|
def update_job(self, sch_id, job_data):
|
||||||
management_helper.update_scheduled_task()
|
management_helper.update_scheduled_task(sch_id, job_data)
|
||||||
|
if job_data['enabled']:
|
||||||
|
self.scheduler.remove_job(str(sch_id))
|
||||||
|
if job_data['cron_string'] != "":
|
||||||
|
cron = job_data['cron_string'].split(' ')
|
||||||
|
self.scheduler.add_job(management_helper.add_command, 'cron', minute = cron[0], hour = cron[1], day = cron[2], month = cron[3], day_of_week = cron[4], args=[job_data['server_id'], self.users_controller.get_id_by_name('system'), '127.0.0.1', job_data['command']])
|
||||||
|
else:
|
||||||
|
if job_data['interval_type'] == 'hours':
|
||||||
|
self.scheduler.add_job(management_helper.add_command, 'cron', minute = 0, hour = '*/'+str(job_data['interval']), id=str(sch_id), args=[job_data['server_id'], self.users_controller.get_id_by_name('system'), '127.0.0.1', job_data['command']])
|
||||||
|
elif job_data['interval_type'] == 'minutes':
|
||||||
|
self.scheduler.add_job(management_helper.add_command, 'cron', minute = '*/'+str(job_data['interval']), id=str(sch_id), args=[job_data['server_id'], self.users_controller.get_id_by_name('system'), '127.0.0.1', job_data['command']])
|
||||||
|
elif job_data['interval_type'] == 'days':
|
||||||
|
time = job_data['start_time'].split(':')
|
||||||
|
self.scheduler.add_job(management_helper.add_command, 'cron', day = '*/'+str(job_data['interval']), hour = time[0], minute = time[1], id=str(sch_id), args=[job_data['server_id'], self.users_controller.get_id_by_name('system'), '127.0.0.1', job_data['command']], )
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
self.scheduler.get_job(str(sch_id))
|
||||||
|
self.scheduler.remove_job(str(sch_id))
|
||||||
|
except:
|
||||||
|
logger.info("APScheduler found no scheduled job on schedule update for schedule with id: {}. Assuming it was already disabled.".format(sch_id))
|
||||||
|
|
||||||
def schedule_watcher(self, event):
|
def schedule_watcher(self, event):
|
||||||
if not event.exception:
|
if not event.exception:
|
||||||
|
@ -8,6 +8,7 @@ import time
|
|||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from tornado import locale
|
||||||
from tornado import iostream
|
from tornado import iostream
|
||||||
from tornado.ioloop import IOLoop
|
from tornado.ioloop import IOLoop
|
||||||
from app.classes.shared.console import console
|
from app.classes.shared.console import console
|
||||||
@ -459,6 +460,98 @@ class PanelHandler(BaseHandler):
|
|||||||
page_data['languages'].append(file.split('.')[0])
|
page_data['languages'].append(file.split('.')[0])
|
||||||
|
|
||||||
template = "panel/panel_edit_user.html"
|
template = "panel/panel_edit_user.html"
|
||||||
|
|
||||||
|
elif page == "add_schedule":
|
||||||
|
server_id = self.get_argument('id', None)
|
||||||
|
page_data['get_players'] = lambda: self.controller.stats.get_server_players(server_id)
|
||||||
|
page_data['active_link'] = 'tasks'
|
||||||
|
page_data['permissions'] = {
|
||||||
|
'Commands': Enum_Permissions_Server.Commands,
|
||||||
|
'Terminal': Enum_Permissions_Server.Terminal,
|
||||||
|
'Logs': Enum_Permissions_Server.Logs,
|
||||||
|
'Schedule': Enum_Permissions_Server.Schedule,
|
||||||
|
'Backup': Enum_Permissions_Server.Backup,
|
||||||
|
'Files': Enum_Permissions_Server.Files,
|
||||||
|
'Config': Enum_Permissions_Server.Config,
|
||||||
|
'Players': Enum_Permissions_Server.Players,
|
||||||
|
}
|
||||||
|
page_data['user_permissions'] = self.controller.server_perms.get_server_permissions_foruser(exec_user_id, server_id)
|
||||||
|
exec_user_server_permissions = self.controller.server_perms.get_user_permissions_list(exec_user_id, server_id)
|
||||||
|
page_data['server_data'] = self.controller.servers.get_server_data_by_id(server_id)
|
||||||
|
page_data['server_stats'] = self.controller.servers.get_server_stats_by_id(server_id)
|
||||||
|
page_data['new_schedule'] = True
|
||||||
|
page_data['schedule'] = {}
|
||||||
|
page_data['schedule']['server_id'] = server_id
|
||||||
|
page_data['schedule']['schedule_id'] = ''
|
||||||
|
page_data['schedule']['action'] = ""
|
||||||
|
page_data['schedule']['enabled'] = True
|
||||||
|
page_data['schedule']['command'] = ''
|
||||||
|
page_data['schedule']['one_time'] = False
|
||||||
|
page_data['schedule']['cron_string'] = ""
|
||||||
|
page_data['schedule']['time'] = ""
|
||||||
|
page_data['schedule']['interval'] = ""
|
||||||
|
#we don't need to check difficulty here. We'll just default to basic for new schedules
|
||||||
|
page_data['schedule']['difficulty'] = "basic"
|
||||||
|
page_data['schedule']['interval_type'] = 'days'
|
||||||
|
|
||||||
|
if not Enum_Permissions_Server.Schedule in exec_user_server_permissions:
|
||||||
|
if not exec_user['superuser']:
|
||||||
|
self.redirect("/panel/error?error=Unauthorized access To Scheduled Tasks")
|
||||||
|
return
|
||||||
|
|
||||||
|
template = "panel/server_schedule_edit.html"
|
||||||
|
|
||||||
|
elif page == "edit_schedule":
|
||||||
|
server_id = self.get_argument('id', None)
|
||||||
|
sch_id = self.get_argument('sch_id', None)
|
||||||
|
schedule = self.controller.management.get_scheduled_task_model(sch_id)
|
||||||
|
page_data['get_players'] = lambda: self.controller.stats.get_server_players(server_id)
|
||||||
|
page_data['active_link'] = 'tasks'
|
||||||
|
page_data['permissions'] = {
|
||||||
|
'Commands': Enum_Permissions_Server.Commands,
|
||||||
|
'Terminal': Enum_Permissions_Server.Terminal,
|
||||||
|
'Logs': Enum_Permissions_Server.Logs,
|
||||||
|
'Schedule': Enum_Permissions_Server.Schedule,
|
||||||
|
'Backup': Enum_Permissions_Server.Backup,
|
||||||
|
'Files': Enum_Permissions_Server.Files,
|
||||||
|
'Config': Enum_Permissions_Server.Config,
|
||||||
|
'Players': Enum_Permissions_Server.Players,
|
||||||
|
}
|
||||||
|
page_data['user_permissions'] = self.controller.server_perms.get_server_permissions_foruser(exec_user_id, server_id)
|
||||||
|
exec_user_server_permissions = self.controller.server_perms.get_user_permissions_list(exec_user_id, server_id)
|
||||||
|
page_data['server_data'] = self.controller.servers.get_server_data_by_id(server_id)
|
||||||
|
page_data['server_stats'] = self.controller.servers.get_server_stats_by_id(server_id)
|
||||||
|
page_data['new_schedule'] = False
|
||||||
|
page_data['schedule'] = {}
|
||||||
|
page_data['schedule']['server_id'] = server_id
|
||||||
|
page_data['schedule']['schedule_id'] = schedule.schedule_id
|
||||||
|
page_data['schedule']['action'] = schedule.action
|
||||||
|
#we check here to see if the command is any of the default ones. We do not want a user changing to a custom command and seeing our command there.
|
||||||
|
if schedule.action != 'start' or schedule.action != 'stop' or schedule.action != 'restart' or schedule.action != 'backup':
|
||||||
|
page_data['schedule']['command'] = schedule.command
|
||||||
|
else:
|
||||||
|
page_data['schedule']['command'] = ''
|
||||||
|
page_data['schedule']['enabled'] = schedule.enabled
|
||||||
|
page_data['schedule']['one_time'] = schedule.one_time
|
||||||
|
page_data['schedule']['cron_string'] = schedule.cron_string
|
||||||
|
page_data['schedule']['time'] = schedule.start_time
|
||||||
|
page_data['schedule']['interval'] = schedule.interval
|
||||||
|
page_data['schedule']['interval_type'] = schedule.interval_type
|
||||||
|
if schedule.cron_string == '':
|
||||||
|
difficulty = 'basic'
|
||||||
|
else:
|
||||||
|
difficulty = 'advanced'
|
||||||
|
page_data['schedule']['difficulty'] = difficulty
|
||||||
|
|
||||||
|
if sch_id == None or server_id == None:
|
||||||
|
self.redirect("/panel/error?error=Invalid server ID or Schedule ID")
|
||||||
|
|
||||||
|
if not Enum_Permissions_Server.Schedule in exec_user_server_permissions:
|
||||||
|
if not exec_user['superuser']:
|
||||||
|
self.redirect("/panel/error?error=Unauthorized access To Scheduled Tasks")
|
||||||
|
return
|
||||||
|
|
||||||
|
template = "panel/server_schedule_edit.html"
|
||||||
|
|
||||||
elif page == "edit_user":
|
elif page == "edit_user":
|
||||||
user_id = self.get_argument('id', None)
|
user_id = self.get_argument('id', None)
|
||||||
@ -815,18 +908,10 @@ class PanelHandler(BaseHandler):
|
|||||||
self.redirect("/panel/error?error=Invalid Server ID")
|
self.redirect("/panel/error?error=Invalid Server ID")
|
||||||
return
|
return
|
||||||
|
|
||||||
if enabled == '0':
|
server_obj = self.controller.servers.get_server_obj(server_id)
|
||||||
#TODO Use Controller method
|
server_obj.backup_path = backup_path
|
||||||
server_obj = self.controller.servers.get_server_obj(server_id)
|
self.controller.servers.update_server(server_obj)
|
||||||
server_obj.backup_path = backup_path
|
self.controller.management.set_backup_config(server_id, max_backups=max_backups)
|
||||||
self.controller.servers.update_server(server_obj)
|
|
||||||
self.controller.management.set_backup_config(server_id, max_backups=max_backups, auto_enabled=False)
|
|
||||||
else:
|
|
||||||
#TODO Use Controller method
|
|
||||||
server_obj = self.controller.servers.get_server_obj(server_id)
|
|
||||||
server_obj.backup_path = backup_path
|
|
||||||
self.controller.servers.update_server(server_obj)
|
|
||||||
self.controller.management.set_backup_config(server_id, max_backups=max_backups)
|
|
||||||
|
|
||||||
self.controller.management.add_to_audit_log(exec_user['user_id'],
|
self.controller.management.add_to_audit_log(exec_user['user_id'],
|
||||||
"Edited server {}: updated backups".format(server_id),
|
"Edited server {}: updated backups".format(server_id),
|
||||||
@ -836,7 +921,7 @@ class PanelHandler(BaseHandler):
|
|||||||
self.redirect("/panel/server_detail?id={}&subpage=backup".format(server_id))
|
self.redirect("/panel/server_detail?id={}&subpage=backup".format(server_id))
|
||||||
|
|
||||||
|
|
||||||
if page == "tasks":
|
if page == "add_schedule":
|
||||||
server_id = bleach.clean(self.get_argument('id', None))
|
server_id = bleach.clean(self.get_argument('id', None))
|
||||||
difficulty = bleach.clean(self.get_argument('difficulty', None))
|
difficulty = bleach.clean(self.get_argument('difficulty', None))
|
||||||
server_obj = self.controller.servers.get_server_obj(server_id)
|
server_obj = self.controller.servers.get_server_obj(server_id)
|
||||||
@ -909,7 +994,7 @@ class PanelHandler(BaseHandler):
|
|||||||
"interval_type": interval_type,
|
"interval_type": interval_type,
|
||||||
"interval": interval,
|
"interval": interval,
|
||||||
"command": command,
|
"command": command,
|
||||||
"time": time,
|
"start_time": time,
|
||||||
"enabled": enabled,
|
"enabled": enabled,
|
||||||
"one_time": one_time,
|
"one_time": one_time,
|
||||||
"cron_string": ''
|
"cron_string": ''
|
||||||
@ -921,7 +1006,7 @@ class PanelHandler(BaseHandler):
|
|||||||
"interval_type": '',
|
"interval_type": '',
|
||||||
"interval": '',
|
"interval": '',
|
||||||
"command": '',
|
"command": '',
|
||||||
"time": current_time,
|
"start_time": current_time,
|
||||||
"command": command,
|
"command": command,
|
||||||
"cron_string": cron_string,
|
"cron_string": cron_string,
|
||||||
"enabled": enabled,
|
"enabled": enabled,
|
||||||
@ -935,7 +1020,7 @@ class PanelHandler(BaseHandler):
|
|||||||
"interval": interval,
|
"interval": interval,
|
||||||
"command": command,
|
"command": command,
|
||||||
"enabled": enabled,
|
"enabled": enabled,
|
||||||
"time": current_time,
|
"start_time": current_time,
|
||||||
"one_time": one_time,
|
"one_time": one_time,
|
||||||
"cron_string": ''
|
"cron_string": ''
|
||||||
}
|
}
|
||||||
@ -943,7 +1028,122 @@ class PanelHandler(BaseHandler):
|
|||||||
self.tasks_manager.schedule_job(job_data)
|
self.tasks_manager.schedule_job(job_data)
|
||||||
|
|
||||||
self.controller.management.add_to_audit_log(exec_user['user_id'],
|
self.controller.management.add_to_audit_log(exec_user['user_id'],
|
||||||
"Edited server {}: updated backups".format(server_id),
|
"Edited server {}: added scheduled job".format(server_id),
|
||||||
|
server_id,
|
||||||
|
self.get_remote_ip())
|
||||||
|
self.tasks_manager.reload_schedule_from_db()
|
||||||
|
self.redirect("/panel/server_detail?id={}&subpage=tasks".format(server_id))
|
||||||
|
|
||||||
|
|
||||||
|
if page == "edit_schedule":
|
||||||
|
server_id = bleach.clean(self.get_argument('id', None))
|
||||||
|
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'))
|
||||||
|
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":
|
||||||
|
time = bleach.clean(self.get_argument('time', None))
|
||||||
|
if action == "command":
|
||||||
|
command = bleach.clean(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', ''))
|
||||||
|
sch_id = self.get_argument('sch_id', None)
|
||||||
|
if len(cron_string.split(' ')) != 5:
|
||||||
|
self.redirect("/panel/error?error=INVALID FORMAT: Invalid Cron Format. Cron must have a space between each character and only have a max of 5 characters * * * * *")
|
||||||
|
action = bleach.clean(self.get_argument('action', None))
|
||||||
|
if action == "command":
|
||||||
|
command = bleach.clean(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', '1'))=='1':
|
||||||
|
enabled = True
|
||||||
|
else:
|
||||||
|
enabled = False
|
||||||
|
if bleach.clean(self.get_argument('one_time', '0')) == '1':
|
||||||
|
one_time = True
|
||||||
|
else:
|
||||||
|
one_time = False
|
||||||
|
|
||||||
|
if not exec_user['superuser'] and not permissions['Backup'] in user_perms:
|
||||||
|
self.redirect("/panel/error?error=Unauthorized access: User not authorized")
|
||||||
|
return
|
||||||
|
elif server_id is None:
|
||||||
|
self.redirect("/panel/error?error=Invalid Server ID")
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
# does this server id exist?
|
||||||
|
if not self.controller.servers.server_id_exists(server_id):
|
||||||
|
self.redirect("/panel/error?error=Invalid Server ID")
|
||||||
|
return
|
||||||
|
minute = datetime.datetime.now().minute
|
||||||
|
hour = datetime.datetime.now().hour
|
||||||
|
if minute < 10:
|
||||||
|
minute = '0' + str(minute)
|
||||||
|
if hour < 10:
|
||||||
|
hour = '0'+str(hour)
|
||||||
|
current_time = str(hour)+':'+str(minute)
|
||||||
|
|
||||||
|
if interval_type == "days":
|
||||||
|
job_data = {
|
||||||
|
"server_id": server_id,
|
||||||
|
"action": action,
|
||||||
|
"interval_type": interval_type,
|
||||||
|
"interval": interval,
|
||||||
|
"command": command,
|
||||||
|
"start_time": time,
|
||||||
|
"enabled": enabled,
|
||||||
|
"one_time": one_time,
|
||||||
|
"cron_string": ''
|
||||||
|
}
|
||||||
|
elif difficulty == "advanced":
|
||||||
|
job_data = {
|
||||||
|
"server_id": server_id,
|
||||||
|
"action": action,
|
||||||
|
"interval_type": '',
|
||||||
|
"interval": '',
|
||||||
|
"command": '',
|
||||||
|
"start_time": current_time,
|
||||||
|
"command": command,
|
||||||
|
"cron_string": cron_string,
|
||||||
|
"enabled": enabled,
|
||||||
|
"one_time": one_time
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
job_data = {
|
||||||
|
"server_id": server_id,
|
||||||
|
"action": action,
|
||||||
|
"interval_type": interval_type,
|
||||||
|
"interval": interval,
|
||||||
|
"command": command,
|
||||||
|
"enabled": enabled,
|
||||||
|
"start_time": current_time,
|
||||||
|
"one_time": one_time,
|
||||||
|
"cron_string": ''
|
||||||
|
}
|
||||||
|
sch_id = self.get_argument('sch_id', None)
|
||||||
|
self.tasks_manager.update_job(sch_id, job_data)
|
||||||
|
|
||||||
|
self.controller.management.add_to_audit_log(exec_user['user_id'],
|
||||||
|
"Edited server {}: updated schedule".format(server_id),
|
||||||
server_id,
|
server_id,
|
||||||
self.get_remote_ip())
|
self.get_remote_ip())
|
||||||
self.tasks_manager.reload_schedule_from_db()
|
self.tasks_manager.reload_schedule_from_db()
|
||||||
@ -1255,8 +1455,8 @@ class PanelHandler(BaseHandler):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
self.set_status(404)
|
self.set_status(404)
|
||||||
page_data = []
|
page_data = {}
|
||||||
page_data['lang'] = tornado.locale.get("en_EN")
|
page_data['lang'] = locale.get("en_EN")
|
||||||
self.render(
|
self.render(
|
||||||
"public/404.html",
|
"public/404.html",
|
||||||
translate=self.translator.translate,
|
translate=self.translator.translate,
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
{% end %}
|
{% end %}
|
||||||
{% if data['permissions']['Schedule'] in data['user_permissions'] %}
|
{% if data['permissions']['Schedule'] in data['user_permissions'] %}
|
||||||
<li class="nav-item term-nav-item">
|
<li class="nav-item term-nav-item">
|
||||||
<a class="nav-link {% if data['active_link'] == 'schedule' %}active{% end %}" href="/panel/server_detail?id={{ data['server_stats']['server_id']['server_id'] }}&subpage=tasks" role="tab" aria-selected="false">
|
<a class="nav-link {% if data['active_link'] == 'tasks' %}active{% end %}" href="/panel/server_detail?id={{ data['server_stats']['server_id']['server_id'] }}&subpage=tasks" role="tab" aria-selected="false">
|
||||||
<i class="fas fa-clock"></i>{{ translate('serverDetails', 'schedule', data['lang']) }}</a>
|
<i class="fas fa-clock"></i>{{ translate('serverDetails', 'schedule', data['lang']) }}</a>
|
||||||
</li>
|
</li>
|
||||||
{% end %}
|
{% end %}
|
||||||
|
@ -36,57 +36,61 @@
|
|||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12 col-sm-12">
|
<div class="col-md-12 col-sm-12">
|
||||||
<form class="forms-sample" method="post" action="/panel/tasks">
|
{% if data['new_schedule'] == True %}
|
||||||
|
<form class="forms-sample" method="post" action="/panel/new_schedule?id={{ data['server_stats']['server_id']['server_id'] }}">
|
||||||
|
{% else %}
|
||||||
|
<form class="forms-sample" method="post" action="/panel/edit_schedule?id={{ data['server_stats']['server_id']['server_id'] }}&sch_id={{ data['schedule']['schedule_id'] }}">
|
||||||
|
{% end %}
|
||||||
{% raw xsrf_form_html() %}
|
{% raw xsrf_form_html() %}
|
||||||
<input type="hidden" name="id" value="{{ data['server_stats']['server_id']['server_id'] }}">
|
<input type="hidden" name="id" value="{{ data['server_stats']['server_id']['server_id'] }}">
|
||||||
<input type="hidden" name="subpage" value="config">
|
<input type="hidden" name="subpage" value="config">
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="difficulty">Basic / Cron Select<small class="text-muted ml-1"></small> </label><br>
|
<label for="difficulty">Basic / Cron Select<small class="text-muted ml-1"></small> </label><br>
|
||||||
<select id="difficulty" name="difficulty" onchange="basicAdvanced(this);" class="form-control form-control-lg select-css">
|
<select id="difficulty" name="difficulty" onchange="basicAdvanced(this);" class="form-control form-control-lg select-css" value="{{ data['schedule']['difficulty'] }}">
|
||||||
<option value="basic">Basic</option>
|
<option id="basic" value="basic">Basic</option>
|
||||||
<option value="advanced">Advanced</option>
|
<option id="advanced" value="advanced">Advanced</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="server_name">Action<small class="text-muted ml-1"></small> </label><br>
|
<label for="server_name">Action<small class="text-muted ml-1"></small> </label><br>
|
||||||
<select id="action" name="action" onchange="yesnoCheck(this);" class="form-control form-control-lg select-css">
|
<select id="action" name="action" onchange="yesnoCheck(this);" class="form-control form-control-lg select-css" value="{{ data['schedule']['action'] }}">
|
||||||
<option value="start">Start Server</option>
|
<option id="start" value="start">Start Server</option>
|
||||||
<option value="restart">Restart Server</option>
|
<option id="restart" value="restart">Restart Server</option>
|
||||||
<option value="shutdown">Shutdown Server</option>
|
<option id="shutdown" value="shutdown">Shutdown Server</option>
|
||||||
<option value="backup">Backup Server</option>
|
<option id="backup" value="backup">Backup Server</option>
|
||||||
<option value="command">Custon Command</option>
|
<option id="command" value="command">Custon Command</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div id="ifBasic">
|
<div id="ifBasic">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="server_path">Interval <small class="text-muted ml-1"> - How often you want this task to execute</small> </label>
|
<label for="server_path">Interval <small class="text-muted ml-1"> - How often you want this task to execute</small> </label>
|
||||||
<input type="number" class="form-control" name="interval" id="interval" value="{{ data['server_stats']['server_id']['path'] }}" placeholder="Interval" required>
|
<input type="number" class="form-control" name="interval" id="interval" value="{{ data['schedule']['interval'] }}" placeholder="Interval" required>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<select id="interval_type" onchange="ifDays(this);" name="interval_type" class="form-control form-control-lg select-css">
|
<select id="interval_type" onchange="ifDays(this);" name="interval_type" class="form-control form-control-lg select-css" value="{{ data['schedule']['interval_type'] }}">
|
||||||
<option value="days">Days</option>
|
<option id = "days" value="days">Days</option>
|
||||||
<option value="hours">Hours</option>
|
<option id = "hours" value="hours">Hours</option>
|
||||||
<option value="minutes">Minutes</option>
|
<option id = "minutes" value="minutes">Minutes</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div id="ifDays" style="display: block;">
|
<div id="ifDays" style="display: block;">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="time">Time <small class="text-muted ml-1"> - What time do you want your task to execute?</small> </label>
|
<label for="time">Time <small class="text-muted ml-1"> - What time do you want your task to execute?</small> </label>
|
||||||
<input type="time" class="form-control" name="time" id="time" value="{{ data['server_stats']['server_id']['log_path'] }}" placeholder="Time" required>
|
<input type="time" class="form-control" name="time" id="time" value="{{ data['schedule']['time'] }}" placeholder="Time" required>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="ifYes" style="display: none;">
|
<div id="ifYes" style="display: none;">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="command">Command <small class="text-muted ml-1"> - What command do you want us to execute? Do not include the '/'</small> </label>
|
<label for="command">Command <small class="text-muted ml-1"> - What command do you want us to execute? Do not include the '/'</small> </label>
|
||||||
<input type="input" class="form-control" name="command" id="command" value="" placeholder="Command" required>
|
<input type="input" class="form-control" name="command" id="command_input" value="{{ data['schedule']['command'] }}" placeholder="Command" required>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="ifAdvanced" style="display: none;">
|
<div id="ifAdvanced" style="display: none;">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="cron">Cron <small class="text-muted ml-1"> - Input your cron string</small> </label>
|
<label for="cron">Cron <small class="text-muted ml-1"> - Input your cron string</small> </label>
|
||||||
<input type="input" class="form-control" name="cron" id="cron" value="" placeholder="* * * * *">
|
<input type="input" class="form-control" name="cron" id="cron" value="{{ data['schedule']['cron_string'] }}" placeholder="* * * * *">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -102,9 +106,8 @@
|
|||||||
</label>
|
</label>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button type="submit" class="btn btn-success mr-2"><i class="fas fa-save"></i> {{ translate('serverConfig', 'save', data['lang']) }}</button>
|
<button type="submit" class="btn btn-success mr-2"><i class="fas fa-save"></i> {{ translate('serverConfig', 'save', data['lang']) }}</button>
|
||||||
<button type="reset" class="btn btn-light"><i class="fas fa-times"></i> {{ translate('serverConfig', 'cancel', data['lang']) }}</button>
|
<button type="reset" onclick="location.href=`/panel/server_detail?id={{ data['server_stats']['server_id']['server_id'] }}&subpage=tasks`" class="btn btn-light"><i class="fas fa-times"></i> {{ translate('serverConfig', 'cancel', data['lang']) }}</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -135,17 +138,17 @@
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function yesnoCheck(that) {
|
function yesnoCheck() {
|
||||||
if (that.value == "command") {
|
if (document.getElementById('command').value == "command") {
|
||||||
document.getElementById("ifYes").style.display = "block";
|
document.getElementById("ifYes").style.display = "block";
|
||||||
document.getElementById("command").required = true;
|
document.getElementById("command").required = true;
|
||||||
} else {
|
} else {
|
||||||
document.getElementById("ifYes").style.display = "none";
|
document.getElementById("ifYes").style.display = "none";
|
||||||
document.getElementById("command").required = false;
|
document.getElementById("command").required = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function basicAdvanced(that) {
|
function basicAdvanced() {
|
||||||
if (that.value == "advanced") {
|
if (document.getElementById('difficulty').value == "advanced") {
|
||||||
document.getElementById("ifAdvanced").style.display = "block";
|
document.getElementById("ifAdvanced").style.display = "block";
|
||||||
document.getElementById("ifBasic").style.display = "none";
|
document.getElementById("ifBasic").style.display = "none";
|
||||||
document.getElementById("interval").required = false;
|
document.getElementById("interval").required = false;
|
||||||
@ -157,8 +160,8 @@
|
|||||||
document.getElementById("time").required = true;
|
document.getElementById("time").required = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function ifDays(that) {
|
function ifDays() {
|
||||||
if (that.value == "days") {
|
if (document.getElementById('interval_type').value == "days") {
|
||||||
document.getElementById("ifDays").style.display = "block";
|
document.getElementById("ifDays").style.display = "block";
|
||||||
document.getElementById("time").required = true;
|
document.getElementById("time").required = true;
|
||||||
} else {
|
} else {
|
||||||
@ -209,7 +212,40 @@ function del_task(sch_id, id){
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function startup(){
|
||||||
|
try{
|
||||||
|
document.getElementById("{{ data['schedule']['interval_type'] }}").setAttribute('selected', true);
|
||||||
|
}catch{
|
||||||
|
console.log("no element named {{ data['schedule']['interval_type'] }}")
|
||||||
|
}
|
||||||
|
try{
|
||||||
|
document.getElementById("{{ data['schedule']['difficulty'] }}").setAttribute('selected', true);
|
||||||
|
}catch{
|
||||||
|
console.log("no element named {{ data['schedule']['difficulty'] }}")
|
||||||
|
}
|
||||||
|
try{
|
||||||
|
document.getElementById("{{ data['schedule']['action'] }}").setAttribute('selected', true);
|
||||||
|
|
||||||
|
}catch{
|
||||||
|
console.log("no element named {{ data['schedule']['action'] }}")
|
||||||
|
}
|
||||||
|
console.log("in on load")
|
||||||
|
yesnoCheck();
|
||||||
|
basicAdvanced();
|
||||||
|
ifDays();
|
||||||
|
if("{{ data['schedule']['enabled'] }}" == 'True'){
|
||||||
|
document.getElementById('enabled').checked = true;
|
||||||
|
}else{
|
||||||
|
document.getElementById('enabled').checked = true;
|
||||||
|
}
|
||||||
|
if("{{ data['schedule']['one_time'] }}" == 'True'){
|
||||||
|
document.getElementById('one_time').checked = true;
|
||||||
|
}else{
|
||||||
|
document.getElementById('one_time').checked = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.onload(startup())
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{% end %}
|
{% end %}
|
@ -35,7 +35,7 @@
|
|||||||
{% include "parts/server_controls_list.html %}
|
{% include "parts/server_controls_list.html %}
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<a href="/panel/server_tasks_edit">Create Task</a>
|
<button onclick="location.href=`/panel/add_schedule?id={{ data['server_stats']['server_id']['server_id'] }}`" class="btn btn-info">Create New Schedule <i class="fas fa-pencil-alt"></i></button>
|
||||||
<div class="col-md-12 col-sm-12" style="overflow-x:auto;">
|
<div class="col-md-12 col-sm-12" style="overflow-x:auto;">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
@ -84,7 +84,7 @@
|
|||||||
</td>
|
</td>
|
||||||
{% end %}
|
{% end %}
|
||||||
<td id="{{schedule.action}}" class="action">
|
<td id="{{schedule.action}}" class="action">
|
||||||
<button onclick="window.location.href='/panel/edit_schedule?id={{schedule.schedule_id}}'" class="btn btn-info">
|
<button onclick="window.location.href='/panel/edit_schedule?id={{ data['server_stats']['server_id']['server_id'] }}&sch_id={{schedule.schedule_id}}'" class="btn btn-info">
|
||||||
<i class="fas fa-pencil-alt"></i>
|
<i class="fas fa-pencil-alt"></i>
|
||||||
</button>
|
</button>
|
||||||
<br>
|
<br>
|
||||||
|
Loading…
Reference in New Issue
Block a user