From 886e13e1af47ba6488ba3c5146d96e48e08403ad Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 19 Jan 2017 16:03:06 +0100 Subject: [statistics_reporting] Overhaul remote reporting structure; default to off --- .../statistics_reporting/inc/remotereport.inc.php | 84 ++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 modules-available/statistics_reporting/inc/remotereport.inc.php (limited to 'modules-available/statistics_reporting/inc/remotereport.inc.php') diff --git a/modules-available/statistics_reporting/inc/remotereport.inc.php b/modules-available/statistics_reporting/inc/remotereport.inc.php new file mode 100644 index 00000000..0bf4e7e2 --- /dev/null +++ b/modules-available/statistics_reporting/inc/remotereport.inc.php @@ -0,0 +1,84 @@ +fetch(PDO::FETCH_ASSOC); @@ -20,59 +24,75 @@ class GetData $row = $res->fetch(PDO::FETCH_ASSOC); $data = array_merge($data, array('totalOfftime' => $row['timeOff'])); - if (!$anonymize) { - $data["time"] = self::formatSeconds($data["time"]); - $data["medianTime"] = self::formatSeconds($data["medianTime"]); - $data["totalOfftime"] = self::formatSeconds($data["totalOfftime"]); + if ($printable) { + $data["time_s"] = self::formatSeconds($data["time"]); + $data["medianTime_s"] = self::formatSeconds($data["medianTime"]); + $data["totalOfftime_s"] = self::formatSeconds($data["totalOfftime"]); } return $data; } // per location - public static function perLocation($anonymize = false) { + public static function perLocation($flags = 0) { + $anonymize = 0 !== ($flags & GETDATA_ANONYMOUS); + $printable = 0 !== ($flags & GETDATA_PRINTABLE); $res = Queries::getLocationStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound); $data = array(); - if (!$anonymize) { - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - $median = self::calcMedian(self::calcMedian($row['medianTime'])); - $data[] = array('location' => $row['locName'], 'time' => self::formatSeconds($row['timeSum']), 'timeInSeconds' => $row['timeSum'], - 'medianTime' => self::formatSeconds($median), 'medianTimeInSeconds' => $median, 'offTime' => self::formatSeconds($row['offlineSum']), - 'offlineTimeInSeconds' => $row['offlineSum'], 'sessions' => $row['longSessions'], 'shortSessions' => $row['shortSessions']); - } - } else { - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - $median = self::calcMedian(self::calcMedian($row['medianTime'])); - $data[] = array('location' => $row['locHash'], 'time' => $row['timeSum'], 'medianTime' => $median, 'offTime' => $row['offlineSum'], - 'sessions' => $row['longSessions'], 'shortSessions' => $row['shortSessions']); + while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + $median = self::calcMedian(self::calcMedian($row['medianTime'])); + $entry = array( + 'location' => ($anonymize ? $row['locHash'] : $row['locName']), + 'time' => $row['timeSum'], + 'medianTime' => $median, + 'offTime' => $row['offlineSum'], + 'sessions' => $row['longSessions'], + 'shortSessions' => $row['shortSessions'] + ); + if ($printable) { + $entry['time_s'] = self::formatSeconds($row['timeSum']); + $entry['medianTime_s'] = self::formatSeconds($median); + $entry['offTime_s'] = self::formatSeconds($row['offlineSum']); } + $data[] = $entry; } return $data; } // per client - public static function perClient($anonymize = false) { + public static function perClient($flags = 0) { + $anonymize = 0 !== ($flags & GETDATA_ANONYMOUS); + $printable = 0 !== ($flags & GETDATA_PRINTABLE); $res = Queries::getClientStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound); $data = array(); - if (!$anonymize) { - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - $median = self::calcMedian(self::calcMedian($row['medianTime'])); - $data[] = array('hostname' => $row['clientName'], 'time' => self::formatSeconds($row['timeSum']), 'timeInSeconds' => $row['timeSum'], - 'medianTime' => self::formatSeconds($median), 'medianTimeInSeconds' => $median, 'offTime' => self::formatSeconds($row['offlineSum']), 'offlineTimeInSeconds' => $row['offlineSum'], 'lastStart' => date(DATE_RSS, $row['lastStart']), 'lastStartUnixtime' => $row['lastStart'], - 'lastLogout' => date(DATE_RSS, $row['lastLogout']), 'lastLogoutUnixtime' => $row['lastLogout'], 'sessions' => $row['longSessions'], 'shortSessions' => $row['shortSessions'], 'locationName' => $row['locName']); - } - } else { - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - $median = self::calcMedian(self::calcMedian($row['medianTime'])); - $data[] = array('hostname' => $row['clientHash'], 'time' => $row['timeSum'], 'medianTime' => $median, 'offTime' => $row['offlineSum'], 'lastStart' => $row['lastStart'], - 'lastLogout' => $row['lastLogout'], 'sessions' => $row['longSessions'], 'shortSessions' => $row['shortSessions'], 'locationName' => $row['locHash']); + while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + $median = self::calcMedian(self::calcMedian($row['medianTime'])); + $entry = array( + 'hostname' => ($anonymize ? $row['clientHash'] : $row['clientName']), + 'time' => $row['timeSum'], + 'medianTime' => $median, + 'offTime' => $row['offlineSum'], + 'lastStart' => $row['lastStart'], + 'lastLogout' => $row['lastLogout'], + 'sessions' => $row['longSessions'], + 'shortSessions' => $row['shortSessions'], + 'location' => ($anonymize ? $row['locHash'] : $row['locName']), + ); + if ($printable) { + $entry['time_s'] = self::formatSeconds($row['timeSum']); + $entry['medianTime_s'] = self::formatSeconds($median); + $entry['offTime_s'] = self::formatSeconds($row['offlineSum']); + $entry['lastStart_s'] = date(DATE_RSS, $row['lastStart']); + $entry['lastLogout_s'] = date(DATE_RSS, $row['lastLogout']); } + $data[] = $entry; } return $data; } // per user - public static function perUser($anonymize = false) { + public static function perUser($flags = 0) { + $anonymize = 0 !== ($flags & GETDATA_ANONYMOUS); $res = Queries::getUserStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound); $data = array(); $user = $anonymize ? 'userHash' : 'name'; @@ -84,7 +104,8 @@ class GetData // per vm - public static function perVM($anonymize = false) { + public static function perVM($flags = 0) { + $anonymize = 0 !== ($flags & GETDATA_ANONYMOUS); $res = Queries::getVMStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound); $data = array(); $vm = $anonymize ? 'vmHash' : 'name'; diff --git a/modules-available/statistics_reporting/inc/remotereport.inc.php b/modules-available/statistics_reporting/inc/remotereport.inc.php index 0bf4e7e2..e00e6758 100644 --- a/modules-available/statistics_reporting/inc/remotereport.inc.php +++ b/modules-available/statistics_reporting/inc/remotereport.inc.php @@ -71,11 +71,11 @@ class RemoteReport GetData::$from = $from; GetData::$to = $to; GetData::$salt = bin2hex(Util::randomBytes(20)); - $data = GetData::total(true); - $data['perLocation'] = GetData::perLocation(true); - $data['perClient'] = GetData::perClient(true); - $data['perUser'] = GetData::perUser(true); - $data['perVM'] = GetData::perVM(true); + $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; return $data; diff --git a/modules-available/statistics_reporting/page.inc.php b/modules-available/statistics_reporting/page.inc.php index 0309be68..052d813d 100644 --- a/modules-available/statistics_reporting/page.inc.php +++ b/modules-available/statistics_reporting/page.inc.php @@ -33,11 +33,11 @@ class Page_Statistics_Reporting extends Page GetData::$lowerTimeBound = Request::get('lower', 0, 'int'); GetData::$upperTimeBound = Request::get('upper', 24, 'int'); - $data = array_merge(GetData::total(), array('perLocation' => array(), 'perClient' => array(), 'perUser' => array(), 'perVM' => array())); - $data['perLocation'] = GetData::perLocation(); - $data['perClient'] = GetData::perClient(); - $data['perUser'] = GetData::perUser(); - $data['perVM'] = GetData::perVM(); + $data = GetData::total(GETDATA_PRINTABLE); + $data['perLocation'] = GetData::perLocation(GETDATA_PRINTABLE); + $data['perClient'] = GetData::perClient(GETDATA_PRINTABLE); + $data['perUser'] = GetData::perUser(GETDATA_PRINTABLE); + $data['perVM'] = GetData::perVM(GETDATA_PRINTABLE); Render::addTemplate('columnChooser'); Render::addTemplate('_page', $data); diff --git a/modules-available/statistics_reporting/templates/_page.html b/modules-available/statistics_reporting/templates/_page.html index 37c3cf90..39726d51 100644 --- a/modules-available/statistics_reporting/templates/_page.html +++ b/modules-available/statistics_reporting/templates/_page.html @@ -15,11 +15,11 @@ {{lang_total}} - {{time}} - {{medianTime}} + {{time_s}} + {{medianTime_s}} {{sessions}} {{shortSessions}} - {{totalOfftime}} + {{totalOfftime_s}} @@ -42,11 +42,11 @@ {{#perLocation}} {{location}} - {{time}} - {{medianTime}} + {{time_s}} + {{medianTime_s}} {{sessions}} {{shortSessions}} - {{offTime}} + {{offTime_s}} {{/perLocation}} @@ -73,14 +73,14 @@ {{#perClient}} {{hostname}} - {{locationName}} - {{time}} - {{medianTime}} + {{location}} + {{time_s}} + {{medianTime_s}} {{sessions}} {{shortSessions}} - {{offTime}} - {{lastLogout}} - {{lastStart}} + {{offTime_s}} + {{lastLogout_s}} + {{lastStart_s}} {{/perClient}} -- cgit v1.2.3-55-g7522 From 5a6575b1c07997ba1af20952f435290ce8ce970c Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 8 Feb 2017 12:13:57 +0100 Subject: [statistics_reporting] Nag user if statistics reporting is disabled --- .../hooks/main-warning.inc.php | 5 +++ .../statistics_reporting/inc/remotereport.inc.php | 2 +- .../lang/de/template-tags.json | 4 +- .../lang/en/template-tags.json | 4 +- .../statistics_reporting/page.inc.php | 26 ++++++++++++- .../templates/columnChooser.html | 43 ++++++++++++---------- 6 files changed, 60 insertions(+), 24 deletions(-) create mode 100644 modules-available/statistics_reporting/hooks/main-warning.inc.php (limited to 'modules-available/statistics_reporting/inc/remotereport.inc.php') diff --git a/modules-available/statistics_reporting/hooks/main-warning.inc.php b/modules-available/statistics_reporting/hooks/main-warning.inc.php new file mode 100644 index 00000000..33381c9f --- /dev/null +++ b/modules-available/statistics_reporting/hooks/main-warning.inc.php @@ -0,0 +1,5 @@ +doExport(); // Does not return } + // Get report - fetch data exactly the way it would automatically be reported + // so the user can know what is going on + if ($this->action === 'getreport') { + $report = RemoteReport::generateReport(strtotime('-7 days'), time('now')); + Header('Content-Disposition: attachment; filename=remote-report.json'); + Header('Content-Type: application/json; charset=utf-8'); + die(json_encode($report)); + } } /** @@ -105,6 +113,13 @@ class Page_Statistics_Reporting extends Page $data['lower'] = $this->lower; $data['upper'] = $this->upper; + if (RemoteReport::isReportingEnabled()) { + $data['settingsButtonClass'] = 'default'; + $data['reportChecked'] = 'checked'; + } else { + $data['settingsButtonClass'] = 'danger'; + } + Render::addTemplate('columnChooser', $data); $data['data'] = $this->fetchData(GETDATA_PRINTABLE); @@ -124,8 +139,15 @@ class Page_Statistics_Reporting extends Page die('Missing setting value.'); } RemoteReport::setReportingEnabled($state); - } elseif ($this->action === 'getReporting') { - echo RemoteReport::isReportingEnabled() ? 'on' : ''; + $data = array(); + if (RemoteReport::isReportingEnabled()) { + $data['class'] = 'default'; + $data['checked'] = true; + } else { + $data['class'] = 'danger'; + } + Header('Content-Type: application/json; charset=utf-8'); + die(json_encode($data)); } else { echo 'Invalid action.'; } diff --git a/modules-available/statistics_reporting/templates/columnChooser.html b/modules-available/statistics_reporting/templates/columnChooser.html index efc1f355..9707c970 100644 --- a/modules-available/statistics_reporting/templates/columnChooser.html +++ b/modules-available/statistics_reporting/templates/columnChooser.html @@ -2,7 +2,7 @@
- + {{lang_displaySelection}}
@@ -72,8 +72,12 @@