$list, "mode" => $mode, "minutes" => $minutes, "locationId" => $locationId, "sshkey" => SSHKey::getPrivateKey(), "port" => 9922, // Hard-coded, must match mgmt-sshd module )); if (!Taskmanager::isFailed($task)) { Property::addToList(RebootControl::KEY_TASKLIST, $locationId . '/' . $task["id"], 60 * 24); } return $task; } /** * @param int[]|null $locations filter by these locations * @return array list of active tasks for reboots/shutdowns. */ public static function getActiveTasks($locations = null) { if (is_array($locations) && in_array(0,$locations)) { $locations = null; } $list = Property::getList(RebootControl::KEY_TASKLIST); $return = []; foreach ($list as $entry) { $p = explode('/', $entry, 2); if (count($p) !== 2) { Property::removeFromList(RebootControl::KEY_TASKLIST, $entry); continue; } if (is_array($locations) && !in_array($p[0], $locations)) // Ignore continue; $id = $p[1]; $task = Taskmanager::status($id); if (!Taskmanager::isTask($task)) { Property::removeFromList(RebootControl::KEY_TASKLIST, $entry); continue; } $return[] = [ 'taskId' => $task['id'], 'locationId' => $task['data']['locationId'], 'time' => $task['data']['time'], 'mode' => $task['data']['mode'], 'clientCount' => count($task['data']['clients']), 'status' => $task['statusCode'], ]; } return $return; } }