<?php
							 | 
						|
								
							 | 
						|
								namespace App\Commands;
							 | 
						|
								
							 | 
						|
								use Illuminate\Console\Scheduling\Schedule;
							 | 
						|
								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()
							 | 
						|
								    {
							 | 
						|
								        $domains = $this->argument('domain');
							 | 
						|
								
							 | 
						|
								        // adding flags
							 | 
						|
								        $domainFlags = '';
							 | 
						|
								
							 | 
						|
								        // 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);
							 | 
						|
								
							 | 
						|
								        foreach($saved as $domain => $file) {
							 | 
						|
								            if (file_exists($file)) {
							 | 
						|
								                $this->info($domain.'...Success!');
							 | 
						|
								            } else {
							 | 
						|
								                $this->error($domain.'...Failed!');
							 | 
						|
								            }
							 | 
						|
								        }
							 | 
						|
								    }
							 | 
						|
								}
							 |