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/hooks/cron.inc.php | 37 ++++------ .../statistics_reporting/inc/remotereport.inc.php | 84 ++++++++++++++++++++++ .../statistics_reporting/page.inc.php | 22 +++--- .../templates/columnChooser.html | 4 +- 4 files changed, 114 insertions(+), 33 deletions(-) create mode 100644 modules-available/statistics_reporting/inc/remotereport.inc.php (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 bd427e64..a48f74c2 100644 --- a/modules-available/statistics_reporting/hooks/cron.inc.php +++ b/modules-available/statistics_reporting/hooks/cron.inc.php @@ -1,32 +1,23 @@ "statistics", "data" => $statisticsReport); - $data = array_merge(GetData::total(true), array('perLocation' => array(), 'perClient' => array(), 'perUser' => array(), 'perVM' => array())); - $data['perLocation'] = GetData::perLocation(true); - $data['perClient'] = GetData::perClient(true); - $data['perUser'] = GetData::perUser(true); - $data['perVM'] = GetData::perVM(true); + $result = Download::asStringPost(CONFIG_REPORTING_URL, $params, 30, $code); - - $statisticsReport = json_encode($data); - - $params = array("action" => "statistics", "data" => $statisticsReport); - - Download::asStringPost(CONFIG_REPORTING_URL, $params, 300, $code); - - if ($code != 200) { - EventLog::warning("Statistics Reporting: ".$code); + if ($code != 200) { + EventLog::warning("Statistics Reporting failed: " . $code, $result); + } } -} +} \ No newline at end of file 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 @@ +action = Request::any('action', false, 'string'); - if ($this->action === 'setReporting') { - Property::set("reportingStatus", Request::get('reporting', "on", 'string')); - } elseif ($this->action === 'getReporting') { - echo Property::get("reportingStatus", "on"); + $this->action = Request::any('action', false, 'string'); + if ($this->action === 'setReporting') { + if (!User::isLoggedIn()) { + die("No."); + } + $state = Request::post('reporting', false, 'string'); + if ($state === false) { + die('Missing setting value.'); } + RemoteReport::setReportingEnabled($state); + } elseif ($this->action === 'getReporting') { + echo RemoteReport::isReportingEnabled() ? 'on' : ''; + } else { + echo 'Invalid action.'; } } + } diff --git a/modules-available/statistics_reporting/templates/columnChooser.html b/modules-available/statistics_reporting/templates/columnChooser.html index 47fef2a5..513bc36b 100644 --- a/modules-available/statistics_reporting/templates/columnChooser.html +++ b/modules-available/statistics_reporting/templates/columnChooser.html @@ -189,8 +189,8 @@ function saveSettings() { $.ajax({ url: '?do=statistics_reporting', - type: 'GET', - data: { action: "setReporting", reporting: $("#checkbox-reporting").is(":checked") ? "on" : "off" } + type: 'POST', + data: { action: "setReporting", reporting: $("#checkbox-reporting").is(":checked") ? "on" : "off", token: TOKEN } }); } \ No newline at end of file -- cgit v1.2.3-55-g7522