Enable sandboxing with PDFs & fix setup page issues

This commit is contained in:
Benjamin Beganović 2020-09-06 04:23:04 +02:00
parent ad6ae61996
commit 7a5027f1b4
4 changed files with 18 additions and 62 deletions

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Invoice Ninja (https://invoiceninja.com). * Invoice Ninja (https://invoiceninja.com).
* *
@ -30,16 +31,11 @@ use Spatie\Browsershot\Browsershot;
*/ */
class SetupController extends Controller class SetupController extends Controller
{ {
/**
* Main setup view.
*
* @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory
*/
public function index() public function index()
{ {
$check = SystemHealth::check(false); $check = SystemHealth::check(false);
if($check['system_health'] == true && $check['simple_db_check'] && Schema::hasTable('accounts') && $account = Account::all()->first()) { if ($check['system_health'] == true && $check['simple_db_check'] && Schema::hasTable('accounts') && $account = Account::all()->first()) {
return redirect('/'); return redirect('/');
} }
@ -53,7 +49,7 @@ class SetupController extends Controller
if ($check['system_health'] === false) { if ($check['system_health'] === false) {
info($check); info($check);
return response('Oops, something went wrong. Check your logs.'); /** We should never reach this block, but jic. */ return response('Oops, something went wrong. Check your storage/logs/laravel.log file.');
} }
$mail_driver = $request->input('mail_driver'); $mail_driver = $request->input('mail_driver');
@ -64,7 +60,7 @@ class SetupController extends Controller
$url = $request->input('url'); $url = $request->input('url');
if(substr($url, -1) != '/') if (substr($url, -1) != '/')
$url = $url . '/'; $url = $url . '/';
$_ENV['APP_KEY'] = config('app.key'); $_ENV['APP_KEY'] = config('app.key');
@ -106,7 +102,7 @@ class SetupController extends Controller
} }
/* Write the .env file */ /* Write the .env file */
$filePath = base_path().'/.env'; $filePath = base_path() . '/.env';
$fp = fopen($filePath, 'w'); $fp = fopen($filePath, 'w');
fwrite($fp, $config); fwrite($fp, $config);
fclose($fp); fclose($fp);
@ -185,7 +181,7 @@ class SetupController extends Controller
if ($response_array instanceof Response) { if ($response_array instanceof Response) {
return true; return true;
} }
return false; return false;
} }
@ -193,16 +189,16 @@ class SetupController extends Controller
public function checkPdf(Request $request) public function checkPdf(Request $request)
{ {
try { try {
if(config('ninja.phantomjs_key')){ if (config('ninja.phantomjs_key')) {
return $this->testPhantom(); return $this->testPhantom();
} }
Browsershot::url('https://www.invoiceninja.com')
Browsershot::url('https://www.invoiceninja.com')->savePdf( ->noSandbox()
// Browsershot::html('If you see this text, generating PDF works! Thanks for using Invoice Ninja!')->savePdf( ->savePdf(
public_path('test.pdf') public_path('test.pdf')
); );
return response(['url' => asset('test.pdf')], 200); return response(['url' => asset('test.pdf')], 200);
} catch (\Exception $e) { } catch (\Exception $e) {
@ -216,7 +212,7 @@ class SetupController extends Controller
{ {
try { try {
$key = config('ninja.phantomjs_key'); $key = config('ninja.phantomjs_key');
$url = 'https://www.invoiceninja.org/'; $url = 'https://www.invoiceninja.org/';
@ -227,14 +223,9 @@ class SetupController extends Controller
Storage::disk('local')->put('test.pdf', $pdf); Storage::disk('local')->put('test.pdf', $pdf);
return response(['url' => Storage::disk('local')->url('test.pdf')], 200); return response(['url' => Storage::disk('local')->url('test.pdf')], 200);
} catch (\Exception $e) {
}
catch(\Exception $e){
return response([], 500); return response([], 500);
} }
} }
} }

View File

@ -40,8 +40,8 @@ trait PdfMaker
->showBackground() ->showBackground()
->deviceScaleFactor(1) ->deviceScaleFactor(1)
->waitUntilNetworkIdle(true) ->waitUntilNetworkIdle(true)
->noSandbox()
->pdf(); ->pdf();
} }
} }

View File

@ -61,42 +61,6 @@
@endif @endif
</dd> </dd>
</div> </div>
<div class="bg-gray-50 px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6 sm:flex sm:items-center">
<dt class="text-sm leading-5 font-medium text-gray-500">
{{ ctrans('texts.npm_status') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
@if($check['npm_status'])
<span class="alert alert-success block flex justify-between items-center">
<span>{{ $check['npm_status'] }} => {{ strtoupper(ctrans('texts.ok')) }}</span>
<span></span>
</span>
@else
<span class="alert alert-failure block flex justify-between items-center">
<span>{{ ctrans('texts.npm_status_not_found') }}</span>
<span></span>
</span>
@endif
</dd>
</div>
<div class="bg-gray-50 px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6 sm:flex sm:items-center">
<dt class="text-sm leading-5 font-medium text-gray-500">
{{ ctrans('texts.node_status') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
@if($check['node_status'])
<span class="alert alert-success block flex justify-between items-center">
<span>{{ $check['node_status'] }} => {{ strtoupper(ctrans('texts.ok')) }}</span>
<span></span>
</span>
@else
<span class="alert alert-failure block flex justify-between items-center">
<span>{{ ctrans('texts.node_status_not_found') }}</span>
<span></span>
</span>
@endif
</dd>
</div>
</dl> </dl>
</div> </div>
</div> </div>

View File

@ -25,6 +25,7 @@ class PdfGenerationTest extends TestCase
//->footerHtml($footer) //->footerHtml($footer)
->waitUntilNetworkIdle() ->waitUntilNetworkIdle()
//->margins(10,10,10,10) //->margins(10,10,10,10)
->noSandbox()
->savePdf($pdf); ->savePdf($pdf);
} }