Advertisement
Guest User

Untitled

a guest
Oct 11th, 2017
722
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>Kahoot bot</title>
  4. </head>
  5. <body>
  6. <?php
  7. $username = 'kahootbot28@gmail.com';
  8. $password = 'botkahoot28';
  9. $loginUrl = 'https://create.kahoot.it/rest/authenticate';
  10. $kahootId = $_GET['quizid'];
  11. $type = $_GET['what'];
  12. if ($type == "bot") {
  13. $call = "~/www/reteps.tk/go/kahoot-auto " . $_GET['gamepin'] . " " . $_GET['username'] . " ";
  14. echo($call);
  15. }
  16. $pageUrl = 'https://create.kahoot.it/rest/kahoots/' . $kahootId;
  17. $loginheader = array();
  18. $loginheader[] = 'content-type: application/json';
  19. $loginpost = new stdClass();
  20. $loginpost->username = $username;
  21. $loginpost->password = $password;
  22. $loginpost->grant_type = "password";
  23. $ch = curl_init();
  24. curl_setopt($ch, CURLOPT_URL, $loginUrl);
  25. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  26. curl_setopt($ch, CURLOPT_POST, 1);
  27. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($loginpost));
  28. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  29. curl_setopt($ch, CURLOPT_HTTPHEADER,$loginheader);
  30. $store = curl_exec($ch);
  31. curl_close($ch);
  32. $token = json_decode($store,true)["access_token"];
  33. //get questions
  34. $quizheader = array();
  35. $quizheader[] = 'authorization: ' . $token;
  36. $options = array(
  37. 'http' => array(
  38. 'method' => 'GET',
  39. 'header' => "Authorization: ".$token."\r\n"
  40. )
  41. );
  42. $pairs = array(
  43. 0 => "red",
  44. 1 => "blue",
  45. 2 => "yellow",
  46. 3 => "green",
  47. );
  48. $context = stream_context_create($options);
  49. $raw_result = file_get_contents($pageUrl, false, $context);
  50. $result = json_decode($raw_result,true)["questions"];
  51. echo("<a href='kahoot_bot'>back</a><br>");
  52. foreach($result as $value) {
  53. if ($type == "text") {
  54. echo($value['question']." ");
  55. }
  56. $choices = $value['choices'];
  57. for($i=0;$i<count($choices);$i++) {
  58. if ($choices[$i]['correct'] == true) {
  59. if ($type == "text") {
  60. echo($choices[$i]['answer']."<br>");
  61. } elseif ($type == "bot") {
  62. $call .= $i;
  63. } else {
  64. echo($pairs[$i].", ");
  65. }
  66. break 1;
  67. }
  68. }
  69. }
  70. if ($type == "bot") {
  71. $old_result = "";
  72. $handle = popen($call . " 2>&1", "r");
  73. $result = fread($handle, 2096);
  74. echo($result);
  75. while ((strpos($result, "end") !== false) != true) {
  76. $result = fread($handle, 2096);
  77. sleep(1);
  78. if ($result != $old_result) {
  79. echo($result);
  80. $old_result = $result;
  81. }
  82. }
  83. pclose($handle);
  84. }
  85. ?>
  86. </body>
  87. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement