|
@ -10,6 +10,7 @@ use Jenssegers\Blade\Blade; |
|
|
use App\Facades\Install; |
|
|
use App\Facades\Install; |
|
|
use App\Facades\NginxVhost; |
|
|
use App\Facades\NginxVhost; |
|
|
use App\Facades\NginxVhostFactory; |
|
|
use App\Facades\NginxVhostFactory; |
|
|
|
|
|
use App\Facades\TerminalHelper; |
|
|
|
|
|
|
|
|
use PhpSchool\CliMenu\Builder\CliMenuBuilder; |
|
|
use PhpSchool\CliMenu\Builder\CliMenuBuilder; |
|
|
use PhpSchool\CliMenu\CliMenu; |
|
|
use PhpSchool\CliMenu\CliMenu; |
|
@ -17,6 +18,9 @@ use PhpSchool\CliMenu\MenuItem\CheckboxItem; |
|
|
use PhpSchool\CliMenu\Style\SelectableStyle; |
|
|
use PhpSchool\CliMenu\Style\SelectableStyle; |
|
|
use PhpSchool\CliMenu\MenuItem\MenuMenuItem; |
|
|
use PhpSchool\CliMenu\MenuItem\MenuMenuItem; |
|
|
|
|
|
|
|
|
|
|
|
use Respect\Validation\Validator as v; |
|
|
|
|
|
use Respect\Validation\Exceptions\NestedValidationException; |
|
|
|
|
|
|
|
|
use Log; |
|
|
use Log; |
|
|
use Closure; |
|
|
use Closure; |
|
|
|
|
|
|
|
@ -34,7 +38,7 @@ class NginxVhostsCommand extends Command |
|
|
const TEMPLATES_DIR = '/resources/nginx/templates'; |
|
|
const TEMPLATES_DIR = '/resources/nginx/templates'; |
|
|
|
|
|
|
|
|
// index for vhosts
|
|
|
// index for vhosts
|
|
|
const VHOST_INDEX = 1; |
|
|
|
|
|
|
|
|
const VHOST_INDEX = 0; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* The signature of the command. |
|
|
* The signature of the command. |
|
@ -155,10 +159,11 @@ class NginxVhostsCommand extends Command |
|
|
$checkboxRedirect->setChecked($configuration['redirect_www']); |
|
|
$checkboxRedirect->setChecked($configuration['redirect_www']); |
|
|
|
|
|
|
|
|
$builder |
|
|
$builder |
|
|
->setTitle('Nginx Vhosts > Add > '.$template['name']) |
|
|
|
|
|
|
|
|
->setTitle('Nginx > Add > '.$template['name']) |
|
|
|
|
|
->setGoBackButtonText('Cancel') |
|
|
|
|
|
|
|
|
// input domain
|
|
|
// input domain
|
|
|
->addItem('domain', function(CliMenu $menu) use (&$configuration) { |
|
|
|
|
|
|
|
|
->addItem('domain: -', function(CliMenu $menu) use (&$configuration) { |
|
|
$result = $menu->askText()->ask(); |
|
|
$result = $menu->askText()->ask(); |
|
|
$configuration['domain'] = $result->fetch(); |
|
|
$configuration['domain'] = $result->fetch(); |
|
|
|
|
|
|
|
@ -167,7 +172,7 @@ class NginxVhostsCommand extends Command |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
// input root
|
|
|
// input root
|
|
|
->addItem('root', function(CliMenu $menu) use (&$configuration) { |
|
|
|
|
|
|
|
|
->addItem('root: -', function(CliMenu $menu) use (&$configuration) { |
|
|
$result = $menu->askText()->ask(); |
|
|
$result = $menu->askText()->ask(); |
|
|
$configuration['root'] = $result->fetch(); |
|
|
$configuration['root'] = $result->fetch(); |
|
|
|
|
|
|
|
@ -176,11 +181,11 @@ class NginxVhostsCommand extends Command |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
// input index
|
|
|
// input index
|
|
|
->addItem($configuration['index'], function(CliMenu $menu) use (&$configuration) { |
|
|
|
|
|
|
|
|
->addItem('index: '.$configuration['index'], function(CliMenu $menu) use (&$configuration) { |
|
|
$result = $menu->askText()->ask(); |
|
|
$result = $menu->askText()->ask(); |
|
|
$configuration['index'] = $result->fetch(); |
|
|
$configuration['index'] = $result->fetch(); |
|
|
|
|
|
|
|
|
$menu->getSelectedItem()->setText($result->fetch()); |
|
|
|
|
|
|
|
|
$menu->getSelectedItem()->setText('index: '.$result->fetch()); |
|
|
$menu->redraw(); |
|
|
$menu->redraw(); |
|
|
}) |
|
|
}) |
|
|
->addLineBreak('-') |
|
|
->addLineBreak('-') |
|
@ -193,23 +198,45 @@ class NginxVhostsCommand extends Command |
|
|
// create
|
|
|
// create
|
|
|
->addItem('Create', function(CliMenu $menu) use (&$configuration, $template, $blade, $self) { |
|
|
->addItem('Create', function(CliMenu $menu) use (&$configuration, $template, $blade, $self) { |
|
|
|
|
|
|
|
|
// render configuration
|
|
|
|
|
|
$content = $blade->render($template['name'], $configuration); |
|
|
|
|
|
|
|
|
$data = $configuration; |
|
|
|
|
|
|
|
|
|
|
|
// add directory for validator to check if file exits
|
|
|
|
|
|
$data['index'] = $data['root'].'/'.$data['index']; |
|
|
|
|
|
|
|
|
|
|
|
$validator = v::key('domain', v::domain()) |
|
|
|
|
|
->key('root', v::directory()) |
|
|
|
|
|
->key('index', v::file()); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
$validator->assert($data); |
|
|
|
|
|
} catch(NestedValidationException $exception) { |
|
|
|
|
|
$errors = $exception->getMessages(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isset($errors)) { |
|
|
|
|
|
TerminalHelper::confirmArray($menu, $errors); |
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
// create filename
|
|
|
|
|
|
$filename = $configuration['domain'].'.conf'; |
|
|
|
|
|
|
|
|
// render configuration
|
|
|
|
|
|
$content = $blade->render($template['name'], $configuration); |
|
|
|
|
|
|
|
|
// write configuration to file
|
|
|
|
|
|
file_put_contents('/etc/nginx/sites-available/'.$filename, $content); |
|
|
|
|
|
|
|
|
// create filename
|
|
|
|
|
|
$filename = $configuration['domain'].'.conf'; |
|
|
|
|
|
|
|
|
// prepare for close current submenu and open mainmenu
|
|
|
|
|
|
$parent = $menu->getParent(); |
|
|
|
|
|
$menu->closeThis(); |
|
|
|
|
|
|
|
|
// write configuration to file
|
|
|
|
|
|
file_put_contents('/etc/nginx/sites-available/'.$filename, $content); |
|
|
|
|
|
|
|
|
$mainmenu = $parent->getParent(); |
|
|
|
|
|
|
|
|
$menu->confirm('Success!')->display('Ok!'); |
|
|
|
|
|
|
|
|
$mainmenu = NginxVhostFactory::addVhosts($mainmenu, NginxVhost::find(), self::VHOST_INDEX); |
|
|
|
|
|
$mainmenu->open(); |
|
|
|
|
|
|
|
|
// prepare for close current submenu and open mainmenu
|
|
|
|
|
|
$parent = $menu->getParent(); |
|
|
|
|
|
$menu->closeThis(); |
|
|
|
|
|
|
|
|
|
|
|
$mainmenu = $parent->getParent(); |
|
|
|
|
|
|
|
|
|
|
|
$mainmenu = NginxVhostFactory::addVhosts($mainmenu, NginxVhost::find(), self::VHOST_INDEX); |
|
|
|
|
|
$mainmenu->open(); |
|
|
|
|
|
} |
|
|
}) |
|
|
}) |
|
|
->addLineBreak('-'); |
|
|
->addLineBreak('-'); |
|
|
}; |
|
|
}; |
|
@ -229,12 +256,6 @@ class NginxVhostsCommand extends Command |
|
|
// create menu
|
|
|
// create menu
|
|
|
$mainmenu = $this->menu('Nginx') |
|
|
$mainmenu = $this->menu('Nginx') |
|
|
|
|
|
|
|
|
// change style of menu
|
|
|
|
|
|
->modifySelectableStyle(function(SelectableStyle $style) { |
|
|
|
|
|
$style->setSelectedMarker("\xE2\x96\xB6 ") |
|
|
|
|
|
->setUnselectedMarker(' '); |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
// add Submenu for select templates
|
|
|
// add Submenu for select templates
|
|
|
->addLineBreak('-') |
|
|
->addLineBreak('-') |
|
|
->addSubMenu('Add', $submenuSelectTemplate); |
|
|
->addSubMenu('Add', $submenuSelectTemplate); |
|
@ -249,6 +270,11 @@ class NginxVhostsCommand extends Command |
|
|
|
|
|
|
|
|
$mainmenu = $mainmenu->build(); |
|
|
$mainmenu = $mainmenu->build(); |
|
|
|
|
|
|
|
|
|
|
|
// remove first item
|
|
|
|
|
|
$items = $mainmenu->getItems(); |
|
|
|
|
|
unset($items[0]); |
|
|
|
|
|
$mainmenu->setItems($items); |
|
|
|
|
|
|
|
|
// adding current vhosts
|
|
|
// adding current vhosts
|
|
|
$mainmenu = NginxVhostFactory::addVhosts($mainmenu, NginxVhost::find(), self::VHOST_INDEX); |
|
|
$mainmenu = NginxVhostFactory::addVhosts($mainmenu, NginxVhost::find(), self::VHOST_INDEX); |
|
|
|
|
|
|
|
|