Skip to content

Commit f15449f

Browse files
committed
Fix servers not being marked as install failed
1 parent cf31d42 commit f15449f

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
1313
and other session data to not be persisted properly when using the database as the session driver.
1414
* Fix a bug introduced at some point in the past that causes internal data integrity exceptions to not bubble up to
1515
the user correctly, leading to extraneous and confusing exception messages.
16+
* Fixes a bug causing servers to not be marked as having failed installation in some cases.
1617

1718
### Changed
1819
* `allocation_limit` for servers now defaults to a null value, and is not required in PATCH/POST requests when adding

app/Http/Controllers/Daemon/ActionController.php

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,61 +5,84 @@
55
use Cache;
66
use Illuminate\Http\Request;
77
use Pterodactyl\Models\Node;
8+
use Illuminate\Http\Response;
89
use Pterodactyl\Models\Server;
10+
use Illuminate\Http\JsonResponse;
911
use Pterodactyl\Http\Controllers\Controller;
12+
use Pterodactyl\Repositories\Eloquent\ServerRepository;
1013
use Pterodactyl\Events\Server\Installed as ServerInstalled;
1114
use Illuminate\Contracts\Events\Dispatcher as EventDispatcher;
15+
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
1216

1317
class ActionController extends Controller
1418
{
1519
/**
1620
* @var \Illuminate\Contracts\Events\Dispatcher
1721
*/
1822
private $eventDispatcher;
23+
/**
24+
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository
25+
*/
26+
private $repository;
1927

2028
/**
2129
* ActionController constructor.
2230
*
23-
* @param \Illuminate\Contracts\Events\Dispatcher $eventDispatcher
31+
* @param \Pterodactyl\Repositories\Eloquent\ServerRepository $repository
32+
* @param \Illuminate\Contracts\Events\Dispatcher $eventDispatcher
2433
*/
25-
public function __construct(EventDispatcher $eventDispatcher)
34+
public function __construct(ServerRepository $repository, EventDispatcher $eventDispatcher)
2635
{
2736
$this->eventDispatcher = $eventDispatcher;
37+
$this->repository = $repository;
2838
}
2939

3040
/**
3141
* Handles install toggle request from daemon.
3242
*
3343
* @param \Illuminate\Http\Request $request
3444
* @return \Illuminate\Http\JsonResponse
45+
*
46+
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
47+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
3548
*/
36-
public function markInstall(Request $request)
49+
public function markInstall(Request $request): JsonResponse
3750
{
38-
$server = Server::where('uuid', $request->input('server'))->with('node')->first();
39-
if (! $server) {
40-
return response()->json([
51+
try {
52+
/** @var \Pterodactyl\Models\Server $server */
53+
$server = $this->repository->findFirstWhere([
54+
'uuid' => $request->input('server'),
55+
]);
56+
} catch (RecordNotFoundException $exception) {
57+
return JsonResponse::create([
4158
'error' => 'No server by that ID was found on the system.',
42-
], 422);
59+
], Response::HTTP_UNPROCESSABLE_ENTITY);
60+
}
61+
62+
if (! $server->relationLoaded('node')) {
63+
$server->load('node');
4364
}
4465

4566
$hmac = $request->input('signed');
4667
$status = $request->input('installed');
4768

48-
if (! hash_equals(base64_decode($hmac), hash_hmac('sha256', $server->uuid, $server->node->daemonSecret, true))) {
49-
return response()->json([
69+
if (! hash_equals(base64_decode($hmac), hash_hmac('sha256', $server->uuid, $server->getRelation('node')->daemonSecret, true))) {
70+
return JsonResponse::create([
5071
'error' => 'Signed HMAC was invalid.',
51-
], 403);
72+
], Response::HTTP_FORBIDDEN);
5273
}
5374

54-
$server->installed = ($status === 'installed') ? 1 : 2;
55-
$server->save();
75+
$this->repository->update($server->id, [
76+
'installed' => ($status === 'installed') ? 1 : 2,
77+
], true, true);
5678

5779
// Only fire event if server installed successfully.
58-
if ($server->installed === 1) {
80+
if ($status === 'installed') {
5981
$this->eventDispatcher->dispatch(new ServerInstalled($server));
6082
}
6183

62-
return response()->json([]);
84+
// Don't use a 204 here, the daemon is hard-checking for a 200 code.
85+
return JsonResponse::create([]);
6386
}
6487

6588
/**

app/Models/Server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class Server extends Model implements CleansAttributes, ValidableContract
8787
'startup' => 'string',
8888
'skip_scripts' => 'boolean',
8989
'image' => 'string|max:255',
90-
'installed' => 'boolean',
90+
'installed' => 'in:0,1,2',
9191
'database_limit' => 'nullable|integer|min:0',
9292
'allocation_limit' => 'nullable|integer|min:0',
9393
];

0 commit comments

Comments
 (0)