Advertisement
Guest User

Untitled

a guest
Jul 10th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | None | 0 0
  1. <?php
  2.  
  3. require_once '../modules/config.php';
  4. require_once '../modules/class/Cookies.php';
  5.  
  6. $cookie = [];
  7.  
  8. $username = trim(filter_input(INPUT_POST, 'username'));
  9. $password = trim(filter_input(INPUT_POST, 'password'));
  10.  
  11. $index_url = 'https://twitter.com';
  12.  
  13. $token = curl_init();
  14. curl_setopt_array($token, [
  15. CURLOPT_URL => $index_url,
  16. CURLOPT_CUSTOMREQUEST => 'GET',
  17. CURLOPT_RETURNTRANSFER => true,
  18. CURLOPT_SSL_VERIFYPEER => false,
  19. CURLOPT_SSL_VERIFYHOST => 2,
  20. CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'],
  21. //CURLOPT_COOKIEFILE => __DIR__ . DIRECTORY_SEPARATOR . 'cookies' . DIRECTORY_SEPARATOR . $username . '.txt',
  22. CURLOPT_COOKIEJAR => __DIR__ . SEPARATOR . 'cookies' . SEPARATOR . $username . '.txt',
  23. CURLOPT_COOKIESESSION => true,
  24. CURLOPT_REFERER => $index_url,
  25. CURLOPT_HEADER => true,
  26. CURLOPT_HTTPHEADER => ['Cookie:' . http_build_query($cookie, '', ';') . ';'],
  27. CURLOPT_HEADERFUNCTION => function ($curl, $header) use (&$cookie) {
  28. if (stripos($header, 'Set-Cookie:') === 0) {
  29. if (preg_match('/Set-Cookie:s?(.*?)=(.*?);/i', $header, $matches)) {
  30. $cookie[$matches[1]] = urldecode($matches[2]);
  31. }
  32. }
  33. return strlen($header);
  34. }
  35. ]
  36. );
  37. $access = curl_exec($token);
  38.  
  39. preg_match('/value="(.*?)" name="authenticity_token"/', $access, $matches);
  40.  
  41. $authenticity_token = $matches[1];
  42.  
  43. $session_post = "session[username_or_email]=$username&session[password]=$password&return_to_ssl=true&scribe_log=&redirect_after_login=%2F&authenticity_token=$authenticity_token";
  44.  
  45. $session_url = 'https://twitter.com/sessions';
  46.  
  47. curl_setopt_array($token, [
  48. CURLOPT_URL => $session_url,
  49. CURLOPT_CUSTOMREQUEST => 'POST',
  50. CURLOPT_POSTFIELDS => $session_post,
  51. CURLOPT_RETURNTRANSFER => true,
  52. CURLOPT_HTTPHEADER => [
  53. "Content-type: application/x-www-form-urlencoded",
  54. 'Cookie: '. http_build_query($cookie, '', ';').';',
  55. ],
  56. CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'],
  57. CURLOPT_HEADER => true,
  58. CURLOPT_FOLLOWLOCATION => true,
  59. CURLOPT_MAXREDIRS => 2,
  60. CURLOPT_REDIR_PROTOCOLS => CURLPROTO_HTTP | CURLPROTO_HTTPS,
  61. CURLOPT_POSTREDIR => 2,
  62. CURLOPT_AUTOREFERER => 1
  63. ]
  64.  
  65. );
  66. $auth = curl_exec($token);
  67.  
  68. if (isset($cookie['auth_token']))
  69. {
  70. $twid = filter_var($cookie['twid'], FILTER_SANITIZE_NUMBER_INT);
  71.  
  72. Cookies::set('login_token', $cookie['ct0']);
  73. Cookies::set('kdt', $cookie['kdt']);
  74. Cookies::set('user_id', $twid);
  75. Cookies::set('auth_token', $cookie['auth_token']);
  76. Cookies::set('username', $username);
  77.  
  78. $_SESSION[SITE_TITLE . '_session'] = $username;
  79.  
  80. echo json_encode(array(
  81. "status" => "success",
  82. "message" => "Autenticação bem sucedida, estamos te redirecionando.",
  83. ));
  84. }
  85. else
  86. {
  87. echo json_encode(
  88. array(
  89. "status" => "error",
  90. 'message'=> "Não foi possível autenticar com o Twitter.",
  91. ));
  92. }
  93.  
  94. <?php
  95.  
  96. require_once '../modules/config.php';
  97. require_once '../modules/class/Cookies.php';
  98.  
  99.  
  100. $username = Cookies::get('username');
  101.  
  102. $friend_url = 'https://api.twitter.com/1.1/friendships/create.json';
  103.  
  104. $friend = curl_init();
  105.  
  106. curl_setopt_array($friend, [
  107. CURLOPT_URL => $friend_url,
  108. CURLOPT_SSL_VERIFYPEER => 1,
  109. CURLOPT_SSL_VERIFYHOST => 2,
  110. CURLOPT_CAINFO => ROOT . 'modules' . SEPARATOR . 'cacert' . SEPARATOR . 'cacert-2017-06-07.pem',
  111. CURLOPT_CUSTOMREQUEST => 'POST',
  112. CURLOPT_POSTFIELDS => 'screen_name=' . $username,
  113. CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'],
  114. CURLOPT_COOKIEJAR => __DIR__ . SEPARATOR . 'cookies' . SEPARATOR . $username . '.txt',
  115. CURLOPT_COOKIESESSION => true,
  116. CURLOPT_RETURNTRANSFER => true,
  117. CURLOPT_HTTPHEADER => [
  118. "Content-type: application/json; charset=utf-8",
  119. ],
  120. CURLOPT_HEADER => 0,
  121. ]
  122.  
  123. );
  124.  
  125. $response = curl_exec($friend);
  126.  
  127. var_dump($response);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement