-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathproxy.php
More file actions
98 lines (80 loc) · 1.99 KB
/
proxy.php
File metadata and controls
98 lines (80 loc) · 1.99 KB
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
<?php
use Inphinit\Proxy\Proxy;
use Inphinit\Proxy\Drivers\CurlDriver;
use Inphinit\Proxy\Drivers\StreamDriver;
if (empty($_GET['url'])) {
echo 'URL not defined';
exit;
}
$url = $_GET['url'];
//Usage without autoload
require 'src/Proxy.php';
require 'src/Drivers/CurlDriver.php';
require 'src/Drivers/StreamDriver.php';
$proxy = new Proxy();
// Set drivers used for download
$proxy->setDrivers([
//CurlDriver::class,
StreamDriver::class
]);
/*
// PHP 5.4 sintax
$proxy->setDrivers([
'Inphinit\Proxy\Drivers\CurlDriver',
'Inphinit\Proxy\Drivers\StreamDriver',
]);
*/
// Set max download size
// $proxy->setMaxDownloadSize(5242880);
// Set max redirections
// $proxy->setMaxRedirs(3);
// Set current referer
if (isset($_SERVER['HTTP_REFERER'])) {
$proxy->setReferer($_SERVER['HTTP_REFERER']);
}
// Set max timeout connection
// $proxy->setTimeout(10);
// Set current user-agent
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$proxy->setUserAgent($_SERVER['HTTP_USER_AGENT']);
}
// Use specific directory
// $proxy->setTemporary(__DIR__ . '/cache');
// Set allowed URLs
/*
$proxy->setAllowedUrls([
'https://*.domain.io/',
'https://cdn.foobar.io/'
]);
*/
// Set allowed Content-Types
// $proxy->addAllowedType('image/ico', true);
// Extra configs for CurlDriver
// $proxy->setOptions('curl', [ CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1_3 ]);
// Extra configs for StreamDriver, see details in: https://www.php.net/manual/en/context.php
/*
$proxy->setOptions('stream', [
'http' => [
'method' => 'POST'
'user_agent' => 'foo/bar',
],
'ssl' => [
...
]
]);
*/
try {
// Execute download
$proxy->download($url);
if (empty($_GET['callback'])) {
// Display raw output
$proxy->response();
} else {
// Display callback with data URI content
$proxy->jsonp($_GET['callback']);
}
} catch (Exception $ee) {
$code = $ee->getCode();
$message = $ee->getMessage();
echo "Error: ({$code}) {$message}";
}