summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics_reporting/hooks/cron.inc.php
blob: bd427e64761b564e528e383010e2847512b8bc0e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php

$nextReporting = Property::get("nextReporting", 0);
$time = time();

$allowReport = Property::get("reportingStatus", "on") == "on";

if ($nextReporting < $time && $allowReport) {

	Property::set("nextReporting", strtotime("Sunday 23:59:59"));

	GetData::$from = strtotime("last sunday - 6 days");
	GetData::$to = strtotime("last sunday 23:59:59");
	GetData::$salt = bin2hex(random_bytes(20));

	$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);


	$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);
	}
}