|
...
|
...
|
@@ -40,10 +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($v['certificate_end_time'] > date('Y-m-d H:i:s',time()+ 24*3600)){
|
|
|
|
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 = [
|
|
...
|
...
|
@@ -67,35 +69,76 @@ class DomainInfo extends Command |
|
|
|
*/
|
|
|
|
public function updatePrivate($param)
|
|
|
|
{
|
|
|
|
$key = $param['private_key'];
|
|
|
|
$cert = $param['private_cert'];
|
|
|
|
if (empty($key) || empty($cert)){
|
|
|
|
$url = 'https://' . $v->domain. '/api/applySsl/';
|
|
|
|
}else{
|
|
|
|
$url = 'https://' . $v->domain. '/api/setSsl/';
|
|
|
|
}
|
|
|
|
|
|
|
|
$extend_config = json_decode($v->extend_config, true);
|
|
|
|
$top_domain = Str::getTopDomain($v->domain);
|
|
|
|
if ((empty($extend_config) || empty($extend_config[0]['origin'])) && $v->id != 3) {
|
|
|
|
$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' => $v->domain]
|
|
|
|
['origin' => $top_domain, 'target' => $param['domain']]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
$param = [
|
|
|
|
'project_id' => $k,
|
|
|
|
'project_id' => $param['project_id'],
|
|
|
|
'type' => 1,
|
|
|
|
'route' => 1,
|
|
|
|
"domain" =>$v->domain,
|
|
|
|
"domain" =>$param['domain'],
|
|
|
|
"rewrite"=> $extend_config,
|
|
|
|
'other_domain' => [$top_domain, '*.' . $top_domain],
|
|
|
|
'private_key' => $key,
|
|
|
|
'cert' => $cert
|
|
|
|
'private_key' => '',
|
|
|
|
'cert' => ''
|
|
|
|
];
|
|
|
|
$result = app(ToolRepository::class)->curlRequest($url, $param);
|
|
|
|
Log::info('domain id: ' . $v->id . ', domain: ' . $v->domain . ', result: ' . var_export($result, true));
|
|
|
|
var_dump($result);
|
|
|
|
$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];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
...
|
...
|
|