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

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
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/letsencrypt/';
  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. $directories = [
  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($directories as $key => $directory) {
  46. if (!file_exists($directory)) {
  47. $errors++;
  48. } else {
  49. if ($key === 'renewal') {
  50. exec('rm '.$directory.'.conf 2>&1', $output);
  51. } else {
  52. exec('rm -rf '.$directory.' 2>&1', $output);
  53. }
  54. }
  55. }
  56. if ($errors === count($directories)) {
  57. $this->error('Error! Certificate for '.$domain.'...not found!');
  58. }
  59. if ($errors > 0 && $errors < count($directories)) {
  60. $this->error('Trouble! Certificate for '.$domain.'...delete! Some files were not found!');
  61. }
  62. if ($errors === 0) {
  63. $this->info('Success! Certificate for '.$domain.'...deleted!');
  64. }
  65. }
  66. }
  67. }