Added possibility to run bash scripts on demand
This commit is contained in:
parent
fa292132fc
commit
241e25582e
45
runnow.php
45
runnow.php
|
@ -38,19 +38,40 @@ $jobnameResult = $jobnameqry->fetchAll(PDO::FETCH_ASSOC);
|
||||||
if ($jobnameResult[0]["user"] != $_SESSION["userID"]) {
|
if ($jobnameResult[0]["user"] != $_SESSION["userID"]) {
|
||||||
die(json_encode(array("error" => "You dirty hacker!")));
|
die(json_encode(array("error" => "You dirty hacker!")));
|
||||||
}
|
}
|
||||||
|
$nosave = false;
|
||||||
|
if (filter_var($result["type"], FILTER_VALIDATE_URL)) {
|
||||||
|
$client = new \GuzzleHttp\Client();
|
||||||
|
|
||||||
|
$res = $client->request('GET', $jobnameResult[0]['url']);
|
||||||
|
|
||||||
|
$statuscode = $res->getStatusCode();
|
||||||
|
$body = $res->getBody();
|
||||||
|
$timestamp = time();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if($result["url"] != "reboot") {
|
||||||
|
$body = '';
|
||||||
|
$result = 0;
|
||||||
|
exec($result["url"], $body, $result);
|
||||||
|
} else {
|
||||||
|
$rebootjobs[] = $result['jobID'];
|
||||||
|
touch("cache/reboot.trigger");
|
||||||
|
$nosave = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($nosave !== true) {
|
||||||
|
$stmt = $db->prepare("INSERT INTO runs(job, statuscode, result, timestamp) VALUES(?, ?, ?, ?)");
|
||||||
|
$stmt->execute(array($jobID, $statuscode, $body, $timestamp));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$client = new \GuzzleHttp\Client();
|
if(file_exists("cache/reboot.trigger")) {
|
||||||
|
$rebootser = serialize($rebootjobs);
|
||||||
$res = $client->request('GET', $jobnameResult[0]['url']);
|
file_put_contents("cache/get-services.trigger", $rebootser);
|
||||||
|
echo json_encode(array("message" => "Reboot is scheduled. Programmer's fuel is awaiting"));
|
||||||
$statuscode = $res->getStatusCode();
|
} else {
|
||||||
$body = $res->getBody();
|
echo json_encode(array("message" => "Cronjob succesfully ran"));
|
||||||
$timestamp = time();
|
}
|
||||||
|
|
||||||
$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';
|
require_once 'include/finalize.inc.php';
|
||||||
|
|
|
@ -62,6 +62,10 @@ $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
$client = new \GuzzleHttp\Client();
|
$client = new \GuzzleHttp\Client();
|
||||||
|
|
||||||
$rebootjobs = array();
|
$rebootjobs = array();
|
||||||
|
if (file_exists("cache/get-services.trigger")) {
|
||||||
|
$rebootjobs = unserialize(file_get_contents("cache/get-services.trigger"));
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($results as $result) {
|
foreach ($results as $result) {
|
||||||
|
|
||||||
if (filter_var($result["type"], FILTER_VALIDATE_URL)) {
|
if (filter_var($result["type"], FILTER_VALIDATE_URL)) {
|
||||||
|
|
Loading…
Reference in New Issue