summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2024-01-18 14:40:35 +0100
committerSimon Rettberg2024-01-18 14:40:35 +0100
commit09847016b8816b5fbf37aeb5af93cd553f76b8ac (patch)
tree4bcb1d5eeaf34b5df3507e4dd077d2879900b758
parentFix type errors (diff)
downloadslx-admin-09847016b8816b5fbf37aeb5af93cd553f76b8ac.tar.gz
slx-admin-09847016b8816b5fbf37aeb5af93cd553f76b8ac.tar.xz
slx-admin-09847016b8816b5fbf37aeb5af93cd553f76b8ac.zip
[locations/statistics] More type safety, array key checks
-rw-r--r--modules-available/locations/inc/locationhooks.inc.php2
-rw-r--r--modules-available/statistics/inc/statisticshooks.inc.php2
-rw-r--r--modules-available/statistics/pages/list.inc.php8
-rw-r--r--modules-available/statistics/pages/machine.inc.php16
4 files changed, 17 insertions, 11 deletions
diff --git a/modules-available/locations/inc/locationhooks.inc.php b/modules-available/locations/inc/locationhooks.inc.php
index fca85575..f6ef02da 100644
--- a/modules-available/locations/inc/locationhooks.inc.php
+++ b/modules-available/locations/inc/locationhooks.inc.php
@@ -21,7 +21,7 @@ class LocationHooks
if ($locs === false || !isset($locs[$id]))
return [];
BaseConfig::prepareWithOverrides([
- 'locationid' => $locs[$id]['parentlocationid']
+ 'locationid' => $locs[$id]['parentlocationid'] ?? 0
]);
return ConfigHolder::getRecursiveConfig(true);
}
diff --git a/modules-available/statistics/inc/statisticshooks.inc.php b/modules-available/statistics/inc/statisticshooks.inc.php
index 405ed5f7..6b9dfa21 100644
--- a/modules-available/statistics/inc/statisticshooks.inc.php
+++ b/modules-available/statistics/inc/statisticshooks.inc.php
@@ -47,7 +47,7 @@ class StatisticsHooks
if (self::$row === false)
return [];
BaseConfig::prepareWithOverrides([
- 'locationid' => self::$row['locationid']
+ 'locationid' => self::$row['locationid'] ?? 0
]);
return ConfigHolder::getRecursiveConfig(true);
}
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 {