diff --git a/runnow.php b/runnow.php index 5b605c2..1041d46 100644 --- a/runnow.php +++ b/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'; diff --git a/webcron.php b/webcron.php index 6ea4c97..71137fa 100644 --- a/webcron.php +++ b/webcron.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)) {