Skip to content

Commit 179885b

Browse files
committed
Add endpoint to return startup variables; send back modified startup when a variable is edited
1 parent d58fd72 commit 179885b

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

app/Http/Controllers/Api/Client/Servers/StartupController.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
use Carbon\CarbonImmutable;
66
use Pterodactyl\Models\Server;
77
use Illuminate\Http\JsonResponse;
8+
use Pterodactyl\Services\Servers\StartupCommandService;
89
use Pterodactyl\Services\Servers\VariableValidatorService;
910
use Pterodactyl\Repositories\Eloquent\ServerVariableRepository;
1011
use Pterodactyl\Transformers\Api\Client\EggVariableTransformer;
1112
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
1213
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1314
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
15+
use Pterodactyl\Http\Requests\Api\Client\Servers\Startup\GetStartupRequest;
1416
use Pterodactyl\Http\Requests\Api\Client\Servers\Startup\UpdateStartupVariableRequest;
1517

1618
class StartupController extends ClientApiController
@@ -25,18 +27,45 @@ class StartupController extends ClientApiController
2527
*/
2628
private $repository;
2729

30+
/**
31+
* @var \Pterodactyl\Services\Servers\StartupCommandService
32+
*/
33+
private $startupCommandService;
34+
2835
/**
2936
* StartupController constructor.
3037
*
3138
* @param \Pterodactyl\Services\Servers\VariableValidatorService $service
39+
* @param \Pterodactyl\Services\Servers\StartupCommandService $startupCommandService
3240
* @param \Pterodactyl\Repositories\Eloquent\ServerVariableRepository $repository
3341
*/
34-
public function __construct(VariableValidatorService $service, ServerVariableRepository $repository)
42+
public function __construct(VariableValidatorService $service, StartupCommandService $startupCommandService, ServerVariableRepository $repository)
3543
{
3644
parent::__construct();
3745

3846
$this->service = $service;
3947
$this->repository = $repository;
48+
$this->startupCommandService = $startupCommandService;
49+
}
50+
51+
/**
52+
* Returns the startup information for the server including all of the variables.
53+
*
54+
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\Startup\GetStartupRequest $request
55+
* @param \Pterodactyl\Models\Server $server
56+
* @return array
57+
*/
58+
public function index(GetStartupRequest $request, Server $server)
59+
{
60+
$startup = $this->startupCommandService->handle($server, false);
61+
62+
return $this->fractal->collection($server->variables)
63+
->transformWith($this->getTransformer(EggVariableTransformer::class))
64+
->addMeta([
65+
'startup_command' => $startup,
66+
'raw_startup_command' => $server->startup,
67+
])
68+
->toArray();
4069
}
4170

4271
/**
@@ -78,8 +107,14 @@ public function update(UpdateStartupVariableRequest $request, Server $server)
78107
$variable = $variable->refresh();
79108
$variable->server_value = $request->input('value');
80109

110+
$startup = $this->startupCommandService->handle($server, false);
111+
81112
return $this->fractal->item($variable)
82113
->transformWith($this->getTransformer(EggVariableTransformer::class))
114+
->addMeta([
115+
'startup_command' => $startup,
116+
'raw_startup_command' => $server->startup,
117+
])
83118
->toArray();
84119
}
85120
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Pterodactyl\Http\Requests\Api\Client\Servers\Startup;
4+
5+
use Pterodactyl\Models\Permission;
6+
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
7+
8+
class GetStartupRequest extends ClientApiRequest
9+
{
10+
/**
11+
* @return string
12+
*/
13+
public function permission()
14+
{
15+
return Permission::ACTION_STARTUP_READ;
16+
}
17+
}

routes/api-client.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
});
104104

105105
Route::group(['prefix' => '/startup'], function () {
106+
Route::get('/', 'Servers\StartupController@index');
106107
Route::put('/variable', 'Servers\StartupController@update');
107108
});
108109

0 commit comments

Comments
 (0)