-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrackmap_analyse.php
137 lines (122 loc) · 5.23 KB
/
trackmap_analyse.php
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
date_default_timezone_set("Europe/Berlin");
error_reporting(E_ALL);
ini_set('memory_limit', '2G');
$dir = 'Tracktree/contextual/';
$toanalyse = "category"; // local, category, or EuropeanUnion (see examples below)
/*
$datasets = array(
60 => 'Austria', # has the wrong categories
61 => 'Ireland', # has only hungarian domains
62 => 'Latvia',
63 => 'France',
64 => 'Hungary',
65 => 'Romania',
66 => 'Spain',
69 => 'Sweden');
*/
$datasets_to_analyse = array(62, 63, 64, 65, 66, 69);
countryOrCategory($datasets_to_analyse, "category");
/*
* Gets data per country or category
*
* e.g. to sum all data for a country, excluding sites of EU
* countryOrCategory(array(65), "local");
* e.g. to group data for a country per category, excluding sites of EU
* countryOrCategory(array(65), "category");
* e.g. to sum all data for all countries, excluding sites of EU
* countryOrCategory($datasets_to_analyse, "category");
* e.g. to get info for EU originating from a particular country
* countryOrCategory(array(65), "EuropeanUnion");
*
*/
function countryOrCategory($datasets_to_analyse, $toanalyse) {
global $dir;
$results = array();
foreach ($datasets_to_analyse as $d) {
if (!in_array($d, $datasets_to_analyse))
continue;
$json = json_decode(file_get_contents("$dir/$d/ObjectDump.json"));
foreach ($json->target as $target) {
# decide what to group by
if ($toanalyse == "local")
$groupby = $json->subject->ISO_name;
elseif ($toanalyse == "category")
$groupby = $target->infos->category;
elseif ($toanalyse == "EuropeanUnion")
$groupby = $json->tester_source_place->ISO_name;
# skip certain sections in certain analyses
if ($toanalyse != "EuropeanUnion" && $target->infos->category == "EuropeanUnion")
continue;
elseif ($toanalyse == "EuropeanUnion" && $target->infos->category !== "EuropeanUnion")
continue;
# collect info for original urls
$results[$groupby]['original_url']['country_of_host'][] = $target->network_awe->trace_info->target_geoip;
$results[$groupby]['original_url']['paths'][] = implode(" -> ", $target->network_awe->country_chain);
$results[$groupby]['original_url']['domain'][] = $target->infos->fqdn;
$cib = $target->network_awe->country_chain;
foreach ($cib as $p)
$results[$groupby]['original_url']['countries_in_between_all_hops'][] = $p;
$cibu = array_unique($cib);
foreach ($cibu as $p)
$results[$groupby]['original_url']['countries_in_between_unique_per_site'][] = $p;
# collect info for included urls
foreach ($target->included as $included) {
# init
$company = $country = $fqdn = "";
$path = array();
if (isset($included->company))
$company = $included->company;
if (isset($included->network_awe->geoip))
$country = $included->network_awe->geoip;
if (isset($included->fqdn))
$fqdn = $included->fqdn;
if (isset($included->network_awe->country_chain))
$path = $included->network_awe->country_chain;
# add company to trackers
if (!empty($company)) {
$type = "included_tracker";
$results[$groupby][$type]['company'][] = $company;
} else
$type = "included_other";
# collect rest
$results[$groupby][$type]['country_of_host'][] = $country;
$results[$groupby][$type]['domain'][] = $fqdn;
$results[$groupby][$type]['paths'][] = implode(" -> ", $path);
foreach ($path as $p)
$results[$groupby][$type]['countries_in_between_all_hops'][] = $p;
$path = array_unique($path);
foreach ($path as $p)
$results[$groupby][$type]['countries_in_between_unique_per_site'][] = $p;
}
}
}
# count and display values
print "<table border='1' cellspacing='1'>";
print "<tr><th>";
if ($toanalyse == "local")
print "country";
elseif ($toanalyse == "category")
print "category";
elseif ($toanalyse == "EuropeanUnion")
print "Country connected from";
print "</th><th>type of url</th><th>type of field</th><th>value</th><th>count</th></tr>";
ksort($results);
foreach ($results as $groupby => $rows) {
ksort($rows);
foreach ($rows as $type => $types) {
ksort($types);
foreach ($types as $k => $v) {
if (is_array($v))
$results[$groupby][$type][$k] = array_count_values($v);
else
$results[$groupby][$type][$k] = array();
ksort($results[$groupby][$type][$k]);
foreach ($results[$groupby][$type][$k] as $nk => $nv)
print "<tr><td>$groupby</td><td>$type</td><td>$k</td><td>$nk</td><td>$nv</td></tr>";
}
}
}
print "</table>";
}
?>