forked from browser-update/browser-update
-
Notifications
You must be signed in to change notification settings - Fork 0
/
count.php
executable file
·212 lines (189 loc) · 5.99 KB
/
count.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
function get_domain($domain, $debug = false)
{
$original = $domain = strtolower($domain);
if (filter_var($domain, FILTER_VALIDATE_IP)) { return $domain; }
$debug ? print('<strong style="color:green">»</strong> Parsing: '.$original) : false;
$arr = array_slice(array_filter(explode('.', $domain, 4), function($value){
return $value !== 'www';
}), 0); //rebuild array indexes
if (count($arr) > 2)
{
$count = count($arr);
$_sub = explode('.', $count === 4 ? $arr[3] : $arr[2]);
$debug ? print(" (parts count: {$count})") : false;
if (count($_sub) === 2) // two level TLD
{
$removed = array_shift($arr);
if ($count === 4) // got a subdomain acting as a domain
{
$removed = array_shift($arr);
}
$debug ? print("<br>\n" . '[*] Two level TLD: <strong>' . join('.', $_sub) . '</strong> ') : false;
}
elseif (count($_sub) === 1) // one level TLD
{
$removed = array_shift($arr); //remove the subdomain
if (strlen($_sub[0]) === 2 && $count === 3) // TLD domain must be 2 letters
{
array_unshift($arr, $removed);
}
else
{
// non country TLD according to IANA
$tlds = array(
'aero',
'arpa',
'asia',
'biz',
'cat',
'com',
'coop',
'edu',
'gov',
'info',
'jobs',
'mil',
'mobi',
'museum',
'name',
'net',
'org',
'post',
'pro',
'tel',
'travel',
'xxx',
);
if (count($arr) > 2 && in_array($_sub[0], $tlds) !== false) //special TLD don't have a country
{
array_shift($arr);
}
}
$debug ? print("<br>\n" .'[*] One level TLD: <strong>'.join('.', $_sub).'</strong> ') : false;
}
else // more than 3 levels, something is wrong
{
for ($i = count($_sub); $i > 1; $i--)
{
$removed = array_shift($arr);
}
$debug ? print("<br>\n" . '[*] Three level TLD: <strong>' . join('.', $_sub) . '</strong> ') : false;
}
}
elseif (count($arr) === 2)
{
$arr0 = array_shift($arr);
if (strpos(join('.', $arr), '.') === false
&& in_array($arr[0], array('localhost','test','invalid')) === false) // not a reserved domain
{
$debug ? print("<br>\n" .'Seems invalid domain: <strong>'.join('.', $arr).'</strong> re-adding: <strong>'.$arr0.'</strong> ') : false;
// seems invalid domain, restore it
array_unshift($arr, $arr0);
}
}
$debug ? print("<br>\n".'<strong style="color:gray">«</strong> Done parsing: <span style="color:red">' . $original . '</span> as <span style="color:blue">'. join('.', $arr) ."</span><br>\n") : false;
return join('.', $arr);
}
require("lib/init.php");
$time = time();
try {
$ref = parse_url(urldecode($_GET["ref"]));
$host = strtolower($ref['host']);
$host = get_domain($host);
} catch (Exception $e) {
$host="decodeerror";
}
$ll=get_country();
if (!isset($_GET["tv"]))
$tv=0;
else
$tv = $_GET["tv"];
if (!isset($_GET["cv"]))
$cv=0;
else
$cv = $_GET["cv"];
if (!isset($_GET["jsv"]))
$jsv=0;
else
$jsv = $_GET["jsv"];
$s=0;
if (isset($_GET["second"]))
$s=1;
$what=filter_input(INPUT_GET, 'what');
$sys=get_system($ua_);
$bx_=get_browserx($ua_);
$browid=$bx_[0];
$brown=$bx_[1];
$browver=$bx_[2];
$q=False;
require_once("config.php");
if ($what=="brow"){
$q=sprintf("INSERT INTO browsers SET ua='%s', info='%s', country='%s', lang='%s', time=NOW(),sysn='%s', sysv=%f, n='%s',v='%d',outdated='%d'",
$mysqli->real_escape_string($_SERVER['HTTP_USER_AGENT']),
$mysqli->real_escape_string($_SERVER['HTTP_ACCEPT_LANGUAGE']),
$mysqli->real_escape_string(get_country()),
$mysqli->real_escape_string(get_lang()),
$mysqli->real_escape_string($sys[3]),
$mysqli->real_escape_string($sys[1]),
$mysqli->real_escape_string($browid),
$mysqli->real_escape_string($browver),
is_outdated() ? 1 : 0
);
}
else if ($what=="view"){
/*
$q=sprintf("INSERT DELAYED INTO viewschoice SET referer='%s', fromn='%s', fromv=%f, lang='%s', time=%d, textversion='%s', choiceversion='%s', second=%d, sysn='%s', sysv=%f",
$mysqli->real_escape_string($host),
$mysqli->real_escape_string($_GET["from"]),
$mysqli->real_escape_string(floatval($_GET["fromv"])),
$mysqli->real_escape_string(get_lang()),
$time,
$mysqli->real_escape_string($tv),
$mysqli->real_escape_string($cv),
$s,
$mysqli->real_escape_string($sys[3]),
$mysqli->real_escape_string($sys[1])
);
*/
}
else if ($what=="noti"){
/*
$q=sprintf("INSERT DELAYED INTO noti SET referer='%s', fromn='%s', fromv=%f, lang='%s', time=NOW(), scriptversion='%d', textversion='%s', ua='%s',more='%s'",
$mysqli->real_escape_string(filter_input(INPUT_GET, 'ref')),
$mysqli->real_escape_string($_GET["from"]),
$mysqli->real_escape_string(floatval($_GET["fromv"])),
$mysqli->real_escape_string(get_lang()),
$mysqli->real_escape_string($jsv),
$mysqli->real_escape_string($tv),
"",//$mysqli->real_escape_string($_SERVER['HTTP_USER_AGENT']),
$mysqli->real_escape_string(urldecode(filter_input(INPUT_GET, 'extra')))
);
*/
}
else {//updates
try {
require_once 'lib/geoip.php';
$country_=get_country_from_ip($_SERVER['REMOTE_ADDR']);
} catch (Exception $e) {
$country_="xx";
}
$q=sprintf("INSERT DELAYED INTO updates SET referer='%s', fromn='%s', fromv=%f, ton='%s', lang='%s',country='%s', time=%d, textversion='%s', choiceversion='%s', second=%d, sysn='%s', sysv=%f",
$mysqli->real_escape_string($host),
$mysqli->real_escape_string($_GET["from"]),
$mysqli->real_escape_string(floatval($_GET["fromv"])),
$mysqli->real_escape_string($_GET["to"]),
$mysqli->real_escape_string(get_lang()),
$mysqli->real_escape_string($country_),
$time,
$mysqli->real_escape_string($tv),
$mysqli->real_escape_string($cv),
$s,
$mysqli->real_escape_string($sys[3]),
$mysqli->real_escape_string($sys[1])
);
}
if ($q) {
$mysqli->query($q)
or trigger_error($mysqli->sqlstate(). $q, E_USER_ERROR);
}