init
Esse commit está contido em:
commit
13439890f0
2
.gitignore
externo
Arquivo normal
2
.gitignore
externo
Arquivo normal
|
@ -0,0 +1,2 @@
|
|||
/vendor
|
||||
/composer.lock
|
24
README.md
Arquivo normal
24
README.md
Arquivo normal
|
@ -0,0 +1,24 @@
|
|||
Domain expiration
|
||||
=================
|
||||
|
||||
Checks the expiration dates of domains.
|
||||
|
||||
## Installation and usage
|
||||
|
||||
PHP 7.3 and [composer](https://getcomposer.org/) required.
|
||||
|
||||
```
|
||||
$ git clone https://gitnet.fr/deblan/domain-expiration.git
|
||||
$ cd domain-expiration
|
||||
$ composer install
|
||||
```
|
||||
|
||||
```
|
||||
$ php7.3 ./domain-expiration check example.com,other-example.com
|
||||
+------------------------+---------------------+
|
||||
| Domain | Date |
|
||||
+------------------------+---------------------+
|
||||
| example.com | YYYY-MM-DD HH:MM:SS |
|
||||
| other-example.com | YYYY-MM-DD HH:MM:SS |
|
||||
+------------------------+---------------------+
|
||||
```
|
10
composer.json
Arquivo normal
10
composer.json
Arquivo normal
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Deblan\\": "src/Deblan"
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"symfony/console": "^4.2"
|
||||
}
|
||||
}
|
11
domain-expiration
Arquivo executável
11
domain-expiration
Arquivo executável
|
@ -0,0 +1,11 @@
|
|||
#!/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();
|
110
src/Deblan/Command/CheckCommand.php
Arquivo normal
110
src/Deblan/Command/CheckCommand.php
Arquivo normal
|
@ -0,0 +1,110 @@
|
|||
<?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;
|
||||
|
||||
/**
|
||||
* class CheckCommand.
|
||||
*
|
||||
* @author Simon Vieille <simon@deblan.fr>
|
||||
*/
|
||||
class CheckCommand extends BaseCommand
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $successes = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $fails = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('check')
|
||||
->addArgument('domains', InputArgument::REQUIRED, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$domains = explode(',', $input->getArgument('domains'));
|
||||
$domains = array_map(function ($v) {
|
||||
return trim($v);
|
||||
}, $domains);
|
||||
|
||||
sort($domains);
|
||||
|
||||
foreach ($domains as $domain) {
|
||||
$this->check($domain);
|
||||
}
|
||||
|
||||
usort($this->successes, function($a, $b) {
|
||||
if ($a[2] > $b[2]) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($a[2] === $b[2]) {
|
||||
if ($a[0] > $b[0]) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
foreach ($this->successes as $k => $v) {
|
||||
unset($this->successes[$k][2]);
|
||||
}
|
||||
|
||||
$results = array_merge($this->successes, $this->fails);
|
||||
|
||||
$table = new Table($output);
|
||||
$table
|
||||
->setHeaders(['Domain', 'Date'])
|
||||
->setRows($results);
|
||||
|
||||
$table->render();
|
||||
}
|
||||
|
||||
protected function check($domain)
|
||||
{
|
||||
$whois = shell_exec(sprintf('whois %s', escapeshellarg($domain)));
|
||||
|
||||
preg_match('/Expiry Date: ([^\s]+)/i', $whois, $match);
|
||||
|
||||
if (!isset($match[0])) {
|
||||
$this->fails[] = [$domain, 'FAIL'];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$date = new \DateTime($match[1]);
|
||||
|
||||
if ($date->getTimestamp() - time() < 3600*24*14) {
|
||||
$color = 'red';
|
||||
} elseif ($date->getTimestamp() - time() < 3600*24*30) {
|
||||
$color = 'yellow';
|
||||
} else {
|
||||
$color = 'green';
|
||||
}
|
||||
|
||||
$content = sprintf('<fg=%s>%s</>', $color, $date->format('Y-m-d H:i:s'));
|
||||
|
||||
$this->successes[] = [$domain, $content, $date->format('Y-m-d H:i:s')];
|
||||
}
|
||||
}
|
Carregando…
Referência em uma nova issue