-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmt1.php
114 lines (104 loc) · 3.05 KB
/
mt1.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
<?php
$cURL = isset($_GET['curl']) ? 1 : 0;
define('MT_RELEASE', '1.0');
define('MT_CURL_OK', ($cURL && in_array('curl', get_loaded_extensions())));
define('MT_TIMEOUT', 10);
define('MT_ERR', !empty($_GET['err']));
if (isset($_GET['mtnotrk'])) {
die();
}
if (MT_ERR) {
error_reporting(E_ALL);
ini_set('display_errors', 'On');
}
else {
error_reporting(0);
}
if (basename(__FILE__) == 'mytracking.php') {
die('For your safety: you should really change the name of this file');
}
if (!empty($_GET['test'])) {
die("OK: ".MT_RELEASE);
}
$hop = isset($_GET['hop']) ? $_GET['hop'] : '';
process_content(retrieve_content(calculate_url($hop)));
exit;
function calculate_url($link) {
$returnurl = '';
if ($link == '') {
$returnurl = 'http://trkapi.com/mytrackingok.gif';
} else if ((preg_match("/.+/", $link))) {
$src = array('/m/', '/r/', '/l/');
$rpl = array('', '/', '/');
$link = str_replace($src, $rpl, $link);
$returnurl = 'http://trkapi.com/' . $link; // 2.0 format
}
return $returnurl;
}
function retrieve_content($url) {
$response = '';
$mt_errstr = '';
$agent = 'MyTracking/'.MT_RELEASE;
$refr = ($_SERVER['SERVER_PORT'] == 443) ? 'https' : 'http';
$refr .= '://';
$refr .= $_SERVER['HTTP_HOST'];
$refr .= $_SERVER['REQUEST_URI'];
if ($url != '') {
if (MT_CURL_OK) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_REFERER, $refr);
curl_setopt($ch, CURLOPT_TIMEOUT, MT_TIMEOUT);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if (!$response = curl_exec($ch)) {
$mt_errstr = curl_errno($ch).' '.curl_error($ch);
}
curl_close($ch);
}
else {
$parts = parse_url($url);
$scheme = isset($parts['scheme']) ? $parts['scheme'] : 'http';
$host = isset($parts['host']) ? $parts['host'] : 'trkapi.com';
$port = isset($parts['port']) ? $parts['port'] : 80;
$path = isset($parts['path']) ? $parts['path'] : '/';
$query = isset($parts['query']) ? $parts['query'] : '';
if ($fp = fsockopen ($host, $port, $errno, $errstr, MT_TIMEOUT)) {
$agent = 'MyTracking/'.MT_RELEASE;
fputs ($fp, "GET $path?$query HTTP/1.0\r\nHost: $host\r\nUser-Agent: $agent\r\nReferer: $refr\r\n\r\n");
while (!feof($fp)) {
$response .= fgets ($fp,128);
}
fclose ($fp);
}
else {
$response = false;
$mt_errstr = $errno.' '.$errstr;
}
}
}
if ($response === false) {
if (MT_ERR) {
echo $mt_errstr;
}
else {
header("Location: /?mtnotrk=1");
exit;
}
}
else {
return $response;
}
}
function process_content($pagecontent) {
if ($pagecontent != '') {
list($headers, $body) = explode("\r\n\r\n", $pagecontent, 2);
$headerlines = explode("\r\n", $headers);
foreach ($headerlines as $header) {
if (preg_match("/^HTTP|Location:|Vary:|Content-Length:|Content-Type:/i", $header)) {
header($header);
}
}
echo $body;
}
}