index.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. $uname = $json["wizard_info"]["wizard_name"]
  14. $uid = $json["wizard_info"]["wizard_id"]
  15. $dtime = (new DateTime())->format('Y-m-dTH:i:s')
  16. $fname = ($_SERVER["DOCUMENT_ROOT"] . "/../application/data/profile_" . $uid . "_" . $uname . "_" . $dtime . ".json");
  17. file_put_contents($fname, $data);
  18. $cmd = $_SERVER["DOCUMENT_ROOT"] . "/../application/bin/log-profile.py " . $key . " " . $fname;
  19. $out = [];
  20. $ret = 0;
  21. exec($cmd, $out, $ret);
  22. if ($ret != 0){
  23. error_log("ERROR: API v1 log-profile exited with status: " . $ret);
  24. error_log("====================");
  25. error_log("|| SCRIPT OUTPUT: ||");
  26. error_log("===============================================================================");
  27. foreach($out as $line){
  28. error_log("|| " . $line);
  29. }
  30. error_log("===============================================================================");
  31. $status = 400;
  32. }
  33. }
  34. }
  35. else{
  36. error_log("ERROR: API v1 log-profile: Invalid JSON");
  37. $status = 400;
  38. }
  39. http_response_code($status);
  40. return $status;
  41. ?>