From 086d666e191264688c0c5a9e34fe1e2228b29820 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 29 Jun 2020 10:51:46 +0200 Subject: [locationinfo] Add option to show hostnames --- .../locationinfo/inc/infopanel.inc.php | 26 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'modules-available/locationinfo/inc/infopanel.inc.php') diff --git a/modules-available/locationinfo/inc/infopanel.inc.php b/modules-available/locationinfo/inc/infopanel.inc.php index 1e2e7313..b0ee0d56 100644 --- a/modules-available/locationinfo/inc/infopanel.inc.php +++ b/modules-available/locationinfo/inc/infopanel.inc.php @@ -65,7 +65,7 @@ class InfoPanel $config['locations'][$lid]['config'] = $overrides[$lid]; } } - self::appendMachineData($config['locations'], $lids, true); + self::appendMachineData($config['locations'], $lids, true, $config['hostname']); } self::appendOpeningTimes($config['locations'], $lids); @@ -87,7 +87,7 @@ class InfoPanel * @param array $array location list to populate with machine data * @param bool $withPosition Defines if coords should be included or not. */ - public static function appendMachineData(&$array, $idList = false, $withPosition = false) + public static function appendMachineData(&$array, $idList = false, $withPosition = false, $withHostname = false) { if (empty($array) && $idList === false) return; @@ -101,8 +101,14 @@ class InfoPanel $ignoreList = RunMode::getAllClients(false, false); } - $positionCol = $withPosition ? 'm.position,' : ''; - $query = "SELECT m.locationid, m.machineuuid, $positionCol m.logintime, m.lastseen, m.lastboot, m.state FROM machine m + $extraCols = ''; + if ($withPosition) { + $extraCols .= 'm.position,'; + } + if ($withHostname) { + $extraCols .= 'm.hostname,'; + } + $query = "SELECT m.locationid, m.machineuuid, m.hostname, $extraCols m.logintime, m.lastseen, m.lastboot, m.state FROM machine m WHERE m.locationid IN (:idlist)"; $dbquery = Database::simpleQuery($query, array('idlist' => $idList)); @@ -129,6 +135,18 @@ class InfoPanel } } } + if ($withHostname) { + if (ip2long($row['hostname']) !== false) { + $pc['host'] = $row['hostname']; + } else { + $i = strpos($row['hostname'], '.'); + if ($i === false) { + $pc['host'] = $row['hostname']; + } else { + $pc['host'] = substr($row['hostname'], 0, $i); + } + } + } $pc['pcState'] = LocationInfo::getPcState($row); //$pc['pcState'] = ['BROKEN', 'OFFLINE', 'IDLE', 'OCCUPIED', 'STANDBY'][mt_rand(0,4)]; // XXX -- cgit v1.2.3-55-g7522