index.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. require_once "../../config.php";
  3. if(isset($_GET['schedid'])){
  4. $schedid = $_GET['schedid'];
  5. }
  6. if(isset($_GET['scriptid'])){
  7. $scriptid = $_GET['scriptid'];
  8. }
  9. if(isset($_GET['hostname'])){
  10. $hostname = $_GET['hostname'];
  11. }
  12. $authorisationheader = getallheaders()['Authorization'];
  13. $getauthqry = mysqli_query($link, "SELECT 1 FROM assets WHERE token = '$authorisationheader' AND name = '$hostname' LIMIT 1");
  14. while($row = mysqli_fetch_array($getauthqry)){
  15. if($row['1'] == '1'){
  16. $auth = 'ok';
  17. }
  18. }
  19. if($auth == 'ok'){
  20. $getassetqry = mysqli_query($link, "SELECT * FROM assets WHERE token = '$authorisationheader' AND name = '$hostname'");
  21. while($row = mysqli_fetch_array($getassetqry)){
  22. $assetid = $row['id'];
  23. $active = $row['active'];
  24. }
  25. if($active == 1){
  26. $getscriptidqry = mysqli_query($link, "SELECT * FROM schedules WHERE id = $schedid");
  27. while($row = mysqli_fetch_array($getscriptidqry)){
  28. $scriptid = $row['scriptid'];
  29. }
  30. $getscriptqry = mysqli_query($link, "SELECT * FROM scripts WHERE id = $scriptid");
  31. while($row = mysqli_fetch_array($getscriptqry)){
  32. $shell = $row['shell'];
  33. $script = $row['data'];
  34. }
  35. $date = new \DateTime();
  36. $datenow = $date->format("Y-m-d H:i:s");
  37. $sql = "UPDATE schedules SET rantime = ?, status = 'runnning' WHERE id = ?";
  38. if($stmt = mysqli_prepare($link, $sql)){
  39. mysqli_stmt_bind_param($stmt, "si", $datenow, $schedid);
  40. if(mysqli_stmt_execute($stmt)){
  41. echo "$shell:$script";
  42. exit();
  43. } else{
  44. echo 0;
  45. }
  46. }
  47. }
  48. }