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.

68 lines
1.6 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. use Respect\Validation\Validator as v;
  6. use Respect\Validation\Exceptions\NestedValidationException;
  7. /**
  8. * Add LetsEncrypt Certificate
  9. *
  10. *
  11. * @author Björn Hase, Tentakelfabrik
  12. * @license http://opensource.org/licenses/MIT The MIT License
  13. * @link https://gitea.tentakelfabrik.de/Tentakelfabrik/mcp
  14. *
  15. */
  16. class LetsEncryptAddCommand extends Command
  17. {
  18. /**
  19. * The signature of the command.
  20. *
  21. * @var string
  22. */
  23. protected $signature = 'lets-encrypt:add {email} {domain}';
  24. /**
  25. * The description of the command.
  26. *
  27. * @var string
  28. */
  29. protected $description = 'Add Certificates from LetsEncrypt';
  30. /**
  31. * Execute the console command.
  32. *
  33. * @return mixed
  34. *
  35. */
  36. public function handle()
  37. {
  38. $email = $this->argument('email');
  39. if (!v::email()->validate($email)) {
  40. $this->error('First argument has to be a valid E-Mail! Failed!');
  41. exit();
  42. }
  43. $domain = $this->argument('domain');
  44. // adding flags
  45. $domainFlags = '';
  46. // add file for domain
  47. $saved = [];
  48. system('certbot --non-interactive --agree-tos -m '.$this->argument('email').' --nginx -d '.$domain);
  49. // check for certificate
  50. if (file_exists( '/etc/letsencrypt/live/'.$domain.'/fullchain.pem')) {
  51. $this->info($domain.'...Success!');
  52. } else {
  53. $this->error($domain.'...Failed!');
  54. }
  55. }
  56. }