作者 刘锟

合并分支 'akun' 到 'master'

Akun



查看合并请求 !683
@@ -15,6 +15,7 @@ use App\Models\Project\CountryCustom; @@ -15,6 +15,7 @@ use App\Models\Project\CountryCustom;
15 use App\Models\Project\Project; 15 use App\Models\Project\Project;
16 use Illuminate\Console\Command; 16 use Illuminate\Console\Command;
17 use App\Models\Domain\DomainInfo as DomainInfoModel; 17 use App\Models\Domain\DomainInfo as DomainInfoModel;
  18 +use Symfony\Component\Process\Process;
18 19
19 class DomainInfo extends Command 20 class DomainInfo extends Command
20 { 21 {
@@ -86,6 +87,7 @@ class DomainInfo extends Command @@ -86,6 +87,7 @@ class DomainInfo extends Command
86 { 87 {
87 $domainModel = new DomainInfoModel(); 88 $domainModel = new DomainInfoModel();
88 $projectModel = new Project(); 89 $projectModel = new Project();
  90 + $serverIpModel = new ServersIp();
89 $end_day = date('Y-m-d H:i:s', time() + 3 * 24 * 3600);//3天后到期 91 $end_day = date('Y-m-d H:i:s', time() + 3 * 24 * 3600);//3天后到期
90 $list = $domainModel->where('status', '=', 1)->where(function ($query) use ($end_day) { 92 $list = $domainModel->where('status', '=', 1)->where(function ($query) use ($end_day) {
91 $query->whereNull('certificate_end_time')->orWhere('certificate_end_time', '<', $end_day); 93 $query->whereNull('certificate_end_time')->orWhere('certificate_end_time', '<', $end_day);
@@ -100,9 +102,8 @@ class DomainInfo extends Command @@ -100,9 +102,8 @@ class DomainInfo extends Command
100 102
101 $project_info = $projectModel->read(['id' => $v['project_id']], ['serve_id']); 103 $project_info = $projectModel->read(['id' => $v['project_id']], ['serve_id']);
102 if ($v['type'] == 1 && $ssl['to'] < $end_day && $project_info) { 104 if ($v['type'] == 1 && $ssl['to'] < $end_day && $project_info) {
103 - $serverIpModel = new ServersIp();  
104 - $servers_ip_info = $serverIpModel->read(['id' => $project_info['serve_id']], ['servers_id']);  
105 - if ($servers_ip_info && $servers_ip_info['servers_id'] != ServerConfig::SELF_SITE_ID) { 105 + $servers_ip_info = $serverIpModel->read(['id' => $project_info['serve_id']], ['servers_id', 'ip', 'domain']);
  106 + if ($servers_ip_info && $servers_ip_info['servers_id'] != ServerConfig::SELF_SITE_ID && $this->check_cname($v['domain'], $servers_ip_info)) {
106 //非自建站项目,申请免费证书 107 //非自建站项目,申请免费证书
107 $this->updatePrivate($v); 108 $this->updatePrivate($v);
108 109
@@ -126,6 +127,7 @@ class DomainInfo extends Command @@ -126,6 +127,7 @@ class DomainInfo extends Command
126 { 127 {
127 $domainModel = new DomainInfoModel(); 128 $domainModel = new DomainInfoModel();
128 $projectModel = new Project(); 129 $projectModel = new Project();
  130 + $serverIpModel = new ServersIp();
129 $end_day = date('Y-m-d H:i:s', time() + 3 * 24 * 3600);//3天后到期 131 $end_day = date('Y-m-d H:i:s', time() + 3 * 24 * 3600);//3天后到期
130 $list = $domainModel->where('status', '=', 1)->where('amp_status', 1)->where(function ($query) use ($end_day) { 132 $list = $domainModel->where('status', '=', 1)->where('amp_status', 1)->where(function ($query) use ($end_day) {
131 $query->whereNull('amp_certificate_end_time')->orWhere('amp_certificate_end_time', '<', $end_day); 133 $query->whereNull('amp_certificate_end_time')->orWhere('amp_certificate_end_time', '<', $end_day);
@@ -149,15 +151,14 @@ class DomainInfo extends Command @@ -149,15 +151,14 @@ class DomainInfo extends Command
149 151
150 $project_info = $projectModel->read(['id' => $v['project_id']], ['serve_id']); 152 $project_info = $projectModel->read(['id' => $v['project_id']], ['serve_id']);
151 if ($v['amp_type'] == 1 && $ssl['to'] < $end_day && $project_info) { 153 if ($v['amp_type'] == 1 && $ssl['to'] < $end_day && $project_info) {
152 - $serverIpModel = new ServersIp();  
153 - $servers_ip_info = $serverIpModel->read(['id' => $project_info['serve_id']], ['servers_id']);  
154 - if ($servers_ip_info && $servers_ip_info['servers_id'] != ServerConfig::SELF_SITE_ID) { 154 + $servers_ip_info = $serverIpModel->read(['id' => $project_info['serve_id']], ['servers_id', 'ip', 'domain']);
  155 + if ($servers_ip_info && $servers_ip_info['servers_id'] != ServerConfig::SELF_SITE_ID && $this->check_cname($amp_domain, $servers_ip_info)) {
155 //非自建站项目,申请免费证书 156 //非自建站项目,申请免费证书
156 $this->updateAmpPrivate($v); 157 $this->updateAmpPrivate($v);
157 158
158 - $ssl_new = $this->updateDomainSsl($v['domain']);  
159 - $ssl_new['from'] && $data['certificate_start_time'] = $ssl_new['from'];  
160 - $ssl_new['to'] && $data['certificate_end_time'] = $ssl_new['to']; 159 + $ssl_new = $this->updateDomainSsl($amp_domain);
  160 + $ssl_new['from'] && $data['amp_certificate_start_time'] = $ssl_new['from'];
  161 + $ssl_new['to'] && $data['amp_certificate_end_time'] = $ssl_new['to'];
161 } 162 }
162 } 163 }
163 164
@@ -173,6 +174,8 @@ class DomainInfo extends Command @@ -173,6 +174,8 @@ class DomainInfo extends Command
173 public function startUpdateCustomCert() 174 public function startUpdateCustomCert()
174 { 175 {
175 $customModel = new CountryCustom(); 176 $customModel = new CountryCustom();
  177 + $projectModel = new Project();
  178 + $serverIpModel = new ServersIp();
176 $end_day = date('Y-m-d H:i:s', time() + 3 * 24 * 3600);//3天后到期 179 $end_day = date('Y-m-d H:i:s', time() + 3 * 24 * 3600);//3天后到期
177 $list = $customModel->where('status', 1)->where('is_create', 1)->where(function ($query) use ($end_day) { 180 $list = $customModel->where('status', 1)->where('is_create', 1)->where(function ($query) use ($end_day) {
178 $query->whereNull('certificate_end_time')->orWhere('certificate_end_time', '<', $end_day); 181 $query->whereNull('certificate_end_time')->orWhere('certificate_end_time', '<', $end_day);
@@ -184,13 +187,17 @@ class DomainInfo extends Command @@ -184,13 +187,17 @@ class DomainInfo extends Command
184 $ssl['from'] && $data['certificate_start_time'] = $ssl['from']; 187 $ssl['from'] && $data['certificate_start_time'] = $ssl['from'];
185 $ssl['to'] && $data['certificate_end_time'] = $ssl['to']; 188 $ssl['to'] && $data['certificate_end_time'] = $ssl['to'];
186 189
187 - if ($v['type'] == 1 && $ssl['to'] < $end_day) {  
188 - //申请免费证书  
189 - $this->updateCustomPrivate($v['custom_domain']); 190 + $project_info = $projectModel->read(['id' => $v['project_id']], ['serve_id']);
  191 + if ($v['type'] == 1 && $ssl['to'] < $end_day && $project_info) {
  192 + $servers_ip_info = $serverIpModel->read(['id' => $project_info['serve_id']], ['servers_id', 'ip', 'domain']);
  193 + if ($servers_ip_info && $servers_ip_info['servers_id'] != ServerConfig::SELF_SITE_ID && $this->check_cname($v['custom_domain'], $servers_ip_info)) {
  194 + //申请免费证书
  195 + $this->updateCustomPrivate($v['custom_domain']);
190 196
191 - $ssl_new = $this->updateDomainSsl($v['domain']);  
192 - $ssl_new['from'] && $data['certificate_start_time'] = $ssl_new['from'];  
193 - $ssl_new['to'] && $data['certificate_end_time'] = $ssl_new['to']; 197 + $ssl_new = $this->updateDomainSsl($v['domain']);
  198 + $ssl_new['from'] && $data['certificate_start_time'] = $ssl_new['from'];
  199 + $ssl_new['to'] && $data['certificate_end_time'] = $ssl_new['to'];
  200 + }
194 } 201 }
195 202
196 $customModel->edit($data, ['id' => $v['id']]); 203 $customModel->edit($data, ['id' => $v['id']]);
@@ -336,4 +343,41 @@ class DomainInfo extends Command @@ -336,4 +343,41 @@ class DomainInfo extends Command
336 } 343 }
337 return ['start' => $start, 'end' => $end]; 344 return ['start' => $start, 'end' => $end];
338 } 345 }
  346 +
  347 + /**
  348 + * 验证是否cname或者A记录解析到目标服务器
  349 + * @param $domain
  350 + * @param $server_info
  351 + * @return mixed
  352 + * @author zbj
  353 + * @date 2023/11/13
  354 + */
  355 + public function check_cname($domain, $server_info)
  356 + {
  357 + $process = new Process(['nslookup', '-qt=a', $domain]);
  358 + $process->run();
  359 + $output = explode(PHP_EOL, $process->getOutput());
  360 + foreach ($output as $line) {
  361 + if ($line) {
  362 + $checkA = strpos($line, $server_info['ip']) !== false;
  363 + if ($checkA) {
  364 + return $domain;
  365 + }
  366 + }
  367 + }
  368 +
  369 + //是否cname
  370 + $process = new Process(['nslookup', '-qt=cname', $domain]);
  371 + $process->run();
  372 + $output = explode(PHP_EOL, $process->getOutput());
  373 + foreach ($output as $line) {
  374 + if ($line) {
  375 + $checkCname = (strpos($line, $server_info['domain']) !== false);
  376 + if ($checkCname) {
  377 + return $domain;
  378 + }
  379 + }
  380 + }
  381 + return false;
  382 + }
339 } 383 }