Browse Source

adding #6

release/0.1
Björn 4 years ago
parent
commit
dcf93574d0
5 changed files with 102 additions and 59 deletions
  1. +46
    -0
      app/BladeFile.php
  2. +1
    -1
      app/Commands/InstallMariadbCommand.php
  3. +11
    -15
      app/Commands/NginxVhostsCommand.php
  4. +2
    -2
      resources/nginx/templates/layouts/ssl.blade.php
  5. +42
    -41
      resources/nginx/templates/wordpress.blade.php

+ 46
- 0
app/BladeFile.php View File

@ -0,0 +1,46 @@
<?php
namespace App;
use Jenssegers\Blade\Blade;
/**
*
*
*
*
*/
class BladeFile
{
// cache dir
const CACHE_DIR = '/storage/cache';
// blade engine
private $blade;
/**
*
*
*
* @param {string} $templateDir
*
*/
public function __construct($templateDir)
{
$this->blade = new Blade(base_path().$templateDir, base_path().self::CACHE_DIR);
}
/**
* put to file
*
* @param {string} $template
* @param {string} $fullpath
* @param {array} $data
*
*/
public function put($template, $fullpath, $data)
{
$content = $this->blade->render($template, $data);
file_put_contents($fullpath, $content);
}
}

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

@ -44,7 +44,7 @@ class InstallMariadbCommand extends Command
//mysql_query("UPDATE mysql.user SET Password=PASSWORD('$password') WHERE User='root';");
//
mysqli_close($link);
//mysqli_close($link);
if (Install::isReady('mariadb-server mariadb-client')) {


+ 11
- 15
app/Commands/NginxVhostsCommand.php View File

@ -5,13 +5,14 @@ namespace App\Commands;
use Illuminate\Console\Scheduling\Schedule;
use LaravelZero\Framework\Commands\Command;
use Illuminate\Support\Facades\File;
use Jenssegers\Blade\Blade;
use App\Facades\Install;
use App\Facades\NginxVhost;
use App\Facades\NginxVhostFactory;
use App\Facades\TerminalHelper;
use App\BladeFile;
use PhpSchool\CliMenu\Builder\CliMenuBuilder;
use PhpSchool\CliMenu\CliMenu;
use PhpSchool\CliMenu\MenuItem\CheckboxItem;
@ -101,17 +102,17 @@ class NginxVhostsCommand extends Command
// getting templates
$templates = $this->getTemplates();
$menu = function(CliMenuBuilder $builder) use ($templates)
{
// writing configuration
$blade = new Blade(base_path().self::TEMPLATES_DIR, base_path().'/storage/cache');
// create blade
$bladeFile = new BladeFile(self::TEMPLATES_DIR);
$menu = function(CliMenuBuilder $builder) use ($templates, $bladeFile)
{
$builder
->setTitle('Nginx > Add')
->setGoBackButtonText('Back');
foreach($templates as $template) {
$submenuCallable = $this->createConfiguration($template, $blade);
$submenuCallable = $this->createConfiguration($template, $bladeFile);
$builder
->addSubMenu($template['name'], $submenuCallable);
}
@ -130,11 +131,9 @@ class NginxVhostsCommand extends Command
* @param Blade $blade
* @return CliMenuBuilder
*/
private function createConfiguration($template, $blade)
private function createConfiguration($template, $bladeFile)
{
$self = $this;
$menu = function(CliMenuBuilder $builder) use ($template, $blade, $self)
$menu = function(CliMenuBuilder $builder) use ($template, $bladeFile)
{
$configuration = [
'domain' => '',
@ -196,7 +195,7 @@ class NginxVhostsCommand extends Command
->addLineBreak('-')
// create
->addItem('Create', function(CliMenu $menu) use (&$configuration, $template, $blade, $self) {
->addItem('Create', function(CliMenu $menu) use (&$configuration, $template, $bladeFile) {
$data = $configuration;
@ -217,14 +216,11 @@ class NginxVhostsCommand extends Command
TerminalHelper::confirmArray($menu, $errors);
} else {
// render configuration
$content = $blade->render($template['name'], $configuration);
// create filename
$filename = $configuration['domain'].'.conf';
// write configuration to file
file_put_contents('/etc/nginx/sites-available/'.$filename, $content);
$bladeFile->put($template['name'], '/etc/nginx/sites-available/'.$filename, $configuration);
$menu->confirm('Success!')->display('Ok!');


+ 2
- 2
resources/nginx/templates/layouts/ssl.blade.php View File

@ -1,7 +1,7 @@
server {
listen 80;
listen [::]:80;
server_name {{ $domain }} @if ($redirect_www) www.{{ $domain }} @endif;
server_name {{ $domain }}@if ($redirect_www) www.{{ $domain }}@endif;
return 301 https://{{ $domain }}$request_uri;
}
@ -39,6 +39,6 @@ server {
";
@include('partials.default', ['domain' => $domain])
@yield('server')
}

+ 42
- 41
resources/nginx/templates/wordpress.blade.php View File

@ -1,45 +1,46 @@
@extends($ssl ? 'layouts.ssl' : 'layouts.no-ssl')
@section('server')
root {{ $root }};
index {{ $index }};
# rewrite
location / {
try_files $uri $uri/ /index.php?$args;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
location ~ /\. {
deny all;
}
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
# php-fpm configuration.
location ~ \.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
include /etc/nginx/fastcgi_params;
}
root {{ $root }};
index {{ $index }};
# rewrite
location / {
try_files $uri $uri/ /index.php?$args;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
location ~ /\. {
deny all;
}
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
# php-fpm configuration.
location ~ \.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
include /etc/nginx/fastcgi_params;
}
@endsection

Loading…
Cancel
Save