|
...
|
...
|
@@ -83,23 +83,28 @@ class DomainInfo extends Command |
|
|
|
public function startUpdateCert()
|
|
|
|
{
|
|
|
|
$domainModel = new DomainInfoModel();
|
|
|
|
$end_day = date('Y-m-d H:i:s', time() + 2 * 24 * 3600);//2天后到期
|
|
|
|
$end_day = date('Y-m-d H:i:s', time() + 3 * 24 * 3600);//3天后到期
|
|
|
|
$list = $domainModel->where('status', '!=', 2)->where(function ($query) use ($end_day) {
|
|
|
|
$query->whereNull('certificate_end_time')->orWhere('certificate_end_time', '<', $end_day);
|
|
|
|
})->get()->toArray();
|
|
|
|
foreach ($list as $v) {
|
|
|
|
//更新证书到期时间
|
|
|
|
$data = [];
|
|
|
|
|
|
|
|
$ssl = $this->updateDomainSsl($v['domain']);
|
|
|
|
$ssl['from'] && $data['certificate_start_time'] = $ssl['from'];
|
|
|
|
$ssl['to'] && $data['certificate_end_time'] = $ssl['to'];
|
|
|
|
|
|
|
|
$domainModel->edit($data, ['id' => $v['id']]);
|
|
|
|
|
|
|
|
if ($v['type'] == 1 && ($data['certificate_end_time'] ?? '') < $end_day) {
|
|
|
|
if ($v['type'] == 1 && $ssl['to'] < $end_day) {
|
|
|
|
//申请免费证书
|
|
|
|
$this->updatePrivate($v);
|
|
|
|
|
|
|
|
$ssl_new = $this->updateDomainSsl($v['domain']);
|
|
|
|
$ssl_new['from'] && $data['certificate_start_time'] = $ssl_new['from'];
|
|
|
|
$ssl_new['to'] && $data['certificate_end_time'] = $ssl_new['to'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$domainModel->edit($data, ['id' => $v['id']]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -111,7 +116,7 @@ class DomainInfo extends Command |
|
|
|
public function startUpdateAmpCert()
|
|
|
|
{
|
|
|
|
$domainModel = new DomainInfoModel();
|
|
|
|
$end_day = date('Y-m-d H:i:s', time() + 2 * 24 * 3600);//2天后到期
|
|
|
|
$end_day = date('Y-m-d H:i:s', time() + 3 * 24 * 3600);//3天后到期
|
|
|
|
$list = $domainModel->where('status', '!=', 2)->where('amp_status', 1)->where(function ($query) use ($end_day) {
|
|
|
|
$query->whereNull('amp_certificate_end_time')->orWhere('amp_certificate_end_time', '<', $end_day);
|
|
|
|
})->get()->toArray();
|
|
...
|
...
|
@@ -132,12 +137,16 @@ class DomainInfo extends Command |
|
|
|
$ssl['from'] && $data['amp_certificate_start_time'] = $ssl['from'];
|
|
|
|
$ssl['to'] && $data['amp_certificate_end_time'] = $ssl['to'];
|
|
|
|
|
|
|
|
$domainModel->edit($data, ['id' => $v['id']]);
|
|
|
|
|
|
|
|
if ($v['amp_type'] == 1 && ($data['amp_certificate_end_time'] ?? '') < $end_day) {
|
|
|
|
if ($v['amp_type'] == 1 && $ssl['to'] < $end_day) {
|
|
|
|
//申请免费证书
|
|
|
|
$this->updateAmpPrivate($v['domain']);
|
|
|
|
|
|
|
|
$ssl_new = $this->updateDomainSsl($v['domain']);
|
|
|
|
$ssl_new['from'] && $data['certificate_start_time'] = $ssl_new['from'];
|
|
|
|
$ssl_new['to'] && $data['certificate_end_time'] = $ssl_new['to'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$domainModel->edit($data, ['id' => $v['id']]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -149,7 +158,7 @@ class DomainInfo extends Command |
|
|
|
public function startUpdateCustomCert()
|
|
|
|
{
|
|
|
|
$customModel = new CountryCustom();
|
|
|
|
$end_day = date('Y-m-d H:i:s', time() + 2 * 24 * 3600);//2天后到期
|
|
|
|
$end_day = date('Y-m-d H:i:s', time() + 3 * 24 * 3600);//3天后到期
|
|
|
|
$list = $customModel->where('status', 1)->where('is_create', 1)->where(function ($query) use ($end_day) {
|
|
|
|
$query->whereNull('certificate_end_time')->orWhere('certificate_end_time', '<', $end_day);
|
|
|
|
})->get()->toArray();
|
|
...
|
...
|
@@ -160,12 +169,16 @@ class DomainInfo extends Command |
|
|
|
$ssl['from'] && $data['certificate_start_time'] = $ssl['from'];
|
|
|
|
$ssl['to'] && $data['certificate_end_time'] = $ssl['to'];
|
|
|
|
|
|
|
|
$customModel->edit($data, ['id' => $v['id']]);
|
|
|
|
|
|
|
|
if ($v['type'] == 1 && ($data['certificate_end_time'] ?? '') < $end_day) {
|
|
|
|
if ($v['type'] == 1 && $ssl['to'] < $end_day) {
|
|
|
|
//申请免费证书
|
|
|
|
$this->updateCustomPrivate($v['custom_domain']);
|
|
|
|
|
|
|
|
$ssl_new = $this->updateDomainSsl($v['domain']);
|
|
|
|
$ssl_new['from'] && $data['certificate_start_time'] = $ssl_new['from'];
|
|
|
|
$ssl_new['to'] && $data['certificate_end_time'] = $ssl_new['to'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$customModel->edit($data, ['id' => $v['id']]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -297,6 +310,8 @@ class DomainInfo extends Command |
|
|
|
*/
|
|
|
|
public function updateDomainSsl($domain)
|
|
|
|
{
|
|
|
|
$valid_from = '';
|
|
|
|
$valid_to = '';
|
|
|
|
try {
|
|
|
|
$context = stream_context_create([
|
|
|
|
'ssl' => [
|
|
...
|
...
|
@@ -307,15 +322,13 @@ class DomainInfo extends Command |
|
|
|
],
|
|
|
|
]);
|
|
|
|
$stream = stream_socket_client('ssl://' . $domain . ':443', $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
|
|
|
|
if (!$stream) {
|
|
|
|
die("Failed to connect: $errno - $errstr");
|
|
|
|
}
|
|
|
|
$remote_cert = stream_context_get_params($stream)['options']['ssl']['peer_certificate'];
|
|
|
|
if (!$remote_cert) {
|
|
|
|
die("Failed to retrieve certificate");
|
|
|
|
if($stream){
|
|
|
|
$remote_cert = stream_context_get_params($stream)['options']['ssl']['peer_certificate'];
|
|
|
|
if($remote_cert){
|
|
|
|
$valid_from = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validFrom_time_t']);
|
|
|
|
$valid_to = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validTo_time_t']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$valid_from = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validFrom_time_t']);
|
|
|
|
$valid_to = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validTo_time_t']);
|
|
|
|
fclose($stream);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
$valid_from = '';
|
...
|
...
|
|