2019-12-09 12:51:46 +01:00
|
|
|
<?php
|
|
|
|
|
2019-12-10 13:49:25 +01:00
|
|
|
namespace Deblan\Parser;
|
2019-12-09 12:51:46 +01:00
|
|
|
|
|
|
|
/**
|
2019-12-10 13:49:25 +01:00
|
|
|
* class SslCertParser.
|
2019-12-09 12:51:46 +01:00
|
|
|
*
|
|
|
|
* @author Simon Vieille <simon@deblan.fr>
|
|
|
|
*/
|
2019-12-10 13:49:25 +01:00
|
|
|
class SslCertParser
|
2019-12-09 12:51:46 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $check;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
|
|
|
* @param mixed $whois
|
|
|
|
*/
|
|
|
|
public function __construct(string $check)
|
|
|
|
{
|
|
|
|
$this->check = $check;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extracts expiry date.
|
|
|
|
*
|
|
|
|
* @return DateTime|null
|
|
|
|
*/
|
|
|
|
public function getExpiryDate(): ? \DateTime
|
|
|
|
{
|
2023-11-03 13:40:53 +01:00
|
|
|
preg_match('/expires in ([^\s]+)\s+/', $this->check, $match);
|
2019-12-09 12:51:46 +01:00
|
|
|
|
|
|
|
if (isset($match[1])) {
|
|
|
|
$days = (int) $match[1];
|
|
|
|
|
|
|
|
if ($days > 0) {
|
|
|
|
$date = 'now +'.$days.' days';
|
|
|
|
} else {
|
|
|
|
$date = 'now '.$days.' days';
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
return new \DateTime($date);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|