-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreply.php
More file actions
executable file
·48 lines (41 loc) · 1.13 KB
/
reply.php
File metadata and controls
executable file
·48 lines (41 loc) · 1.13 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
<?php
set_time_limit(15);
require_once(dirname(__FILE__).'/core.php');
authorize();
$postdata = file_get_contents("php://input");
if(!isset($postdata)) exit ('Invalid replies: ');
$replies = json_decode($postdata);
if(!isset($replies) || count($replies)<=0) exit ('Invalid replies: '.htmlspecialchars($postdata));
$result = array();
foreach($replies as $reply){
if(!isset($reply->id))continue;
$id = $reply->id;
$result[$id]=false;
if(!file_exists(generateRequestPath($id))){
$result[$id]='Request file does not exist';
continue;
}
$replyPath = generateReplyPath($id);
//Open
if (!$replyHandle = fopen($replyPath,'w')){
$result[$id]="Cannot open reply file";
fclose($replyHandle);
continue;
}
//Lock
if (flock($replyHandle,LOCK_EX)===false){
$result[$id]="Cannot acquire exclusive lock on reply file";
fclose($replyHandle);
continue;
}
//Write
if (fwrite($replyHandle,json_encode($reply))===false){
$result[$id]="Cannot write to reply file";
fclose($replyHandle);
continue;
}
//Close
fclose($replyHandle);
$result[$id]=true;
}
echo json_encode($result);