OpenSource CLI-App to install and handle stuff related to Web-Server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

79 lines
2.1 KiB

<?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/letsencrypt/';
/**
* 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) {
$directories = [
'archive' => self::CERT_DIR.'archive/'.$domain,
'live' => self::CERT_DIR.'live/'.$domain,
'renwal' => self::CERT_DIR.'renewal/'.$domain
];
$errors = 0;
foreach($directories as $key => $directory) {
if (!file_exists($directory)) {
$errors++;
} else {
if ($key === 'renewal') {
exec('rm '.$directory.'.conf 2>&1', $output);
} else {
exec('rm -rf '.$directory.' 2>&1', $output);
}
}
}
if ($errors === count($directories)) {
$this->error('Error! Certificate for '.$domain.'...not found!');
}
if ($errors > 0 && $errors < count($directories)) {
$this->error('Trouble! Certificate for '.$domain.'...delete! Some files were not found!');
}
if ($errors === 0) {
$this->info('Success! Certificate for '.$domain.'...deleted!');
}
}
}
}