From c415a9374872c6235fe822a5e038546522817e3a Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 21 Mar 2017 12:18:47 +0100 Subject: Fix a couple of warnings and notices from error.log --- modules-available/statistics_reporting/inc/remotereport.inc.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'modules-available/statistics_reporting') diff --git a/modules-available/statistics_reporting/inc/remotereport.inc.php b/modules-available/statistics_reporting/inc/remotereport.inc.php index 7aad8b3a..a2234849 100644 --- a/modules-available/statistics_reporting/inc/remotereport.inc.php +++ b/modules-available/statistics_reporting/inc/remotereport.inc.php @@ -40,7 +40,7 @@ class RemoteReport if ($ts === 0) { // No timestamp stored yet - might be a fresh install // schedule for next time - self::updateNextReportingTimestamp(); + self::writeNextReportingTimestamp(); $ts = Property::get(self::NEXT_SUBMIT_ID, 0); } elseif ($ts < strtotime('last monday')) { // Too long ago, move forward to last monday @@ -63,14 +63,14 @@ class RemoteReport * Generate the multi-dimensional array containing the anonymized * (weekly) statistics to report. * - * @param $from start timestamp - * @param $to end timestamp + * @param int $from start timestamp + * @param int $to end timestamp * @return array wrapped up statistics, ready for reporting */ public static function generateReport($from, $to) { GetData::$from = $from; GetData::$to = $to; - GetData::$salt = bin2hex(Util::randomBytes(20)); + GetData::$salt = bin2hex(Util::randomBytes(20, false)); $data = GetData::total(GETDATA_ANONYMOUS); $data['perLocation'] = GetData::perLocation(GETDATA_ANONYMOUS); $data['perClient'] = GetData::perClient(GETDATA_ANONYMOUS); -- cgit v1.2.3-55-g7522 From 09d0d4957f0013c0b83843ccf5e254d0e395518e Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 21 Mar 2017 14:42:11 +0100 Subject: [statistics_reporting] cron: Write message to event log on successful submit --- modules-available/statistics_reporting/hooks/cron.inc.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'modules-available/statistics_reporting') diff --git a/modules-available/statistics_reporting/hooks/cron.inc.php b/modules-available/statistics_reporting/hooks/cron.inc.php index a48f74c2..45f39719 100644 --- a/modules-available/statistics_reporting/hooks/cron.inc.php +++ b/modules-available/statistics_reporting/hooks/cron.inc.php @@ -18,6 +18,8 @@ if (RemoteReport::isReportingEnabled()) { if ($code != 200) { EventLog::warning("Statistics Reporting failed: " . $code, $result); + } else { + EventLog::info('Statistics report sent to ' . CONFIG_REPORTING_URL); } } } \ No newline at end of file -- cgit v1.2.3-55-g7522 From 62b5d166578c227f375c406d1c11c5d81ebb30eb Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 3 Apr 2017 12:36:17 +0200 Subject: [statistics_reporting] Don't return so many NULL fields from queries --- modules-available/statistics_reporting/inc/queries.inc.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules-available/statistics_reporting') diff --git a/modules-available/statistics_reporting/inc/queries.inc.php b/modules-available/statistics_reporting/inc/queries.inc.php index 3e944c92..bf28a592 100644 --- a/modules-available/statistics_reporting/inc/queries.inc.php +++ b/modules-available/statistics_reporting/inc/queries.inc.php @@ -8,7 +8,7 @@ class Queries public static function getClientStatistics($from, $to, $lowerTimeBound = 0, $upperTimeBound = 24, $excludeToday = false) { $notassigned = Dictionary::translate('notAssigned', true); Database::exec("SET SESSION group_concat_max_len = 1000000000"); - $res = Database::simpleQuery("SELECT name AS clientName, timeSum, medianSessionLength, offlineSum, IFNULL(lastStart, 0) as lastStart, IFNULL(lastLogout, 0) as lastLogout, longSessions, shortSessions, locId, locName, MD5(CONCAT(locId, :salt)) AS locHash, MD5(CONCAT(t1.uuid, :salt)) AS clientHash FROM ( + $res = Database::simpleQuery("SELECT t2.name AS clientName, timeSum, medianSessionLength, offlineSum, IFNULL(lastStart, 0) as lastStart, IFNULL(lastLogout, 0) as lastLogout, longSessions, shortSessions, t2.locId, t2.locName, MD5(CONCAT(t2.locId, :salt)) AS locHash, MD5(CONCAT(t2.uuid, :salt)) AS clientHash FROM ( SELECT machine.machineuuid AS 'uuid', SUM(CAST(sessionTable.length AS UNSIGNED)) AS 'timeSum', GROUP_CONCAT(sessionTable.length) AS 'medianSessionLength', SUM(sessionTable.length >= 60) AS 'longSessions', SUM(sessionTable.length < 60) AS 'shortSessions', MAX(sessionTable.endInBound) AS 'lastLogout' FROM ".self::getBoundedTableQueryString('~session-length', $from, $to, $lowerTimeBound, $upperTimeBound)." sessionTable INNER JOIN machine ON sessionTable.machineuuid = machine.machineuuid @@ -30,7 +30,7 @@ class Queries public static function getLocationStatistics($from, $to, $lowerTimeBound = 0, $upperTimeBound = 24, $excludeToday = false) { $notassigned = Dictionary::translate('notAssigned', true); Database::exec("SET SESSION group_concat_max_len = 1000000000"); - $res = Database::simpleQuery("SELECT t1.locId, locName AS locName, MD5(CONCAT(t1.locId, :salt)) AS locHash, timeSum, medianSessionLength, offlineSum, longSessions, shortSessions FROM ( + $res = Database::simpleQuery("SELECT t2.locId, t2.locName, MD5(CONCAT(t2.locId, :salt)) AS locHash, timeSum, medianSessionLength, offlineSum, longSessions, shortSessions FROM ( SELECT location.locationid AS 'locId', SUM(CAST(sessionTable.length AS UNSIGNED)) AS 'timeSum', GROUP_CONCAT(sessionTable.length) AS 'medianSessionLength', SUM(sessionTable.length >= 60) AS 'longSessions', SUM(sessionTable.length < 60) AS 'shortSessions' FROM ".self::getBoundedTableQueryString('~session-length', $from, $to, $lowerTimeBound, $upperTimeBound)." sessionTable INNER JOIN machine ON sessionTable.machineuuid = machine.machineuuid -- cgit v1.2.3-55-g7522 From 3cd3abab1a33459d3613fa342cbd8fd9135b1202 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 3 Apr 2017 13:51:34 +0200 Subject: [statistics_reporting] Convert NULL to 0 so stupidtable doesn't mess up --- modules-available/statistics_reporting/inc/getdata.inc.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'modules-available/statistics_reporting') diff --git a/modules-available/statistics_reporting/inc/getdata.inc.php b/modules-available/statistics_reporting/inc/getdata.inc.php index f65ee868..a167c2e5 100644 --- a/modules-available/statistics_reporting/inc/getdata.inc.php +++ b/modules-available/statistics_reporting/inc/getdata.inc.php @@ -40,6 +40,7 @@ class GetData $res = Queries::getLocationStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound); $data = array(); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + self::nullToZero($row); $median = self::calcMedian(self::calcMedian($row['medianSessionLength'])); $entry = array( 'location' => ($anonymize ? $row['locHash'] : $row['locName']), @@ -69,6 +70,7 @@ class GetData $res = Queries::getClientStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound); $data = array(); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + self::nullToZero($row); $median = self::calcMedian(self::calcMedian($row['medianSessionLength'])); $entry = array( 'hostname' => ($anonymize ? $row['clientHash'] : $row['clientName']), @@ -116,12 +118,20 @@ class GetData $data = array(); $vm = $anonymize ? 'vmHash' : 'name'; while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + self::nullToZero($row); $data[] = array('vm' => $row[$vm], 'sessions' => $row['count']); } return $data; } - + private function nullToZero(&$row) + { + foreach ($row as &$field) { + if (is_null($field)) { + $field = 0; + } + } + } // Format $seconds into ".d .h .m .s" format (day, hour, minute, second) private static function formatSeconds($seconds) -- cgit v1.2.3-55-g7522 From 136ba2c3736f8e5d47ebc4f8b5f44a16da57784c Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 3 Apr 2017 13:56:34 +0200 Subject: [statistics_reporting] Sort by first sortable column by default --- modules-available/statistics_reporting/templates/columnChooser.html | 2 ++ 1 file changed, 2 insertions(+) (limited to 'modules-available/statistics_reporting') diff --git a/modules-available/statistics_reporting/templates/columnChooser.html b/modules-available/statistics_reporting/templates/columnChooser.html index f08daf1c..a5ac828b 100644 --- a/modules-available/statistics_reporting/templates/columnChooser.html +++ b/modules-available/statistics_reporting/templates/columnChooser.html @@ -150,6 +150,8 @@ updateColumn(box); } }); + + $('th[data-sort]').first().click(); }); function updateColumn(checkbox) { -- cgit v1.2.3-55-g7522 From 0b0579fd2fdfd2d1f19e2d6ff51ddc49401da604 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 3 Apr 2017 13:58:13 +0200 Subject: [statistics_reporting] Fallback to ip if client has no hostname --- modules-available/statistics_reporting/inc/queries.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules-available/statistics_reporting') diff --git a/modules-available/statistics_reporting/inc/queries.inc.php b/modules-available/statistics_reporting/inc/queries.inc.php index bf28a592..f00138ec 100644 --- a/modules-available/statistics_reporting/inc/queries.inc.php +++ b/modules-available/statistics_reporting/inc/queries.inc.php @@ -15,7 +15,7 @@ class Queries GROUP BY machine.machineuuid ) t1 RIGHT JOIN ( - SELECT machine.hostname AS 'name', machine.machineuuid AS 'uuid', SUM(CAST(offlineTable.length AS UNSIGNED)) AS 'offlineSum', MAX(offlineTable.endInBound) AS 'lastStart', IFNULL(location.locationname, '$notassigned') AS 'locName', location.locationid AS 'locId' + SELECT IF(machine.hostname = '', machine.clientip, machine.hostname) AS 'name', machine.machineuuid AS 'uuid', SUM(CAST(offlineTable.length AS UNSIGNED)) AS 'offlineSum', MAX(offlineTable.endInBound) AS 'lastStart', IFNULL(location.locationname, '$notassigned') AS 'locName', location.locationid AS 'locId' FROM ".self::getBoundedTableQueryString('~offline-length', $from, $to, $lowerTimeBound, $upperTimeBound)." offlineTable INNER JOIN machine ON offlineTable.machineuuid = machine.machineuuid LEFT JOIN location ON machine.locationid = location.locationid -- cgit v1.2.3-55-g7522 From 3a94f3629aada7197caafc696a86eada598648f1 Mon Sep 17 00:00:00 2001 From: Udo Walter Date: Tue, 4 Apr 2017 16:11:03 +0200 Subject: [statistics_reporting] fixed clients/locations without offline-length entries not showing --- modules-available/statistics_reporting/inc/getdata.inc.php | 2 +- modules-available/statistics_reporting/inc/queries.inc.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'modules-available/statistics_reporting') diff --git a/modules-available/statistics_reporting/inc/getdata.inc.php b/modules-available/statistics_reporting/inc/getdata.inc.php index a167c2e5..da3a9a26 100644 --- a/modules-available/statistics_reporting/inc/getdata.inc.php +++ b/modules-available/statistics_reporting/inc/getdata.inc.php @@ -124,7 +124,7 @@ class GetData return $data; } - private function nullToZero(&$row) + private static function nullToZero(&$row) { foreach ($row as &$field) { if (is_null($field)) { diff --git a/modules-available/statistics_reporting/inc/queries.inc.php b/modules-available/statistics_reporting/inc/queries.inc.php index f00138ec..2269e764 100644 --- a/modules-available/statistics_reporting/inc/queries.inc.php +++ b/modules-available/statistics_reporting/inc/queries.inc.php @@ -11,13 +11,13 @@ class Queries $res = Database::simpleQuery("SELECT t2.name AS clientName, timeSum, medianSessionLength, offlineSum, IFNULL(lastStart, 0) as lastStart, IFNULL(lastLogout, 0) as lastLogout, longSessions, shortSessions, t2.locId, t2.locName, MD5(CONCAT(t2.locId, :salt)) AS locHash, MD5(CONCAT(t2.uuid, :salt)) AS clientHash FROM ( SELECT machine.machineuuid AS 'uuid', SUM(CAST(sessionTable.length AS UNSIGNED)) AS 'timeSum', GROUP_CONCAT(sessionTable.length) AS 'medianSessionLength', SUM(sessionTable.length >= 60) AS 'longSessions', SUM(sessionTable.length < 60) AS 'shortSessions', MAX(sessionTable.endInBound) AS 'lastLogout' FROM ".self::getBoundedTableQueryString('~session-length', $from, $to, $lowerTimeBound, $upperTimeBound)." sessionTable - INNER JOIN machine ON sessionTable.machineuuid = machine.machineuuid + RIGHT JOIN machine ON sessionTable.machineuuid = machine.machineuuid GROUP BY machine.machineuuid ) t1 RIGHT JOIN ( SELECT IF(machine.hostname = '', machine.clientip, machine.hostname) AS 'name', machine.machineuuid AS 'uuid', SUM(CAST(offlineTable.length AS UNSIGNED)) AS 'offlineSum', MAX(offlineTable.endInBound) AS 'lastStart', IFNULL(location.locationname, '$notassigned') AS 'locName', location.locationid AS 'locId' FROM ".self::getBoundedTableQueryString('~offline-length', $from, $to, $lowerTimeBound, $upperTimeBound)." offlineTable - INNER JOIN machine ON offlineTable.machineuuid = machine.machineuuid + RIGHT JOIN machine ON offlineTable.machineuuid = machine.machineuuid LEFT JOIN location ON machine.locationid = location.locationid GROUP BY machine.machineuuid ) t2 @@ -33,14 +33,14 @@ class Queries $res = Database::simpleQuery("SELECT t2.locId, t2.locName, MD5(CONCAT(t2.locId, :salt)) AS locHash, timeSum, medianSessionLength, offlineSum, longSessions, shortSessions FROM ( SELECT location.locationid AS 'locId', SUM(CAST(sessionTable.length AS UNSIGNED)) AS 'timeSum', GROUP_CONCAT(sessionTable.length) AS 'medianSessionLength', SUM(sessionTable.length >= 60) AS 'longSessions', SUM(sessionTable.length < 60) AS 'shortSessions' FROM ".self::getBoundedTableQueryString('~session-length', $from, $to, $lowerTimeBound, $upperTimeBound)." sessionTable - INNER JOIN machine ON sessionTable.machineuuid = machine.machineuuid + RIGHT JOIN machine ON sessionTable.machineuuid = machine.machineuuid LEFT JOIN location ON machine.locationid = location.locationid GROUP BY machine.locationid ) t1 RIGHT JOIN ( SELECT IFNULL(location.locationname, '$notassigned') AS 'locName', location.locationid AS 'locId', SUM(CAST(offlineTable.length AS UNSIGNED)) AS 'offlineSum' FROM ".self::getBoundedTableQueryString('~offline-length', $from, $to, $lowerTimeBound, $upperTimeBound)." offlineTable - INNER JOIN machine ON offlineTable.machineuuid = machine.machineuuid + RIGHT JOIN machine ON offlineTable.machineuuid = machine.machineuuid LEFT JOIN location ON machine.locationid = location.locationid GROUP BY machine.locationid ) t2 -- cgit v1.2.3-55-g7522 From 6b1a519b152d6a7a92c527220569f53ed0b95a70 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 10 Apr 2017 12:32:37 +0200 Subject: [statistics_reporting] Don't include perUser and perClient in remote report --- modules-available/statistics_reporting/inc/remotereport.inc.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'modules-available/statistics_reporting') diff --git a/modules-available/statistics_reporting/inc/remotereport.inc.php b/modules-available/statistics_reporting/inc/remotereport.inc.php index a2234849..4c5f604b 100644 --- a/modules-available/statistics_reporting/inc/remotereport.inc.php +++ b/modules-available/statistics_reporting/inc/remotereport.inc.php @@ -73,8 +73,6 @@ class RemoteReport GetData::$salt = bin2hex(Util::randomBytes(20, false)); $data = GetData::total(GETDATA_ANONYMOUS); $data['perLocation'] = GetData::perLocation(GETDATA_ANONYMOUS); - $data['perClient'] = GetData::perClient(GETDATA_ANONYMOUS); - $data['perUser'] = GetData::perUser(GETDATA_ANONYMOUS); $data['perVM'] = GetData::perVM(GETDATA_ANONYMOUS); $data['tsFrom'] = $from; $data['tsTo'] = $to; -- cgit v1.2.3-55-g7522 From 106bc16250bf7fb99a451d64783f705aa6ac212d Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 10 Apr 2017 14:45:33 +0200 Subject: [statistics_reporting] Send backlogged reports in cronjob --- modules-available/statistics_reporting/hooks/cron.inc.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'modules-available/statistics_reporting') diff --git a/modules-available/statistics_reporting/hooks/cron.inc.php b/modules-available/statistics_reporting/hooks/cron.inc.php index 45f39719..afb18a23 100644 --- a/modules-available/statistics_reporting/hooks/cron.inc.php +++ b/modules-available/statistics_reporting/hooks/cron.inc.php @@ -4,7 +4,7 @@ if (RemoteReport::isReportingEnabled()) { $nextReporting = RemoteReport::getReportingTimestamp(); // It's time to generate a new report - if ($nextReporting <= time()) { + while ($nextReporting <= time()) { RemoteReport::writeNextReportingTimestamp(); $from = strtotime("-7 days", $nextReporting); @@ -21,5 +21,6 @@ if (RemoteReport::isReportingEnabled()) { } else { EventLog::info('Statistics report sent to ' . CONFIG_REPORTING_URL); } + $nextReporting = strtotime("+7 days", $nextReporting); } } \ No newline at end of file -- cgit v1.2.3-55-g7522