-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson.php
More file actions
47 lines (40 loc) · 1.44 KB
/
json.php
File metadata and controls
47 lines (40 loc) · 1.44 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
<?php
function main(){
// Delete old json object to avoid it being returned
$outputfh = fopen('/tmp/json.json', 'w') or die("can't open file");
fwrite($outputfh, "");
$a = $_POST['args'];
$reqID = $_POST['requestID'];
$jsonFile = "/tmp/jsonargs.txt";
$logfile = "/tmp/log.txt";
$logfh = fopen($logfile, 'w') or die("can't open file");
fwrite($logfh, $_POST["logfile"]);
fclose($logfh);
$jsonfh = fopen($jsonFile, 'w') or die("can't open file");
fwrite($jsonfh, $a);
fwrite($jsonfh, "\n");
fwrite($jsonfh, "-o /tmp/json\n");
fwrite($jsonfh, "-j\n");
fclose($jsonfh);
$output = shell_exec(' ./perfume.sh --noModelOutput -c /tmp/jsonargs.txt ' . "/tmp/log.txt 2>&1");
$json = file_get_contents('/tmp/json.json');
$outputfh = fopen("/tmp/jsonout.txt", 'w') or die("can't open file");
fwrite($outputfh, $output);
// Check for SEVERE messages that indicate an error
if ($json === "" || preg_match("/\nSEVERE:/", $output)
|| preg_match("/\nWARNING: Using a default regular expression to parse/", $output)) {
header('HTTP/1.1 500 Internal Server Error');
header('Access-Control-Allow-Origin:*');
header('Content-Type: application/json; charset=UTF-8');
die(json_encode(array("message" => $output, "responseID" => $reqID)));
}
else {
$jsonArr = json_decode($json, true);
$jsonArr["responseID"] = $reqID;
header('Access-Control-Allow-Origin:*');
header('Content-Type: application/json');
echo json_encode($jsonArr);
}
}
main();
?>