|
...
|
...
|
@@ -3,11 +3,13 @@ |
|
|
|
namespace App\Http\Logic\Aside\Domain;
|
|
|
|
|
|
|
|
|
|
|
|
use App\Helper\Arr;
|
|
|
|
use App\Http\Logic\Aside\BaseLogic;
|
|
|
|
use App\Models\Devops\ServerConfig;
|
|
|
|
use App\Models\Devops\ServersIp;
|
|
|
|
use App\Models\Domain\DomainCreateTask;
|
|
|
|
use App\Models\Domain\DomainInfo;
|
|
|
|
use App\Models\Domain\DomainRedirectTask;
|
|
|
|
use App\Models\Project\CountryCustom;
|
|
|
|
use App\Models\Project\Project;
|
|
|
|
use Symfony\Component\Process\Process;
|
|
...
|
...
|
@@ -151,7 +153,7 @@ class DomainInfoLogic extends BaseLogic |
|
|
|
*/
|
|
|
|
public function sslSave(){
|
|
|
|
$info = $this->model->read(['id'=>$this->param['id']]);
|
|
|
|
if($info === false){
|
|
|
|
if($info === false || empty($info['domain'])){
|
|
|
|
$this->fail('当前数据不存在或者已被删除');
|
|
|
|
}
|
|
|
|
//获取项目数据
|
|
...
|
...
|
@@ -173,14 +175,21 @@ class DomainInfoLogic extends BaseLogic |
|
|
|
$this->fail('自建站服务器无法生成站点');
|
|
|
|
}
|
|
|
|
//域名是否都已经解析
|
|
|
|
if(!empty($info['domain']) && !$this->check_cname($info['domain'], $serversIpInfo)){
|
|
|
|
if(!$this->check_cname($info['domain'], $serversIpInfo)){
|
|
|
|
$this->fail('域名' . $info['domain'] . '未解析至目标服务器');
|
|
|
|
}
|
|
|
|
$domain_301 = [];
|
|
|
|
foreach ($this->param['other_domain']??[] as $other_domain){
|
|
|
|
if($other_domain && !$this->check_cname($other_domain, $serversIpInfo)){
|
|
|
|
if($other_domain && substr($other_domain,0,2) != '*.'){
|
|
|
|
if($this->check_a($other_domain,DomainInfo::SERVER_IP_301)){
|
|
|
|
$domain_301[] = $other_domain;
|
|
|
|
}else{
|
|
|
|
if(!$this->check_cname($other_domain, $serversIpInfo)){
|
|
|
|
$this->fail('域名' . $other_domain . '未解析至目标服务器');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//如果要开通amp站点,判断m域名是否已经解析
|
|
|
|
if(isset($this->param['amp_status']) && $this->param['amp_status'] == 1){
|
|
...
|
...
|
@@ -261,6 +270,19 @@ class DomainInfoLogic extends BaseLogic |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//新增重定向任务
|
|
|
|
$redirect_model = new DomainRedirectTask();
|
|
|
|
if($domain_301){
|
|
|
|
$domain_301 = Arr::a2s($domain_301);
|
|
|
|
$task_redirect_info = $redirect_model->read(['origin_domain'=>$domain_301,'status'=>['<',DomainRedirectTask::STATUS_SUC]]);
|
|
|
|
if(!$task_redirect_info){
|
|
|
|
$redirect_model->add([
|
|
|
|
'origin_domain'=> $domain_301,
|
|
|
|
'target_domain' => $info['domain']
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -274,9 +296,6 @@ class DomainInfoLogic extends BaseLogic |
|
|
|
* @date 2023/11/13
|
|
|
|
*/
|
|
|
|
public function check_cname($domain, $server_info){
|
|
|
|
$checkA = false;
|
|
|
|
$checkCname = false;
|
|
|
|
|
|
|
|
$process = new Process(['nslookup', '-qt=a', $domain]);
|
|
|
|
$process->run();
|
|
|
|
$output = explode(PHP_EOL, $process->getOutput());
|
|
...
|
...
|
@@ -305,6 +324,27 @@ class DomainInfoLogic extends BaseLogic |
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 验证是否A记录解析到目标服务器
|
|
|
|
* @param $domain
|
|
|
|
* @param $ip
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function check_a($domain, $ip){
|
|
|
|
$process = new Process(['nslookup', '-qt=a', $domain]);
|
|
|
|
$process->run();
|
|
|
|
$output = explode(PHP_EOL, $process->getOutput());
|
|
|
|
foreach ($output as $line){
|
|
|
|
if($line){
|
|
|
|
$checkA = strpos($line, $ip) !== false;
|
|
|
|
if($checkA){
|
|
|
|
return $domain;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 设置语种自定义跳转链接
|
|
|
|
* @param $project_id
|
|
|
|
* @return array
|
...
|
...
|
|