Skip to content

Commit 88562b5

Browse files
committed
Fix inability to create a server
1 parent 5170bcf commit 88562b5

File tree

8 files changed

+102
-50
lines changed

8 files changed

+102
-50
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
1010
* `[beta.1]` — Fixes wrong URL redirect being provided when creating a subuser.
1111
* `[beta.1]` — Fixes missing check in environment setup that would leave the Hashids salt empty.
1212
* `[beta.1]` — Fixes bug preventing loading of allocations when trying to create a new server.
13+
* `[beta.1]` — Fixes bug causing inability to create new servers on the Panel.
1314

1415
## v0.7.0-beta.1 (Derelict Dermodactylus)
1516
### Added

app/Contracts/Repository/ServerRepositoryInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ public function getAllServers($paginate);
3131
*/
3232
public function getDataForRebuild($server = null, $node = null);
3333

34+
/**
35+
* Load the egg relations onto the server model.
36+
*
37+
* @param \Pterodactyl\Models\Server $server
38+
* @param bool $refresh
39+
* @return \Pterodactyl\Models\Server
40+
*/
41+
public function loadEggRelations(Server $server, bool $refresh = false): Server;
42+
3443
/**
3544
* Return a server model and all variables associated with the server.
3645
*
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
namespace Pterodactyl\Http\Controllers\API\Remote;
4+
5+
use Illuminate\Http\Request;
6+
use Illuminate\Http\JsonResponse;
7+
use Pterodactyl\Http\Controllers\Controller;
8+
use Pterodactyl\Services\Servers\EnvironmentService;
9+
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
10+
11+
class EggInstallController extends Controller
12+
{
13+
/**
14+
* @var \Pterodactyl\Services\Servers\EnvironmentService
15+
*/
16+
private $environment;
17+
18+
/**
19+
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
20+
*/
21+
private $repository;
22+
23+
/**
24+
* EggInstallController constructor.
25+
*
26+
* @param \Pterodactyl\Services\Servers\EnvironmentService $environment
27+
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
28+
*/
29+
public function __construct(EnvironmentService $environment, ServerRepositoryInterface $repository)
30+
{
31+
$this->environment = $environment;
32+
$this->repository = $repository;
33+
}
34+
35+
/**
36+
* Handle request to get script and installation information for a server
37+
* that is being created on the node.
38+
*
39+
* @param \Illuminate\Http\Request $request
40+
* @param string $uuid
41+
* @return \Illuminate\Http\JsonResponse
42+
*
43+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
44+
*/
45+
public function index(Request $request, string $uuid): JsonResponse
46+
{
47+
$node = $request->attributes->get('node');
48+
49+
/** @var \Pterodactyl\Models\Server $server */
50+
$server = $this->repository->findFirstWhere([
51+
['uuid', '=', $uuid],
52+
['node_id', '=', $node->id],
53+
]);
54+
55+
$this->repository->loadEggRelations($server);
56+
$egg = $server->getRelation('egg');
57+
58+
return response()->json([
59+
'scripts' => [
60+
'install' => ! $egg->copy_script_install ? null : str_replace(["\r\n", "\n", "\r"], "\n", $egg->copy_script_install),
61+
'privileged' => $egg->script_is_privileged,
62+
],
63+
'config' => [
64+
'container' => $egg->copy_script_container,
65+
'entry' => $egg->copy_script_entry,
66+
],
67+
'env' => $this->environment->handle($server),
68+
]);
69+
}
70+
}

app/Http/Controllers/Daemon/OptionController.php

Lines changed: 0 additions & 49 deletions
This file was deleted.

app/Repositories/Eloquent/ServerRepository.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ public function getAllServers($paginate = 25)
3939
return is_null($paginate) ? $instance->get($this->getColumns()) : $instance->paginate($paginate, $this->getColumns());
4040
}
4141

42+
/**
43+
* Load the egg relations onto the server model.
44+
*
45+
* @param \Pterodactyl\Models\Server $server
46+
* @param bool $refresh
47+
* @return \Pterodactyl\Models\Server
48+
*/
49+
public function loadEggRelations(Server $server, bool $refresh = false): Server
50+
{
51+
if (! $server->relationLoaded('egg') || $refresh) {
52+
$server->load('egg.scriptFrom');
53+
}
54+
55+
return $server;
56+
}
57+
4258
/**
4359
* {@inheritdoc}
4460
*/

config/pterodactyl.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@
184184
'remote/*',
185185
],
186186

187+
'default_api_version' => 'application/vnd.pterodactyl.v1+json',
188+
187189
/*
188190
|--------------------------------------------------------------------------
189191
| Dynamic Environment Variables

routes/api-remote.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
Route::get('/{uuid}', 'EggRetrievalController@download')->name('api.remote.eggs.download');
1414
});
1515

16+
Route::group(['prefix' => '/scripts'], function () {
17+
Route::get('/{uuid}', 'EggInstallController@index')->name('api.remote.scripts');
18+
});
19+
1620
Route::group(['prefix' => '/sftp'], function () {
1721
Route::post('/', 'SftpController@index')->name('api.remote.sftp');
1822
});

routes/daemon.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*/
99
Route::get('/packs/pull/{uuid}', 'PackController@pull')->name('daemon.pack.pull');
1010
Route::get('/packs/pull/{uuid}/hash', 'PackController@hash')->name('daemon.pack.hash');
11-
Route::get('/details/option/{server}', 'OptionController@details')->name('daemon.option.details');
1211
Route::get('/configure/{token}', 'ActionController@configuration')->name('daemon.configuration');
1312

1413
Route::post('/download', 'ActionController@authenticateDownload')->name('daemon.download');

0 commit comments

Comments
 (0)