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"]) {
|
||||
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();
|
||||
|
||||
$res = $client->request('GET', $jobnameResult[0]['url']);
|
||||
|
||||
$statuscode = $res->getStatusCode();
|
||||
$body = $res->getBody();
|
||||
$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"));
|
||||
if(file_exists("cache/reboot.trigger")) {
|
||||
$rebootser = serialize($rebootjobs);
|
||||
file_put_contents("cache/get-services.trigger", $rebootser);
|
||||
echo json_encode(array("message" => "Reboot is scheduled. Programmer's fuel is awaiting"));
|
||||
} else {
|
||||
echo json_encode(array("message" => "Cronjob succesfully ran"));
|
||||
}
|
||||
|
||||
require_once 'include/finalize.inc.php';
|
||||
|
|
|
@ -62,6 +62,10 @@ $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|||
$client = new \GuzzleHttp\Client();
|
||||
|
||||
$rebootjobs = array();
|
||||
if (file_exists("cache/get-services.trigger")) {
|
||||
$rebootjobs = unserialize(file_get_contents("cache/get-services.trigger"));
|
||||
}
|
||||
|
||||
foreach ($results as $result) {
|
||||
|
||||
if (filter_var($result["type"], FILTER_VALIDATE_URL)) {
|
||||
|
|
Loading…
Reference in New Issue