From 179885b546f3d818b60bd6497588c567c79001de Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Tue, 25 Aug 2020 19:22:17 -0700 Subject: [PATCH] Add endpoint to return startup variables; send back modified startup when a variable is edited --- .../Api/Client/Servers/StartupController.php | 37 ++++++++++++++++++- .../Servers/Startup/GetStartupRequest.php | 17 +++++++++ routes/api-client.php | 1 + 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 app/Http/Requests/Api/Client/Servers/Startup/GetStartupRequest.php diff --git a/app/Http/Controllers/Api/Client/Servers/StartupController.php b/app/Http/Controllers/Api/Client/Servers/StartupController.php index 92961e1c9..16975a1be 100644 --- a/app/Http/Controllers/Api/Client/Servers/StartupController.php +++ b/app/Http/Controllers/Api/Client/Servers/StartupController.php @@ -5,12 +5,14 @@ namespace Pterodactyl\Http\Controllers\Api\Client\Servers; use Carbon\CarbonImmutable; use Pterodactyl\Models\Server; use Illuminate\Http\JsonResponse; +use Pterodactyl\Services\Servers\StartupCommandService; use Pterodactyl\Services\Servers\VariableValidatorService; use Pterodactyl\Repositories\Eloquent\ServerVariableRepository; use Pterodactyl\Transformers\Api\Client\EggVariableTransformer; use Pterodactyl\Http\Controllers\Api\Client\ClientApiController; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; +use Pterodactyl\Http\Requests\Api\Client\Servers\Startup\GetStartupRequest; use Pterodactyl\Http\Requests\Api\Client\Servers\Startup\UpdateStartupVariableRequest; class StartupController extends ClientApiController @@ -25,18 +27,45 @@ class StartupController extends ClientApiController */ private $repository; + /** + * @var \Pterodactyl\Services\Servers\StartupCommandService + */ + private $startupCommandService; + /** * StartupController constructor. * * @param \Pterodactyl\Services\Servers\VariableValidatorService $service + * @param \Pterodactyl\Services\Servers\StartupCommandService $startupCommandService * @param \Pterodactyl\Repositories\Eloquent\ServerVariableRepository $repository */ - public function __construct(VariableValidatorService $service, ServerVariableRepository $repository) + public function __construct(VariableValidatorService $service, StartupCommandService $startupCommandService, ServerVariableRepository $repository) { parent::__construct(); $this->service = $service; $this->repository = $repository; + $this->startupCommandService = $startupCommandService; + } + + /** + * Returns the startup information for the server including all of the variables. + * + * @param \Pterodactyl\Http\Requests\Api\Client\Servers\Startup\GetStartupRequest $request + * @param \Pterodactyl\Models\Server $server + * @return array + */ + public function index(GetStartupRequest $request, Server $server) + { + $startup = $this->startupCommandService->handle($server, false); + + return $this->fractal->collection($server->variables) + ->transformWith($this->getTransformer(EggVariableTransformer::class)) + ->addMeta([ + 'startup_command' => $startup, + 'raw_startup_command' => $server->startup, + ]) + ->toArray(); } /** @@ -78,8 +107,14 @@ class StartupController extends ClientApiController $variable = $variable->refresh(); $variable->server_value = $request->input('value'); + $startup = $this->startupCommandService->handle($server, false); + return $this->fractal->item($variable) ->transformWith($this->getTransformer(EggVariableTransformer::class)) + ->addMeta([ + 'startup_command' => $startup, + 'raw_startup_command' => $server->startup, + ]) ->toArray(); } } diff --git a/app/Http/Requests/Api/Client/Servers/Startup/GetStartupRequest.php b/app/Http/Requests/Api/Client/Servers/Startup/GetStartupRequest.php new file mode 100644 index 000000000..25ab2ce21 --- /dev/null +++ b/app/Http/Requests/Api/Client/Servers/Startup/GetStartupRequest.php @@ -0,0 +1,17 @@ + '/servers/{server}', 'middleware' => [AuthenticateServ }); Route::group(['prefix' => '/startup'], function () { + Route::get('/', 'Servers\StartupController@index'); Route::put('/variable', 'Servers\StartupController@update'); });