From 4a0627d182b1e57eb3b63d277f50371ecd952b1a Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Tue, 23 Jun 2020 20:24:09 -0700 Subject: [PATCH] Don't trigger a 500 error due to unchecked data being inserted; closes #2087 This also clears up allowed values for the disk input and normalizes the messaging between edit and create screens. --- .../Controllers/Admin/ServersController.php | 19 +++++++++++++------ .../Servers/BuildModificationService.php | 4 ++-- resources/views/admin/servers/new.blade.php | 9 ++++----- .../views/admin/servers/view/build.blade.php | 2 +- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/Admin/ServersController.php b/app/Http/Controllers/Admin/ServersController.php index 9dc3b8a13..e163804cb 100644 --- a/app/Http/Controllers/Admin/ServersController.php +++ b/app/Http/Controllers/Admin/ServersController.php @@ -15,9 +15,11 @@ use Pterodactyl\Models\Server; use Prologue\Alerts\AlertsMessageBag; use Pterodactyl\Exceptions\DisplayException; use Pterodactyl\Http\Controllers\Controller; +use Illuminate\Validation\ValidationException; use Pterodactyl\Services\Servers\SuspensionService; use Pterodactyl\Services\Servers\ServerDeletionService; use Pterodactyl\Services\Servers\ReinstallServerService; +use Pterodactyl\Exceptions\Model\DataValidationException; use Pterodactyl\Services\Servers\BuildModificationService; use Pterodactyl\Services\Databases\DatabasePasswordService; use Pterodactyl\Services\Servers\DetailsModificationService; @@ -255,16 +257,21 @@ class ServersController extends Controller * @return \Illuminate\Http\RedirectResponse * * @throws \Pterodactyl\Exceptions\DisplayException - * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException + * @throws \Illuminate\Validation\ValidationException */ public function updateBuild(Request $request, Server $server) { - $this->buildModificationService->handle($server, $request->only([ - 'allocation_id', 'add_allocations', 'remove_allocations', - 'memory', 'swap', 'io', 'cpu', 'threads', 'disk', - 'database_limit', 'allocation_limit', 'backup_limit', 'oom_disabled', - ])); + try { + $this->buildModificationService->handle($server, $request->only([ + 'allocation_id', 'add_allocations', 'remove_allocations', + 'memory', 'swap', 'io', 'cpu', 'threads', 'disk', + 'database_limit', 'allocation_limit', 'backup_limit', 'oom_disabled', + ])); + } catch (DataValidationException $exception) { + throw new ValidationException($exception->validator); + } + $this->alert->success(trans('admin/server.alerts.build_updated'))->flash(); return redirect()->route('admin.servers.view.build', $server->id); diff --git a/app/Services/Servers/BuildModificationService.php b/app/Services/Servers/BuildModificationService.php index 5f4b10d34..b6768fdb1 100644 --- a/app/Services/Servers/BuildModificationService.php +++ b/app/Services/Servers/BuildModificationService.php @@ -71,8 +71,8 @@ class BuildModificationService * @return \Pterodactyl\Models\Server * * @throws \Pterodactyl\Exceptions\DisplayException - * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException + * @throws \Pterodactyl\Exceptions\Model\DataValidationException */ public function handle(Server $server, array $data) { @@ -91,7 +91,7 @@ class BuildModificationService } } - /** @var \Pterodactyl\Models\Server $server */ + /* @var \Pterodactyl\Models\Server $server */ $server = $this->repository->withFreshModel()->update($server->id, [ 'oom_disabled' => array_get($data, 'oom_disabled'), 'memory' => array_get($data, 'memory'), diff --git a/resources/views/admin/servers/new.blade.php b/resources/views/admin/servers/new.blade.php index d72a80abd..026be8be3 100644 --- a/resources/views/admin/servers/new.blade.php +++ b/resources/views/admin/servers/new.blade.php @@ -176,6 +176,8 @@ MB + +

The maximum amount of memory allowed for this container. Setting this to 0 will allow unlimited memory in a container.

@@ -185,21 +187,18 @@ MB
+

Setting this to 0 will disable swap space on this server. Setting to -1 will allow unlimited swap.

- -
-
MB
+

This server will not be allowed to boot if it is using more than this amount of space. If a server goes over this limit while running it will be safely stopped and locked until enough space is available. Set to 0 to allow unlimited disk usage.

diff --git a/resources/views/admin/servers/view/build.blade.php b/resources/views/admin/servers/view/build.blade.php index c3925c074..c1f8defca 100644 --- a/resources/views/admin/servers/view/build.blade.php +++ b/resources/views/admin/servers/view/build.blade.php @@ -66,7 +66,7 @@ MB
-

This server will not be allowed to boot if it is using more than this amount of space. If a server goes over this limit while running it will be safely stopped and locked until enough space is available.

+

This server will not be allowed to boot if it is using more than this amount of space. If a server goes over this limit while running it will be safely stopped and locked until enough space is available. Set to 0 to allow unlimited disk usage.