Browse Source

init

develop
Simon Vieille 4 months ago
commit
13439890f0
Signed by: Simon Vieille <simon@deblan.fr> GPG Key ID: 03383D15A1D31745
5 changed files with 157 additions and 0 deletions
  1. 2
    0
      .gitignore
  2. 24
    0
      README.md
  3. 10
    0
      composer.json
  4. 11
    0
      domain-expiration
  5. 110
    0
      src/Deblan/Command/CheckCommand.php

+ 2
- 0
.gitignore View File

@@ -0,0 +1,2 @@
/vendor
/composer.lock

+ 24
- 0
README.md View File

@@ -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
- 0
composer.json View File

@@ -0,0 +1,10 @@
{
"autoload": {
"psr-4": {
"Deblan\\": "src/Deblan"
}
},
"require": {
"symfony/console": "^4.2"
}
}

+ 11
- 0
domain-expiration View File

@@ -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
- 0
src/Deblan/Command/CheckCommand.php View File

@@ -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')];
}
}

Loading…
Cancel
Save