diff --git a/app/BladeFile.php b/app/BladeFile.php new file mode 100644 index 0000000..9f27e84 --- /dev/null +++ b/app/BladeFile.php @@ -0,0 +1,46 @@ +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); + } +} \ No newline at end of file diff --git a/app/Commands/InstallMariadbCommand.php b/app/Commands/InstallMariadbCommand.php index 748123f..d03ce6a 100644 --- a/app/Commands/InstallMariadbCommand.php +++ b/app/Commands/InstallMariadbCommand.php @@ -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')) { diff --git a/app/Commands/NginxVhostsCommand.php b/app/Commands/NginxVhostsCommand.php index 6c7e3ce..e74b4fa 100644 --- a/app/Commands/NginxVhostsCommand.php +++ b/app/Commands/NginxVhostsCommand.php @@ -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!'); diff --git a/resources/nginx/templates/layouts/ssl.blade.php b/resources/nginx/templates/layouts/ssl.blade.php index 7f6698f..cf58613 100644 --- a/resources/nginx/templates/layouts/ssl.blade.php +++ b/resources/nginx/templates/layouts/ssl.blade.php @@ -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') } \ No newline at end of file diff --git a/resources/nginx/templates/wordpress.blade.php b/resources/nginx/templates/wordpress.blade.php index 5e89ced..d83808c 100644 --- a/resources/nginx/templates/wordpress.blade.php +++ b/resources/nginx/templates/wordpress.blade.php @@ -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 \ No newline at end of file