作者 刘锟

update

@@ -310,6 +310,8 @@ class DomainInfo extends Command @@ -310,6 +310,8 @@ class DomainInfo extends Command
310 */ 310 */
311 public function updateDomainSsl($domain) 311 public function updateDomainSsl($domain)
312 { 312 {
  313 + $valid_from = '';
  314 + $valid_to = '';
313 try { 315 try {
314 $context = stream_context_create([ 316 $context = stream_context_create([
315 'ssl' => [ 317 'ssl' => [
@@ -320,15 +322,13 @@ class DomainInfo extends Command @@ -320,15 +322,13 @@ class DomainInfo extends Command
320 ], 322 ],
321 ]); 323 ]);
322 $stream = stream_socket_client('ssl://' . $domain . ':443', $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context); 324 $stream = stream_socket_client('ssl://' . $domain . ':443', $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
323 - if (!$stream) {  
324 - die("Failed to connect: $errno - $errstr"); 325 + if($stream){
  326 + $remote_cert = stream_context_get_params($stream)['options']['ssl']['peer_certificate'];
  327 + if($remote_cert){
  328 + $valid_from = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validFrom_time_t']);
  329 + $valid_to = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validTo_time_t']);
  330 + }
325 } 331 }
326 - $remote_cert = stream_context_get_params($stream)['options']['ssl']['peer_certificate'];  
327 - if (!$remote_cert) {  
328 - die("Failed to retrieve certificate");  
329 - }  
330 - $valid_from = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validFrom_time_t']);  
331 - $valid_to = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validTo_time_t']);  
332 fclose($stream); 332 fclose($stream);
333 } catch (\Exception $e) { 333 } catch (\Exception $e) {
334 $valid_from = ''; 334 $valid_from = '';