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.

76 lines
1.9 KiB

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