index.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. require_once "../../config.php";
  3. if(isset($_GET['do'])){
  4. $do = $_GET['do'];
  5. }
  6. if(isset($_GET['hostname'])){
  7. $hostname = $_GET['hostname'];
  8. }
  9. $authorisationheader = getallheaders()['Authorization'];
  10. $getauthqry = mysqli_query($link, "SELECT 1 FROM installs WHERE secret = '$authorisationheader' LIMIT 1");
  11. while($row = mysqli_fetch_array($getauthqry)){
  12. if($row['1'] == '1'){
  13. $auth = 'ok';
  14. }
  15. }
  16. if($auth == 'ok'){
  17. $getsecretqry = mysqli_query($link, "SELECT * from installs where secret = '$authorisationheader'");
  18. while($row = mysqli_fetch_array($getsecretqry)){
  19. $timegenerated = $row['timegenerated'];
  20. $userid = $row['userid'];
  21. }
  22. $getuserqry = mysqli_query($link, "SELECT * from users where id = $userid");
  23. while($row = mysqli_fetch_array($getuserqry)){
  24. $active = $row['active'];
  25. }
  26. if(isset($do)){
  27. if($do == "newasset" && isset($hostname)){
  28. $assetsecret = substr(str_shuffle(str_repeat('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', mt_rand(1,250))), 1, 250);
  29. $addasset = "INSERT INTO assets (name, token) values (?, ?)";
  30. if($stmt = mysqli_prepare($link, $addasset)){
  31. mysqli_stmt_bind_param($stmt, "ss", $hostname, $assetsecret);
  32. if(mysqli_stmt_execute($stmt)){
  33. echo $assetsecret;
  34. exit;
  35. }else{
  36. echo "1";
  37. }
  38. }
  39. }
  40. }
  41. }