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.

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