This commit is contained in:
make
2025-06-02 16:42:16 +08:00
parent 83c3bd512c
commit fe1e2c04d8

View File

@@ -112,7 +112,7 @@ class SiteContext
public function initCfg() public function initCfg()
{ {
$this->limitRequestRate(); $this->limitRequestRate();
if(config('app.default_app_type') == 'novel'){ if (config('app.default_app_type') == 'novel') {
// 全局使用的URL模板 // 全局使用的URL模板
$strPcUrlTemp = $this->DomainModel->getFomartSubject('PC_PATH_URL', '', false); $strPcUrlTemp = $this->DomainModel->getFomartSubject('PC_PATH_URL', '', false);
$strNanUrlTemp = $this->DomainModel->getFomartSubject('NAN_SHENG_URL', '', false); $strNanUrlTemp = $this->DomainModel->getFomartSubject('NAN_SHENG_URL', '', false);
@@ -138,7 +138,7 @@ class SiteContext
View::assign("strHistoryUrlTemp", $strHistoryUrlTemp); View::assign("strHistoryUrlTemp", $strHistoryUrlTemp);
View::assign("strBookShelfUrlTemp", $strBookShelfUrlTemp); View::assign("strBookShelfUrlTemp", $strBookShelfUrlTemp);
View::assign("strUserUrlTemp", $strUserUrlTemp); View::assign("strUserUrlTemp", $strUserUrlTemp);
}else{ } else {
// $strPcUrlTemp = $this->DomainModel->getFomartSubject('VIDEO_PC_PATH_URL', '', false); // $strPcUrlTemp = $this->DomainModel->getFomartSubject('VIDEO_PC_PATH_URL', '', false);
$strRankUrlTemp = $this->DomainModel->getFomartSubject('VIDEO_RANK_INDEX_URL', '', false); $strRankUrlTemp = $this->DomainModel->getFomartSubject('VIDEO_RANK_INDEX_URL', '', false);
$strSearchListUrlTemp = $this->DomainModel->getFomartSubject('VIDEO_SEARCH_LIST_URL', '', false); $strSearchListUrlTemp = $this->DomainModel->getFomartSubject('VIDEO_SEARCH_LIST_URL', '', false);
@@ -231,20 +231,19 @@ class SiteContext
{ {
if ($strPlatform == 'h5') { if ($strPlatform == 'h5') {
if ($this->DomainModel->info_id > 0) { if ($this->DomainModel->info_id > 0) {
if(config('app.default_app_type') == 'video'){ if (config('app.default_app_type') == 'video') {
$strView = 'video/getVideoInfo.html'; $strView = 'video/getVideoInfo.html';
}else{ } else {
$strView = 'novel/getNovelInfo.html'; $strView = 'novel/getNovelInfo.html';
} }
} else { } else {
$strView = 'index/index.html'; $strView = 'index/index.html';
} }
} else { } else {
if ($this->DomainModel->info_id > 0) { if ($this->DomainModel->info_id > 0) {
if(config('app.default_app_type') == 'video'){ if (config('app.default_app_type') == 'video') {
$strView = 'pc/getVideoInfo.html'; $strView = 'pc/getVideoInfo.html';
}else{ } else {
$strView = 'pc/getNovelInfo.html'; $strView = 'pc/getNovelInfo.html';
} }
} else { } else {
@@ -516,7 +515,7 @@ class SiteContext
// 判断是否为爬虫 // 判断是否为爬虫
$arrVisitInfo['vil_is_spider'] = $this->isSpider($arrVisitInfo['vil_user_agent']); $arrVisitInfo['vil_is_spider'] = $this->isSpider($arrVisitInfo['vil_user_agent']);
$strIp = $this->Request->ip(); $strIp = $this->getRealClientIp();
$strKeyLimit10 = 'access:' . $strIp; $strKeyLimit10 = 'access:' . $strIp;
$strKeyLimit100 = 'access100:' . $strIp; $strKeyLimit100 = 'access100:' . $strIp;
$strKeyBlacklist = 'blacklist:ips'; // 黑名单缓存键 $strKeyBlacklist = 'blacklist:ips'; // 黑名单缓存键
@@ -554,7 +553,7 @@ class SiteContext
} }
$strAGEN = 'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Amazonbot/0.1; +https://developer.amazon.com/support/amazonbot) Chrome/119.0.6045.214 Safari/537.36'; $strAGEN = 'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Amazonbot/0.1; +https://developer.amazon.com/support/amazonbot) Chrome/119.0.6045.214 Safari/537.36';
if($arrVisitInfo['vil_user_agent'] == $strAGEN){ if ($arrVisitInfo['vil_user_agent'] == $strAGEN) {
throw new HttpException(404, 'Too Many Requests100'); throw new HttpException(404, 'Too Many Requests100');
//abort(403, 'Too Many Requests100'); //abort(403, 'Too Many Requests100');
} }
@@ -562,7 +561,6 @@ class SiteContext
throw new HttpException(404, 'Too Many Requests100'); throw new HttpException(404, 'Too Many Requests100');
//abort(403, 'Too Many Requests100'); //abort(403, 'Too Many Requests100');
} }
} }
/** /**
@@ -599,4 +597,24 @@ class SiteContext
return false; return false;
} }
/**
* 获取真实ip
*
* @return void
*/
protected function getRealClientIp()
{
$headers = $this->Request->header();
if (isset($headers['x-forwarded-for'])) {
$ips = explode(',', $headers['x-forwarded-for']);
return trim($ips[0]); // 取第一个(用户 IP
}
if (isset($headers['x-real-ip'])) {
return $headers['x-real-ip'];
}
return $this->Request->ip(); // 备用
}
} }