Browse Source

adding #2

release/0.1
Björn 4 years ago
parent
commit
794174f064
4 changed files with 128 additions and 28 deletions
  1. +55
    -0
      app/Commands/LetsEncryptInstallCommand.php
  2. +1
    -1
      app/Commands/MonitoringStateCommand.php
  3. +46
    -12
      app/Commands/NginxVhostsCommand.php
  4. +26
    -15
      app/Helpers/NginxVhostHelper.php

+ 55
- 0
app/Commands/LetsEncryptInstallCommand.php View File

@ -0,0 +1,55 @@
<?php
namespace App\Commands;
use Illuminate\Console\Scheduling\Schedule;
use LaravelZero\Framework\Commands\Command;
use Illuminate\Support\Facades\File;
use App\Facades\Install;
use Log;
class LetsEncryptInstallCommand extends Command
{
/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'lets-encrypt:install';
/**
* The description of the command.
*
* @var string
*/
protected $description = 'Install LetsEncrypt';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->info('LetsEncrypt install...');
exec('apt update 2>&1');
exec('apt-get install software-properties-common 2>&1');
exec('add-apt-repository universe 2>&1');
exec('add-apt-repository ppa:certbot/certbot 2>&1');
exec('apt-get update 2>&1');
exec('apt-get install certbot python3-certbot-nginx 2>&1');
if (Install::isReady('nginx')) {
// get status of nginx
exec('nginx -v 2>&1', $output);
$status = "$output[0] installed";
$this->info($status);
Log::info($status);
}
}
}

+ 1
- 1
app/Commands/MonitoringStateCommand.php View File

@ -57,6 +57,6 @@ class MonitoringStateCommand extends Command
} }
} }
echo (implode("\n", $upgrades));
$result = implode("\n", $upgrades);
} }
} }

+ 46
- 12
app/Commands/NginxVhostsCommand.php View File

@ -112,7 +112,7 @@ class NginxVhostsCommand extends Command
} }
/** /**
* create Configuration, add for each template a submenu
* create Configuration, add for each template a submenu
* *
* *
* @param array $template * @param array $template
@ -121,7 +121,9 @@ class NginxVhostsCommand extends Command
*/ */
private function createConfiguration($template, $blade) private function createConfiguration($template, $blade)
{ {
$menu = function(CliMenuBuilder $builder) use ($template, $blade)
$self = $this;
$menu = function(CliMenuBuilder $builder) use ($template, $blade, $self)
{ {
$configuration = [ $configuration = [
'domain' => '', 'domain' => '',
@ -172,9 +174,15 @@ class NginxVhostsCommand extends Command
->addMenuItem($checkboxSSL) ->addMenuItem($checkboxSSL)
->addMenuItem($checkboxRedirect) ->addMenuItem($checkboxRedirect)
->addLineBreak('-') ->addLineBreak('-')
->addItem('save', function() use (&$configuration, $template, $blade) {
->addItem('save', function(CliMenu $menu) use (&$configuration, $template, $blade, $self) {
$content = $blade->render($template['name'], $configuration); $content = $blade->render($template['name'], $configuration);
file_put_contents('/etc/nginx/sites-available/'.$configuration['domain'].'.conf', $content); file_put_contents('/etc/nginx/sites-available/'.$configuration['domain'].'.conf', $content);
$parent = $menu->getParent();
$menu->closeThis();
$mainmenu = $parent->getParent();
$mainmenu->open();
}) })
->addLineBreak('-'); ->addLineBreak('-');
}; };
@ -182,6 +190,13 @@ class NginxVhostsCommand extends Command
return $menu; return $menu;
} }
/**
*
*
*
*/
/** /**
* create submenu for vhost * create submenu for vhost
* *
@ -192,7 +207,7 @@ class NginxVhostsCommand extends Command
*/ */
private function vhost($vhost) private function vhost($vhost)
{ {
$menu = function(CliMenuBuilder $builder) use ($vhost)
$currentMenu = function(CliMenuBuilder $builder) use ($vhost)
{ {
$checkbox = new CheckboxItem('enabled', function(CliMenu $menu) use ($vhost) { $checkbox = new CheckboxItem('enabled', function(CliMenu $menu) use ($vhost) {
@ -234,6 +249,14 @@ class NginxVhostsCommand extends Command
} else { } else {
unlink('/etc/nginx/sites-available/'.$vhost['file']); unlink('/etc/nginx/sites-available/'.$vhost['file']);
$menu->confirm($vhost['domain'].' is deleted!')->display('OK!'); $menu->confirm($vhost['domain'].' is deleted!')->display('OK!');
// get
$parent = $menu->getParent();
$menu->closeThis();
// remove current vhost from mainmenu
$parent->removeItem($parent->getSelectedItem());
$parent->open();
} }
}) })
->addLineBreak('-') ->addLineBreak('-')
@ -241,6 +264,24 @@ class NginxVhostsCommand extends Command
->addLineBreak('-'); ->addLineBreak('-');
}; };
return $currentMenu;
}
/**
*
*
*/
protected function updateVhosts($menu)
{
// getting vhosts
$vhosts = NginxVhost::find();
// add submenu for each vhost
foreach($vhosts as $vhost) {
$submenuEditVhost = $this->vhost($vhost);
$menu->addSubMenu($vhost['domain'], $submenuEditVhost);
}
return $menu; return $menu;
} }
@ -260,14 +301,7 @@ class NginxVhostsCommand extends Command
->addSubMenu('add', $submenuSelectTemplate) ->addSubMenu('add', $submenuSelectTemplate)
->addLineBreak('-'); ->addLineBreak('-');
// getting vhosts
$vhosts = NginxVhost::find();
// add submenu for each vhost
foreach($vhosts as $vhost) {
$submenuEditVhost = $this->vhost($vhost);
$main->addSubMenu($vhost['domain'], $submenuEditVhost);
}
$main = $this->updateVhosts($main);
$main->addLineBreak('-'); $main->addLineBreak('-');
$main->open(); $main->open();


+ 26
- 15
app/Helpers/NginxVhostHelper.php View File

@ -91,6 +91,31 @@ class NginxVhostHelper
return $result; return $result;
} }
private function getVhost($filename, $enabled)
{
// getting full path
$path = self::SITES_AVAILABLE.'/'.$filename;
// getting certificates from a configuration
$certificate = $this->getCertificate($path);
$result = array_merge([
'domain' => str_replace('.conf', '', $filename),
'path' => $path,
'file' => $filename,
'enabled' => in_array($filename, $enabled),
], $certificate);
return $result;
}
public function findOneByFilename($filename)
{
// getting enabled
$enabled = $this->getSitesEnabled();
return $this->getVhost($filename, $enabled);
}
/** /**
* getting vhosts * getting vhosts
* *
@ -108,21 +133,7 @@ class NginxVhostHelper
foreach($available as $filename) foreach($available as $filename)
{ {
if (!in_array($filename, self::IGNORE_FILES)) { if (!in_array($filename, self::IGNORE_FILES)) {
// getting full path
$path = self::SITES_AVAILABLE.'/'.$filename;
// getting certificates from a configuration
$certificate = $this->getCertificate($path);
$result = array_merge([
'domain' => str_replace('.conf', '', $filename),
'path' => $path,
'file' => $filename,
'enabled' => in_array($filename, $enabled),
], $certificate);
$results[] = $result;
$results[] = $this->getVhost($filename, $enabled);
} }
} }


Loading…
Cancel
Save