-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
70 lines (52 loc) · 1.9 KB
/
index.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
<?php
include 'options.php';
$requestUri = str_replace($relativeUri, '', $_SERVER['REQUEST_URI']);
$requestUriPath = parse_url($requestUri, PHP_URL_PATH);
$code = 404;
$content = 'Not found';
if (in_array($requestUriPath, $whitelist)) {
$url = $backendUrl . $requestUri;
if (array_key_exists($requestUriPath, $mapping)) {
$url = $backendUrl . str_replace(
$requestUriPath,
$mapping[$requestUriPath],
$requestUri
);
}
$ch = curl_init($url);
$headers = [];
foreach (getallheaders() as $key => $value) {
if (!in_array($key, ['Host', 'Accept-Encoding', 'X-Forwarded-For', 'Client-IP'])) {
$headers[$key] = $key . ': ' . $value;
}
}
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
$headers['X-Forwarded-For'] = 'X-Forwarded-For: ' . $ip;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
if (strtolower($_SERVER['REQUEST_METHOD']) === 'post') {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents('php://input'));
}
$content = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
curl_close($ch);
}
http_response_code($code);
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Credentials: true');
if (isset($contentType)) {
header('content-type: ' . $contentType);
}
echo $content;