From 18a2f6b48f3e02c004947392c6f886f610572313 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 30 May 2022 17:01:26 +0200 Subject: [rebootcontrol] Pick better variable names --- .../rebootcontrol/inc/rebootcontrol.inc.php | 52 +++++++++++++--------- 1 file changed, 30 insertions(+), 22 deletions(-) (limited to 'modules-available/rebootcontrol') diff --git a/modules-available/rebootcontrol/inc/rebootcontrol.inc.php b/modules-available/rebootcontrol/inc/rebootcontrol.inc.php index c0ff3a43..94ac7665 100644 --- a/modules-available/rebootcontrol/inc/rebootcontrol.inc.php +++ b/modules-available/rebootcontrol/inc/rebootcontrol.inc.php @@ -59,6 +59,14 @@ class RebootControl return $task; } + /** + * Add wake task metadata to database, so we can display job details on the summary page. + * @param string $taskId + * @param string $type + * @param array $clients + * @param ?array $other + * @return void + */ private static function addTask(string $taskId, string $type, array $clients, array $other = null) { $lids = ArrayUtil::flattenByKey($clients, 'locationid'); @@ -308,7 +316,7 @@ class RebootControl } /** - * @param array $clientList list of clients containing each keys 'macaddr' and 'clientip' + * @param array $clientList list of clients containing each keys 'macaddr' and 'clientip', optionally 'locationid' * @param ?array $failed list of failed clients from $clientList * @return ?string taskid of this job */ @@ -342,8 +350,8 @@ class RebootControl if (empty($overrideBroadcast)) { $overrideBroadcast = false; } - foreach ($clientList as $client) { - $ip = sprintf('%u', ip2long($client['clientip'])); // 32Bit snprintf + foreach ($clientList as $dbClient) { + $ip = sprintf('%u', ip2long($dbClient['clientip'])); // 32Bit snprintf unset($subnet); $subnet = false; foreach ($subnets as &$sn) { @@ -353,47 +361,47 @@ class RebootControl } } if ($subnet === false) { - $unknown[] = $client; + $unknown[] = $dbClient; continue; } - $c = [ + $taskClient = [ 'ip' => long2ip($subnet['end']), - 'mac' => $client['macaddr'], + 'mac' => $dbClient['macaddr'], 'methods' => [], ]; // If we have an override broadcast address, unconditionally add this as the // first method if ($overrideBroadcast !== false) { - $c['ip'] = $overrideBroadcast; - $c['methods'][] = 'DIRECT'; + $taskClient['ip'] = $overrideBroadcast; + $taskClient['methods'][] = 'DIRECT'; } self::findMachinesForSubnet($subnet); // Highest priority - clients in same subnet, no directed broadcast // required, should be most reliable - self::addSshMethodUsingClient($subnet['dclients'], $c['methods'], $taskSsh); + self::addSshMethodUsingClient($subnet['dclients'], $taskClient['methods'], $taskSsh); // Jumphost - usually in same subnet - self::addSshMethodUsingJumphost($subnet['djumphosts'], true, $c['methods'], $taskSsh); + self::addSshMethodUsingJumphost($subnet['djumphosts'], true, $taskClient['methods'], $taskSsh); // Use clients in other subnets, known to be able to reach the destination net - self::addSshMethodUsingClient($subnet['iclients'], $c['methods'], $taskSsh); + self::addSshMethodUsingClient($subnet['iclients'], $taskClient['methods'], $taskSsh); // Jumphosts in other subnets, determined to be able to reach destination subnet - self::addSshMethodUsingJumphost($subnet['ijumphosts'], true, $c['methods'], $taskSsh); + self::addSshMethodUsingJumphost($subnet['ijumphosts'], true, $taskClient['methods'], $taskSsh); // If directly reachable from server, prefer this now over the questionable approaches below, // but only if we didn't already add this above because of override if ($overrideBroadcast === false && $subnet['isdirect']) { - $c['methods'][] = 'DIRECT'; + $taskClient['methods'][] = 'DIRECT'; } - if (empty($c['methods'])) { - $unreachable[] = $client; + if (empty($taskClient['methods'])) { + $unreachable[] = $dbClient; } else { // TODO: Remember WOL was attempted } // Last fallback is jumphosts that were not reachable when last checked, this is really a last resort - self::addSshMethodUsingJumphost($subnet['djumphosts'], false, $c['methods'], $taskSsh); - self::addSshMethodUsingJumphost($subnet['ijumphosts'], false, $c['methods'], $taskSsh); + self::addSshMethodUsingJumphost($subnet['djumphosts'], false, $taskClient['methods'], $taskSsh); + self::addSshMethodUsingJumphost($subnet['ijumphosts'], false, $taskClient['methods'], $taskSsh); - if (!empty($c['methods'])) { - $taskClients[] = $c; - $sent[] = $client; + if (!empty($taskClient['methods'])) { + $taskClients[] = $taskClient; + $sent[] = $dbClient; } } unset($subnet); @@ -414,8 +422,8 @@ class RebootControl if (isset($task['id'])) { $id = $task['id']; self::addTask($id, self::TASK_WOL, $clientList, ['log' => $errors]); - foreach ($sent as $client) { - EventLog::applyFilterRules('#action-wol', $client); + foreach ($sent as $dbClient) { + EventLog::applyFilterRules('#action-wol', $dbClient); } return $id; } -- cgit v1.2.3-55-g7522