-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.php
More file actions
72 lines (62 loc) · 2.86 KB
/
Copy pathproxy.php
File metadata and controls
72 lines (62 loc) · 2.86 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
<?php
/**
* used to load external resources, because sfw flash files cant do this because of policy issues
* need to add crossdomain.xml to all websites root whre we need to download files or use this proxy
*/
$srv = $_GET['srv'];
$path = $_GET['path'];
//if($srv=='tpsadminfuncs') $srv = 'http://srv1.toopro.org:3088/'; else die();
switch ($srv) {
case 'tpsadminfuncs': $srv = 'http://adm.toopro.org:3088/'; break;
case 'nfeya.com' : $srv = 'https://nfeya.com/'; break;
case 'daemon' : $srv = 'http://localhost:3100/'; break; //example: http://petr.tps.my/proxy.php?srv=daemon&path=api/pos-terminal/ping
case 'imgrequest' : $srv = ''; break; //we allow any url but add webp to jpg conversion
default: die();
}
$url = $srv . $path;
// Get the headers from the destination URL (this makes double request, so only for nfeya.com image requests)
if(
strpos($url, 'nfeya.com') !== FALSE || //for images we need headeres, for json not
$srv == 'imgrequest'
) {
//get headers from server re-add headers to our response to client
$responseHeaders = get_headers($url, 1); //print_r($responseHeaders);die();
foreach ($responseHeaders as $name => $value) {
if (is_array($value)) foreach ($value as $item) header("$name: $item", false);
else header("$name: $value", false);
}
//check if its webp image then it will echo jpg and return true
$jpegConverted = checkWebp($responseHeaders, $url); if($jpegConverted) die($jpegConverted);
}
// Finally, output the content
$timeout = 10;
if($_GET['srv']=='daemon') {
$timeout = 120; // for daemon we need more time
ini_set('max_execution_time', 120); // set max execution time to 120 seconds
ini_set('max_input_time', 120); // set max input time to 120 seconds
}
$context = stream_context_create([
'http' => [ 'timeout' => $timeout ]
]);
echo file_get_contents($url, false, $context);
///////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
function checkWebp($headers, $url) {
//if its not webp image, return false
if(!isset($headers['Content-Type']) || $headers['Content-Type'] != 'image/webp') return false;
//for webp we need to convert it to jpg
$img = imagecreatefromwebp($url);
//output to var
ob_start();
imagejpeg($img, null, 60);
$content = ob_get_clean(); // Get the content of the output buffer
imagedestroy($img);
//remove old header and set new one
header_remove();
header_remove('Content-Type');
header('Content-Type: image/jpeg');
//add header with filename of the downloaded file
//header('Content-Disposition: inline; filename="'.basename($url).'.jpg"');
header('Content-Disposition: inline; filename=photo.jpeg');
return $content;
}