-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrequest.php
More file actions
executable file
·104 lines (89 loc) · 2.35 KB
/
request.php
File metadata and controls
executable file
·104 lines (89 loc) · 2.35 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
99
100
101
102
103
104
<?php
set_time_limit(60);
require_once(dirname(__FILE__).'/core.php');
$path = null;
if(isset($_REQUEST['path']))$path=$_REQUEST['path'];
else exit;
$data = null;
if(isset($_REQUEST['d']))$data=(get_magic_quotes_gpc()?stripcslashes($_REQUEST['d']):$_REQUEST['d']);
$id = rand();
$request = array('id'=>$id,'path'=>$path,'cookies'=>$_COOKIE);
if(isset($data))$request['d']=$data;
else if(isset($_POST)){
if (get_magic_quotes_gpc() === 1) $request['d']=array_map('stripcslashes', $_POST);
else $request['d']=$_POST;
}
$requestStr = json_encode($request);
$requestPath = generateRequestPath($id);
//Open
if (!$requestHandle = fopen($requestPath,'w')){
exit ("Cannot open request file");
}
//Lock
if (flock($requestHandle,LOCK_EX)===false){
exit ("Cannot acquire exclusive lock on request file");
}
//Write
if (fwrite($requestHandle,$requestStr)===false){
exit ("Cannot write to request file");
}
//Close
fclose($requestHandle);
$replyPath = generateReplyPath($id);
$reply = null;
for($i = 0; $i<90; $i++){
if(file_exists($replyPath)){
//Open
if (!$replyHandle = fopen($replyPath,'r')){
//echo ("Cannot open reply file");
fclose($replyHandle);
break;
}
//Lock
if (flock($replyHandle,LOCK_SH)===false){
//echo ("Cannot acquire shared lock on reply file");
fclose($replyHandle);
break;
}
//Calculate size
$replySize = filesize($replyPath);
if($replySize<1){
//echo ("Empty reply file");
fclose($replyHandle);
continue;
}
//Read
$replyStr = fread($replyHandle, $replySize);
if($replyStr===false){
//echo ("Cannot read reply file");
fclose($replyHandle);
break;
}
fclose($replyHandle);
//Set Reply
if($replyStr!=null){
$reply = $replyStr;
break;
}
}
time_nanosleep(0, 500000000);
}
if(isset($reply))$reply = json_decode($reply);
if(isset($reply)){
if(isset($reply->status)){
header('HTTP/'.$_SERVER['version'].' '.$reply->status);
}
if(isset($reply->headers)){
foreach($reply->headers as $header){
header($header->Key.': '.$header->Value);
}
}
if(isset($reply->body))echo $reply->body;
}
else{
header('HTTP/'.$_SERVER['version'].' 504 Gateway Timeout');
}
flush();
//Remove request file
if(file_exists($requestPath))unlink($requestPath);
if(file_exists($replyPath))unlink($replyPath);