Primo Committ
This commit is contained in:
46
vendor/facade/ignition/src/Http/Controllers/ExecuteSolutionController.php
vendored
Normal file
46
vendor/facade/ignition/src/Http/Controllers/ExecuteSolutionController.php
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Facade\Ignition\Http\Controllers;
|
||||
|
||||
use Facade\Ignition\Http\Requests\ExecuteSolutionRequest;
|
||||
use Facade\IgnitionContracts\SolutionProviderRepository;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
|
||||
class ExecuteSolutionController
|
||||
{
|
||||
use ValidatesRequests;
|
||||
|
||||
public function __invoke(
|
||||
ExecuteSolutionRequest $request,
|
||||
SolutionProviderRepository $solutionProviderRepository
|
||||
) {
|
||||
$this->ensureLocalEnvironment();
|
||||
$this->ensureLocalRequest();
|
||||
|
||||
$solution = $request->getRunnableSolution();
|
||||
|
||||
$solution->run($request->get('parameters', []));
|
||||
|
||||
return response('');
|
||||
}
|
||||
|
||||
public function ensureLocalEnvironment()
|
||||
{
|
||||
if (! app()->environment('local')) {
|
||||
abort(403, "Runnable solutions are disabled in non-local environments. Please make sure `APP_ENV` is set correctly. Additionally please make sure `APP_DEBUG` is set to false on ANY production environment!");
|
||||
}
|
||||
}
|
||||
|
||||
public function ensureLocalRequest()
|
||||
{
|
||||
$ipIsPublic = filter_var(
|
||||
request()->ip(),
|
||||
FILTER_VALIDATE_IP,
|
||||
FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE
|
||||
);
|
||||
|
||||
if ($ipIsPublic) {
|
||||
abort(403, "Solutions can only be executed by requests from a local IP address. Please also make sure `APP_DEBUG` is set to false on ANY production environment.");
|
||||
}
|
||||
}
|
||||
}
|
||||
25
vendor/facade/ignition/src/Http/Controllers/HealthCheckController.php
vendored
Normal file
25
vendor/facade/ignition/src/Http/Controllers/HealthCheckController.php
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Facade\Ignition\Http\Controllers;
|
||||
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class HealthCheckController
|
||||
{
|
||||
public function __invoke()
|
||||
{
|
||||
return [
|
||||
'can_execute_commands' => $this->canExecuteCommands(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function canExecuteCommands(): bool
|
||||
{
|
||||
Artisan::call('help', ['--version']);
|
||||
|
||||
$output = Artisan::output();
|
||||
|
||||
return Str::contains($output, app()->version());
|
||||
}
|
||||
}
|
||||
23
vendor/facade/ignition/src/Http/Controllers/ScriptController.php
vendored
Normal file
23
vendor/facade/ignition/src/Http/Controllers/ScriptController.php
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Facade\Ignition\Http\Controllers;
|
||||
|
||||
use Facade\Ignition\Ignition;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ScriptController
|
||||
{
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
if (!isset(Ignition::scripts()[$request->script])) {
|
||||
abort(404, 'Script not found');
|
||||
}
|
||||
return response(
|
||||
file_get_contents(
|
||||
Ignition::scripts()[$request->script]
|
||||
),
|
||||
200,
|
||||
['Content-Type' => 'application/javascript']
|
||||
);
|
||||
}
|
||||
}
|
||||
19
vendor/facade/ignition/src/Http/Controllers/ShareReportController.php
vendored
Normal file
19
vendor/facade/ignition/src/Http/Controllers/ShareReportController.php
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Facade\Ignition\Http\Controllers;
|
||||
|
||||
use Facade\Ignition\Actions\ShareReportAction;
|
||||
use Facade\Ignition\Exceptions\UnableToShareErrorException;
|
||||
use Facade\Ignition\Http\Requests\ShareReportRequest;
|
||||
|
||||
class ShareReportController
|
||||
{
|
||||
public function __invoke(ShareReportRequest $request, ShareReportAction $shareReportAction)
|
||||
{
|
||||
try {
|
||||
return $shareReportAction->handle(json_decode($request->get('report'), true), $request->get('tabs'), $request->get('lineSelection'));
|
||||
} catch (UnableToShareErrorException $exception) {
|
||||
abort(500, 'Unable to share the error '.$exception->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
18
vendor/facade/ignition/src/Http/Controllers/StyleController.php
vendored
Normal file
18
vendor/facade/ignition/src/Http/Controllers/StyleController.php
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Facade\Ignition\Http\Controllers;
|
||||
|
||||
use Facade\Ignition\Ignition;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class StyleController
|
||||
{
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
return response(
|
||||
file_get_contents(Ignition::styles()[$request->style]),
|
||||
200,
|
||||
['Content-Type' => 'text/css']
|
||||
);
|
||||
}
|
||||
}
|
||||
27
vendor/facade/ignition/src/Http/Middleware/IgnitionConfigValueEnabled.php
vendored
Normal file
27
vendor/facade/ignition/src/Http/Middleware/IgnitionConfigValueEnabled.php
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Facade\Ignition\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Facade\Ignition\IgnitionConfig;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class IgnitionConfigValueEnabled
|
||||
{
|
||||
/** @var \Facade\Ignition\IgnitionConfig */
|
||||
protected $ignitionConfig;
|
||||
|
||||
public function __construct(IgnitionConfig $ignitionConfig)
|
||||
{
|
||||
$this->ignitionConfig = $ignitionConfig;
|
||||
}
|
||||
|
||||
public function handle(Request $request, Closure $next, string $value)
|
||||
{
|
||||
if (! $this->ignitionConfig->toArray()[$value]) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
30
vendor/facade/ignition/src/Http/Middleware/IgnitionEnabled.php
vendored
Normal file
30
vendor/facade/ignition/src/Http/Middleware/IgnitionEnabled.php
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Facade\Ignition\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class IgnitionEnabled
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if (! $this->ignitionEnabled()) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
protected function ignitionEnabled(): bool
|
||||
{
|
||||
return config('app.debug');
|
||||
}
|
||||
}
|
||||
41
vendor/facade/ignition/src/Http/Requests/ExecuteSolutionRequest.php
vendored
Normal file
41
vendor/facade/ignition/src/Http/Requests/ExecuteSolutionRequest.php
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Facade\Ignition\Http\Requests;
|
||||
|
||||
use Facade\IgnitionContracts\RunnableSolution;
|
||||
use Facade\IgnitionContracts\Solution;
|
||||
use Facade\IgnitionContracts\SolutionProviderRepository;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ExecuteSolutionRequest extends FormRequest
|
||||
{
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'solution' => 'required',
|
||||
'parameters' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
public function getSolution(): Solution
|
||||
{
|
||||
$solution = app(SolutionProviderRepository::class)
|
||||
->getSolutionForClass($this->get('solution'));
|
||||
|
||||
abort_if(is_null($solution), 404, 'Solution could not be found');
|
||||
|
||||
/** @var Solution */
|
||||
return $solution;
|
||||
}
|
||||
|
||||
public function getRunnableSolution(): RunnableSolution
|
||||
{
|
||||
$solution = $this->getSolution();
|
||||
|
||||
if (! $solution instanceof RunnableSolution) {
|
||||
abort(404, 'Runnable solution could not be found');
|
||||
}
|
||||
|
||||
return $solution;
|
||||
}
|
||||
}
|
||||
17
vendor/facade/ignition/src/Http/Requests/ShareReportRequest.php
vendored
Normal file
17
vendor/facade/ignition/src/Http/Requests/ShareReportRequest.php
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Facade\Ignition\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ShareReportRequest extends FormRequest
|
||||
{
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'report' => 'required',
|
||||
'tabs' => 'required|array|min:1',
|
||||
'lineSelection' => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user