From dbc7c597d0d7a7ea725dee9d97af26879585ae3e Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 19 Jan 2020 13:50:38 -0800 Subject: [PATCH] Route and handle install state updates --- .../Servers/ServerInstallController.php | 25 +++++++++++++++++- .../Api/Remote/InstallationDataRequest.php | 26 +++++++++++++++++++ routes/api-remote.php | 3 ++- 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 app/Http/Requests/Api/Remote/InstallationDataRequest.php diff --git a/app/Http/Controllers/Api/Remote/Servers/ServerInstallController.php b/app/Http/Controllers/Api/Remote/Servers/ServerInstallController.php index 0dfc1dd64..db89811b9 100644 --- a/app/Http/Controllers/Api/Remote/Servers/ServerInstallController.php +++ b/app/Http/Controllers/Api/Remote/Servers/ServerInstallController.php @@ -3,9 +3,11 @@ namespace Pterodactyl\Http\Controllers\Api\Remote\Servers; use Illuminate\Http\Request; +use Illuminate\Http\Response; use Illuminate\Http\JsonResponse; use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Repositories\Eloquent\ServerRepository; +use Pterodactyl\Http\Requests\Api\Remote\InstallationDataRequest; class ServerInstallController extends Controller { @@ -33,7 +35,7 @@ class ServerInstallController extends Controller * * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException */ - public function __invoke(Request $request, string $uuid) + public function index(Request $request, string $uuid) { $server = $this->repository->getByUuid($uuid); $egg = $server->egg; @@ -44,4 +46,25 @@ class ServerInstallController extends Controller 'script' => $egg->copy_script_install, ]); } + + /** + * Updates the installation state of a server. + * + * @param \Pterodactyl\Http\Requests\Api\Remote\InstallationDataRequest $request + * @param string $uuid + * @return \Illuminate\Http\JsonResponse + * + * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException + * @throws \Pterodactyl\Exceptions\Model\DataValidationException + */ + public function store(InstallationDataRequest $request, string $uuid) + { + $server = $this->repository->getByUuid($uuid); + + $this->repository->update($server->id, [ + 'installed' => ((bool) $request->input('successful', false)) ? 1 : 2, + ]); + + return JsonResponse::create([], Response::HTTP_NO_CONTENT); + } } diff --git a/app/Http/Requests/Api/Remote/InstallationDataRequest.php b/app/Http/Requests/Api/Remote/InstallationDataRequest.php new file mode 100644 index 000000000..0737d71b4 --- /dev/null +++ b/app/Http/Requests/Api/Remote/InstallationDataRequest.php @@ -0,0 +1,26 @@ + 'present|boolean', + ]; + } +} diff --git a/routes/api-remote.php b/routes/api-remote.php index fa8989ddc..4fb77b291 100644 --- a/routes/api-remote.php +++ b/routes/api-remote.php @@ -9,5 +9,6 @@ Route::post('/download-file', 'FileDownloadController@index'); Route::post('/sftp/auth', 'SftpAuthenticationController'); Route::group(['prefix' => '/servers/{uuid}'], function () { Route::get('/', 'Servers\ServerDetailsController'); - Route::get('/install', 'Servers\ServerInstallController'); + Route::get('/install', 'Servers\ServerInstallController@index'); + Route::post('/install', 'Servers\ServerInstallController@store'); });