From db82c6326bcbf09bcb8f938728394bf39d4681a3 Mon Sep 17 00:00:00 2001 From: Steffen Ritter Date: Tue, 5 Sep 2017 16:25:33 +0200 Subject: [translation] Added translation for 'subnet' filter --- modules-available/statistics/lang/de/template-tags.json | 3 ++- modules-available/statistics/lang/en/template-tags.json | 3 ++- modules-available/statistics/templates/filterbox.html | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) (limited to 'modules-available/statistics') diff --git a/modules-available/statistics/lang/de/template-tags.json b/modules-available/statistics/lang/de/template-tags.json index e0be0d48..02c3e4d6 100644 --- a/modules-available/statistics/lang/de/template-tags.json +++ b/modules-available/statistics/lang/de/template-tags.json @@ -69,6 +69,7 @@ "lang_showList": "Liste", "lang_showVisualization": "Visualisierung", "lang_sockets": "Sockel", + "lang_subnet": "Subnetz", "lang_tempPart": "Temp. Partition", "lang_tempPartStats": "Tempor\u00e4re Partition", "lang_thoseAreProjectors": "Diese Modellnamen werden als Beamer behandelt, auch wenn die EDID-Informationen des Ger\u00e4tes anderes berichten.", @@ -81,4 +82,4 @@ "lang_virtualCores": "Virtuelle Kerne", "lang_when": "Wann", "lang_withBadSectors": "Clients mit potentiell defekten Festplatten (mehr als 10 defekte Sektoren)" -} \ No newline at end of file +} diff --git a/modules-available/statistics/lang/en/template-tags.json b/modules-available/statistics/lang/en/template-tags.json index 4a31a5ee..c097ce37 100644 --- a/modules-available/statistics/lang/en/template-tags.json +++ b/modules-available/statistics/lang/en/template-tags.json @@ -69,6 +69,7 @@ "lang_showList": "Show list", "lang_showVisualization": "Show visualization", "lang_sockets": "Sockets", + "lang_subnet": "Subnet", "lang_tempPart": "Temp. partition", "lang_tempPartStats": "Temporary partition", "lang_thoseAreProjectors": "These model names will always be treated as beamers, even if the device's EDID data says otherwise.", @@ -81,4 +82,4 @@ "lang_virtualCores": "Virtual cores", "lang_when": "When", "lang_withBadSectors": "Clients with potentially bad HDDs (more than 10 reallocated sectors)" -} \ No newline at end of file +} diff --git a/modules-available/statistics/templates/filterbox.html b/modules-available/statistics/templates/filterbox.html index 95fbab84..7cd0f617 100644 --- a/modules-available/statistics/templates/filterbox.html +++ b/modules-available/statistics/templates/filterbox.html @@ -75,7 +75,8 @@ var slxFilterNames = { clientip: '{{lang_ip}}', state: '{{lang_usageState}}', location: '{{lang_location}}', - currentuser: '{{lang_currentUser}}' + currentuser: '{{lang_currentUser}}', + subnet: '{{lang_subnet}}' }; slxLocations = {{{locations}}}; -- cgit v1.2.3-55-g7522 From 1ceddec798dd39ecb798a1c230c711db7d24db87 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 3 Nov 2017 13:29:40 +0100 Subject: [statistics] api: Allow specifying client type --- modules-available/statistics/api.inc.php | 69 +++++++++++++++++++------------- 1 file changed, 42 insertions(+), 27 deletions(-) (limited to 'modules-available/statistics') diff --git a/modules-available/statistics/api.inc.php b/modules-available/statistics/api.inc.php index 126c6e91..566b1d69 100644 --- a/modules-available/statistics/api.inc.php +++ b/modules-available/statistics/api.inc.php @@ -31,14 +31,17 @@ if ($type{0} === '~') { $uuid = $override; } } + // External mode of operation? + $mode = Request::post('mode', false, 'string'); $NOW = time(); - $old = Database::queryFirst('SELECT clientip, logintime, lastseen FROM machine WHERE machineuuid = :uuid', array('uuid' => $uuid)); + $old = Database::queryFirst('SELECT clientip, logintime, lastseen, lastboot FROM machine WHERE machineuuid = :uuid', array('uuid' => $uuid)); if ($old !== false) { settype($old['logintime'], 'integer'); settype($old['lastseen'], 'integer'); + settype($old['lastboot'], 'integer'); } // Handle event type - if ($type === '~poweron') { + if ($mode === false && $type === '~poweron') { // Poweron & hw stats $uptime = Request::post('uptime', '', 'integer'); if (strlen($macaddr) > 17) die("Invalid MAC.\n"); @@ -138,42 +141,54 @@ if ($type{0} === '~') { } else if ($type === '~runstate') { // Usage (occupied/free) $sessionLength = 0; - $used = Request::post('used', 0, 'integer'); if ($old === false) die("Unknown machine.\n"); if ($old['clientip'] !== $ip) { EventLog::warning("[runstate] IP address of client $uuid seems to have changed ({$old['clientip']} -> $ip)"); die("Address changed.\n"); } - // Figure out what's happening - if ($used === 0) { - // Is not in use + $used = Request::post('used', 0, 'integer'); + if ($old['lastboot'] === 0 && $NOW - $old['lastseen'] > 300) { + $strUpdateBoottime = ' lastboot = UNIX_TIMESTAMP(), '; + } else { + $strUpdateBoottime = ''; + } + // 1) Log last session length if we didn't see the machine for a while + if ($NOW - $old['lastseen'] > 610 && $old['lastseen'] !== 0) { + // Old session timed out - might be caused by hard reboot if ($old['logintime'] !== 0) { - // Was in use, is free now - // 1) Log last session length - if ($NOW - $old['lastseen'] > 610) { - // Old session timed out - might be caused by hard reboot + if ($old['lastseen'] > $old['logintime']) { $sessionLength = $old['lastseen'] - $old['logintime']; - } else { - $sessionLength = $NOW - $old['logintime']; } + $old['logintime'] = 0; } - Database::exec('UPDATE machine SET lastseen = UNIX_TIMESTAMP(), logintime = 0 WHERE machineuuid = :uuid', array('uuid' => $uuid)); - } else { - // Machine is in use - if ($old['logintime'] !== 0 && $NOW - $old['lastseen'] > 610) { - // Old session timed out - might be caused by hard reboot - $sessionLength = $old['lastseen'] - $old['logintime']; - } + $old['lastboot'] = 0; + } + // Figure out what's happening - state changes + if ($used === 0 && $old['logintime'] !== 0) { + // Is not in use, was in use before + $sessionLength = $NOW - $old['logintime']; + Database::exec('UPDATE machine SET lastseen = UNIX_TIMESTAMP(),' + . $strUpdateBoottime + . ' logintime = 0, currentuser = NULL WHERE machineuuid = :uuid', array('uuid' => $uuid)); + } elseif ($used === 1 && $old['logintime'] === 0) { + // Machine is in use, was free before if ($sessionLength !== 0 || $old['logintime'] === 0) { // This event is a start of a new session, rather than an update - Database::exec('UPDATE machine SET lastseen = UNIX_TIMESTAMP(), logintime = UNIX_TIMESTAMP() WHERE machineuuid = :uuid', array('uuid' => $uuid)); - } else { - // Nothing changed, simple lastseen update - Database::exec('UPDATE machine SET lastseen = UNIX_TIMESTAMP() WHERE machineuuid = :uuid', array('uuid' => $uuid)); + Database::exec('UPDATE machine SET lastseen = UNIX_TIMESTAMP(),' + . $strUpdateBoottime + . ' logintime = UNIX_TIMESTAMP(), currentuser = :user WHERE machineuuid = :uuid', array( + 'uuid' => $uuid, + 'user' => Request::post('user', null, 'string'), + )); } + } else { + // Nothing changed, simple lastseen update + Database::exec('UPDATE machine SET ' + . $strUpdateBoottime + . ' lastseen = UNIX_TIMESTAMP() WHERE machineuuid = :uuid', array('uuid' => $uuid)); } // 9) Log last session length if applicable - if ($sessionLength > 0 && $sessionLength < 86400*2 && $old['logintime'] !== 0) { + if ($mode === false && $sessionLength > 0 && $sessionLength < 86400*2 && $old['logintime'] !== 0) { Database::exec('INSERT INTO statistic (dateline, typeid, machineuuid, clientip, username, data)' . " VALUES (:start, '~session-length', :uuid, :clientip, '', :length)", array( 'start' => $old['logintime'], @@ -188,7 +203,7 @@ if ($type{0} === '~') { EventLog::warning("[poweroff] IP address of client $uuid seems to have changed ({$old['clientip']} -> $ip)"); die("Address changed.\n"); } - if ($old['logintime'] !== 0) { + if ($mode === false && $old['logintime'] !== 0) { $sessionLength = $old['lastseen'] - $old['logintime']; if ($sessionLength > 0 && $sessionLength < 86400*2) { Database::exec('INSERT INTO statistic (dateline, typeid, machineuuid, clientip, username, data)' @@ -201,7 +216,7 @@ if ($type{0} === '~') { } } Database::exec('UPDATE machine SET logintime = 0, lastseen = UNIX_TIMESTAMP(), lastboot = 0 WHERE machineuuid = :uuid', array('uuid' => $uuid)); - } elseif ($type === '~screens') { + } elseif ($mode === false && $type === '~screens') { $screens = Request::post('screen', false, 'array'); if (is_array($screens)) { // `devicetype`, `devicename`, `subid`, `machineuuid` @@ -273,7 +288,7 @@ if ($type{0} === '~') { } } } else { - die("INVALID ACTION '$type'"); + die("INVALID ACTION '$type'\n"); } die("OK. (RESULT=0)\n"); } -- cgit v1.2.3-55-g7522 From 83097db5279b319cd7b6631aad52c7ab43d0d11b Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 13 Nov 2017 23:38:56 +0100 Subject: [statistics] Show client details if filter has exactly one result --- modules-available/statistics/page.inc.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'modules-available/statistics') diff --git a/modules-available/statistics/page.inc.php b/modules-available/statistics/page.inc.php index 2b12c69f..479f3089 100644 --- a/modules-available/statistics/page.inc.php +++ b/modules-available/statistics/page.inc.php @@ -308,6 +308,14 @@ class Page_Statistics extends Page } } + private function redirectFirst($where, $join, $args) + { + $res = Database::queryFirst("SELECT machineuuid FROM machine $join WHERE ($where) LIMIT 1", $args); + if ($res !== false) { + Util::redirect('?do=statistics&uuid=' . $res['machineuuid']); + } + } + /** * @param \FilterSet $filterSet */ @@ -316,6 +324,10 @@ class Page_Statistics extends Page $filterSet->makeFragments($where, $join, $sort, $args); $known = Database::queryFirst("SELECT Count(*) AS val FROM machine $join WHERE ($where)", $args); + // If we only have one machine, redirect to machine details + if ($known['val'] == 1) { + $this->redirectFirst($where, $join, $args); + } $on = Database::queryFirst("SELECT Count(*) AS val FROM machine $join WHERE lastboot <> 0 AND ($where)", $args); $used = Database::queryFirst("SELECT Count(*) AS val FROM machine $join WHERE lastboot <> 0 AND logintime <> 0 AND ($where)", $args); $hdd = Database::queryFirst("SELECT Count(*) AS val FROM machine $join WHERE badsectors >= 10 AND ($where)", $args); @@ -565,7 +577,13 @@ class Page_Statistics extends Page . " $join WHERE $where $sort", $args); $rows = array(); $NOW = time(); + $singleMachine = 'none'; while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + if ($singleMachine === 'none') { + $singleMachine = $row['machineuuid']; + } else { + $singleMachine = false; + } if ($row['lastboot'] == 0) { $row['state_off'] = true; } elseif ($row['logintime'] == 0) { @@ -596,6 +614,9 @@ class Page_Statistics extends Page } $rows[] = $row; } + if ($singleMachine !== false && $singleMachine !== 'none') { + Util::redirect('?do=statistics&uuid=' . $singleMachine); + } Render::addTemplate('clientlist', array( 'rowCount' => count($rows), 'rows' => $rows, -- cgit v1.2.3-55-g7522 From 9f7e2c4c794495f2a32410fd373cc313e0b0d4cf Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 15 Nov 2017 15:16:51 +0100 Subject: [statistics&syslog] Fix possible cron delete query overflow --- modules-available/statistics/hooks/cron.inc.php | 17 ++++++++++++++--- modules-available/syslog/hooks/cron.inc.php | 5 ++++- 2 files changed, 18 insertions(+), 4 deletions(-) (limited to 'modules-available/statistics') diff --git a/modules-available/statistics/hooks/cron.inc.php b/modules-available/statistics/hooks/cron.inc.php index 94c65248..575ab6ba 100644 --- a/modules-available/statistics/hooks/cron.inc.php +++ b/modules-available/statistics/hooks/cron.inc.php @@ -1,8 +1,5 @@ 86400 * 190"); -Database::exec("DELETE FROM machine WHERE (UNIX_TIMESTAMP() - lastseen) > 86400 * 365"); - function logstats() { $NOW = time(); $cutoff = $NOW - 86400 * 30; @@ -15,4 +12,18 @@ function logstats() { 'vals' => $known['val'] . '#' . $on['val'] . '#' . $used['val'], )); } + logstats(); + +if (mt_rand(1, 10) === 1) { + Database::exec("DELETE FROM statistic WHERE (UNIX_TIMESTAMP() - 86400 * 190) > dateline"); + if (mt_rand(1, 100) === 1) { + Database::exec("OPTIMIZE TABLE statistic"); + } +} +if (mt_rand(1, 10) === 1) { + Database::exec("DELETE FROM machine WHERE (UNIX_TIMESTAMP() - 86400 * 365) > lastseen"); + if (mt_rand(1, 100) === 1) { + Database::exec("OPTIMIZE TABLE machine"); + } +} diff --git a/modules-available/syslog/hooks/cron.inc.php b/modules-available/syslog/hooks/cron.inc.php index c796675f..bae882a9 100644 --- a/modules-available/syslog/hooks/cron.inc.php +++ b/modules-available/syslog/hooks/cron.inc.php @@ -1,5 +1,8 @@ 86400 * 190"); + Database::exec("DELETE FROM clientlog WHERE (UNIX_TIMESTAMP() - 86400 * 190) > dateline"); + if (mt_rand(1, 100) === 1) { + Database::exec("OPTIMIZE TABLE clientlog"); + } } \ No newline at end of file -- cgit v1.2.3-55-g7522 From 6eca1321a35ba0b11b417cf1f58442a4e70e568d Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 21 Nov 2017 14:46:38 +0100 Subject: [statistics] Also adapt MAC-UUID fixing code to mltk changes Refs #3227 --- modules-available/statistics/api.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules-available/statistics') diff --git a/modules-available/statistics/api.inc.php b/modules-available/statistics/api.inc.php index 566b1d69..c395220a 100644 --- a/modules-available/statistics/api.inc.php +++ b/modules-available/statistics/api.inc.php @@ -16,7 +16,7 @@ if ($type{0} === '~') { $uuid = Request::post('uuid', '', 'string'); if (strlen($uuid) !== 36) die("Invalid UUID.\n"); $macaddr = Request::post('macaddr', '', 'string'); - if (!empty($macaddr) && substr($uuid, 0, 16) === '000000000000000-') { + if (!empty($macaddr) && substr($uuid, 0, 16) === '000000000000001-') { // Override uuid if the mac is known and unique $res = Database::simpleQuery('SELECT machineuuid FROM machine WHERE macaddr = :macaddr AND machineuuid <> :uuid', compact('macaddr', 'uuid')); $override = false; -- cgit v1.2.3-55-g7522