index.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. include 'inc/req.php';
  3. $uafile = dirname(__FILE__).'/ua.txt';
  4. $file = fopen($uafile,'r');
  5. $useragent = fread($file,filesize($uafile));
  6. fclose($file);
  7. $valid_requests = $ALLOWED_HOSTS;
  8. include 'inc/headers.php';
  9. $request_url = "https://www.semrush.com".$_SERVER['REQUEST_URI'];
  10. $p_request_url = parse_url( $request_url );
  11. include 'inc/requeired.php';
  12. if ( $request_method == 'GET' && count( $request_params ) > 0 && (!array_key_exists( 'query', $p_request_url ) || empty( $p_request_url['query'] ) ) ) {
  13. $request_url .= '?' . http_build_query( $request_params );
  14. }
  15. $cookie = $cookie = dirname(__FILE__).'/cookie.txt';
  16. $uaa = $useragent;
  17. // let the request begin
  18. $ch = curl_init( $request_url );
  19. curl_setopt ($ch, CURLOPT_USERAGENT, $uaa);
  20. curl_setopt($ch, CURLOPT_REFERER, "https://www.semrush.com");
  21. curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers ); // (re-)send headers
  22. curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie);
  23. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  24. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  25. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); // return response
  26. curl_setopt( $ch, CURLOPT_HEADER, true ); // enabled response headers
  27. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true );
  28. // add data for POST, PUT or DELETE requests
  29. if ( 'POST' == $request_method ) {
  30. $post_data = is_array( $request_params ) ? http_build_query( $request_params ) : $request_params;
  31. $has_files = false;
  32. $file_params = array();
  33. foreach ($_FILES as $f => $file) {
  34. if($file['size']){
  35. $file_params[$f] = '@'. $file['tmp_name'] .";type=". $file['type'];
  36. $has_files = true;
  37. }
  38. }
  39. if($isMultiPart || $has_files){
  40. foreach(explode("&",$post_data) as $i => $param) {
  41. $params = explode("=", $param);
  42. $xvarname = $params[0];
  43. if (!empty($xvarname))
  44. $file_params[$xvarname] = $params[1];
  45. }
  46. }
  47. curl_setopt( $ch, CURLOPT_POST, true );
  48. curl_setopt( $ch, CURLOPT_POSTFIELDS, $isMultiPart || $has_files ? $file_params : $post_data );
  49. } elseif ( 'PUT' == $request_method || 'DELETE' == $request_method ) {
  50. curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, $request_method );
  51. curl_setopt( $ch, CURLOPT_POSTFIELDS, $request_params );
  52. }
  53. // retrieve response (headers and content)
  54. $response = curl_exec( $ch );
  55. $response = str_replace('srf-browser-unhappy"', 'srf-browser-unhappy" style="display:none;"', $response);
  56. $response = str_replace('srf-navbar__right"', 'srf-navbar__right" style="display:none;"', $response);
  57. $response = str_replace('<footer', '<footer style="display:none;"', $response);
  58. $response = str_replace('srf-report-sidebar-management "', 'srf-report-sidebar-management " style="display:none;"', $response);
  59. $response = str_replace('srf-report-sidebar-extras "', 'srf-report-sidebar-extras " style="display:none;"', $response);
  60. $response = str_replace('www.semrush.com', 'sem.bunnytools.shop', $response);
  61. $response_headers = substr($response, 0, curl_getinfo($ch, CURLINFO_HEADER_SIZE));
  62. $response_content = substr($response, curl_getinfo($ch, CURLINFO_HEADER_SIZE));
  63. curl_close( $ch );
  64. // split response to header and content
  65. //list($response_headers, $response_content) = preg_split( '/(\r\n){2}/', $response, 2 );
  66. // (re-)send the headers
  67. $response_headers = preg_split( '/(\r\n){1}/', $response_headers );
  68. foreach ( $response_headers as $key => $response_header ) {
  69. // Rewrite the `Location` header, so clients will also use the proxy for redirects.
  70. if ( !preg_match( '/^(Transfer-Encoding):/', $response_header ) ) {
  71. header( $response_header, false );
  72. }
  73. }
  74. if($_SERVER['REQUEST_URI'] === "/"){
  75. header('Location: https://sem.bunnytools.shop/analytics/overview/');
  76. }
  77. if($_SERVER['REQUEST_URI'] === "/_compatibility/traffic/overview/"){
  78. header('Location: https://sem.bunnytools.shop/analytics/traffic/overview/ebay.com');
  79. }
  80. print_r($response_content);
  81. function csajax_debug_message( $message )
  82. {
  83. if ( true == CSAJAX_DEBUG ) {
  84. print $message . PHP_EOL;
  85. }
  86. }
  87. if (strpos($_SERVER['REQUEST_URI'], '/switch_language_api/') !== false) exit();