getCommands.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. include_once('includes/db_connect.php');
  3. include_once('includes/global_functions.php');
  4. $radioid = $_GET['radioid'];
  5. $radiomac = $_GET['radiomac'];
  6. if($radioid == "" && $radiomac == ""){
  7. print(json_encode([error => "Not a valid radioid"]));
  8. die();
  9. }else{
  10. if($radiomac != ""){
  11. $radiomac = str_replace(':', '', $radiomac);
  12. $radioid = substr($radiomac, 6 , 11);
  13. }
  14. $array = array();
  15. $delete = "DELETE FROM `CommandQue` WHERE idCommand IN (";
  16. if($stmt = $mysqli -> prepare("SELECT idCommand, command, value FROM CommandQue LEFT JOIN users ON CommandQue.uid = users.uid WHERE users.radiotoken = ? LIMIT 5")){
  17. $stmt -> bind_param("s", $radioid);
  18. $stmt -> execute();
  19. $stmt -> bind_result($idcommand, $command, $value);
  20. while($result = $stmt -> fetch()){
  21. $delete = $delete.$idcommand.",";
  22. if($command == "startstream"){
  23. $streamsplit = parse_url($value);
  24. $streamip = gethostbyname($streamsplit["host"]);
  25. $streamurl = $streamsplit["path"];
  26. $streamport = $streamsplit["port"];
  27. if($streamport == ""){
  28. $streamport = 80;
  29. }
  30. array_push($array, array( command => $command,
  31. value => array(streamip => $streamip, streamurl => $streamurl, streamport => $streamport),
  32. )
  33. );
  34. }else{
  35. array_push($array, array( command => $command,
  36. value => $value,
  37. )
  38. );
  39. }
  40. };
  41. $stmt -> close();
  42. }
  43. $delete = rtrim($delete, ",");
  44. $delete = $delete.");";
  45. if($stmt = $mysqli -> prepare($delete)){
  46. $stmt -> execute();
  47. $stmt -> close();
  48. }
  49. print(json_encode($array, JSON_UNESCAPED_SLASHES));
  50. }