diff options
author | Simon Rettberg | 2016-09-09 18:16:46 +0200 |
---|---|---|
committer | Simon Rettberg | 2016-09-09 18:16:46 +0200 |
commit | d2d7f27f58235db9ac428b9dd952e7b108f3c381 (patch) | |
tree | 6d59083fd82fb09e2db7444af0525e78b5b5fa76 /modules-available/locations/page.inc.php | |
parent | [exams] Less bla (diff) | |
download | slx-admin-d2d7f27f58235db9ac428b9dd952e7b108f3c381.tar.gz slx-admin-d2d7f27f58235db9ac428b9dd952e7b108f3c381.tar.xz slx-admin-d2d7f27f58235db9ac428b9dd952e7b108f3c381.zip |
[locations/statistics] Make machine counting more consistent
Diffstat (limited to 'modules-available/locations/page.inc.php')
-rw-r--r-- | modules-available/locations/page.inc.php | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/modules-available/locations/page.inc.php b/modules-available/locations/page.inc.php index 26c5d1ed..5f3c87dd 100644 --- a/modules-available/locations/page.inc.php +++ b/modules-available/locations/page.inc.php @@ -290,30 +290,37 @@ class Page_Locations extends Page } } + private function queryMachineCount($lid, $subnets) + { + if (!isset($subnets[$lid])) + return 0; + $loc =& $subnets[$lid]; + if (empty($loc['subnets'])) { + $query = "SELECT Count(*) AS cnt FROM machine WHERE locationid = :locationid"; + } else { + $query = "SELECT Count(*) AS cnt FROM machine WHERE locationid = :locationid OR (locationid IS NULL AND (0"; + foreach ($loc['subnets'] as $sub) { + $query .= ' OR INET_ATON(clientip) BETWEEN ' . $sub['startaddr'] . ' AND ' . $sub['endaddr']; + } + $query .= '))'; + } + $ret = Database::queryFirst($query, array('locationid' => $lid)); + return $ret['cnt']; + } + private function showLocationList() { $overlapSelf = $overlapOther = true; - $subnets = Location::getSubnetsByLocation($overlapSelf, $overlapOther); + $subnetsFlat = Location::getSubnetsByLocation($overlapSelf, $overlapOther, false); + $subnetsRecursive = Location::getSubnetsByLocation($overlapSelf, $overlapOther, true); $locs = Location::getLocations(0, 0, false, true); // Statistics: Count machines for each subnet $unassigned = false; if (Module::get('statistics') !== false) { foreach ($locs as &$location) { $lid = (int)$location['locationid']; - if (!isset($subnets[$lid])) - continue; - $loc =& $subnets[$lid]; - if (empty($loc['subnets'])) { - $query = "SELECT Count(*) AS cnt FROM machine WHERE locationid = :locationid"; - } else { - $query = "SELECT Count(*) AS cnt FROM machine WHERE locationid = :locationid OR (locationid IS NULL AND (0"; - foreach ($loc['subnets'] as $sub) { - $query .= ' OR INET_ATON(clientip) BETWEEN ' . $sub['startaddr'] . ' AND ' . $sub['endaddr']; - } - $query .= '))'; - } - $ret = Database::queryFirst($query, array('locationid' => $lid)); - $location['clientCount'] = $ret['cnt']; + $location['clientCount'] = $this->queryMachineCount($lid, $subnetsFlat); + $location['clientCountSum'] = $this->queryMachineCount($lid, $subnetsRecursive); } $res = Database::queryFirst("SELECT Count(*) AS cnt FROM machine m" . " LEFT JOIN subnet s ON (INET_ATON(m.clientip) BETWEEN s.startaddr AND s.endaddr)" @@ -432,7 +439,7 @@ class Page_Locations extends Page if (Module::get('statistics') !== false) { $mres = Database::simpleQuery("SELECT lastseen, logintime FROM machine" . " INNER JOIN subnet ON (INET_ATON(machine.clientip) BETWEEN startaddr AND endaddr)" - . " WHERE subnet.locationid = :lid OR machine.locationid = :lid", array('lid' => $locationId)); + . " WHERE (subnet.locationid = :lid AND machine.locationid IS NULL) OR machine.locationid = :lid", array('lid' => $locationId)); $DL = time() - 605; while ($row = $mres->fetch(PDO::FETCH_ASSOC)) { $count++; |