Compare commits
7 commits
Author | SHA1 | Date | |
---|---|---|---|
53be613099 | |||
1dc4a47320 | |||
059300dde6 | |||
Simon Vieille | e9af453f57 | ||
Simon Vieille | c13d3953b5 | ||
Simon Vieille | c13d3131bb | ||
Simon Vieille | 7899c45545 |
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
[submodule "lib/check_ssl_cert"]
|
||||||
|
path = lib/check_ssl_cert
|
||||||
|
url = https://github.com/matteocorti/check_ssl_cert.git
|
19
README.md
19
README.md
|
@ -1,20 +1,27 @@
|
||||||
Domain expiration
|
Domain expiration
|
||||||
=================
|
=================
|
||||||
|
|
||||||
Checks the expiration dates of domains.
|
Checks the expiration dates of domains et HTTPS certificates.
|
||||||
|
|
||||||
## Installation and usage
|
## Installation and usage
|
||||||
|
|
||||||
PHP 7.3, [composer](https://getcomposer.org/) and `whois` required.
|
PHP 7.3, [composer](https://getcomposer.org/), `whois` and `openssl` required.
|
||||||
|
|
||||||
```text
|
```text
|
||||||
$ git clone https://gitnet.fr/deblan/domain-expiration.git
|
git clone --recurse-submodules https://gitnet.fr/deblan/domain-expiration.git
|
||||||
$ cd domain-expiration
|
cd domain-expiration
|
||||||
$ composer install
|
composer install
|
||||||
```
|
```
|
||||||
|
|
||||||
```text
|
```text
|
||||||
$ php7.3 ./domain-expiration check example.com other-example.com
|
$ php7.3 ./check domains example.com other-example.com
|
||||||
|
+-------------------+------+---------------------+
|
||||||
|
| Domain | Days | Date |
|
||||||
|
+-------------------+------+---------------------+
|
||||||
|
| example.com | XX | YYYY-MM-DD HH:MM:SS |
|
||||||
|
| other-example.com | XXX | YYYY-MM-DD HH:MM:SS |
|
||||||
|
+-------------------+------+---------------------+
|
||||||
|
$ php7.3 ./check https-certificates example.com other-example.com
|
||||||
+-------------------+------+---------------------+
|
+-------------------+------+---------------------+
|
||||||
| Domain | Days | Date |
|
| Domain | Days | Date |
|
||||||
+-------------------+------+---------------------+
|
+-------------------+------+---------------------+
|
||||||
|
|
15
check
Executable file
15
check
Executable file
|
@ -0,0 +1,15 @@
|
||||||
|
#!/usr/bin/env php7.3
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require __DIR__.'/vendor/autoload.php';
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Application;
|
||||||
|
use Deblan\Command\CheckDomainsCommand;
|
||||||
|
use Deblan\Command\CheckHttpsCertificatesCommand;
|
||||||
|
|
||||||
|
chdir(__DIR__);
|
||||||
|
|
||||||
|
$application = new Application();
|
||||||
|
$application->add(new CheckDomainsCommand());
|
||||||
|
$application->add(new CheckHttpsCertificatesCommand());
|
||||||
|
$application->run();
|
|
@ -1,11 +0,0 @@
|
||||||
#!/usr/bin/env php7.3
|
|
||||||
<?php
|
|
||||||
|
|
||||||
require __DIR__.'/vendor/autoload.php';
|
|
||||||
|
|
||||||
use Symfony\Component\Console\Application;
|
|
||||||
use Deblan\Command\CheckCommand;
|
|
||||||
|
|
||||||
$application = new Application();
|
|
||||||
$application->add(new CheckCommand());
|
|
||||||
$application->run();
|
|
1
lib/check_ssl_cert
Submodule
1
lib/check_ssl_cert
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 3935a6d0ac8239bde3207d2a39681db0e6d517d4
|
|
@ -8,7 +8,7 @@ use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Command\Command as BaseCommand;
|
use Symfony\Component\Console\Command\Command as BaseCommand;
|
||||||
use Symfony\Component\Console\Helper\Table;
|
use Symfony\Component\Console\Helper\Table;
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
use Deblan\Whois\Parser;
|
use Deblan\Parser\WhoisParser as Parser;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,7 +16,7 @@ use Symfony\Component\Console\Input\InputOption;
|
||||||
*
|
*
|
||||||
* @author Simon Vieille <simon@deblan.fr>
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
class CheckCommand extends BaseCommand
|
abstract class CheckCommand extends BaseCommand
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
|
@ -44,47 +44,12 @@ class CheckCommand extends BaseCommand
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
->setName('check')
|
|
||||||
->addArgument('domains', InputArgument::IS_ARRAY | InputArgument::REQUIRED, 'List of domains')
|
->addArgument('domains', InputArgument::IS_ARRAY | InputArgument::REQUIRED, 'List of domains')
|
||||||
->addOption('short', 's', InputOption::VALUE_NONE, 'Simplify the table output')
|
->addOption('short', 's', InputOption::VALUE_NONE, 'Simplify the table output')
|
||||||
->addOption('no-headers', null, InputOption::VALUE_NONE, 'Remove the table headers')
|
->addOption('no-headers', null, InputOption::VALUE_NONE, 'Remove the table headers')
|
||||||
->addOption('wait', 'w', InputOption::VALUE_REQUIRED, 'Wait between each whois (in second, default: 0)')
|
->addOption('wait', 'w', InputOption::VALUE_REQUIRED, 'Wait between each whois (in second, default: 0)')
|
||||||
->addOption('json', 'j', InputOption::VALUE_NONE, 'Select json as output')
|
->addOption('json', 'j', InputOption::VALUE_NONE, 'Select json as output')
|
||||||
->addOption('table', 't', InputOption::VALUE_NONE, 'Select table as output (default)')
|
->addOption('table', 't', InputOption::VALUE_NONE, 'Select table as output (default)');
|
||||||
->setHelp(<<<'EOF'
|
|
||||||
The <info>%command.name%</info> retrieves the expiration dates of the given domains.
|
|
||||||
|
|
||||||
Example: %command.full_name% example.com other-example.com
|
|
||||||
EOF
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
|
||||||
{
|
|
||||||
$this->input = $input;
|
|
||||||
$this->output = $output;
|
|
||||||
$wait = (int) $this->input->getOption('wait');
|
|
||||||
|
|
||||||
$this->checkDomains($wait);
|
|
||||||
|
|
||||||
$short = $this->input->getOption('short');
|
|
||||||
$json = $this->input->getOption('json');
|
|
||||||
$table = $this->input->getOption('table') || !$json;
|
|
||||||
$noHeaders = $this->input->getOption('no-headers');
|
|
||||||
|
|
||||||
$successes = $this->sort($this->successes);
|
|
||||||
$fails = $this->sort($this->fails);
|
|
||||||
|
|
||||||
if ($json) {
|
|
||||||
return $this->output->write(json_encode(array_merge($successes, $fails)));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($table) {
|
|
||||||
$this->renderTable($successes, $fails, $short, $noHeaders);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -160,59 +125,6 @@ EOF
|
||||||
return $domains;
|
return $domains;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks domains.
|
|
||||||
*/
|
|
||||||
protected function checkDomains(int $wait):void
|
|
||||||
{
|
|
||||||
$domains = $this->getDomains();
|
|
||||||
$count = count($domains);
|
|
||||||
|
|
||||||
foreach ($domains as $key => $domain) {
|
|
||||||
$data = $this->checkDomain($domain);
|
|
||||||
|
|
||||||
if ($data['expiryDate'] === null) {
|
|
||||||
$this->fails[] = $data;
|
|
||||||
} else {
|
|
||||||
$this->successes[] = $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($wait > 0 && $key !== $count - 1) {
|
|
||||||
sleep($wait);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks domain.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected function checkDomain($domain):array
|
|
||||||
{
|
|
||||||
$process = new Process(['whois', $domain]);
|
|
||||||
$process->run();
|
|
||||||
|
|
||||||
$whois = $process->getOutput();
|
|
||||||
$parser = new Parser($whois);
|
|
||||||
$expiryDate = $parser->getExpiryDate();
|
|
||||||
|
|
||||||
if ($expiryDate) {
|
|
||||||
$comparison = $expiryDate->getTimestamp();
|
|
||||||
$dayUntilExpiry = floor(($expiryDate->getTimestamp() - time()) / 3600 / 24);
|
|
||||||
} else {
|
|
||||||
$comparison = 'FAIL';
|
|
||||||
$dayUntilExpiry = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
'domain' => $domain,
|
|
||||||
'expiryDate' => $expiryDate,
|
|
||||||
'dayUntilExpiry' => $dayUntilExpiry,
|
|
||||||
'comparison' => $expiryDate ? $expiryDate->getTimestamp() : 'FAIL',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorts by expiry date and domain.
|
* Sorts by expiry date and domain.
|
||||||
*
|
*
|
||||||
|
@ -263,3 +175,4 @@ EOF
|
||||||
return sprintf('<fg=%s>%s</>', $color, $date->format('Y-m-d H:i:s'));
|
return sprintf('<fg=%s>%s</>', $color, $date->format('Y-m-d H:i:s'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
119
src/Deblan/Command/CheckDomainsCommand.php
Normal file
119
src/Deblan/Command/CheckDomainsCommand.php
Normal file
|
@ -0,0 +1,119 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Deblan\Command;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Helper\Table;
|
||||||
|
use Symfony\Component\Process\Process;
|
||||||
|
use Deblan\Parser\WhoisParser as Parser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* class CheckDomainsCommand.
|
||||||
|
*
|
||||||
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
|
*/
|
||||||
|
class CheckDomainsCommand extends CheckCommand
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function configure()
|
||||||
|
{
|
||||||
|
parent::configure();
|
||||||
|
|
||||||
|
$this
|
||||||
|
->setName('domains')
|
||||||
|
->setHelp(<<<'EOF'
|
||||||
|
The <info>%command.name%</info> retrieves the expiration dates of the given domains.
|
||||||
|
|
||||||
|
Example: %command.full_name% example.com other-example.com
|
||||||
|
EOF
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
|
{
|
||||||
|
$this->input = $input;
|
||||||
|
$this->output = $output;
|
||||||
|
$wait = (int) $this->input->getOption('wait');
|
||||||
|
|
||||||
|
$this->checkDomains($wait);
|
||||||
|
|
||||||
|
$short = $this->input->getOption('short');
|
||||||
|
$json = $this->input->getOption('json');
|
||||||
|
$table = $this->input->getOption('table') || !$json;
|
||||||
|
$noHeaders = $this->input->getOption('no-headers');
|
||||||
|
|
||||||
|
$successes = $this->sort($this->successes);
|
||||||
|
$fails = $this->sort($this->fails);
|
||||||
|
|
||||||
|
if ($json) {
|
||||||
|
return $this->output->write(json_encode(array_merge($successes, $fails)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($table) {
|
||||||
|
$this->renderTable($successes, $fails, $short, $noHeaders);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks domains.
|
||||||
|
*
|
||||||
|
* @param int $wait
|
||||||
|
*/
|
||||||
|
protected function checkDomains(int $wait):void
|
||||||
|
{
|
||||||
|
$domains = $this->getDomains();
|
||||||
|
$count = count($domains);
|
||||||
|
|
||||||
|
foreach ($domains as $key => $domain) {
|
||||||
|
$data = $this->checkDomain($domain);
|
||||||
|
|
||||||
|
if ($data['expiryDate'] === null) {
|
||||||
|
$this->fails[] = $data;
|
||||||
|
} else {
|
||||||
|
$this->successes[] = $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($wait > 0 && $key !== $count - 1) {
|
||||||
|
sleep($wait);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks domain.
|
||||||
|
*
|
||||||
|
* @param mixed $domain
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function checkDomain($domain):array
|
||||||
|
{
|
||||||
|
$process = new Process(['whois', $domain]);
|
||||||
|
$process->run();
|
||||||
|
|
||||||
|
$whois = $process->getOutput();
|
||||||
|
$parser = new Parser($whois);
|
||||||
|
$expiryDate = $parser->getExpiryDate();
|
||||||
|
|
||||||
|
if ($expiryDate) {
|
||||||
|
$comparison = $expiryDate->getTimestamp();
|
||||||
|
$dayUntilExpiry = floor(($expiryDate->getTimestamp() - time()) / 3600 / 24);
|
||||||
|
} else {
|
||||||
|
$comparison = 'FAIL';
|
||||||
|
$dayUntilExpiry = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'domain' => $domain,
|
||||||
|
'expiryDate' => $expiryDate,
|
||||||
|
'dayUntilExpiry' => $dayUntilExpiry,
|
||||||
|
'comparison' => $expiryDate ? $expiryDate->getTimestamp() : 'FAIL',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
126
src/Deblan/Command/CheckHttpsCertificatesCommand.php
Normal file
126
src/Deblan/Command/CheckHttpsCertificatesCommand.php
Normal file
|
@ -0,0 +1,126 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Deblan\Command;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
use Symfony\Component\Console\Command\Command as BaseCommand;
|
||||||
|
use Symfony\Component\Console\Helper\Table;
|
||||||
|
use Symfony\Component\Process\Process;
|
||||||
|
use Deblan\Parser\SslCertParser as Parser;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* class CheckHttpsCertificatesCommand.
|
||||||
|
*
|
||||||
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
|
*/
|
||||||
|
class CheckHttpsCertificatesCommand extends CheckCommand
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function configure()
|
||||||
|
{
|
||||||
|
parent::configure();
|
||||||
|
|
||||||
|
$this
|
||||||
|
->setName('https-certificates')
|
||||||
|
->setHelp(<<<'EOF'
|
||||||
|
The <info>%command.name%</info> retrieves the expiration dates of the HTTPS certificates of domains.
|
||||||
|
|
||||||
|
Example: %command.full_name% example.com other-example.com
|
||||||
|
EOF
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
|
{
|
||||||
|
$this->input = $input;
|
||||||
|
$this->output = $output;
|
||||||
|
$wait = (int) $this->input->getOption('wait');
|
||||||
|
|
||||||
|
$this->checkHttpsCertificates($wait);
|
||||||
|
|
||||||
|
$short = $this->input->getOption('short');
|
||||||
|
$json = $this->input->getOption('json');
|
||||||
|
$table = $this->input->getOption('table') || !$json;
|
||||||
|
$noHeaders = $this->input->getOption('no-headers');
|
||||||
|
|
||||||
|
$successes = $this->sort($this->successes);
|
||||||
|
$fails = $this->sort($this->fails);
|
||||||
|
|
||||||
|
if ($json) {
|
||||||
|
return $this->output->write(json_encode(array_merge($successes, $fails)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($table) {
|
||||||
|
$this->renderTable($successes, $fails, $short, $noHeaders);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check HTTPS Certificates.
|
||||||
|
*
|
||||||
|
* @param int $wait
|
||||||
|
*/
|
||||||
|
protected function checkHttpsCertificates(int $wait):void
|
||||||
|
{
|
||||||
|
$domains = $this->getDomains();
|
||||||
|
$count = count($domains);
|
||||||
|
|
||||||
|
foreach ($domains as $key => $domain) {
|
||||||
|
$data = $this->checkHttpsCertificate($domain);
|
||||||
|
|
||||||
|
if ($data['expiryDate'] === null) {
|
||||||
|
$this->fails[] = $data;
|
||||||
|
} else {
|
||||||
|
$this->successes[] = $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($wait > 0 && $key !== $count - 1) {
|
||||||
|
sleep($wait);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check HTTPS Certificate using a domain.
|
||||||
|
*
|
||||||
|
* @param mixed $domain
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function checkHttpsCertificate($domain):array
|
||||||
|
{
|
||||||
|
$process = new Process([
|
||||||
|
'lib/check_ssl_cert/check_ssl_cert',
|
||||||
|
'-H',
|
||||||
|
$domain,
|
||||||
|
]);
|
||||||
|
$process->run();
|
||||||
|
|
||||||
|
$content = $process->getOutput();
|
||||||
|
$parser = new Parser($content);
|
||||||
|
$expiryDate = $parser->getExpiryDate();
|
||||||
|
|
||||||
|
if ($expiryDate) {
|
||||||
|
$comparison = $expiryDate->getTimestamp();
|
||||||
|
$dayUntilExpiry = floor(($expiryDate->getTimestamp() - time()) / 3600 / 24);
|
||||||
|
} else {
|
||||||
|
$comparison = 'FAIL';
|
||||||
|
$dayUntilExpiry = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'domain' => $domain,
|
||||||
|
'expiryDate' => $expiryDate,
|
||||||
|
'dayUntilExpiry' => $dayUntilExpiry,
|
||||||
|
'comparison' => $expiryDate ? $expiryDate->getTimestamp() : 'FAIL',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
53
src/Deblan/Parser/SslCertParser.php
Normal file
53
src/Deblan/Parser/SslCertParser.php
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Deblan\Parser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* class SslCertParser.
|
||||||
|
*
|
||||||
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
|
*/
|
||||||
|
class SslCertParser
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @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
|
||||||
|
{
|
||||||
|
preg_match('/expires in ([^\s]+)\s+/', $this->check, $match);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,13 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Deblan\Whois;
|
namespace Deblan\Parser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class Parser.
|
* class WhoisParser.
|
||||||
*
|
*
|
||||||
* @author Simon Vieille <simon@deblan.fr>
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
class Parser
|
class WhoisParser
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
Loading…
Reference in a new issue