Browse Source

adding #44

master
Björn 4 years ago
parent
commit
0f11e6d5fe
1 changed files with 27 additions and 15 deletions
  1. +27
    -15
      app/Commands/LetsEncryptAddCommand.php

+ 27
- 15
app/Commands/LetsEncryptAddCommand.php View File

@ -3,6 +3,7 @@
namespace App\Commands;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Support\Facades\Validator;
use LaravelZero\Framework\Commands\Command;
/**
@ -21,7 +22,7 @@ class LetsEncryptAddCommand extends Command
*
* @var string
*/
protected $signature = 'lets-encrypt:add {email} {domain*} ';
protected $signature = 'lets-encrypt:add {email} {domain}';
/**
* The description of the command.
@ -38,7 +39,25 @@ class LetsEncryptAddCommand extends Command
*/
public function handle()
{
$domains = $this->argument('domain');
$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 = '';
@ -46,20 +65,13 @@ class LetsEncryptAddCommand extends Command
// add file for domain
$saved = [];
// create flags
foreach($domains as $domain) {
$domainFlags .= '-d '.$domain.' ';
$saved[$domain] = '/etc/letsencrypt/live/'.$domain.'/fullchain.pem';
}
system('certbot --non-interactive --agree-tos -m '.$this->argument('email').' --nginx '.$domainFlags);
system('certbot --non-interactive --agree-tos -m '.$this->argument('email').' --nginx -d '.$domain);
foreach($saved as $domain => $file) {
if (file_exists($file)) {
$this->info($domain.'...Success!');
} else {
$this->error($domain.'...Failed!');
}
// check for certificate
if (file_exists( '/etc/letsencrypt/live/'.$domain.'/fullchain.pem')) {
$this->info($domain.'...Success!');
} else {
$this->error($domain.'...Failed!');
}
}
}

Loading…
Cancel
Save