-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents_report.html
55 lines (48 loc) · 1.43 KB
/
events_report.html
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
require_once 'php/vendor/autoload.php';
require_once 'php/login.php';
//parse command line parameters
if (isset($_GET['duration'])) $duration=$_GET['duration'];
else $duration=1;
$timestamp = time() - ($duration * 24 * 60 * 60);
if (isset($_GET['domain'])) $match_clause=['domain' => $_GET['domain'], 'maximum_timestamp' => ['$gte' => $timestamp]];
else $match_clause=['maximum_timestamp' => ['$gte' => $timestamp]];
//open driver manager and geoip reader
$manager = new MongoDB\Driver\Manager(
$mongodbConnectionString,
[
'ssl' => TRUE,
'username' => $mongodbUsername,
'password' => $mongodbPassword,
'authSource' => $mongodbAuthSource
],
[
'ca_file' => $mongodbSslCaCert,
'pem_file' => $mongodbSslPem
]
);
$reader = new GeoIp2\Database\Reader('/usr/local/share/GeoLite2/GeoLite2-City.mmdb');
//query for results
$cursor = $manager->executeCommand(
'tipup',
new MongoDB\Driver\Command(
[
'aggregate' => 'events',
'pipeline' => [
[
'$match' => $match_clause
],
[
'$sort' => ['maximum_timestamp' => -1]
]
]
]
)
);
//iterate over results
$array = $cursor->toArray();
for ($i=0; $i < count($array); ++$i) {
$result = $array[$i];
echo ($i != 0 ? ',' : '') . MongoDB\BSON\toJSON(MongoDB\BSON\fromPHP($result));
}
?>