Add possibility to run on demand
This commit is contained in:
parent
7903c276df
commit
d60511970e
16
js/site.js
16
js/site.js
|
@ -28,4 +28,20 @@ $(document).ready(function() {
|
|||
if(this.value != "custom") { $("input#delay").val($(this).data("val")); }
|
||||
});
|
||||
$('#nextrunselector').datetimepicker();
|
||||
|
||||
$("body").on("click", ".runcron", function() {
|
||||
fullurl = "/runnow.php?jobID=" + $(this).data("id");
|
||||
$.ajax(fullurl).done(function(data) {
|
||||
results = JSON.parse(data);
|
||||
|
||||
if(results["error"] !== undefined) {
|
||||
$("#resulttitle").html("Error");
|
||||
$("#resultbody").text(results["error"]);
|
||||
} else {
|
||||
$("#resulttitle").html("Success");
|
||||
$("#resultbody").text(results["message"]);
|
||||
}
|
||||
$('#resultmodal').modal('show');
|
||||
})
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright 2017 Jeroen De Meerleer <me@jeroened.be>.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
require_once "include/initialize.inc.php";
|
||||
|
||||
if(!isset($_GET['jobID'])) {
|
||||
header("location:/overview.php");
|
||||
exit;
|
||||
}
|
||||
$jobID = $_GET['jobID'];
|
||||
|
||||
$jobnameqry = $db->prepare("SELECT * FROM jobs WHERE jobID = ?");
|
||||
$jobnameqry->execute(array($_GET['jobID']));
|
||||
$jobnameResult = $jobnameqry->fetchAll(PDO::FETCH_ASSOC);
|
||||
if ($jobnameResult[0]["user"] != $_SESSION["userID"]) {
|
||||
die(json_encode(array("error" => "You dirty hacker!")));
|
||||
}
|
||||
|
||||
|
||||
$client = new \GuzzleHttp\Client();
|
||||
|
||||
$res = $client->request('GET', $jobnameResult[0]['url']);
|
||||
|
||||
$stmt = $db->prepare("INSERT INTO runs(job, statuscode, result, timestamp) VALUES(?, ?, ?, ?)");
|
||||
$stmt->execute(array($jobID, $statuscode, $body, $timestamp));
|
||||
|
||||
echo json_encode(array("message" => "Cronjob succesfully ran"));
|
||||
|
||||
require_once 'include/finalize.inc.php';
|
|
@ -23,7 +23,8 @@
|
|||
<td>{{ job.delay }}</td>
|
||||
<td>{{ job.nextrun }}</td>
|
||||
<td>
|
||||
<div class="btn-group" role="group" aria-label="...">
|
||||
<div class="btn-group" role="group">
|
||||
<a href="#" data-id="{{ job.jobID }}" class="runcron btn btn-default"><span class="glyphicon glyphicon-play"><span></a>
|
||||
<a href="runs.php?jobID={{ job.jobID }}" class="btn btn-default"><span class="glyphicon glyphicon-align-justify"></span></a>
|
||||
<a href="editjob.php?jobID={{ job.jobID }}" class="btn btn-default"><span class="glyphicon glyphicon-edit"><span></a>
|
||||
<a onclick="return confirm('Are you sure you want to delete this job?')" href="overview.php?jobID={{ job.jobID }}&action=delete" class="btn btn-default"><span class="glyphicon glyphicon-remove"></span></a>
|
||||
|
@ -32,4 +33,19 @@
|
|||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
<div id="resultmodal" class="modal fade" role="dialog">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal">×</button>
|
||||
<h4 class="modal-title" id="resulttitle"> </h4>
|
||||
</div>
|
||||
<div class="modal-body"><p id="resultbody"> </p></div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
Loading…
Reference in New Issue