Added possibility to run bash scripts on demand

This commit is contained in:
Jeroen De Meerleer 2017-05-10 10:41:34 +02:00
parent fa292132fc
commit 241e25582e
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG Key ID: 28CCCB8F62BFADD6
2 changed files with 37 additions and 12 deletions

View File

@ -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';

View File

@ -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)) {