|
...
|
...
|
@@ -40,6 +40,12 @@ class DomainInfo extends Command |
|
|
|
$map = ['status'=>['!=',2]];
|
|
|
|
$list = $domainModel->list($map);
|
|
|
|
foreach ($list as $v){
|
|
|
|
if(empty($v['private_key']) || empty($v['private_cert'])){
|
|
|
|
//域名结束时间<2天时,重新生成
|
|
|
|
if(!empty($v['certificate_end_time']) && ($v['certificate_end_time'] > date('Y-m-d H:i:s',time() + 24*3600))){
|
|
|
|
$this->updatePrivate($v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$ssl = $this->updateDomainSsl($v['domain']);
|
|
|
|
$time = $this->updateDomain($v['domain']);
|
|
|
|
$data = [
|
|
...
|
...
|
@@ -48,12 +54,94 @@ class DomainInfo extends Command |
|
|
|
'domain_start_time'=>$time['start'],
|
|
|
|
'domain_end_time'=>$time['end']
|
|
|
|
];
|
|
|
|
|
|
|
|
$domainModel->edit($data,['id'=>$v['id']]);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :更新正式
|
|
|
|
* @name :updatePrivate
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/8 16:16
|
|
|
|
*/
|
|
|
|
public function updatePrivate($param)
|
|
|
|
{
|
|
|
|
$url = 'https://' . $param['domain']. '/api/applySsl/';
|
|
|
|
$extend_config = json_decode($param['extend_config'], true);
|
|
|
|
$top_domain = $this->getTopDomain($param['domain']);
|
|
|
|
if ((empty($extend_config) || empty($extend_config[0]['origin'])) && $param['id'] != 3) {
|
|
|
|
$extend_config = [
|
|
|
|
['origin' => $top_domain, 'target' => $param['domain']]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
$param = [
|
|
|
|
'project_id' => $param['project_id'],
|
|
|
|
'type' => 1,
|
|
|
|
'route' => 1,
|
|
|
|
"domain" =>$param['domain'],
|
|
|
|
"rewrite"=> $extend_config,
|
|
|
|
'other_domain' => [$top_domain, '*.' . $top_domain],
|
|
|
|
'private_key' => '',
|
|
|
|
'cert' => ''
|
|
|
|
];
|
|
|
|
$result = $this->curlRequest($url, $param);
|
|
|
|
Log::info('domain id: ' . $param['id'] . ', domain: ' . $param['domain'] . ', result: ' . var_export($result, true));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getTopDomain ($url) {
|
|
|
|
$url = strtolower($url); //首先转成小写
|
|
|
|
$url = mb_ereg_replace('^( | )+', '', trim($url));
|
|
|
|
$url = mb_ereg_replace('( | )+$', '', $url);
|
|
|
|
if (!preg_match('/^(http:\/\/|https)/', $url)) {
|
|
|
|
$url = "https://".$url;
|
|
|
|
}
|
|
|
|
$hosts = parse_url($url);
|
|
|
|
$host = $hosts['host'] ?? '';
|
|
|
|
//查看是几级域名
|
|
|
|
$data = explode('.', $host);
|
|
|
|
$n = count($data);
|
|
|
|
if ($n < 2) {
|
|
|
|
return $host;
|
|
|
|
}
|
|
|
|
//判断是否是双后缀
|
|
|
|
$preg = '/[\w].+\.(com|net|org|gov|edu|co|ne)\.[\w]/';
|
|
|
|
if (($n > 2) && preg_match($preg, $host)) {
|
|
|
|
//双后缀取后3位
|
|
|
|
$host = $data[$n - 3].'.'.$data[$n - 2].'.'.$data[$n - 1];
|
|
|
|
} else {
|
|
|
|
//非双后缀取后两位
|
|
|
|
$host = $data[$n - 2].'.'.$data[$n - 1];
|
|
|
|
}
|
|
|
|
return $host;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function curlRequest($url, $data, $method = 'POST', $header = [], $time_out = 60)
|
|
|
|
{
|
|
|
|
$ch = curl_init();
|
|
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, $time_out);
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
|
|
|
|
if ($data)
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array_merge([
|
|
|
|
'Expect:',
|
|
|
|
'Content-type: application/json',
|
|
|
|
'Accept: application/json',
|
|
|
|
], $header)
|
|
|
|
);
|
|
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
|
|
|
|
$response = curl_exec($ch);
|
|
|
|
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
|
curl_close($ch);
|
|
|
|
return [$code, $response];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :更新域名证书
|
|
|
|
* @name :updateDomainSsl
|
|
|
|
* @author :lyh
|
...
|
...
|
|