diff options
author | Christian Hofmaier | 2021-02-23 21:03:50 +0100 |
---|---|---|
committer | Christian Hofmaier | 2021-02-23 21:03:50 +0100 |
commit | bc09d8c59af1ac9e0eddb4f40f03ab02b5849d88 (patch) | |
tree | 7887f27323f2c4ef8ed0d2336b0aa0282c686ccc /modules-available/rebootcontrol/hooks/cron.inc.php | |
parent | [statistics] Add soft-delete feature: Resets a client's IP and location (diff) | |
download | slx-admin-bc09d8c59af1ac9e0eddb4f40f03ab02b5849d88.tar.gz slx-admin-bc09d8c59af1ac9e0eddb4f40f03ab02b5849d88.tar.xz slx-admin-bc09d8c59af1ac9e0eddb4f40f03ab02b5849d88.zip |
[rebootcontrol] add Scheduler Cron Job
Diffstat (limited to 'modules-available/rebootcontrol/hooks/cron.inc.php')
-rw-r--r-- | modules-available/rebootcontrol/hooks/cron.inc.php | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/modules-available/rebootcontrol/hooks/cron.inc.php b/modules-available/rebootcontrol/hooks/cron.inc.php index 67e17c83..c80a87b1 100644 --- a/modules-available/rebootcontrol/hooks/cron.inc.php +++ b/modules-available/rebootcontrol/hooks/cron.inc.php @@ -10,6 +10,29 @@ if (in_array((int)date('G'), [6, 7, 9, 12, 15]) && in_array(date('i'), ['00', '0 } } +// CRON for Scheduler +$now = time(); +$res = Database::simpleQuery("SELECT * FROM reboot_scheduler WHERE nextexecution < :now", ['now' => $now]); +while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + + // Calculate next_execution for the event. + $location = Database::queryFirst("SELECT openingtime FROM `location` WHERE locationid = :lid", array('lid' => $row['locationid'])); + Scheduler::updateSchedule($row['locationid'], $row['action'], $row['options'], $location['openingtime']); + + if ($row['nextexecution'] + 1200 < $now) continue; + + $machinedb = Database::simpleQuery("SELECT machineuuid, clientip, macaddr, locationid FROM machine WHERE locationid = :locid", ['locid' => $row['locationid']]); + $machines = []; + while ($machine = $machinedb->fetch(PDO::FETCH_ASSOC)) { + settype($machine['locationid'], 'int'); + $machines[] = $machine; + } + // Options not yet used. + $options = json_decode($row['options']); + if ($row['action'] === 'sd') RebootControl::execute($machines, RebootControl::SHUTDOWN, 0); + else if ($row['action'] === 'wol') RebootControl::wakeMachines($machines); +} + /* * Client reachability test -- can be disabled */ |