| 
						
						
						
					 | 
				
				 | 
				
					@ -1,126 +0,0 @@ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					<?php | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					namespace App\Commands; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use Illuminate\Console\Scheduling\Schedule; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use LaravelZero\Framework\Commands\Command; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use Illuminate\Support\Facades\File; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use App\Facades\Install; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use PhpSchool\CliMenu\Builder\CliMenuBuilder; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use PhpSchool\CliMenu\CliMenu; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use PhpSchool\CliMenu\MenuItem\CheckboxItem; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use PhpSchool\CliMenu\Style\SelectableStyle; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use Log; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use App\Facades\Nginx; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					class NginxCertsCommand extends Command | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    /** | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * The signature of the command. | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * @var string | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     */ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    protected $signature = 'nginx:certs'; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    /** | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * The description of the command. | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * @var string | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     */ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    protected $description = 'Create and Manage Nginx Vhosts'; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    /** | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     */ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    /** | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * Execute the console command. | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * @return mixed | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     */ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    public function handle() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        var_dump(Nginx::getVhosts()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        // create menu
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //$main = $this->menu('Nginx Let\'s Encrypt');
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //$main
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //    ->addLineBreak('-')
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //    ->open();
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        /*** | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        $itemCallable = function(CliMenu $menu) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            // getting sites-available
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            $sitesAvailable = scandir('/etc/nginx/sites-available'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            // getting sites-endabled
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            $sitesEnabled = scandir('/etc/nginx/sites-enabled'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            foreach($sitesAvailable as $site) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                if ($site !== '.' && $site !== '..') { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    // getting title
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    $title = str_replace('.conf', '', $site); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    $checkbox = new CheckboxItem('enabled', function(CliMenu $menu) use ($site, $title) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        // check status
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        if ($menu->getSelectedItem()->getChecked()) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                            symlink('/etc/nginx/sites-available/'.$site, '/etc/nginx/sites-enabled/'.$site); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                            $status = 'enabled'; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        } else { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                            unlink('/etc/nginx/sites-enabled/'.$site); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                            $status = 'disabled'; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        // starting
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        exec('service nginx restart'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        exec('service nginx status', $output); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        if (strpos(implode(' ', $output), 'active') !== false) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                            $menu->confirm($title.' is '.$status.'!')->display('OK!'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        } else { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                            $menu->confirm('Error! Something not working!')->display('OK!'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    }); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    // adding checkbox
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    if (in_array($site, $sitesEnabled)) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        $checkbox->setChecked(true); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    $menuMain | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        ->addSubmenu($title, function(CliMenuBuilder $builder) use ($site, $title, $checkbox) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                            $builder->setTitle("Nginx > $title") | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                                ->addItem('edit', function(CliMenu $menu) use ($site, $title) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                                    system('nano /etc/nginx/sites-available/'.$site.' > `tty`'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                                }) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                                ->addItem('delete', function(CliMenu $menu) use ($site) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                                    if (file_exists('/etc/nginx/sites-enabled/'.$site)) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                                        $menu->confirm('Error! Please disable '.$title.' first!')->display('OK!'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                                    } else { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                                        unlink('/etc/nginx/sites-available/'.$site); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                                        $menu->confirm("$site is deleted!")->display('OK!'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                                    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                                }) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                                ->addLineBreak('-') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                                ->addMenuItem($checkbox) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                                ->addLineBreak('-'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        }); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        };*/ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} |