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.

77 lines
1.7 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
  1. <?php
  2. namespace App\Commands;
  3. use Illuminate\Console\Scheduling\Schedule;
  4. use Illuminate\Support\Facades\Validator;
  5. use LaravelZero\Framework\Commands\Command;
  6. /**
  7. * Add LetsEncrypt Certificate
  8. *
  9. *
  10. * @author Björn Hase, Tentakelfabrik
  11. * @license http://opensource.org/licenses/MIT The MIT License
  12. * @link https://gitea.tentakelfabrik.de/Tentakelfabrik/mcp
  13. *
  14. */
  15. class LetsEncryptAddCommand extends Command
  16. {
  17. /**
  18. * The signature of the command.
  19. *
  20. * @var string
  21. */
  22. protected $signature = 'lets-encrypt:add {email} {domain}';
  23. /**
  24. * The description of the command.
  25. *
  26. * @var string
  27. */
  28. protected $description = 'Add Certificates from LetsEncrypt';
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return mixed
  33. *
  34. */
  35. public function handle()
  36. {
  37. $email = $this->argument('email');
  38. // email for validator
  39. $validator = Validator::make([
  40. 'email' => $email
  41. ], [
  42. 'email' => ['email'],
  43. ]);
  44. // show if error if first argument is not a email
  45. if ($validator->fails()) {
  46. foreach ($validator->errors()->all() as $error) {
  47. $this->error($error);
  48. }
  49. exit();
  50. }
  51. $domain = $this->argument('domain');
  52. // adding flags
  53. $domainFlags = '';
  54. // add file for domain
  55. $saved = [];
  56. system('certbot --non-interactive --agree-tos -m '.$this->argument('email').' --nginx -d '.$domain);
  57. // check for certificate
  58. if (file_exists( '/etc/letsencrypt/live/'.$domain.'/fullchain.pem')) {
  59. $this->info($domain.'...Success!');
  60. } else {
  61. $this->error($domain.'...Failed!');
  62. }
  63. }
  64. }