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.

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