Selaa lähdekoodia

initialized the new go module

AETH-erial 1 vuosi sitten
vanhempi
sitoutus
8e6d2e0566
8 muutettua tiedostoa jossa 217 lisäystä ja 0 poistoa
  1. 3 0
      go.mod
  2. 6 0
      inc/.htaccess
  3. 3 0
      inc/cookie.txt
  4. 46 0
      inc/inc/headers.php
  5. 15 0
      inc/inc/req.php
  6. 25 0
      inc/inc/requeired.php
  7. 118 0
      inc/index.php
  8. 1 0
      inc/ua.txt

+ 3 - 0
go.mod

@@ -0,0 +1,3 @@
+module git.aetherial.dev/aeth/http-proxy
+
+go 1.22.1

+ 6 - 0
inc/.htaccess

@@ -0,0 +1,6 @@
+
+
+RewriteEngine on
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteRule ^(.*)$ index.php [QSA,L]
+

+ 3 - 0
inc/cookie.txt

@@ -0,0 +1,3 @@
+#HttpOnly_.semrush.com	TRUE	/	TRUE	0	PHPSESSID	d8e0075bbcd44e3197be7257e187e846
+#HttpOnly_.semrush.com	TRUE	/	TRUE	0	sso_token
+

+ 46 - 0
inc/inc/headers.php

@@ -0,0 +1,46 @@
+<?php 
+
+$request_headers = array( );
+$setContentType = true;
+$isMultiPart = false;
+foreach ( $_SERVER as $key => $value ) {
+    if(preg_match('/Content.Type/i', $key)){
+        $setContentType = false;
+        $content_type = explode(";", $value)[0];
+        $isMultiPart = preg_match('/multipart/i', $content_type);
+        $request_headers[] = "Content-Type: ".$content_type;
+        continue;
+    }
+	if ( substr( $key, 0, 5 ) == 'HTTP_' ) {
+		$headername = str_replace( '_', ' ', substr( $key, 5 ) );
+		$headername = str_replace( ' ', '-', ucwords( strtolower( $headername ) ) );
+		if ( !in_array( $headername, array( 'Host', 'X-Proxy-Url' ) ) ) {
+		    if($headername != 'User-Agent' && $headername != 'Cookie' && $headername != 'Accept-Encoding')
+			if($headername != 'Referer'){
+			    $request_headers[] = "$headername: $value";
+			}
+		}
+	}
+}
+
+if($setContentType)
+    $request_headers[] = "Content-Type: application/json";
+$request_headers[] = "user-agent: ".$useragent;
+
+$request_method = $_SERVER['REQUEST_METHOD'];
+if ( 'GET' == $request_method ) {
+	$request_params = $_GET;
+} elseif ( 'POST' == $request_method ) {
+	$request_params = $_POST;
+	if ( empty( $request_params ) ) {
+		$data = file_get_contents( 'php://input' );
+		if ( !empty( $data ) ) {
+			$request_params = $data;
+		}
+	}
+} elseif ( 'PUT' == $request_method || 'DELETE' == $request_method ) {
+	$request_params = file_get_contents( 'php://input' );
+} else {
+	$request_params = null;
+}
+?>

+ 15 - 0
inc/inc/req.php

@@ -0,0 +1,15 @@
+<?php
+
+
+$SETTING_ALLOWED_HOSTS = array(
+    "www.semrush.com",
+);
+
+$ALLOWED_HOSTS = array();
+if(isset($SETTING_ALLOWED_HOSTS))
+    $ALLOWED_HOSTS = $SETTING_ALLOWED_HOSTS; 
+
+define( 'CSAJAX_FILTERS', true );
+define( 'CSAJAX_FILTER_DOMAIN', true );
+define( 'CSAJAX_DEBUG', true );
+?>

+ 25 - 0
inc/inc/requeired.php

@@ -0,0 +1,25 @@
+<?php
+
+if ( is_array( $request_params ) && array_key_exists('csurl', $request_params ) )
+	unset( $request_params['csurl'] );
+
+if ( CSAJAX_FILTERS ) {
+	$parsed = $p_request_url;
+	if ( CSAJAX_FILTER_DOMAIN ) {
+		if ( !in_array( $parsed['host'], $valid_requests ) ) {
+			csajax_debug_message( 'Invalid domain - ' . $parsed['host'] . ' is not included in valid request domains' );
+			exit;
+		}
+	} else {
+		$check_url = isset( $parsed['scheme'] ) ? $parsed['scheme'] . '://' : '';
+		$check_url .= isset( $parsed['user'] ) ? $parsed['user'] . ($parsed['pass'] ? ':' . $parsed['pass'] : '') . '@' : '';
+		$check_url .= isset( $parsed['host'] ) ? $parsed['host'] : '';
+		$check_url .= isset( $parsed['port'] ) ? ':' . $parsed['port'] : '';
+		$check_url .= isset( $parsed['path'] ) ? $parsed['path'] : '';
+		if ( !in_array( $check_url, $valid_requests ) ) {
+			csajax_debug_message( 'Invalid domain - ' . $request_url . ' is not included in valid request domain' );
+			exit;
+		}
+	}
+}
+?>

+ 118 - 0
inc/index.php

@@ -0,0 +1,118 @@
+<?php
+
+
+
+include 'inc/req.php';
+
+
+$uafile = dirname(__FILE__).'/ua.txt';
+$file = fopen($uafile,'r');
+$useragent = fread($file,filesize($uafile));
+fclose($file);
+$valid_requests = $ALLOWED_HOSTS;
+
+include 'inc/headers.php';
+
+$request_url = "https://www.semrush.com".$_SERVER['REQUEST_URI'];
+
+
+$p_request_url = parse_url( $request_url );
+
+include 'inc/requeired.php';
+
+if ( $request_method == 'GET' && count( $request_params ) > 0 && (!array_key_exists( 'query', $p_request_url ) || empty( $p_request_url['query'] ) ) ) {
+	$request_url .= '?' . http_build_query( $request_params );
+}
+
+
+$cookie = $cookie = dirname(__FILE__).'/cookie.txt';
+
+$uaa = $useragent;
+// let the request begin
+$ch = curl_init( $request_url );
+
+curl_setopt ($ch, CURLOPT_USERAGENT, $uaa);
+curl_setopt($ch, CURLOPT_REFERER, "https://www.semrush.com");
+curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers );   // (re-)send headers
+curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie);
+curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
+curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
+curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );	 // return response
+curl_setopt( $ch, CURLOPT_HEADER, true );	   // enabled response headers
+curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true );
+// add data for POST, PUT or DELETE requests
+if ( 'POST' == $request_method ) {
+	$post_data = is_array( $request_params ) ? http_build_query( $request_params ) : $request_params;
+
+    $has_files = false;
+    $file_params = array();
+
+    foreach ($_FILES as $f => $file) {
+        if($file['size']){
+            $file_params[$f] = '@'. $file['tmp_name'] .";type=". $file['type'];
+            $has_files = true;
+        }
+    }
+
+    if($isMultiPart || $has_files){
+        foreach(explode("&",$post_data) as $i => $param) {
+            $params = explode("=", $param);
+            $xvarname = $params[0];
+            if (!empty($xvarname))
+                $file_params[$xvarname] = $params[1];
+        }
+    }
+
+	curl_setopt( $ch, CURLOPT_POST, true );
+	curl_setopt( $ch, CURLOPT_POSTFIELDS,  $isMultiPart || $has_files ? $file_params : $post_data );
+} elseif ( 'PUT' == $request_method || 'DELETE' == $request_method ) {
+	curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, $request_method );
+	curl_setopt( $ch, CURLOPT_POSTFIELDS, $request_params );
+}
+
+// retrieve response (headers and content)
+ $response = curl_exec( $ch );
+ 
+$response = str_replace('srf-browser-unhappy"', 'srf-browser-unhappy" style="display:none;"', $response);
+ $response = str_replace('srf-navbar__right"', 'srf-navbar__right" style="display:none;"', $response);
+ $response = str_replace('<footer', '<footer style="display:none;"', $response);
+ $response = str_replace('srf-report-sidebar-management "', 'srf-report-sidebar-management " style="display:none;"', $response);
+$response = str_replace('srf-report-sidebar-extras "', 'srf-report-sidebar-extras " style="display:none;"', $response);
+$response = str_replace('www.semrush.com', 'sem.bunnytools.shop', $response);
+$response_headers = substr($response, 0, curl_getinfo($ch, CURLINFO_HEADER_SIZE));
+$response_content = substr($response, curl_getinfo($ch, CURLINFO_HEADER_SIZE));
+curl_close( $ch );
+
+// split response to header and content
+//list($response_headers, $response_content) = preg_split( '/(\r\n){2}/', $response, 2 );
+
+// (re-)send the headers
+$response_headers = preg_split( '/(\r\n){1}/', $response_headers );
+foreach ( $response_headers as $key => $response_header ) {
+	// Rewrite the `Location` header, so clients will also use the proxy for redirects.
+
+	if ( !preg_match( '/^(Transfer-Encoding):/', $response_header ) ) {
+		header( $response_header, false );
+	}
+}
+
+if($_SERVER['REQUEST_URI'] === "/"){
+    header('Location: https://sem.bunnytools.shop/analytics/overview/');
+}
+
+
+if($_SERVER['REQUEST_URI'] === "/_compatibility/traffic/overview/"){
+    header('Location: https://sem.bunnytools.shop/analytics/traffic/overview/ebay.com');
+}
+
+
+ print_r($response_content);
+
+function csajax_debug_message( $message )
+{
+	if ( true == CSAJAX_DEBUG ) {
+		print $message . PHP_EOL;
+	}
+}
+
+if (strpos($_SERVER['REQUEST_URI'], '/switch_language_api/') !== false) exit();

+ 1 - 0
inc/ua.txt

@@ -0,0 +1 @@
+Opera/9.80 (J2ME/MIDP; Opera Mini/9.80 (S60; SymbOS; Opera Nokia200/23.348; U; en) Presto/2.5.25 Version/10.54