|
|
- <?php
-
- namespace App\Commands;
-
- use Illuminate\Console\Scheduling\Schedule;
- use Illuminate\Support\Facades\Validator;
- use LaravelZero\Framework\Commands\Command;
-
- /**
- * Add LetsEncrypt Certificate
- *
- *
- * @author Björn Hase, Tentakelfabrik
- * @license http://opensource.org/licenses/MIT The MIT License
- * @link https://gitea.tentakelfabrik.de/Tentakelfabrik/mcp
- *
- */
- class LetsEncryptAddCommand extends Command
- {
- /**
- * The signature of the command.
- *
- * @var string
- */
- protected $signature = 'lets-encrypt:add {email} {domain}';
-
- /**
- * The description of the command.
- *
- * @var string
- */
- protected $description = 'Add Certificates from LetsEncrypt';
-
- /**
- * Execute the console command.
- *
- * @return mixed
- *
- */
- public function handle()
- {
- $email = $this->argument('email');
-
- // email for validator
- $validator = Validator::make([
- 'email' => $email
- ], [
- 'email' => ['email'],
- ]);
-
- // show if error if first argument is not a email
- if ($validator->fails()) {
- foreach ($validator->errors()->all() as $error) {
- $this->error($error);
- }
-
- exit();
- }
-
- $domain = $this->argument('domain');
-
- // adding flags
- $domainFlags = '';
-
- // add file for domain
- $saved = [];
-
- system('certbot --non-interactive --agree-tos -m '.$this->argument('email').' --nginx -d '.$domain);
-
- // check for certificate
- if (file_exists( '/etc/letsencrypt/live/'.$domain.'/fullchain.pem')) {
- $this->info($domain.'...Success!');
- } else {
- $this->error($domain.'...Failed!');
- }
- }
- }
|