From cd55ead3e2810e209b726faca12fa749f6875d0f Mon Sep 17 00:00:00 2001
From: Simon Rettberg
Date: Sat, 16 Dec 2017 18:33:16 +0100
Subject: Fix A LOT of type problems, logic flaws, uninitialized variables etc.
Most of them were found by phpstorm, so I put in some time and
went through the list, fixing quite a bunch of them.
---
modules-available/statistics/inc/parser.inc.php | 3 +--
modules-available/statistics/page.inc.php | 7 +++----
modules-available/statistics/templates/filterbox.html | 7 ++++---
3 files changed, 8 insertions(+), 9 deletions(-)
(limited to 'modules-available/statistics')
diff --git a/modules-available/statistics/inc/parser.inc.php b/modules-available/statistics/inc/parser.inc.php
index acf6ebd4..679055a7 100644
--- a/modules-available/statistics/inc/parser.inc.php
+++ b/modules-available/statistics/inc/parser.inc.php
@@ -99,8 +99,8 @@ class Parser {
$hdds = array();
// Could have more than one disk - linear scan
$lines = preg_split("/[\r\n]+/", $data);
- $dev = false;
$i = 0;
+ $mbrToMbFactor = $sectorToMbFactor = 0;
foreach ($lines as $line) {
if (preg_match('/^Disk (\S+):.* (\d+) bytes/i', $line, $out)) {
// --- Beginning of MBR disk ---
@@ -260,7 +260,6 @@ class Parser {
public static function parseSmartctl(&$hdds, $data)
{
$lines = preg_split("/[\r\n]+/", $data);
- $i = 0;
foreach ($lines as $line) {
if (preg_match('/^NEXTHDD=(.+)$/', $line, $out)) {
unset($dev);
diff --git a/modules-available/statistics/page.inc.php b/modules-available/statistics/page.inc.php
index c3ecf52b..bd67123e 100644
--- a/modules-available/statistics/page.inc.php
+++ b/modules-available/statistics/page.inc.php
@@ -622,7 +622,6 @@ class Page_Statistics extends Page
. ' badsectors ' . $xtra . ' FROM machine'
. " $join WHERE $where $sort", $args);
$rows = array();
- $NOW = time();
$singleMachine = 'none';
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
if ($singleMachine === 'none') {
@@ -894,7 +893,7 @@ class Page_Statistics extends Page
continue; // Don't differentiate between session and idle for non-clients
if ($first && $row['dateline'] > $cutoff && $client['lastboot'] > $cutoff) {
// Special case: offline before
- $spans['graph'] .= '
';
+ $spans['graph'] .= '
';
}
$first = false;
if ($row['dateline'] + $row['data'] < $cutoff || $row['data'] > 864000) {
@@ -931,10 +930,10 @@ class Page_Statistics extends Page
}
if ($first && $client['lastboot'] > $cutoff) {
// Special case: offline before
- $spans['graph'] .= '
';
+ $spans['graph'] .= '
';
} elseif ($first) {
// Not seen in last two weeks
- $spans['graph'] .= '
';
+ $spans['graph'] .= '
';
}
if (isset($client['state_occupied'])) {
$spans['graph'] .= '
';
diff --git a/modules-available/statistics/templates/filterbox.html b/modules-available/statistics/templates/filterbox.html
index 31daabc6..32464031 100644
--- a/modules-available/statistics/templates/filterbox.html
+++ b/modules-available/statistics/templates/filterbox.html
@@ -105,6 +105,7 @@ var slxFilterNames = {
slxLocations = {{{locations}}};
var slxFilterDel = '{{delimiter}}';
+var $modal, $queryForm;
document.addEventListener("DOMContentLoaded", function () {
@@ -217,7 +218,7 @@ function popupFilter(field) {
function addFilterFromForm() {
var argument1 = $('#argumentInput').val();
var argument2 = $('#argumentSelect').val();
- var argument = argument1 == '' ? argument2 : argument1;
+ var argument = argument1 ? argument1 : argument2;
var col = $('#columnSelect').val();
var op = $('#operatorSelect').val();
@@ -246,8 +247,8 @@ function toggleSort(field) {
/* equal sign should always be first, the rest doesn't matter*/
function myOpSort(a,b) {
- if (a == '=') { return -1; }
- else if (a == b) {return 0}
+ if (a === '=') { return -1; }
+ else if (a === b) {return 0}
else { return 1;}
}
--
cgit v1.2.3-55-g7522
From 8d8362dd7ce06c4f9771c619ec4f2625ff82b877 Mon Sep 17 00:00:00 2001
From: Simon Rettberg
Date: Thu, 21 Dec 2017 13:23:18 +0100
Subject: [statistics] Properly mark disconnected sceens as such if the output
name changed
---
modules-available/statistics/api.inc.php | 46 +++++----
modules-available/statistics/page.inc.php | 113 ++++++++-------------
.../statistics/pages/projectors.inc.php | 58 +++++++++++
.../statistics/templates/machine-main.html | 4 +-
.../statistics/templates/page-replace.html | 104 +++++++++++++++++++
.../statistics/templates/projector-list.html | 2 +-
6 files changed, 239 insertions(+), 88 deletions(-)
create mode 100644 modules-available/statistics/pages/projectors.inc.php
create mode 100644 modules-available/statistics/templates/page-replace.html
(limited to 'modules-available/statistics')
diff --git a/modules-available/statistics/api.inc.php b/modules-available/statistics/api.inc.php
index a614658a..3cb1e961 100644
--- a/modules-available/statistics/api.inc.php
+++ b/modules-available/statistics/api.inc.php
@@ -263,6 +263,7 @@ if ($type{0} === '~') {
// `devicetype`, `devicename`, `subid`, `machineuuid`
// Make sure all screens are in the general hardware table
$hwids = array();
+ $ports = array();
foreach ($screens as $port => $screen) {
if (!array_key_exists('name', $screen))
continue;
@@ -274,6 +275,7 @@ if ($type{0} === '~') {
$hwids[$screen['name']] = $hwid;
}
// Now add new entries
+ $ports[] = $port;
$machinehwid = Database::insertIgnore('machine_x_hw', 'machinehwid', array(
'hwid' => $hwid,
'machineuuid' => $uuid,
@@ -302,30 +304,40 @@ if ($type{0} === '~') {
Database::exec("DELETE FROM machine_x_hw_prop WHERE machinehwid = :machinehwid AND prop NOT LIKE '@%'",
array('machinehwid' => $machinehwid));
} else {
- $qs = '?' . str_repeat(',?', count($validProps) - 1);
- array_unshift($validProps, $machinehwid);
- Database::exec("DELETE FROM machine_x_hw_prop"
- . " WHERE machinehwid = ? AND prop NOT LIKE '@%' AND prop NOT IN ($qs)",
- $validProps);
+ Database::exec("DELETE FROM machine_x_hw_prop
+ WHERE machinehwid = :mhwid AND prop NOT LIKE '@%' AND prop NOT IN (:props)", array(
+ 'mhwid' => $machinehwid,
+ 'props' => array_values($validProps),
+ ));
}
}
// Remove/disable stale entries
- if (empty($hwids)) {
+ if (empty($ports)) {
// No screens connected at all, purge all screen entries for this machine
- Database::exec("UPDATE machine_x_hw x, statistic_hw h"
- . " SET x.disconnecttime = UNIX_TIMESTAMP()"
- . " WHERE x.machineuuid = :uuid AND x.hwid = h.hwid AND h.hwtype = :type AND x.disconnecttime = 0",
+ Database::exec("UPDATE machine_x_hw x, statistic_hw h
+ SET x.disconnecttime = UNIX_TIMESTAMP()
+ WHERE x.machineuuid = :uuid AND x.hwid = h.hwid AND h.hwtype = :type AND x.disconnecttime = 0",
array('uuid' => $uuid, 'type' => DeviceType::SCREEN));
} else {
// Some screens connected, make sure old entries get removed
- $params = array_values($hwids);
- array_unshift($params, $uuid);
- array_unshift($params, DeviceType::SCREEN);
- $qs = '?' . str_repeat(',?', count($hwids) - 1);
- Database::exec("UPDATE machine_x_hw x, statistic_hw h"
- . " SET x.disconnecttime = UNIX_TIMESTAMP()"
- . " WHERE h.hwid = x.hwid AND x.disconnecttime = 0 AND h.hwtype = ? AND x.machineuuid = ? AND x.hwid NOT IN ($qs)", $params);
-
+ Database::exec("UPDATE machine_x_hw x, statistic_hw h
+ SET x.disconnecttime = UNIX_TIMESTAMP()
+ WHERE h.hwid = x.hwid AND x.disconnecttime = 0 AND h.hwtype = :type
+ AND x.machineuuid = :uuid AND x.devpath NOT IN (:ports)", array(
+ 'ports' => array_values($ports),
+ 'uuid' => $uuid,
+ 'type' => DeviceType::SCREEN,
+ ));
+ if (!empty($hwids)) {
+ Database::exec("UPDATE machine_x_hw x, statistic_hw h
+ SET x.disconnecttime = UNIX_TIMESTAMP()
+ WHERE h.hwid = x.hwid AND x.disconnecttime = 0 AND h.hwtype = :type
+ AND x.machineuuid = :uuid AND x.hwid NOT IN (:hwids)", array(
+ 'hwids' => array_values($hwids),
+ 'uuid' => $uuid,
+ 'type' => DeviceType::SCREEN,
+ ));
+ }
}
}
} else if ($type === '~suspend') {
diff --git a/modules-available/statistics/page.inc.php b/modules-available/statistics/page.inc.php
index bd67123e..ea5b6f03 100644
--- a/modules-available/statistics/page.inc.php
+++ b/modules-available/statistics/page.inc.php
@@ -21,6 +21,11 @@ class Page_Statistics extends Page
private $query;
+ /**
+ * @var bool whether we have a SubPage from the pages/ subdir
+ */
+ private $haveSubpage;
+
/* PHP sucks, no static, const array definitions... Or am I missing something? */
public function initConstants()
{
@@ -125,53 +130,6 @@ class Page_Statistics extends Page
/* TODO ... */
}
- /*
- * TODO: Move to separate unit... hardware configurator?
- */
-
- protected function handleProjector($action)
- {
- $hwid = Request::post('hwid', false, 'int');
- if ($hwid === false) {
- Util::traceError('Param hwid missing');
- }
- if ($action === 'addprojector') {
- Database::exec('INSERT INTO statistic_hw_prop (hwid, prop, value)'
- . ' VALUES (:hwid, :prop, :value)', array(
- 'hwid' => $hwid,
- 'prop' => 'projector',
- 'value' => 'true',
- ));
- } else {
- Database::exec('DELETE FROM statistic_hw_prop WHERE hwid = :hwid AND prop = :prop', array(
- 'hwid' => $hwid,
- 'prop' => 'projector',
- ));
- }
- if (Module::isAvailable('sysconfig')) {
- ConfigTgz::rebuildAllConfigs();
- }
- Util::redirect('?do=statistics&show=projectors');
- }
-
- protected function showProjectors()
- {
- $res = Database::simpleQuery('SELECT h.hwname, h.hwid FROM statistic_hw h'
- . " INNER JOIN statistic_hw_prop p ON (h.hwid = p.hwid AND p.prop = :projector)"
- . " WHERE h.hwtype = :screen ORDER BY h.hwname ASC", array(
- 'projector' => 'projector',
- 'screen' => DeviceType::SCREEN,
- ));
- $data = array(
- 'projectors' => $res->fetchAll(PDO::FETCH_ASSOC)
- );
- Render::addTemplate('projector-list', $data);
- }
-
- /*
- * End TODO
- */
-
protected function doPreprocess()
{
$this->initConstants();
@@ -180,24 +138,42 @@ class Page_Statistics extends Page
Message::addError('main.no-permission');
Util::redirect('?do=Main');
}
- $action = Request::post('action');
- if ($action === 'setnotes') {
- $uuid = Request::post('uuid', '', 'string');
- $text = Request::post('content', '', 'string');
- if (empty($text)) {
- $text = null;
+
+ $show = Request::any('show', 'stat', 'string');
+ $show = preg_replace('/[^a-z0-9_\-]/', '', $show);
+
+ if (file_exists('modules/statistics/pages/' . $show . '.inc.php')) {
+
+ require_once 'modules/statistics/pages/' . $show . '.inc.php';
+ $this->haveSubpage = true;
+ SubPage::doPreprocess();
+
+ } else {
+
+ $action = Request::post('action');
+ if ($action === 'setnotes') {
+ $uuid = Request::post('uuid', '', 'string');
+ $text = Request::post('content', '', 'string');
+ if (empty($text)) {
+ $text = null;
+ }
+ Database::exec('UPDATE machine SET notes = :text WHERE machineuuid = :uuid', array(
+ 'uuid' => $uuid,
+ 'text' => $text,
+ ));
+ Message::addSuccess('notes-saved');
+ Util::redirect('?do=Statistics&uuid=' . $uuid);
+ } elseif ($action === 'delmachines') {
+ $this->deleteMachines();
+ Util::redirect('?do=statistics', true);
}
- Database::exec('UPDATE machine SET notes = :text WHERE machineuuid = :uuid', array(
- 'uuid' => $uuid,
- 'text' => $text,
- ));
- Message::addSuccess('notes-saved');
- Util::redirect('?do=Statistics&uuid=' . $uuid);
- } elseif ($action === 'addprojector' || $action === 'delprojector') {
- $this->handleProjector($action);
- } elseif ($action === 'delmachines') {
- $this->deleteMachines();
- Util::redirect('?do=statistics', true);
+
+ }
+
+ if (Request::isPost()) {
+ // Make sure we don't render any content for POST requests - should be handled above and then
+ // redirected properly
+ Util::redirect('?do=statistics');
}
}
@@ -229,6 +205,11 @@ class Page_Statistics extends Page
protected function doRender()
{
+ if ($this->haveSubpage) {
+ SubPage::doRender();
+ return;
+ }
+
$uuid = Request::get('uuid', false, 'string');
if ($uuid !== false) {
$this->showMachine($uuid);
@@ -236,10 +217,6 @@ class Page_Statistics extends Page
}
$show = Request::get('show', 'stat', 'string');
- if ($show === 'projectors') {
- $this->showProjectors();
- return;
- }
/* read filter */
$this->query = Request::any('filters', false);
diff --git a/modules-available/statistics/pages/projectors.inc.php b/modules-available/statistics/pages/projectors.inc.php
new file mode 100644
index 00000000..cde542c6
--- /dev/null
+++ b/modules-available/statistics/pages/projectors.inc.php
@@ -0,0 +1,58 @@
+ $hwid,
+ 'prop' => 'projector',
+ 'value' => 'true',
+ ));
+ } else {
+ Database::exec('DELETE FROM statistic_hw_prop WHERE hwid = :hwid AND prop = :prop', array(
+ 'hwid' => $hwid,
+ 'prop' => 'projector',
+ ));
+ }
+ if (Module::isAvailable('sysconfig')) {
+ ConfigTgz::rebuildAllConfigs();
+ }
+ Util::redirect('?do=statistics&show=projectors');
+ }
+
+ public static function doRender()
+ {
+ self::showProjectors();
+ }
+
+ private static function showProjectors()
+ {
+ $res = Database::simpleQuery('SELECT h.hwname, h.hwid FROM statistic_hw h'
+ . " INNER JOIN statistic_hw_prop p ON (h.hwid = p.hwid AND p.prop = :projector)"
+ . " WHERE h.hwtype = :screen ORDER BY h.hwname ASC", array(
+ 'projector' => 'projector',
+ 'screen' => DeviceType::SCREEN,
+ ));
+ $data = array(
+ 'projectors' => $res->fetchAll(PDO::FETCH_ASSOC)
+ );
+ Render::addTemplate('projector-list', $data);
+ }
+
+}
\ No newline at end of file
diff --git a/modules-available/statistics/templates/machine-main.html b/modules-available/statistics/templates/machine-main.html
index 19deb8b3..d8f2c521 100644
--- a/modules-available/statistics/templates/machine-main.html
+++ b/modules-available/statistics/templates/machine-main.html
@@ -144,11 +144,11 @@
{{lang_screens}} |
-
-
diff --git a/modules-available/statistics/templates/page-replace.html b/modules-available/statistics/templates/page-replace.html
new file mode 100644
index 00000000..f87610a2
--- /dev/null
+++ b/modules-available/statistics/templates/page-replace.html
@@ -0,0 +1,104 @@
+{{lang_replaceMachinesHeading}}
+
+
+
+
+
+
\ No newline at end of file
diff --git a/modules-available/statistics/templates/projector-list.html b/modules-available/statistics/templates/projector-list.html
index bc9ecdbd..c33aae09 100644
--- a/modules-available/statistics/templates/projector-list.html
+++ b/modules-available/statistics/templates/projector-list.html
@@ -1,7 +1,7 @@
|