This repository has been archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
hop.php
96 lines (84 loc) · 2.15 KB
/
hop.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
<?php
$server = rtrim("REPLACE_SERVER", '/');
$hopName = "REPLACE_HOP_NAME";
function do_get_request($url, $optionalHeaders = null)
{
global $hopName;
$aContext = array(
'http' => array(
'method' => 'GET'
),
'ssl'=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
$headers = array('Hop-Name' => $hopName);
if ($optionalHeaders !== null) {
$headers['Cookie'] = $optionalHeaders;
}
$aContext['http']['header'] = prepareHeaders($headers);
$cxContext = stream_context_create($aContext);
echo file_get_contents($url, False, $cxContext);
}
function do_post_request($url, $data, $optionalHeaders = null)
{
global $hopName;
$params = array(
'http' => array(
'method' => 'POST',
'content' => $data
),
'ssl'=>array(
'verify_peer'=>false,
'verify_peer_name'=>false,
),
);
$headers = array('Hop-Name' => $hopName);
if ($optionalHeaders !== null) {
$headers['Cookie'] = $optionalHeaders;
}
$params['http']['header'] = prepareHeaders($headers);
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
return '';
}
$response = @stream_get_contents($fp);
if ($response === false) {
return '';
}
echo $response;
}
function prepareHeaders($headers) {
$flattened = array();
foreach ($headers as $key => $header) {
if (is_int($key)) {
$flattened[] = $header;
} else {
$flattened[] = $key.': '.$header;
}
}
return implode("\r\n", $flattened);
}
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$requestURI = $_SERVER['REQUEST_URI'];
if(isset($_COOKIE['session'])) {
return do_get_request($server.$requestURI, "session=".str_replace(' ', '+', $_COOKIE['session']));
}
else {
return do_get_request($server.$requestURI);
}
}
else {
// otherwise it's a POST
$requestURI = $_SERVER['REQUEST_URI'];
$postdata = file_get_contents("php://input");
if(isset($_COOKIE['session'])) {
return do_post_request($server.$requestURI, $postdata, "session=".str_replace(' ', '+', $_COOKIE['session']));
}
else {
return do_post_request($server.$requestURI, $postdata);
}
}
?>