From 50b059cace9b1003d383d5e8da0b5c697307d1ca Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Thu, 25 Apr 2019 16:08:46 +0200 Subject: [PATCH] Added advanced reboot commands --- webcron.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/webcron.php b/webcron.php index 00ef954..985dd91 100644 --- a/webcron.php +++ b/webcron.php @@ -42,8 +42,16 @@ if (file_exists("cache/get-services.trigger")) { foreach($rebootjobs as $job) { $services = array(); - $url = "ssh " . $job['host'] . " '" . "sudo systemctl list-units | cat" . "' 2>&1"; + parse_str(str_replace("reboot ", "", $job['url']), $rebootcommands); + $cmd = $rebootcommands['services']; + + if ($cmd == '') { + $cmd = "sudo systemctl list-units | cat"; + } + $url = "ssh " . $job['host'] . " '" . $cmd . "' 2>&1"; exec($url, $services); + + $cmd = ''; $services = implode("\n", $services); $stmt = $db->prepare("INSERT INTO runs(job, statuscode, result, timestamp) VALUES(?, ?, ?, ?)"); @@ -86,6 +94,8 @@ foreach ($results as $result) { } if (!job_in_array($result['jobID'], $rebootjobs)) { $rebootjobs[] = $result; + $rebootser = serialize($rebootjobs); + file_put_contents("cache/get-services.trigger", $rebootser); touch("cache/reboot.trigger"); $nosave = true; } @@ -118,9 +128,15 @@ if(file_exists("cache/reboot.trigger")) { file_put_contents("cache/reboot-time.trigger", time() + (get_configvalue('jobs.reboottime') * 60)); $rebooted_hosts = array(); foreach($rebootjobs as $job) { - - $url = "ssh " . $job['host'] . " '" . 'sudo shutdown -r +' . get_configvalue('jobs.reboottime') . ' "A reboot has been scheduled. Please save your work."' . "'"; + parse_str(str_replace("reboot ", "", $job['url']), $rebootcommands); + $cmd = $rebootcommands['cmd']; + + if ($cmd == '') { + $cmd = 'sudo shutdown -r +' . get_configvalue('jobs.reboottime') . ' "A reboot has been scheduled. Please save your work."'; + } + $url = "ssh " . $job['host'] . " '" . $cmd . "'"; exec($url); + $cmd = ''; } } require_once 'include/finalize.inc.php';