index.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. global $path;
  3. $status = 200;
  4. if (isset($_POST["data"]) && isset($_POST["key"])){
  5. $data = $_POST["data"];
  6. $key = $_POST["key"];
  7. if (json_decode($data) === null){
  8. error_log("ERROR: API v1 log-profile: Invalid JSON");
  9. $status = 400;
  10. }
  11. else{
  12. $json = json_decode($data);
  13. $winfo = $json->{"wizard_info"};
  14. $uname = $winfo->{"wizard_name"};
  15. $uid = $winfo->{"wizard_id"};
  16. $dtime = (new DateTime())->format('Y-m-dTH:i:s');
  17. $fname = ($_SERVER["DOCUMENT_ROOT"] . "/../data/profile_" . $uid . "_" . $uname . "_" . $dtime . ".json");
  18. file_put_contents($fname, $data);
  19. $cmd = $_SERVER["DOCUMENT_ROOT"] . "/../application/bin/log-profile.py " . $key . " " . $fname;
  20. $out = [];
  21. $ret = 0;
  22. exec($cmd, $out, $ret);
  23. if ($ret != 0){
  24. error_log("ERROR: API v1 log-profile exited with status: " . $ret);
  25. error_log("====================");
  26. error_log("|| SCRIPT OUTPUT: ||");
  27. error_log("===============================================================================");
  28. foreach($out as $line){
  29. error_log("|| " . $line);
  30. }
  31. error_log("===============================================================================");
  32. $status = 400;
  33. }
  34. }
  35. }
  36. else{
  37. error_log("ERROR: API v1 log-profile: Invalid JSON");
  38. $status = 400;
  39. }
  40. http_response_code($status);
  41. return $status;
  42. ?>