index.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  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-run: Invalid JSON");
  9. $status = 400;
  10. }
  11. else{
  12. $cmd = $_SERVER["DOCUMENT_ROOT"] . "/../application/bin/log-run.py " . $key . " " . escapeshellarg($data);
  13. $out = [];
  14. $ret = 0;
  15. exec($cmd, $out, $ret);
  16. if ($ret != 0){
  17. error_log("ERROR: API v1 log-run exited with status: " . $ret);
  18. error_log("====================");
  19. error_log("|| SCRIPT OUTPUT: ||");
  20. error_log("===============================================================================");
  21. foreach($out as $line){
  22. error_log("|| " . $line);
  23. }
  24. error_log("===============================================================================");
  25. $status = 400;
  26. }
  27. }
  28. }
  29. else{
  30. error_log("ERROR: API v1 log-run: Invalid JSON");
  31. $status = 400;
  32. }
  33. http_response_code($status);
  34. return $status;
  35. ?>