diff options
-rw-r--r-- | config.php.example | 2 | ||||
-rw-r--r-- | modules-available/statistics_reporting/hooks/cron.inc.php | 34 |
2 files changed, 35 insertions, 1 deletions
diff --git a/config.php.example b/config.php.example index 82fd1b77..41949fc8 100644 --- a/config.php.example +++ b/config.php.example @@ -30,6 +30,8 @@ define('CONFIG_PROXY_CONF', '/opt/openslx/proxy/config'); define('CONFIG_DOZMOD_URL', 'http://127.0.0.1:9080'); define('CONFIG_DOZMOD_EXPIRE', 60); +define('CONFIG_REPORTING_URL', 'https://bwlp-masterserver.ruf.uni-freiburg.de/rpc/'); + // Sort order for menu // Optional - if missing, will be sorted by module id (internal name) // Here it is also possible to assign a module to a different category, diff --git a/modules-available/statistics_reporting/hooks/cron.inc.php b/modules-available/statistics_reporting/hooks/cron.inc.php index b79883df..57e64a84 100644 --- a/modules-available/statistics_reporting/hooks/cron.inc.php +++ b/modules-available/statistics_reporting/hooks/cron.inc.php @@ -1,3 +1,35 @@ <?php -$lastReporting = Property::get("lastReporting", 7); +$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("Monday last week"); + GetData::$to = strtotime("Sunday last week 23:59:59"); + + $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(); + + + $statisticsReport = json_encode($data); + + $url = CONFIG_REPORTING_URL; + + $curl = curl_init($url); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/json")); + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, $statisticsReport); + + $json_response = curl_exec($curl); + + curl_close($curl); +} |