diff options
author | Simon Rettberg | 2024-01-18 14:40:35 +0100 |
---|---|---|
committer | Simon Rettberg | 2024-01-18 14:40:35 +0100 |
commit | 09847016b8816b5fbf37aeb5af93cd553f76b8ac (patch) | |
tree | 4bcb1d5eeaf34b5df3507e4dd077d2879900b758 /modules-available/statistics/pages | |
parent | Fix type errors (diff) | |
download | slx-admin-09847016b8816b5fbf37aeb5af93cd553f76b8ac.tar.gz slx-admin-09847016b8816b5fbf37aeb5af93cd553f76b8ac.tar.xz slx-admin-09847016b8816b5fbf37aeb5af93cd553f76b8ac.zip |
[locations/statistics] More type safety, array key checks
Diffstat (limited to 'modules-available/statistics/pages')
-rw-r--r-- | modules-available/statistics/pages/list.inc.php | 8 | ||||
-rw-r--r-- | modules-available/statistics/pages/machine.inc.php | 16 |
2 files changed, 15 insertions, 9 deletions
diff --git a/modules-available/statistics/pages/list.inc.php b/modules-available/statistics/pages/list.inc.php index facffdd0..f08cd71c 100644 --- a/modules-available/statistics/pages/list.inc.php +++ b/modules-available/statistics/pages/list.inc.php @@ -76,6 +76,7 @@ class SubPage $rows = []; $colValCount = []; // Count unique values for several columns foreach ($allRows as &$row) { + settype($row['locationid'], 'int'); $row['link_details'] = in_array($row['locationid'], $detailsAllowedLocations); //$row['firstseen'] = Util::prettyTime($row['firstseen']); $row['lastseen_int'] = $row['lastseen']; @@ -157,8 +158,9 @@ class SubPage $roomsvg = null; $side = []; if (!empty($rows) && !empty($colValCount)) { - if (count($colValCount['locationid']) === 1 && ($lid = array_key_first($colValCount['locationid'])) !== null - && Module::isAvailable('roomplanner')) { + if (count($colValCount['locationid']) === 1 + && ($lid = array_key_first($colValCount['locationid'])) > 0 + && Module::isAvailable('roomplanner')) { $roomsvg = PvsGenerator::generateSvg($lid, false, 0, 1, true, $colValCount['locationid'][$lid]); } // Handle our selected attributes @@ -168,6 +170,8 @@ class SubPage // Suffixes are not localized, but hopefully generic enough for now switch ($key) { case 'locationid': + if (!isset($location[$val])) + continue 2; $val = $location[$val]['name']; break; case 'gbram': diff --git a/modules-available/statistics/pages/machine.inc.php b/modules-available/statistics/pages/machine.inc.php index fe82797d..1d46b523 100644 --- a/modules-available/statistics/pages/machine.inc.php +++ b/modules-available/statistics/pages/machine.inc.php @@ -229,18 +229,20 @@ class SubPage } // BIOS update check if (!empty($client['bios']['BIOS Revision']) || !empty($client['bios']['Release Date'])) { - if (preg_match('#^(\d{1,2})/(\d{1,2})/(\d{4})#', $client['bios']['Release Date'], $out)) { + if (preg_match('#^(\d{1,2})/(\d{1,2})/(\d{4})#', $client['bios']['Release Date'] ?? '', $out)) { $client['bios']['Release Date'] = $out[2] . '.' . $out[1] . '.' . $out[3]; } $mainboard = ($client['mainboard']['Manufacturer'] ?? '') . '##' . ($client['mainboard']['Product Name'] ?? ''); $system = ($client['system']['Manufacturer'] ?? '') . '##' . ($client['system']['Product Name'] ?? ''); - $ret = self::checkBios($mainboard, $system, $client['bios']['Release Date'], $client['bios']['BIOS Revision']); + $ret = self::checkBios($mainboard, $system, + $client['bios']['Release Date'] ?? null, + $client['bios']['BIOS Revision'] ?? null); if ($ret === false) { // Not loaded, use AJAX $params = [ 'mainboard' => $mainboard, 'system' => $system, - 'date' => $client['bios']['Release Date'], - 'revision' => $client['bios']['BIOS Revision'], + 'date' => $client['bios']['Release Date'] ?? null, + 'revision' => $client['bios']['BIOS Revision'] ?? null, ]; $client['biosurl'] = '?do=statistics&action=bios&' . http_build_query($params); } elseif (!isset($ret['status']) || $ret['status'] !== 0) { @@ -677,7 +679,7 @@ class SubPage die(Render::parse('machine-bios-update', $reply)); } - private static function checkBios($mainboard, $system, $date, $revision, $json = null) + private static function checkBios(string $mainboard, string $system, ?string $date, ?string $revision, $json = null) { if ($json === null) { if (!file_exists(self::BIOS_CACHE) || filemtime(self::BIOS_CACHE) + 3600 < time()) @@ -694,10 +696,10 @@ class SubPage return ['status' => 0]; } $key = $match['match']; - if ($key === 'revision') { + if ($key === 'revision' && $revision !== null) { $cmp = function ($item) { $s = explode('.', $item); return $s[0] * 0x10000 + $s[1]; }; $reference = $cmp($revision); - } elseif ($key === 'date') { + } elseif ($key === 'date' && $date !== null) { $cmp = function ($item) { $s = explode('.', $item); return $s[2] * 10000 + $s[1] * 100 + $s[0]; }; $reference = $cmp($date); } else { |