作者 Your Name
@@ -55,21 +55,21 @@ class QuanqiusouApi @@ -55,21 +55,21 @@ class QuanqiusouApi
55 * @date 2023/5/11 55 * @date 2023/5/11
56 */ 56 */
57 public function getSiteResPer($api_no){ 57 public function getSiteResPer($api_no){
58 - $key = 'quanqiusou_api_site_res_per_' . $api_no . '_' . date('Y-m-d');  
59 - $res = Cache::get($key);  
60 - if (!$res) { 58 +// $key = 'quanqiusou_api_site_res_per_' . $api_no . '_' . date('Y-m-d');
  59 +// $res = Cache::get($key);
  60 +// if (!$res) {
61 $api_url = $this->url . '/google-rank/echo_site_res_per.php'; 61 $api_url = $this->url . '/google-rank/echo_site_res_per.php';
62 try { 62 try {
63 $res = HttpUtils::get($api_url, ['apino' => $api_no]); 63 $res = HttpUtils::get($api_url, ['apino' => $api_no]);
64 if($res){ 64 if($res){
65 $res = Arr::s2a($res); 65 $res = Arr::s2a($res);
66 - Cache::put($key, $res, 2 * 3600); 66 +// Cache::put($key, $res, 2 * 3600);
67 } 67 }
68 } catch (\Exception | GuzzleException $e) { 68 } catch (\Exception | GuzzleException $e) {
69 errorLog('获取站点收录页面数', [], $e); 69 errorLog('获取站点收录页面数', [], $e);
70 return false; 70 return false;
71 } 71 }
72 - } 72 +// }
73 return $res; 73 return $res;
74 } 74 }
75 75
@@ -3,11 +3,13 @@ @@ -3,11 +3,13 @@
3 namespace App\Http\Logic\Aside\Domain; 3 namespace App\Http\Logic\Aside\Domain;
4 4
5 5
  6 +use App\Helper\Arr;
6 use App\Http\Logic\Aside\BaseLogic; 7 use App\Http\Logic\Aside\BaseLogic;
7 use App\Models\Devops\ServerConfig; 8 use App\Models\Devops\ServerConfig;
8 use App\Models\Devops\ServersIp; 9 use App\Models\Devops\ServersIp;
9 use App\Models\Domain\DomainCreateTask; 10 use App\Models\Domain\DomainCreateTask;
10 use App\Models\Domain\DomainInfo; 11 use App\Models\Domain\DomainInfo;
  12 +use App\Models\Domain\DomainRedirectTask;
11 use App\Models\Project\CountryCustom; 13 use App\Models\Project\CountryCustom;
12 use App\Models\Project\Project; 14 use App\Models\Project\Project;
13 use Symfony\Component\Process\Process; 15 use Symfony\Component\Process\Process;
@@ -151,7 +153,7 @@ class DomainInfoLogic extends BaseLogic @@ -151,7 +153,7 @@ class DomainInfoLogic extends BaseLogic
151 */ 153 */
152 public function sslSave(){ 154 public function sslSave(){
153 $info = $this->model->read(['id'=>$this->param['id']]); 155 $info = $this->model->read(['id'=>$this->param['id']]);
154 - if($info === false){ 156 + if($info === false || empty($info['domain'])){
155 $this->fail('当前数据不存在或者已被删除'); 157 $this->fail('当前数据不存在或者已被删除');
156 } 158 }
157 //获取项目数据 159 //获取项目数据
@@ -173,12 +175,19 @@ class DomainInfoLogic extends BaseLogic @@ -173,12 +175,19 @@ class DomainInfoLogic extends BaseLogic
173 $this->fail('自建站服务器无法生成站点'); 175 $this->fail('自建站服务器无法生成站点');
174 } 176 }
175 //域名是否都已经解析 177 //域名是否都已经解析
176 - if(!empty($info['domain']) && !$this->check_cname($info['domain'], $serversIpInfo)){ 178 + if(!$this->check_cname($info['domain'], $serversIpInfo)){
177 $this->fail('域名' . $info['domain'] . '未解析至目标服务器'); 179 $this->fail('域名' . $info['domain'] . '未解析至目标服务器');
178 } 180 }
  181 + $domain_301 = [];
179 foreach ($this->param['other_domain']??[] as $other_domain){ 182 foreach ($this->param['other_domain']??[] as $other_domain){
180 - if($other_domain && !$this->check_cname($other_domain, $serversIpInfo)){  
181 - $this->fail('域名' . $other_domain . '未解析至目标服务器'); 183 + if($other_domain && substr($other_domain,0,2) != '*.'){
  184 + if($this->check_a($other_domain,DomainInfo::SERVER_IP_301)){
  185 + $domain_301[] = $other_domain;
  186 + }else{
  187 + if(!$this->check_cname($other_domain, $serversIpInfo)){
  188 + $this->fail('域名' . $other_domain . '未解析至目标服务器');
  189 + }
  190 + }
182 } 191 }
183 } 192 }
184 193
@@ -261,6 +270,19 @@ class DomainInfoLogic extends BaseLogic @@ -261,6 +270,19 @@ class DomainInfoLogic extends BaseLogic
261 } 270 }
262 } 271 }
263 272
  273 + //新增重定向任务
  274 + $redirect_model = new DomainRedirectTask();
  275 + if($domain_301){
  276 + $domain_301 = Arr::a2s($domain_301);
  277 + $task_redirect_info = $redirect_model->read(['origin_domain'=>$domain_301,'status'=>['<',DomainRedirectTask::STATUS_SUC]]);
  278 + if(!$task_redirect_info){
  279 + $redirect_model->add([
  280 + 'origin_domain'=> $domain_301,
  281 + 'target_domain' => $info['domain']
  282 + ]);
  283 + }
  284 + }
  285 +
264 return $this->success(); 286 return $this->success();
265 } 287 }
266 288
@@ -274,9 +296,6 @@ class DomainInfoLogic extends BaseLogic @@ -274,9 +296,6 @@ class DomainInfoLogic extends BaseLogic
274 * @date 2023/11/13 296 * @date 2023/11/13
275 */ 297 */
276 public function check_cname($domain, $server_info){ 298 public function check_cname($domain, $server_info){
277 - $checkA = false;  
278 - $checkCname = false;  
279 -  
280 $process = new Process(['nslookup', '-qt=a', $domain]); 299 $process = new Process(['nslookup', '-qt=a', $domain]);
281 $process->run(); 300 $process->run();
282 $output = explode(PHP_EOL, $process->getOutput()); 301 $output = explode(PHP_EOL, $process->getOutput());
@@ -305,6 +324,27 @@ class DomainInfoLogic extends BaseLogic @@ -305,6 +324,27 @@ class DomainInfoLogic extends BaseLogic
305 } 324 }
306 325
307 /** 326 /**
  327 + * 验证是否A记录解析到目标服务器
  328 + * @param $domain
  329 + * @param $ip
  330 + * @return mixed
  331 + */
  332 + public function check_a($domain, $ip){
  333 + $process = new Process(['nslookup', '-qt=a', $domain]);
  334 + $process->run();
  335 + $output = explode(PHP_EOL, $process->getOutput());
  336 + foreach ($output as $line){
  337 + if($line){
  338 + $checkA = strpos($line, $ip) !== false;
  339 + if($checkA){
  340 + return $domain;
  341 + }
  342 + }
  343 + }
  344 + return false;
  345 + }
  346 +
  347 + /**
308 * 设置语种自定义跳转链接 348 * 设置语种自定义跳转链接
309 * @param $project_id 349 * @param $project_id
310 * @return array 350 * @return array
@@ -15,6 +15,7 @@ use App\Models\Base; @@ -15,6 +15,7 @@ use App\Models\Base;
15 */ 15 */
16 class DomainInfo extends Base 16 class DomainInfo extends Base
17 { 17 {
  18 + const SERVER_IP_301 = '43.135.137.172';
18 const STATUS_ONE = 1; 19 const STATUS_ONE = 1;
19 const STATUS_ZERO = 0; 20 const STATUS_ZERO = 0;
20 public $btAction = [ 21 public $btAction = [
  1 +<?php
  2 +
  3 +namespace App\Models\Domain;
  4 +
  5 +use App\Models\Base;
  6 +
  7 +class DomainRedirectTask extends Base
  8 +{
  9 + protected $table = 'gl_domain_redirect_task';
  10 +
  11 + const STATUS_UN = 0;
  12 + const STATUS_ING = 1;
  13 + const STATUS_SUC = 2;
  14 + const STATUS_FAL = 3;
  15 +}