index.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. require_once "../../config.php";
  3. if(isset($_GET['hostname'])){
  4. $hostname = $_GET['hostname'];
  5. }
  6. $authorisationheader = getallheaders()['Authorization'];
  7. $getauthqry = mysqli_query($link, "SELECT 1 FROM assets WHERE token = '$authorisationheader' AND name = '$hostname' LIMIT 1");
  8. while($row = mysqli_fetch_array($getauthqry)){
  9. if($row['1'] == '1'){
  10. $auth = 'ok';
  11. }
  12. }
  13. if($auth == 'ok'){
  14. $getassetqry = mysqli_query($link, "SELECT * FROM assets WHERE token = '$authorisationheader' AND name = '$hostname'");
  15. while($row = mysqli_fetch_array($getassetqry)){
  16. $assetid = $row['id'];
  17. $active = $row['active'];
  18. }
  19. if($active == 1){
  20. $date = new \DateTime();
  21. $datenow = $date->format("Y-m-d H:i:s");
  22. $date = new DateTime();
  23. $tosub = new DateInterval('PT12H00M');
  24. $halfdayago = $date->sub($tosub);
  25. $datehalfdayago = $date->format("Y-m-d H:i:s");
  26. $getschedqry = mysqli_query($link, "SELECT * FROM schedules WHERE assetid = $assetid AND runtime <= '$datenow' AND runtime >= '$datehalfdayago' AND rantime IS NULL ORDER BY runtime ASC LIMIT 1");
  27. while($row = mysqli_fetch_array($getschedqry)){
  28. $schedid = $row['id'];
  29. }
  30. if(isset($schedid)){
  31. echo "$schedid";
  32. }else{
  33. echo 0;
  34. }
  35. }
  36. }