summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics/page.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/statistics/page.inc.php')
-rw-r--r--modules-available/statistics/page.inc.php131
1 files changed, 54 insertions, 77 deletions
diff --git a/modules-available/statistics/page.inc.php b/modules-available/statistics/page.inc.php
index 20ff929a..4f11e835 100644
--- a/modules-available/statistics/page.inc.php
+++ b/modules-available/statistics/page.inc.php
@@ -2,7 +2,6 @@
class Page_Statistics extends Page
{
- private $query;
private $show;
/**
@@ -22,6 +21,17 @@ class Page_Statistics extends Page
$this->transformLegacyQuery();
}
+ /*
+ Dictionary::translate('submenu_projectors');
+ Dictionary::translate('submenu_replace');
+ Dictionary::translate('submenu_hints');
+ */
+
+ foreach (['projectors', 'replace', 'hints'] as $section) {
+ Dashboard::addSubmenu('?do=statistics&show=' . $section,
+ Dictionary::translate('submenu_' . $section));
+ }
+
$this->show = Request::any('show', false, 'string');
if ($this->show === false && Request::isGet()) {
if (Request::get('uuid') !== false) {
@@ -81,6 +91,8 @@ class Page_Statistics extends Page
$this->rebootControl(false);
} elseif ($action === 'wol') {
$this->wol();
+ } elseif ($action === 'benchmark') {
+ $this->vmstoreBenchmark();
} elseif ($action === 'prepare-exec') {
if (Module::isAvailable('rebootcontrol')) {
RebootControl::prepareExec();
@@ -133,7 +145,7 @@ class Page_Statistics extends Page
/**
* @param bool $reboot true = reboot, false = shutdown
*/
- private function rebootControl($reboot)
+ private function rebootControl(bool $reboot)
{
if (!Module::isAvailable('rebootcontrol'))
return;
@@ -159,6 +171,25 @@ class Page_Statistics extends Page
}
}
+ /**
+ * @param bool $reboot true = reboot, false = shutdown
+ */
+ private function vmstoreBenchmark()
+ {
+ if (!Module::isAvailable('vmstore'))
+ return;
+ $ids = Request::post('uuid', [], 'array');
+ $ids = array_values($ids);
+ if (empty($ids)) {
+ Message::addError('main.parameter-empty', 'uuid');
+ return;
+ }
+ $this->getAllowedMachines(".vmstore.benchmark", $ids, $allowedMachines);
+ if (empty($allowedMachines))
+ return;
+ VmStoreBenchmark::prepareSelectDialog($allowedMachines);
+ }
+
private function getAllowedMachines($permission, $ids, &$allowedMachines)
{
$allowedLocations = User::getAllowedLocations($permission);
@@ -171,7 +202,7 @@ class Page_Statistics extends Page
$ids = array_flip($ids);
$allowedMachines = [];
$seenLocations = [];
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
unset($ids[$row['machineuuid']]);
settype($row['locationid'], 'int');
if (in_array($row['locationid'], $allowedLocations)) {
@@ -202,7 +233,7 @@ class Page_Statistics extends Page
$res = Database::simpleQuery('SELECT machineuuid, locationid FROM machine WHERE machineuuid IN (:ids)', compact('ids'));
$ids = array_flip($ids);
$delete = [];
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
unset($ids[$row['machineuuid']]);
if (in_array($row['locationid'], $allowedLocations)) {
$delete[] = $row['machineuuid'];
@@ -236,38 +267,31 @@ class Page_Statistics extends Page
return;
}
- $sortColumn = Request::any('sortColumn');
- $sortDirection = Request::any('sortDirection');
-
- $filters = StatisticsFilter::parseQuery();
- $filterSet = new StatisticsFilterSet($filters);
- $filterSet->setSort($sortColumn, $sortDirection);
-
- if (!$filterSet->setAllowedLocationsFromPermission('view.' . $this->show)) {
- Message::addError('main.no-permission');
- Util::redirect('?do=main');
- }
Message::addError('main.value-invalid', 'show', $this->show);
}
- private function redirectFirst($where, $join, $args)
- {
- // TODO Annoying at times, restore this?
- $res = Database::queryFirst("SELECT machineuuid FROM machine $join WHERE ($where) LIMIT 1", $args);
- if ($res !== false) {
- Util::redirect('?do=statistics&uuid=' . $res['machineuuid']);
- }
- }
-
protected function doAjax()
{
if (!User::load())
return;
- if (Request::any('action') === 'bios') {
+ $action = Request::any('action');
+ if ($action === 'bios') {
require_once 'modules/statistics/pages/machine.inc.php';
SubPage::ajaxCheckBios();
return;
}
+ if ($action === 'json-lookup') {
+ $reply = [];
+ foreach (Request::post('list', [], 'array') as $item) {
+ $name = PciId::getPciId(PciId::AUTO, $item, true);
+ if ($name === false) {
+ $name = '?????';
+ }
+ $reply[$item] = $name;
+ }
+ header('Content-Type: application/json');
+ die(json_encode($reply));
+ }
$param = Request::any('lookup', false, 'string');
if ($param === false) {
@@ -275,61 +299,14 @@ class Page_Statistics extends Page
}
$add = '';
if (preg_match('/^([a-f0-9]{4}):([a-f0-9]{4})$/', $param, $out)) {
- $cat = 'DEVICE';
- $host = $out[2] . '.' . $out[1];
$add = ' (' . $param . ')';
- } elseif (preg_match('/^([a-f0-9]{4})$/', $param, $out)) {
- $cat = 'VENDOR';
- $host = $out[1];
- } elseif (preg_match('/^c\.([a-f0-9]{2})([a-f0-9]{2})$/', $param, $out)) {
- $cat = 'CLASS';
- $host = $out[2] . '.' . $out[1] . '.c';
- } else {
- die('Invalid format requested');
}
- $cached = Page_Statistics::getPciId($cat, $param);
- if ($cached !== false && $cached['dateline'] > time()) {
- echo $cached['value'], $add;
- exit;
+ $cached = PciId::getPciId(PciId::AUTO, $param, true);
+ if ($cached === false) {
+ $cached = 'Unknown';
}
- $res = dns_get_record($host . '.pci.id.ucw.cz', DNS_TXT);
- if (is_array($res)) {
- foreach ($res as $entry) {
- if (isset($entry['txt']) && substr($entry['txt'], 0, 2) === 'i=') {
- $string = substr($entry['txt'], 2);
- Page_Statistics::setPciId($cat, $param, $string);
- echo $string, $add;
- exit;
- }
- }
- }
- if ($cached !== false) {
- echo $cached['value'], $add;
- exit;
- }
- die('Not found');
- }
-
- public static function getPciId($cat, $id)
- {
- static $cache = [];
- $key = $cat . '-' . $id;
- if (isset($cache[$key]))
- return $cache[$key];
- return $cache[$key] = Database::queryFirst('SELECT value, dateline FROM pciid WHERE category = :cat AND id = :id LIMIT 1',
- array('cat' => $cat, 'id' => $id));
- }
-
- private static function setPciId($cat, $id, $value)
- {
- Database::exec('INSERT INTO pciid (category, id, value, dateline) VALUES (:cat, :id, :value, :timeout)'
- . ' ON DUPLICATE KEY UPDATE value = VALUES(value), dateline = VALUES(dateline)',
- array(
- 'cat' => $cat,
- 'id' => $id,
- 'value' => $value,
- 'timeout' => time() + mt_rand(10, 30) * 86400,
- ), true);
+ echo $cached, $add;
+ exit;
}
}