mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Cron tasks working.
Starting to rearrange front end for better UX
This commit is contained in:
parent
c220c6d3d3
commit
5e7d0d64bd
@ -113,6 +113,7 @@ class Schedules(Model):
|
|||||||
command = CharField(null=True)
|
command = CharField(null=True)
|
||||||
comment = CharField()
|
comment = CharField()
|
||||||
one_time = BooleanField(default=False)
|
one_time = BooleanField(default=False)
|
||||||
|
cron_string = CharField(default="")
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
table_name = 'schedules'
|
table_name = 'schedules'
|
||||||
@ -206,7 +207,7 @@ class helpers_management:
|
|||||||
# Schedules Methods
|
# Schedules Methods
|
||||||
#************************************************************************************************
|
#************************************************************************************************
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_scheduled_task(server_id, action, interval, interval_type, start_time, command, comment=None, enabled=True, one_time=False):
|
def create_scheduled_task(server_id, action, interval, interval_type, start_time, command, comment=None, enabled=True, one_time=False, cron_string='* * * * *'):
|
||||||
sch_id = Schedules.insert({
|
sch_id = Schedules.insert({
|
||||||
Schedules.server_id: server_id,
|
Schedules.server_id: server_id,
|
||||||
Schedules.action: action,
|
Schedules.action: action,
|
||||||
@ -216,7 +217,9 @@ class helpers_management:
|
|||||||
Schedules.start_time: start_time,
|
Schedules.start_time: start_time,
|
||||||
Schedules.command: command,
|
Schedules.command: command,
|
||||||
Schedules.comment: comment,
|
Schedules.comment: comment,
|
||||||
Schedules.one_time: one_time
|
Schedules.one_time: one_time,
|
||||||
|
Schedules.cron_string: cron_string
|
||||||
|
|
||||||
}).execute()
|
}).execute()
|
||||||
return sch_id
|
return sch_id
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ import asyncio
|
|||||||
import shutil
|
import shutil
|
||||||
from schedule import Scheduler
|
from schedule import Scheduler
|
||||||
from tzlocal import get_localzone
|
from tzlocal import get_localzone
|
||||||
|
import tzlocal
|
||||||
|
|
||||||
from pytz import HOUR, timezone
|
from pytz import HOUR, timezone
|
||||||
from app.classes.controllers.users_controller import Users_Controller
|
from app.classes.controllers.users_controller import Users_Controller
|
||||||
@ -54,7 +55,7 @@ class TasksManager:
|
|||||||
self.controller = controller
|
self.controller = controller
|
||||||
self.tornado = Webserver(controller, self)
|
self.tornado = Webserver(controller, self)
|
||||||
|
|
||||||
self.scheduler = BackgroundScheduler()
|
self.scheduler = BackgroundScheduler(timezone=str(tzlocal.get_localzone()))
|
||||||
|
|
||||||
self.users_controller = Users_Controller()
|
self.users_controller = Users_Controller()
|
||||||
|
|
||||||
@ -163,33 +164,39 @@ class TasksManager:
|
|||||||
|
|
||||||
def scheduler_thread(self):
|
def scheduler_thread(self):
|
||||||
schedules = management_helper.get_schedules_enabled()
|
schedules = management_helper.get_schedules_enabled()
|
||||||
tz = get_localzone()
|
|
||||||
self.scheduler.configure(timezone=tz)
|
|
||||||
self.scheduler.add_listener(self.schedule_watcher, mask=EVENT_JOB_EXECUTED)
|
self.scheduler.add_listener(self.schedule_watcher, mask=EVENT_JOB_EXECUTED)
|
||||||
#self.scheduler.add_job(self.scheduler.print_jobs, 'interval', seconds=10, id='-1')
|
#self.scheduler.add_job(self.scheduler.print_jobs, 'interval', seconds=10, id='-1')
|
||||||
#load schedules from DB
|
#load schedules from DB
|
||||||
for schedule in schedules:
|
for schedule in schedules:
|
||||||
if schedule.interval_type == 'hours':
|
if schedule.cron_string != "":
|
||||||
self.scheduler.add_job(management_helper.add_command, 'cron', minute = 0, hour = '*/'+str(schedule.interval), id=str(schedule.schedule_id), args=[schedule.server_id, self.users_controller.get_id_by_name('system'), '127.0.0.1', schedule.command])
|
cron = schedule.cron_string.split(' ')
|
||||||
elif schedule.interval_type == 'minutes':
|
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], id=str(schedule.schedule_id), args=[schedule.server_id, self.users_controller.get_id_by_name('system'), '127.0.0.1', schedule.command])
|
||||||
self.scheduler.add_job(management_helper.add_command, 'cron', minute = '*/'+str(schedule.interval), id=str(schedule.schedule_id), args=[schedule.server_id, self.users_controller.get_id_by_name('system'), '127.0.0.1', schedule.command])
|
else:
|
||||||
elif schedule.interval_type == 'days':
|
if schedule.interval_type == 'hours':
|
||||||
time = schedule.start_time.split(':')
|
self.scheduler.add_job(management_helper.add_command, 'cron', minute = 0, hour = '*/'+str(schedule.interval), id=str(schedule.schedule_id), args=[schedule.server_id, self.users_controller.get_id_by_name('system'), '127.0.0.1', schedule.command])
|
||||||
self.scheduler.add_job(management_helper.add_command, 'cron', day = '*/'+str(schedule.interval), hour=time[0], minute=time[1], id=str(schedule.schedule_id), args=[schedule.server_id, self.users_controller.get_id_by_name('system'), '127.0.0.1', schedule.command])
|
elif schedule.interval_type == 'minutes':
|
||||||
|
self.scheduler.add_job(management_helper.add_command, 'cron', minute = '*/'+str(schedule.interval), id=str(schedule.schedule_id), args=[schedule.server_id, self.users_controller.get_id_by_name('system'), '127.0.0.1', schedule.command])
|
||||||
|
elif schedule.interval_type == 'days':
|
||||||
|
time = schedule.start_time.split(':')
|
||||||
|
self.scheduler.add_job(management_helper.add_command, 'cron', day = '*/'+str(schedule.interval), hour=time[0], minute=time[1], id=str(schedule.schedule_id), args=[schedule.server_id, self.users_controller.get_id_by_name('system'), '127.0.0.1', schedule.command])
|
||||||
|
|
||||||
self.scheduler.start()
|
self.scheduler.start()
|
||||||
|
|
||||||
|
|
||||||
def schedule_job(self, job_data):
|
def schedule_job(self, job_data):
|
||||||
sch_id = management_helper.create_scheduled_task(job_data['server_id'], job_data['action'], job_data['interval'], job_data['interval_type'], job_data['time'], job_data['command'], "None", job_data['enabled'], job_data['one_time'])
|
sch_id = management_helper.create_scheduled_task(job_data['server_id'], job_data['action'], job_data['interval'], job_data['interval_type'], job_data['time'], job_data['command'], "None", job_data['enabled'], job_data['one_time'], job_data['cron_string'])
|
||||||
if job_data['enabled']:
|
if job_data['enabled']:
|
||||||
if job_data['interval_type'] == 'hours':
|
if job_data['cron_string'] != "":
|
||||||
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']])
|
cron = job_data['cron_string'].split(' ')
|
||||||
elif job_data['interval_type'] == 'minutes':
|
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], 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']])
|
else:
|
||||||
elif job_data['interval_type'] == 'days':
|
if job_data['interval_type'] == 'hours':
|
||||||
time = job_data['time'].split(':')
|
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']])
|
||||||
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']], )
|
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['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']], )
|
||||||
|
|
||||||
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)
|
||||||
|
@ -859,7 +859,10 @@ class PanelHandler(BaseHandler):
|
|||||||
elif action == "backup":
|
elif action == "backup":
|
||||||
command = "backup_server"
|
command = "backup_server"
|
||||||
else:
|
else:
|
||||||
|
interval_type = ''
|
||||||
cron_string = bleach.clean(self.get_argument('cron', ''))
|
cron_string = bleach.clean(self.get_argument('cron', ''))
|
||||||
|
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))
|
action = bleach.clean(self.get_argument('action', None))
|
||||||
if action == "command":
|
if action == "command":
|
||||||
command = bleach.clean(self.get_argument('command', None))
|
command = bleach.clean(self.get_argument('command', None))
|
||||||
@ -891,6 +894,13 @@ class PanelHandler(BaseHandler):
|
|||||||
if not self.controller.servers.server_id_exists(server_id):
|
if not self.controller.servers.server_id_exists(server_id):
|
||||||
self.redirect("/panel/error?error=Invalid Server ID")
|
self.redirect("/panel/error?error=Invalid Server ID")
|
||||||
return
|
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":
|
if interval_type == "days":
|
||||||
job_data = {
|
job_data = {
|
||||||
@ -901,12 +911,17 @@ class PanelHandler(BaseHandler):
|
|||||||
"command": command,
|
"command": command,
|
||||||
"time": time,
|
"time": time,
|
||||||
"enabled": enabled,
|
"enabled": enabled,
|
||||||
"one_time": one_time
|
"one_time": one_time,
|
||||||
|
"cron_string": ''
|
||||||
}
|
}
|
||||||
elif difficulty == "advanced":
|
elif difficulty == "advanced":
|
||||||
job_data = {
|
job_data = {
|
||||||
"server_id": server_id,
|
"server_id": server_id,
|
||||||
"action": action,
|
"action": action,
|
||||||
|
"interval_type": '',
|
||||||
|
"interval": '',
|
||||||
|
"command": '',
|
||||||
|
"time": current_time,
|
||||||
"command": command,
|
"command": command,
|
||||||
"cron_string": cron_string,
|
"cron_string": cron_string,
|
||||||
"enabled": enabled,
|
"enabled": enabled,
|
||||||
@ -920,8 +935,9 @@ class PanelHandler(BaseHandler):
|
|||||||
"interval": interval,
|
"interval": interval,
|
||||||
"command": command,
|
"command": command,
|
||||||
"enabled": enabled,
|
"enabled": enabled,
|
||||||
"time": '00:00',
|
"time": current_time,
|
||||||
"one_time": one_time
|
"one_time": one_time,
|
||||||
|
"cron_string": ''
|
||||||
}
|
}
|
||||||
|
|
||||||
self.tasks_manager.schedule_job(job_data)
|
self.tasks_manager.schedule_job(job_data)
|
||||||
|
@ -35,79 +35,8 @@
|
|||||||
{% include "parts/server_controls_list.html %}
|
{% include "parts/server_controls_list.html %}
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-4 col-sm-12">
|
<a href="/panel/server_tasks_edit">Create Task</a>
|
||||||
<form class="forms-sample" method="post" action="/panel/tasks">
|
<div class="col-md-12 col-sm-12" style="overflow-x:auto;">
|
||||||
{% raw xsrf_form_html() %}
|
|
||||||
<input type="hidden" name="id" value="{{ data['server_stats']['server_id']['server_id'] }}">
|
|
||||||
<input type="hidden" name="subpage" value="config">
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<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">
|
|
||||||
<option value="basic">Basic</option>
|
|
||||||
<option value="advanced">Advanced</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<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">
|
|
||||||
<option value="start">Start Server</option>
|
|
||||||
<option value="restart">Restart Server</option>
|
|
||||||
<option value="shutdown">Shutdown Server</option>
|
|
||||||
<option value="backup">Backup Server</option>
|
|
||||||
<option value="command">Custon Command</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div id="ifBasic">
|
|
||||||
<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>
|
|
||||||
<input type="number" class="form-control" name="interval" id="interval" value="{{ data['server_stats']['server_id']['path'] }}" placeholder="Interval" required>
|
|
||||||
<br>
|
|
||||||
<br>
|
|
||||||
<select id="interval_type" name="interval_type" class="form-control form-control-lg select-css">
|
|
||||||
<option value="days">Days</option>
|
|
||||||
<option value="hours">Hours</option>
|
|
||||||
<option value="minutes">Minutes</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<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>
|
|
||||||
<input type="time" class="form-control" name="time" id="time" value="{{ data['server_stats']['server_id']['log_path'] }}" placeholder="Time">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div id="ifYes" style="display: none;">
|
|
||||||
<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>
|
|
||||||
<input type="input" class="form-control" name="command" id="command" value="" placeholder="Command">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div id="ifAdvanced" style="display: none;">
|
|
||||||
<div class="form-group">
|
|
||||||
<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="* * * * *">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-check-flat">
|
|
||||||
<label for="enabled" class="form-check-label ml-4 mb-4">
|
|
||||||
<input type="checkbox" class="form-check-input" id="enabled" name="enabled" checked="" value="1">Enabled
|
|
||||||
</label>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<div class="form-check-flat">
|
|
||||||
<label for="one_time" class="form-check-label ml-4 mb-4">
|
|
||||||
<input type="checkbox" class="form-check-input" id="one_time" name="one_time" value="1">Delete After Execution
|
|
||||||
</label>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<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>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col-md-8 col-sm-12" style="overflow-x:auto;">
|
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h4 class="card-title">Scheduled Tasks</h4>
|
<h4 class="card-title">Scheduled Tasks</h4>
|
||||||
@ -115,6 +44,7 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<tr class="rounded">
|
<tr class="rounded">
|
||||||
<th>Action</th>
|
<th>Action</th>
|
||||||
|
<th>Command</th>
|
||||||
<th>Interval</th>
|
<th>Interval</th>
|
||||||
<th>Start Time</th>
|
<th>Start Time</th>
|
||||||
<th>Enabled</th>
|
<th>Enabled</th>
|
||||||
@ -127,9 +57,17 @@
|
|||||||
<td id="{{schedule.action}}" class="action">
|
<td id="{{schedule.action}}" class="action">
|
||||||
<p>{{schedule.action}}</p>
|
<p>{{schedule.action}}</p>
|
||||||
</td>
|
</td>
|
||||||
|
<td id="{{schedule.command}}" class="action">
|
||||||
|
<p>{{schedule.command}}</p>
|
||||||
|
</td>
|
||||||
<td id="{{schedule.interval}}" class="action">
|
<td id="{{schedule.interval}}" class="action">
|
||||||
|
{% if schedule.interval != '' %}
|
||||||
<p>Every</p>
|
<p>Every</p>
|
||||||
<p>{{schedule.interval}} {{schedule.interval_type}}</p>
|
<p>{{schedule.interval}} {{schedule.interval_type}}</p>
|
||||||
|
{% else %}
|
||||||
|
<p>Cron String:</p>
|
||||||
|
<p>{{schedule.cron_string}}</p>
|
||||||
|
{% end %}
|
||||||
</td>
|
</td>
|
||||||
<td id="{{schedule.start_time}}" class="action">
|
<td id="{{schedule.start_time}}" class="action">
|
||||||
<p>{{schedule.start_time}}</p>
|
<p>{{schedule.start_time}}</p>
|
||||||
@ -194,19 +132,34 @@
|
|||||||
function yesnoCheck(that) {
|
function yesnoCheck(that) {
|
||||||
if (that.value == "command") {
|
if (that.value == "command") {
|
||||||
document.getElementById("ifYes").style.display = "block";
|
document.getElementById("ifYes").style.display = "block";
|
||||||
|
document.getElementById("command").required = true;
|
||||||
} else {
|
} else {
|
||||||
document.getElementById("ifYes").style.display = "none";
|
document.getElementById("ifYes").style.display = "none";
|
||||||
|
document.getElementById("command").required = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function basicAdvanced(that) {
|
function basicAdvanced(that) {
|
||||||
if (that.value == "advanced") {
|
if (that.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("time").required = false;
|
||||||
} else {
|
} else {
|
||||||
document.getElementById("ifAdvanced").style.display = "none";
|
document.getElementById("ifAdvanced").style.display = "none";
|
||||||
document.getElementById("ifBasic").style.display = "block";
|
document.getElementById("ifBasic").style.display = "block";
|
||||||
|
document.getElementById("interval").required = true;
|
||||||
|
document.getElementById("time").required = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function ifDays(that) {
|
||||||
|
if (that.value == "days") {
|
||||||
|
document.getElementById("ifDays").style.display = "block";
|
||||||
|
document.getElementById("time").required = true;
|
||||||
|
} else {
|
||||||
|
document.getElementById("ifDays").style.display = "none";
|
||||||
|
document.getElementById("time").required = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$( ".del_button" ).click(function() {
|
$( ".del_button" ).click(function() {
|
||||||
var sch_id = $(this).data('sch');
|
var sch_id = $(this).data('sch');
|
||||||
|
215
app/frontend/templates/panel/server_tasks_edit.html
Normal file
215
app/frontend/templates/panel/server_tasks_edit.html
Normal file
@ -0,0 +1,215 @@
|
|||||||
|
{% extends ../base.html %}
|
||||||
|
|
||||||
|
{% block meta %}
|
||||||
|
<!-- <meta http-equiv="refresh" content="60">-->
|
||||||
|
{% end %}
|
||||||
|
|
||||||
|
{% block title %}Crafty Controller - {{ translate('serverDetails', 'serverDetails', data['lang']) }}{% end %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<div class="content-wrapper">
|
||||||
|
|
||||||
|
<!-- Page Title Header Starts-->
|
||||||
|
<div class="row page-title-header">
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="page-header">
|
||||||
|
<h4 class="page-title">
|
||||||
|
{{ translate('serverDetails', 'serverDetails', data['lang']) }} - {{ data['server_stats']['server_id']['server_name'] }}
|
||||||
|
<br />
|
||||||
|
<small>UUID: {{ data['server_stats']['server_id']['server_uuid'] }}</small>
|
||||||
|
</h4>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<!-- Page Title Header Ends-->
|
||||||
|
|
||||||
|
{% include "parts/details_stats.html %}
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
|
||||||
|
<div class="col-sm-12 grid-margin">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body pt-0">
|
||||||
|
{% include "parts/server_controls_list.html %}
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12 col-sm-12">
|
||||||
|
<form class="forms-sample" method="post" action="/panel/tasks">
|
||||||
|
{% raw xsrf_form_html() %}
|
||||||
|
<input type="hidden" name="id" value="{{ data['server_stats']['server_id']['server_id'] }}">
|
||||||
|
<input type="hidden" name="subpage" value="config">
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<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">
|
||||||
|
<option value="basic">Basic</option>
|
||||||
|
<option value="advanced">Advanced</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<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">
|
||||||
|
<option value="start">Start Server</option>
|
||||||
|
<option value="restart">Restart Server</option>
|
||||||
|
<option value="shutdown">Shutdown Server</option>
|
||||||
|
<option value="backup">Backup Server</option>
|
||||||
|
<option value="command">Custon Command</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div id="ifBasic">
|
||||||
|
<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>
|
||||||
|
<input type="number" class="form-control" name="interval" id="interval" value="{{ data['server_stats']['server_id']['path'] }}" placeholder="Interval" required>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<select id="interval_type" onchange="ifDays(this);" name="interval_type" class="form-control form-control-lg select-css">
|
||||||
|
<option value="days">Days</option>
|
||||||
|
<option value="hours">Hours</option>
|
||||||
|
<option value="minutes">Minutes</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div id="ifDays" style="display: block;">
|
||||||
|
<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>
|
||||||
|
<input type="time" class="form-control" name="time" id="time" value="{{ data['server_stats']['server_id']['log_path'] }}" placeholder="Time" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id="ifYes" style="display: none;">
|
||||||
|
<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>
|
||||||
|
<input type="input" class="form-control" name="command" id="command" value="" placeholder="Command" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id="ifAdvanced" style="display: none;">
|
||||||
|
<div class="form-group">
|
||||||
|
<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="* * * * *">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-check-flat">
|
||||||
|
<label for="enabled" class="form-check-label ml-4 mb-4">
|
||||||
|
<input type="checkbox" class="form-check-input" id="enabled" name="enabled" checked="" value="1">Enabled
|
||||||
|
</label>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="form-check-flat">
|
||||||
|
<label for="one_time" class="form-check-label ml-4 mb-4">
|
||||||
|
<input type="checkbox" class="form-check-input" id="one_time" name="one_time" value="1">Delete After Execution
|
||||||
|
</label>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<!-- content-wrapper ends -->
|
||||||
|
|
||||||
|
{% end %}
|
||||||
|
|
||||||
|
{% block js %}
|
||||||
|
<script>
|
||||||
|
|
||||||
|
|
||||||
|
//used to get cookies from browser - this is part of tornados xsrf protection - it's for extra security
|
||||||
|
function getCookie(name) {
|
||||||
|
var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
|
||||||
|
return r ? r[1] : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
$( document ).ready(function() {
|
||||||
|
console.log( "ready!" );
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
function yesnoCheck(that) {
|
||||||
|
if (that.value == "command") {
|
||||||
|
document.getElementById("ifYes").style.display = "block";
|
||||||
|
document.getElementById("command").required = true;
|
||||||
|
} else {
|
||||||
|
document.getElementById("ifYes").style.display = "none";
|
||||||
|
document.getElementById("command").required = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function basicAdvanced(that) {
|
||||||
|
if (that.value == "advanced") {
|
||||||
|
document.getElementById("ifAdvanced").style.display = "block";
|
||||||
|
document.getElementById("ifBasic").style.display = "none";
|
||||||
|
document.getElementById("interval").required = false;
|
||||||
|
document.getElementById("time").required = false;
|
||||||
|
} else {
|
||||||
|
document.getElementById("ifAdvanced").style.display = "none";
|
||||||
|
document.getElementById("ifBasic").style.display = "block";
|
||||||
|
document.getElementById("interval").required = true;
|
||||||
|
document.getElementById("time").required = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function ifDays(that) {
|
||||||
|
if (that.value == "days") {
|
||||||
|
document.getElementById("ifDays").style.display = "block";
|
||||||
|
document.getElementById("time").required = true;
|
||||||
|
} else {
|
||||||
|
document.getElementById("ifDays").style.display = "none";
|
||||||
|
document.getElementById("time").required = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$( ".del_button" ).click(function() {
|
||||||
|
var sch_id = $(this).data('sch');
|
||||||
|
var server_id = {{ data['server_stats']['server_id']['server_id'] }};
|
||||||
|
|
||||||
|
console.log(sch_id)
|
||||||
|
|
||||||
|
bootbox.confirm({
|
||||||
|
title: "Test",
|
||||||
|
message: "{{ translate('serverBackups', 'confirmDelete', data['lang']) }}",
|
||||||
|
buttons: {
|
||||||
|
cancel: {
|
||||||
|
label: '<i class="fas fa-times"></i> {{ translate("serverBackups", "cancel", data['lang']) }}'
|
||||||
|
},
|
||||||
|
confirm: {
|
||||||
|
label: '<i class="fas fa-check"></i> {{ translate("serverBackups", "confirm", data['lang']) }}'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
callback: function (result) {
|
||||||
|
console.log(result);
|
||||||
|
if (result == true) {
|
||||||
|
del_task(sch_id, server_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function del_task(sch_id, id){
|
||||||
|
var token = getCookie("_xsrf")
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type: "DELETE",
|
||||||
|
headers: {'X-XSRFToken': token},
|
||||||
|
url: '/ajax/del_task?server_id='+id+'&schedule_id='+sch_id,
|
||||||
|
data: {
|
||||||
|
schedule_id: sch_id,
|
||||||
|
id: id
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
location.reload();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{% end %}
|
16
app/migrations/20210915205501_cron_task.py
Normal file
16
app/migrations/20210915205501_cron_task.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# Generated by database migrator
|
||||||
|
import peewee
|
||||||
|
|
||||||
|
def migrate(migrator, database, **kwargs):
|
||||||
|
migrator.add_columns('schedules', cron_string=peewee.CharField(default=""))
|
||||||
|
"""
|
||||||
|
Write your migrations here.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def rollback(migrator, database, **kwargs):
|
||||||
|
migrator.drop_columns('schedules', ['cron_string'])
|
||||||
|
"""
|
||||||
|
Write your rollback migrations here.
|
||||||
|
"""
|
Loading…
Reference in New Issue
Block a user