google.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. class google{
  3. public function __construct(){
  4. include "lib/backend.php";
  5. $this->backend = new backend("google");
  6. include "lib/fuckhtml.php";
  7. $this->fuckhtml = new fuckhtml();
  8. }
  9. private function get(/*$proxy, */$url, $get = []){
  10. $curlproc = curl_init();
  11. if($get !== []){
  12. $get = http_build_query($get);
  13. $url .= "?" . $get;
  14. }
  15. curl_setopt($curlproc, CURLOPT_URL, $url);
  16. // http2 bypass
  17. curl_setopt($curlproc, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
  18. $headers =
  19. ["User-Agent: " . config::USER_AGENT,
  20. "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
  21. "Accept-Language: en-US,en;q=0.5",
  22. "Accept-Encoding: gzip, deflate, br, zstd",
  23. "DNT: 1",
  24. "Sec-GPC: 1",
  25. "Connection: keep-alive",
  26. "Upgrade-Insecure-Requests: 1",
  27. "Sec-Fetch-Dest: document",
  28. "Sec-Fetch-Mode: navigate",
  29. "Sec-Fetch-Site: none",
  30. "Sec-Fetch-User: ?1",
  31. "Priority: u=0, i"];
  32. // i dont think proxies are necessary here...
  33. //$this->backend->assign_proxy($curlproc, $proxy);
  34. curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
  35. curl_setopt($curlproc, CURLOPT_HTTPHEADER, $headers);
  36. curl_setopt($curlproc, CURLOPT_RETURNTRANSFER, true);
  37. curl_setopt($curlproc, CURLOPT_SSL_VERIFYHOST, 2);
  38. curl_setopt($curlproc, CURLOPT_SSL_VERIFYPEER, true);
  39. curl_setopt($curlproc, CURLOPT_CONNECTTIMEOUT, 30);
  40. curl_setopt($curlproc, CURLOPT_TIMEOUT, 30);
  41. $data = curl_exec($curlproc);
  42. if(curl_errno($curlproc)){
  43. throw new Exception(curl_error($curlproc));
  44. }
  45. curl_close($curlproc);
  46. return $data;
  47. }
  48. function resolve($id){
  49. $html =
  50. $this->get(
  51. //$this->backend->get_ip(),
  52. "https://www.google.com/goto",
  53. [
  54. "url" => $id
  55. ]
  56. );
  57. $this->fuckhtml->load($html);
  58. $a =
  59. $this->fuckhtml
  60. ->getElementsByTagName(
  61. "a"
  62. );
  63. if(count($a) === 0){
  64. throw new Exception("Failed to find link");
  65. }
  66. $link =
  67. $this->fuckhtml
  68. ->getTextContent(
  69. $a[0]["attributes"]["href"]
  70. );
  71. if(
  72. preg_match(
  73. '/^https?/',
  74. $link
  75. )
  76. ){
  77. return $link;
  78. }
  79. throw new Exception("Got malformed link: " . $link);
  80. }
  81. }