diff options
Diffstat (limited to 'modules-available/statistics')
9 files changed, 143 insertions, 25 deletions
diff --git a/modules-available/statistics/hooks/config-tgz.inc.php b/modules-available/statistics/hooks/config-tgz.inc.php index 1272a94f..8dffbff6 100644 --- a/modules-available/statistics/hooks/config-tgz.inc.php +++ b/modules-available/statistics/hooks/config-tgz.inc.php @@ -7,26 +7,28 @@ $res = Database::simpleQuery('SELECT h.hwname FROM statistic_hw h' 'screen' => DeviceType::SCREEN, )); -$content = ''; -while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - $content .= $row['hwname'] . "=beamer\n"; -} +if ($res !== false) { // CHeck this in case we're running on old DB during update + $content = ''; + while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + $content .= $row['hwname'] . "=beamer\n"; + } -if (!empty($content)) { - $tmpfile = '/tmp/bwlp-' . md5($content) . '.tar'; - if (!is_file($tmpfile) || !is_readable($tmpfile) || filemtime($tmpfile) + 86400 < time()) { - if (file_exists($tmpfile)) { - unlink($tmpfile); - } - try { - $a = new PharData($tmpfile); - $a->addFromString("/opt/openslx/beamergui/beamer.conf", $content); + if (!empty($content)) { + $tmpfile = '/tmp/bwlp-' . md5($content) . '.tar'; + if (!is_file($tmpfile) || !is_readable($tmpfile) || filemtime($tmpfile) + 86400 < time()) { + if (file_exists($tmpfile)) { + unlink($tmpfile); + } + try { + $a = new PharData($tmpfile); + $a->addFromString("/opt/openslx/beamergui/beamer.conf", $content); + $file = $tmpfile; + } catch (Exception $e) { + EventLog::failure('Could not include beamer.conf in config.tgz', (string)$e); + unlink($tmpfile); + } + } elseif (is_file($tmpfile) && is_readable($tmpfile)) { $file = $tmpfile; - } catch (Exception $e) { - EventLog::failure('Could not include beamer.conf in config.tgz', (string)$e); - unlink($tmpfile); } - } elseif (is_file($tmpfile) && is_readable($tmpfile)) { - $file = $tmpfile; } -} +}
\ No newline at end of file diff --git a/modules-available/statistics/inc/filter.inc.php b/modules-available/statistics/inc/filter.inc.php index 6af6eed1..0afce572 100644 --- a/modules-available/statistics/inc/filter.inc.php +++ b/modules-available/statistics/inc/filter.inc.php @@ -91,7 +91,6 @@ class Filter if ($lhs == 'gbram') { $filters[] = new RamGbFilter($operator, $rhs); } elseif ($lhs == 'state') { - error_log('new state filter with ' . $rhs); $filters[] = new StateFilter($operator, $rhs); } elseif ($lhs == 'hddgb') { $filters[] = new Id44Filter($operator, $rhs); diff --git a/modules-available/statistics/inc/machine.inc.php b/modules-available/statistics/inc/machine.inc.php new file mode 100644 index 00000000..8cb5e884 --- /dev/null +++ b/modules-available/statistics/inc/machine.inc.php @@ -0,0 +1,73 @@ +<?php + +class Machine +{ + const NO_DATA = 0; + const RAW_DATA = 1; + + /** + * @var string UUID + */ + public $machineuuid; + + /** + * @var int|null locationid machine belongs to + */ + public $locationid; + + /** + * @var string mac address + */ + public $macaddr; + + /** + * @var string client's ip address + */ + public $clientip; + + /** + * @var string client's host name + */ + public $hostname; + + /** + * @var int timestamp of when this machine booted from this server for the first time + */ + public $firstseen; + + /** + * @var int last time this machine was seen active + */ + public $lastseen; + + /** + * @var int timestamp of when the machine was booted, 0 if machine is powered off + */ + public $lastboot; + + /** + * @var int timestamp of when the current user logged in, 0 if machine is idle + */ + public $logintime; + + /** + * @var string json data of position inside room (if any), null/empty otherwise + */ + public $position; + + /** + * @var string|null UUID or name of currently running lecture/session + */ + public $currentsession; + + /** + * @var string|null name of currently logged in user + */ + public $currentuser; + + /** + * @var string|null raw data of machine, if requested + */ + public $data; + +} diff --git a/modules-available/statistics/inc/statistics.inc.php b/modules-available/statistics/inc/statistics.inc.php new file mode 100644 index 00000000..1c9ebf07 --- /dev/null +++ b/modules-available/statistics/inc/statistics.inc.php @@ -0,0 +1,40 @@ +<?php + + + +class Statistics +{ + + private static $machineFields = false; + + /** + * @param string $machineuuid + * @param int $returnData + * @return \Machine|false + */ + public static function getMachine($machineuuid, $returnData) + { + if (self::$machineFields === false) { + $r = new ReflectionClass('Machine'); + $props = $r->getProperties(ReflectionProperty::IS_PUBLIC); + self::$machineFields = array_flip(array_map(function($e) { return $e->getName(); }, $props)); + } + if ($returnData === Machine::NO_DATA) { + unset(self::$machineFields['data']); + } elseif ($returnData === Machine::RAW_DATA) { + self::$machineFields['data'] = true; + } else { + Util::traceError('Invalid $returnData option passed'); + } + $fields = implode(',', array_keys(self::$machineFields)); + $row = Database::queryFirst("SELECT * FROM machine WHERE machineuuid = :machineuuid", compact('machineuuid')); + if ($row === false) + return false; + $m = new Machine(); + foreach ($row as $key => $val) { + $m->{$key} = $val; + } + return $m; + } + +} diff --git a/modules-available/statistics/install.inc.php b/modules-available/statistics/install.inc.php index 79346f99..bfa342c4 100644 --- a/modules-available/statistics/install.inc.php +++ b/modules-available/statistics/install.inc.php @@ -27,7 +27,7 @@ $res[] = tableCreate('statistic', " $res[] = $machineCreate = tableCreate('machine', " `machineuuid` char(36) CHARACTER SET ascii NOT NULL, `fixedlocationid` int(11) DEFAULT NULL COMMENT 'Manually set location (e.g. roomplanner)', - `subnetlocationid` int(11) DEFAULT NULL COMMENT 'Automatically determined location (e.g. from subnet match), + `subnetlocationid` int(11) DEFAULT NULL COMMENT 'Automatically determined location (e.g. from subnet match)', `locationid` int(11) DEFAULT NULL COMMENT 'Will be automatically set to fixedlocationid if not null, subnetlocationid otherwise', `macaddr` char(17) CHARACTER SET ascii NOT NULL, `clientip` varchar(45) CHARACTER SET ascii NOT NULL, diff --git a/modules-available/statistics/lang/de/template-tags.json b/modules-available/statistics/lang/de/template-tags.json index 7274aef4..e0be0d48 100644 --- a/modules-available/statistics/lang/de/template-tags.json +++ b/modules-available/statistics/lang/de/template-tags.json @@ -47,6 +47,7 @@ "lang_modelStats": "PC-Modelle", "lang_more": "Mehr", "lang_newMachines": "Neue Ger\u00e4te", + "lang_noEdid": "Kein EDID", "lang_noProjectorsDefined": "Keine Beamer-Overrides definiert", "lang_notes": "Anmerkungen", "lang_onlineMachines": "Gestartete Clients", diff --git a/modules-available/statistics/lang/en/template-tags.json b/modules-available/statistics/lang/en/template-tags.json index 4e135388..4a31a5ee 100644 --- a/modules-available/statistics/lang/en/template-tags.json +++ b/modules-available/statistics/lang/en/template-tags.json @@ -47,6 +47,7 @@ "lang_modelStats": "PC models", "lang_more": "More", "lang_newMachines": "New machines", + "lang_noEdid": "No EDID", "lang_noProjectorsDefined": "No projector overrides defined", "lang_notes": "Notes", "lang_onlineMachines": "Online clients", diff --git a/modules-available/statistics/page.inc.php b/modules-available/statistics/page.inc.php index 5ad8bc20..2b12c69f 100644 --- a/modules-available/statistics/page.inc.php +++ b/modules-available/statistics/page.inc.php @@ -404,7 +404,7 @@ class Page_Statistics extends Page $res = Database::simpleQuery("SELECT mbram, Count(*) AS `count` FROM machine $join WHERE $where GROUP BY mbram", $args); $lines = array(); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - $gb = ceil($row['mbram'] / 1024); + $gb = (int)ceil($row['mbram'] / 1024); for ($i = 1; $i < count($SIZE_RAM); ++$i) { if ($SIZE_RAM[$i] < $gb) { continue; @@ -476,7 +476,7 @@ class Page_Statistics extends Page $total = 0; while ($row = $res->fetch(PDO::FETCH_ASSOC)) { $total += $row['count']; - $gb = ceil($row['id44mb'] / 1024); + $gb = (int)ceil($row['id44mb'] / 1024); for ($i = 1; $i < count($SIZE_ID44); ++$i) { if ($SIZE_ID44[$i] < $gb) { continue; diff --git a/modules-available/statistics/templates/machine-main.html b/modules-available/statistics/templates/machine-main.html index bdc51167..74df80c4 100644 --- a/modules-available/statistics/templates/machine-main.html +++ b/modules-available/statistics/templates/machine-main.html @@ -143,6 +143,7 @@ </form> {{#screens}} <div class="small"> + {{#hwname}} <div class="pull-right btn-group btn-group-xs"> {{#projector}} <a href="?do=statistics&show=projectors" class="btn btn-default">{{lang_projector}}</a> @@ -154,7 +155,8 @@ class="btn btn-success"><span class="glyphicon glyphicon-plus"></span> {{lang_projector}}</button> {{/projector}} </div> - {{connector}}: <b>{{hwname}}</b> {{resolution}} + {{/hwname}} + {{connector}}: <b>{{hwname}}</b> {{^hwname}}<i>{{lang_noEdid}}</i>{{/hwname}} {{resolution}} <div class="clearfix"></div> </div> {{/screens}} @@ -187,4 +189,4 @@ document.addEventListener("DOMContentLoaded", function () { $(this).load('?do=statistics&lookup=' + $(this).text()); }); }, false); -// --></script>
\ No newline at end of file +// --></script> |