<?php
|
|
|
|
namespace App\Commands;
|
|
|
|
use Illuminate\Console\Scheduling\Schedule;
|
|
use LaravelZero\Framework\Commands\Command;
|
|
|
|
/**
|
|
* Remove LetsEncrypt Cerficates
|
|
*
|
|
* @author Björn Hase, Tentakelfabrik
|
|
* @license http://opensource.org/licenses/MIT The MIT License
|
|
* @link https://gitea.tentakelfabrik.de/Tentakelfabrik/mcp
|
|
*
|
|
*/
|
|
class LetsEncryptRemoveCommand extends Command
|
|
{
|
|
// directory
|
|
const CERT_DIR = '/etc/certbot/';
|
|
|
|
/**
|
|
* The signature of the command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'lets-encrypt:remove {domain*}';
|
|
|
|
/**
|
|
* The description of the command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Remove Certificates from LetsEncrypt';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
*
|
|
*/
|
|
public function handle()
|
|
{
|
|
$domains = $this->argument('domain');
|
|
|
|
foreach($domains as $domain) {
|
|
|
|
$diretories = [
|
|
'archive' => self::CERT_DIR.'archive/'.$domain,
|
|
'live' => self::CERT_DIR.'live/'.$domain,
|
|
'renwal' => self::CERT_DIR.'renewal/'.$domain
|
|
];
|
|
|
|
$errors = 0;
|
|
|
|
foreach($diretories as $diretory) {
|
|
if (!file_exists($diretory)) {
|
|
$errors++;
|
|
} else {
|
|
rmdir($archiv);
|
|
}
|
|
}
|
|
|
|
if ($errors === (count($diretories) - 1)) {
|
|
$this->error('Error! Certificate for '.$domain.'...not found!');
|
|
}
|
|
|
|
if ($erros > 0 && $errors < (count($diretories) - 1)) {
|
|
$this->error('Trouble! Certificate for '.$domain.'...delete! Some files were not found!');
|
|
}
|
|
|
|
if ($errors === 0) {
|
|
$this->info('Success! Certificate for '.$domain.'...deleted!');
|
|
}
|
|
}
|
|
}
|
|
}
|