-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinclude.php
140 lines (119 loc) · 6.29 KB
/
include.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
138
139
140
<?php
include __DIR__ . "/config/settings.php";
require_once __DIR__ . "/classes/analyse/user.php";
require_once __DIR__ . "/classes/dirHelper.php";
require_once __DIR__ . "/classes/analyse/country.php";
require_once __DIR__ . "/classes/analyse/reference.php";
require_once __DIR__ . "/classes/analyse/security.php";
require_once __DIR__ . "/classes/analyse/UASparser.php";
$user = new User(getenv("REMOTE_ADDR"), $_SERVER['HTTP_USER_AGENT']);
$dirhelper = new DirHelper(__DIR__);
if(
($dirhelper->checkExists($fstat_data_dir) == false) ||
($dirhelper->checkExists($fstat_cache_dir) == false) ||
($dirhelper->checkExists($fstat_cache_dir . "ip/") == false)
){
return 0;
}
//Delete old entrys in the Ip directory
$dirhelper->deleteOldIPs($fstat_cache_dir."ip", $fstat_new_user);
//get the user from cache, on success it is a old user is_new is false then
$user->getFromCache(__DIR__ . "/" . $fstat_cache_dir . "ip");
if ($user->is_new) {
//Daten auswerten
$current_folder = __DIR__ . "/" . $fstat_data_dir . "stat/" . gmdate("Y", $user->time) . "/" . gmdate("m", $user->time);
if (
($dirhelper->checkExists($fstat_data_dir . "stat") == false) ||
($dirhelper->checkExists($fstat_data_dir . "stat/" . gmdate("Y", $user->time)) == false) ||
($dirhelper->checkExists($current_folder, true) == false)
){
//quit the execution here
return 0;
}
//User Agent Parser
$parser = new UAS\Parser(__DIR__ . "/".$fstat_cache_dir, $fstat_update_interval, false, $fstat_update_auto);
$uaa = $parser->Parse($user->agent);
//ReferParser
$ref = new Reference(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "");
$ref->parse();
//Country Parser
$country = new Country(__DIR__ . "/dbip-country-1.csv", __DIR__ . "/dbip-country-2.csv", __DIR__ . "/dbip-country-3.csv", __DIR__ . "/dbip-country-4.csv", __DIR__ . "/dbip-country-5.csv");
$country->parse($user->ip);
//Browser Typ ist bis jetzt nicht deklariert
$user->type = $uaa['typ'];
//Daten in XML schreiben:
$tmp_filename = $current_folder . "/" . gmdate("d", $user->time) . ".xml";
if (file_exists($tmp_filename)) {
$xmldoc = new DOMDocument();
$xmldoc->preserveWhiteSpace = false;
$xmldoc->formatOutput = true;
$xmldoc->load($tmp_filename);
$root = $xmldoc->documentElement;
} else {
$xmldoc = new DOMDocument('1.0', 'UTF-8');
$xmldoc->xmlStandalone = true;
$xmldoc->preserveWhiteSpace = false;
$xmldoc->formatOutput = true;
$root = $xmldoc->createElement("list");
$xmldoc->appendChild($root);
}
$newvisitor = $xmldoc->createElement("visitor");
$newvisitor->appendChild($xmldoc->createElement('typ', htmlspecialchars($uaa['typ'])));
$newvisitor->appendChild($xmldoc->createElement('uas', htmlspecialchars($user->agent)));
$newvisitor->appendChild($xmldoc->createElement('uip', htmlspecialchars($user->ip)));
$newvisitor->appendChild($xmldoc->createElement('uhost', htmlspecialchars(gethostbyaddr($user->ip))));
$newvisitor->appendChild($xmldoc->createElement('uti', $user->time));
$newvisitor->appendChild($xmldoc->createElement('ufam', htmlspecialchars($uaa['ua_family'])));
$newvisitor->appendChild($xmldoc->createElement('unam', htmlspecialchars($uaa['ua_name'])));
$newvisitor->appendChild($xmldoc->createElement('uico', htmlspecialchars($uaa['ua_icon'])));
if($user->type == "Robot" or $user->type == "Validator"){
$newvisitor->appendChild($xmldoc->createElement('uurl', htmlspecialchars($uaa['ua_url'])));
}
$newvisitor->appendChild($xmldoc->createElement('usec', Security::isHTTPS() ? 'HTTPS' : 'HTTP'));
$newvisitor->appendChild($xmldoc->createElement('ofam', htmlspecialchars($uaa['os_family'])));
$newvisitor->appendChild($xmldoc->createElement('onam', htmlspecialchars($uaa['os_name'])));
$newvisitor->appendChild($xmldoc->createElement('oico', htmlspecialchars($uaa['os_icon'])));
$newvisitor->appendChild($xmldoc->createElement('ucoi', htmlspecialchars($country->getCountryShort())));
$newvisitor->appendChild($xmldoc->createElement('ucon', htmlspecialchars($country->getCountry())));
$newvisitor->appendChild($xmldoc->createElement('rkey', htmlspecialchars($ref->getKeywords())));
$newvisitor->appendChild($xmldoc->createElement('rdom', htmlspecialchars($ref->getDomain())));
$newvisitor->appendChild($xmldoc->createElement('host', htmlspecialchars($_SERVER['HTTP_HOST']))); // the requested host
$root->appendChild($newvisitor);
$xmldoc->formatOutput = true;
$xmldoc->save($tmp_filename, LIBXML_NOEMPTYTAG);
//IP Cache schreiben:
$user->writeToCache(__DIR__ . "/" . $fstat_cache_dir . "ip");
}
//Daten ausgewertet...
//Pfade notieren
$current_folder = __DIR__ . "/" . $fstat_data_dir . "paths/" . gmdate("Y", $user->time) . "/" . gmdate("m", $user->time);
if (
($dirhelper->checkExists($fstat_data_dir . "paths") == false) ||
($dirhelper->checkExists($fstat_data_dir . "paths/" . gmdate("Y", $user->time)) == false) ||
($dirhelper->checkExists($current_folder, true) == false)
){
return 0;
}
if ($user->type == "Robot" or $user->type == "Validator") {
$f_cont = @fopen($current_folder . "/bot_" . $user->escapedIP . "_" . gmdate("d_H", $user->time) . ".path", 'a');
} else {
$f_cont = @fopen($current_folder . "/" . $user->escapedIP . "_" . gmdate("d_H", $user->time) . ".path", 'a');
}
if ($fstat_use_site_var) {
$site_name = $fstat_default_site_name; //default
$tmp_sitevar_array = explode(",", $fstat_site_variable);
foreach ($tmp_sitevar_array as $tmp_sitevar) {
$tmp_sitevar = trim($tmp_sitevar);
if (isset($_GET[$tmp_sitevar])) {
$site_name = htmlspecialchars($_GET[$tmp_sitevar]);
$site_name = str_replace("|", "|", $site_name); //to prevent corruption of table ;)
break; //use first one from config
}
}
fputs($f_cont, time() . "|" . basename($_SERVER['SCRIPT_FILENAME']) . "|" . $site_name . "\n");
} else {
fputs($f_cont, time() . "|" . basename($_SERVER['SCRIPT_FILENAME']) . "\n");
}
fclose($f_cont);
//Pfade notiert
?>