Skip to content

Commit 4a0627d

Browse files
committed
Don't trigger a 500 error due to unchecked data being inserted; closes pterodactyl#2087
This also clears up allowed values for the disk input and normalizes the messaging between edit and create screens.
1 parent 497f73d commit 4a0627d

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

app/Http/Controllers/Admin/ServersController.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
use Prologue\Alerts\AlertsMessageBag;
1616
use Pterodactyl\Exceptions\DisplayException;
1717
use Pterodactyl\Http\Controllers\Controller;
18+
use Illuminate\Validation\ValidationException;
1819
use Pterodactyl\Services\Servers\SuspensionService;
1920
use Pterodactyl\Services\Servers\ServerDeletionService;
2021
use Pterodactyl\Services\Servers\ReinstallServerService;
22+
use Pterodactyl\Exceptions\Model\DataValidationException;
2123
use Pterodactyl\Services\Servers\BuildModificationService;
2224
use Pterodactyl\Services\Databases\DatabasePasswordService;
2325
use Pterodactyl\Services\Servers\DetailsModificationService;
@@ -255,16 +257,21 @@ public function manageSuspension(Request $request, Server $server)
255257
* @return \Illuminate\Http\RedirectResponse
256258
*
257259
* @throws \Pterodactyl\Exceptions\DisplayException
258-
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
259260
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
261+
* @throws \Illuminate\Validation\ValidationException
260262
*/
261263
public function updateBuild(Request $request, Server $server)
262264
{
263-
$this->buildModificationService->handle($server, $request->only([
264-
'allocation_id', 'add_allocations', 'remove_allocations',
265-
'memory', 'swap', 'io', 'cpu', 'threads', 'disk',
266-
'database_limit', 'allocation_limit', 'backup_limit', 'oom_disabled',
267-
]));
265+
try {
266+
$this->buildModificationService->handle($server, $request->only([
267+
'allocation_id', 'add_allocations', 'remove_allocations',
268+
'memory', 'swap', 'io', 'cpu', 'threads', 'disk',
269+
'database_limit', 'allocation_limit', 'backup_limit', 'oom_disabled',
270+
]));
271+
} catch (DataValidationException $exception) {
272+
throw new ValidationException($exception->validator);
273+
}
274+
268275
$this->alert->success(trans('admin/server.alerts.build_updated'))->flash();
269276

270277
return redirect()->route('admin.servers.view.build', $server->id);

app/Services/Servers/BuildModificationService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ public function __construct(
7171
* @return \Pterodactyl\Models\Server
7272
*
7373
* @throws \Pterodactyl\Exceptions\DisplayException
74-
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
7574
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
75+
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
7676
*/
7777
public function handle(Server $server, array $data)
7878
{
@@ -91,7 +91,7 @@ public function handle(Server $server, array $data)
9191
}
9292
}
9393

94-
/** @var \Pterodactyl\Models\Server $server */
94+
/* @var \Pterodactyl\Models\Server $server */
9595
$server = $this->repository->withFreshModel()->update($server->id, [
9696
'oom_disabled' => array_get($data, 'oom_disabled'),
9797
'memory' => array_get($data, 'memory'),

resources/views/admin/servers/new.blade.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@
176176
<input type="text" id="pMemory" name="memory" class="form-control" value="{{ old('memory') }}" />
177177
<span class="input-group-addon">MB</span>
178178
</div>
179+
180+
<p class="text-muted small">The maximum amount of memory allowed for this container. Setting this to <code>0</code> will allow unlimited memory in a container.</p>
179181
</div>
180182

181183
<div class="form-group col-xs-6">
@@ -185,21 +187,18 @@
185187
<input type="text" id="pSwap" name="swap" class="form-control" value="{{ old('swap', 0) }}" />
186188
<span class="input-group-addon">MB</span>
187189
</div>
190+
<p class="text-muted small">Setting this to <code>0</code> will disable swap space on this server. Setting to <code>-1</code> will allow unlimited swap.</p>
188191
</div>
189192
</div>
190193

191-
<div class="box-footer no-border no-pad-top no-pad-bottom">
192-
<p class="text-muted small">If you do not want to assign swap space to a server, simply put <code>0</code> for the value, or <code>-1</code> to allow unlimited swap space. If you want to disable memory limiting on a server, simply enter <code>0</code> into the memory field.<p>
193-
</div>
194-
195194
<div class="box-body row">
196195
<div class="form-group col-xs-6">
197196
<label for="pDisk">Disk Space</label>
198-
199197
<div class="input-group">
200198
<input type="text" id="pDisk" name="disk" class="form-control" value="{{ old('disk') }}" />
201199
<span class="input-group-addon">MB</span>
202200
</div>
201+
<p class="text-muted small">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 <code>0</code> to allow unlimited disk usage.</p>
203202
</div>
204203

205204
<div class="form-group col-xs-6">

resources/views/admin/servers/view/build.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
<input type="text" name="disk" class="form-control" value="{{ old('disk', $server->disk) }}"/>
6767
<span class="input-group-addon">MB</span>
6868
</div>
69-
<p class="text-muted small">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.</p>
69+
<p class="text-muted small">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 <code>0</code> to allow unlimited disk usage.</p>
7070
</div>
7171
<div class="form-group">
7272
<label for="io" class="control-label">Block IO Proportion</label>

0 commit comments

Comments
 (0)