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.

73 lines
1.7 KiB

  1. <?php
  2. namespace App\Commands;
  3. use Illuminate\Console\Scheduling\Schedule;
  4. use LaravelZero\Framework\Commands\Command;
  5. /**
  6. *
  7. *
  8. *
  9. */
  10. class LetsEncryptRemoveCommand extends Command
  11. {
  12. // directory
  13. const CERT_DIR = '/etc/certbot/';
  14. /**
  15. * The signature of the command.
  16. *
  17. * @var string
  18. */
  19. protected $signature = 'lets-encrypt:remove {domain*}';
  20. /**
  21. * The description of the command.
  22. *
  23. * @var string
  24. */
  25. protected $description = 'Remove Certificates from LetsEncrypt';
  26. /**
  27. * Execute the console command.
  28. *
  29. * @return mixed
  30. *
  31. */
  32. public function handle()
  33. {
  34. $domains = $this->argument('domain');
  35. foreach($domains as $domain) {
  36. $diretories = [
  37. 'archive' => self::CERT_DIR.'archive/'.$domain,
  38. 'live' => self::CERT_DIR.'live/'.$domain,
  39. 'renwal' => self::CERT_DIR.'renewal/'.$domain
  40. ];
  41. $errors = 0;
  42. foreach($diretories as $diretory) {
  43. if (!file_exists($diretory)) {
  44. $errors++;
  45. } else {
  46. rmdir($archiv);
  47. }
  48. }
  49. if ($errors === (count($diretories) - 1)) {
  50. $this->error('Error! Certificate for '.$domain.' ...not found!');
  51. }
  52. if ($erros > 0 && $errors < (count($diretories) - 1)) {
  53. $this->error('Trouble! Certificate for '.$domain.' ...delete! Some files were not found!');
  54. }
  55. if ($errors === 0) {
  56. $this->info('Success! Certificate for '.$domain.' ...deleted!');
  57. }
  58. }
  59. }
  60. }