|  | @ -3,6 +3,7 @@ | 
														
													
														
															
																|  |  | namespace App\Commands; |  |  | namespace App\Commands; | 
														
													
														
															
																|  |  |  |  |  |  | 
														
													
														
															
																|  |  | use Illuminate\Console\Scheduling\Schedule; |  |  | use Illuminate\Console\Scheduling\Schedule; | 
														
													
														
															
																|  |  |  |  |  | use Illuminate\Support\Facades\Validator; | 
														
													
														
															
																|  |  | use LaravelZero\Framework\Commands\Command; |  |  | use LaravelZero\Framework\Commands\Command; | 
														
													
														
															
																|  |  |  |  |  |  | 
														
													
														
															
																|  |  | /** |  |  | /** | 
														
													
												
													
														
															
																|  | @ -21,7 +22,7 @@ class LetsEncryptAddCommand extends Command | 
														
													
														
															
																|  |  | * |  |  | * | 
														
													
														
															
																|  |  | * @var string |  |  | * @var string | 
														
													
														
															
																|  |  | */ |  |  | */ | 
														
													
														
															
																|  |  | protected $signature = 'lets-encrypt:add {email} {domain*} '; |  |  |  | 
														
													
														
															
																|  |  |  |  |  | protected $signature = 'lets-encrypt:add {email} {domain}'; | 
														
													
														
															
																|  |  |  |  |  |  | 
														
													
														
															
																|  |  | /** |  |  | /** | 
														
													
														
															
																|  |  | * The description of the command. |  |  | * The description of the command. | 
														
													
												
													
														
															
																|  | @ -38,7 +39,25 @@ class LetsEncryptAddCommand extends Command | 
														
													
														
															
																|  |  | */ |  |  | */ | 
														
													
														
															
																|  |  | public function handle() |  |  | 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 |  |  | // adding flags | 
														
													
														
															
																|  |  | $domainFlags = ''; |  |  | $domainFlags = ''; | 
														
													
												
													
														
															
																|  | @ -46,20 +65,13 @@ class LetsEncryptAddCommand extends Command | 
														
													
														
															
																|  |  | // add file for domain |  |  | // add file for domain | 
														
													
														
															
																|  |  | $saved = []; |  |  | $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!'); | 
														
													
														
															
																|  |  | } |  |  | } | 
														
													
														
															
																|  |  | } |  |  | } | 
														
													
														
															
																|  |  | } |  |  | } |