-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy.php
66 lines (44 loc) · 1.53 KB
/
proxy.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
<?php
include('settings.php');
#Proxy has short fuse;
ini_set('default_socket_timeout', $config['eye']['cache']*4);
if(isset($_REQUEST['eye']) && isset($config['eye'][$_REQUEST['eye']])){
$eye = $config['eye'][$_REQUEST['eye']];
if(!file_exists($eye['cache']) || (time() - filemtime($eye['cache']))>$config['eye']['cache']){
if(!file_exists($eye['cache']))
@mkdir(dirname($eye['cache']),0777,true);
$image = @copy($eye['url'],$eye['cache']);
if($image!==true){
@copy('images/eye_lost.jpg',$eye['cache']);
}
}
header('Content-Type: image/jpeg');
readfile($eye['cache']);
exit();
}
if(isset($_REQUEST['fetch']) && isset($config['fetch'][$_REQUEST['fetch']])) {
$fetch = $config['fetch'][$_REQUEST['fetch']];
if(!file_exists($fetch['cache']) || (time() - filemtime($fetch['cache']))>$config['fetch']['cache']){
if(!file_exists($fetch['cache']))
@mkdir(dirname($fetch['cache']),0777,true);
$fe = @copy($fetch['url'],$fetch['cache']);
}
header('Content-Type: application/json');
readfile($fetch['cache']);
exit();
}
if(isset($_REQUEST['task']) && $_REQUEST['task'] == $_REQUEST['task']){
$entityBody = file_get_contents('php://input');
echo $entityBody;
$options = array(
'http' => array(
'method' => 'POST',
'content' => $entityBody,
'protocol_version' => 1.0
)
);
$context = stream_context_create($options);
$result = file_get_contents($config['brain']['events']['url'], false, $context);
header('Content-Type: application/json');
echo $result;
}