diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a6603ab9..39a3a8b18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. * `[beta.1]` — Fixes wrong URL redirect being provided when creating a subuser. * `[beta.1]` — Fixes missing check in environment setup that would leave the Hashids salt empty. * `[beta.1]` — Fixes bug preventing loading of allocations when trying to create a new server. +* `[beta.1]` — Fixes bug causing inability to create new servers on the Panel. ## v0.7.0-beta.1 (Derelict Dermodactylus) ### Added diff --git a/app/Contracts/Repository/ServerRepositoryInterface.php b/app/Contracts/Repository/ServerRepositoryInterface.php index c1862b953..e074d7059 100644 --- a/app/Contracts/Repository/ServerRepositoryInterface.php +++ b/app/Contracts/Repository/ServerRepositoryInterface.php @@ -31,6 +31,15 @@ interface ServerRepositoryInterface extends RepositoryInterface, SearchableInter */ public function getDataForRebuild($server = null, $node = null); + /** + * Load the egg relations onto the server model. + * + * @param \Pterodactyl\Models\Server $server + * @param bool $refresh + * @return \Pterodactyl\Models\Server + */ + public function loadEggRelations(Server $server, bool $refresh = false): Server; + /** * Return a server model and all variables associated with the server. * diff --git a/app/Http/Controllers/API/Remote/EggInstallController.php b/app/Http/Controllers/API/Remote/EggInstallController.php new file mode 100644 index 000000000..98c83b00c --- /dev/null +++ b/app/Http/Controllers/API/Remote/EggInstallController.php @@ -0,0 +1,70 @@ +environment = $environment; + $this->repository = $repository; + } + + /** + * Handle request to get script and installation information for a server + * that is being created on the node. + * + * @param \Illuminate\Http\Request $request + * @param string $uuid + * @return \Illuminate\Http\JsonResponse + * + * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException + */ + public function index(Request $request, string $uuid): JsonResponse + { + $node = $request->attributes->get('node'); + + /** @var \Pterodactyl\Models\Server $server */ + $server = $this->repository->findFirstWhere([ + ['uuid', '=', $uuid], + ['node_id', '=', $node->id], + ]); + + $this->repository->loadEggRelations($server); + $egg = $server->getRelation('egg'); + + return response()->json([ + 'scripts' => [ + 'install' => ! $egg->copy_script_install ? null : str_replace(["\r\n", "\n", "\r"], "\n", $egg->copy_script_install), + 'privileged' => $egg->script_is_privileged, + ], + 'config' => [ + 'container' => $egg->copy_script_container, + 'entry' => $egg->copy_script_entry, + ], + 'env' => $this->environment->handle($server), + ]); + } +} diff --git a/app/Http/Controllers/Daemon/OptionController.php b/app/Http/Controllers/Daemon/OptionController.php deleted file mode 100644 index 38b348b36..000000000 --- a/app/Http/Controllers/Daemon/OptionController.php +++ /dev/null @@ -1,49 +0,0 @@ -. - * - * This software is licensed under the terms of the MIT license. - * https://opensource.org/licenses/MIT - */ - -namespace Pterodactyl\Http\Controllers\Daemon; - -use Illuminate\Http\Request; -use Pterodactyl\Models\Server; -use Pterodactyl\Http\Controllers\Controller; - -class OptionController extends Controller -{ - public function details(Request $request, $server) - { - $server = Server::with('allocation', 'option', 'variables.variable')->where('uuid', $server)->firstOrFail(); - - $environment = $server->variables->map(function ($item) { - return sprintf('%s=%s', $item->variable->env_variable, $item->variable_value); - }); - - $mergeInto = [ - 'STARTUP=' . $server->startup, - 'SERVER_MEMORY=' . $server->memory, - 'SERVER_IP=' . $server->allocation->ip, - 'SERVER_PORT=' . $server->allocation->port, - ]; - - if ($environment->count() === 0) { - $environment = collect($mergeInto); - } - - return response()->json([ - 'scripts' => [ - 'install' => (! $server->option->copy_script_install) ? null : str_replace(["\r\n", "\n", "\r"], "\n", $server->option->copy_script_install), - 'privileged' => $server->option->script_is_privileged, - ], - 'config' => [ - 'container' => $server->option->copy_script_container, - 'entry' => $server->option->copy_script_entry, - ], - 'env' => $environment->toArray(), - ]); - } -} diff --git a/app/Repositories/Eloquent/ServerRepository.php b/app/Repositories/Eloquent/ServerRepository.php index ac023ff17..d66b68132 100644 --- a/app/Repositories/Eloquent/ServerRepository.php +++ b/app/Repositories/Eloquent/ServerRepository.php @@ -39,6 +39,22 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt return is_null($paginate) ? $instance->get($this->getColumns()) : $instance->paginate($paginate, $this->getColumns()); } + /** + * Load the egg relations onto the server model. + * + * @param \Pterodactyl\Models\Server $server + * @param bool $refresh + * @return \Pterodactyl\Models\Server + */ + public function loadEggRelations(Server $server, bool $refresh = false): Server + { + if (! $server->relationLoaded('egg') || $refresh) { + $server->load('egg.scriptFrom'); + } + + return $server; + } + /** * {@inheritdoc} */ diff --git a/config/pterodactyl.php b/config/pterodactyl.php index 77667a80b..bd157df23 100644 --- a/config/pterodactyl.php +++ b/config/pterodactyl.php @@ -184,6 +184,8 @@ return [ 'remote/*', ], + 'default_api_version' => 'application/vnd.pterodactyl.v1+json', + /* |-------------------------------------------------------------------------- | Dynamic Environment Variables diff --git a/routes/api-remote.php b/routes/api-remote.php index 0aa42b1a2..a06a72feb 100644 --- a/routes/api-remote.php +++ b/routes/api-remote.php @@ -13,6 +13,10 @@ Route::group(['prefix' => '/eggs'], function () { Route::get('/{uuid}', 'EggRetrievalController@download')->name('api.remote.eggs.download'); }); +Route::group(['prefix' => '/scripts'], function () { + Route::get('/{uuid}', 'EggInstallController@index')->name('api.remote.scripts'); +}); + Route::group(['prefix' => '/sftp'], function () { Route::post('/', 'SftpController@index')->name('api.remote.sftp'); }); diff --git a/routes/daemon.php b/routes/daemon.php index 96dd4e682..b74a005a7 100644 --- a/routes/daemon.php +++ b/routes/daemon.php @@ -8,7 +8,6 @@ */ Route::get('/packs/pull/{uuid}', 'PackController@pull')->name('daemon.pack.pull'); Route::get('/packs/pull/{uuid}/hash', 'PackController@hash')->name('daemon.pack.hash'); -Route::get('/details/option/{server}', 'OptionController@details')->name('daemon.option.details'); Route::get('/configure/{token}', 'ActionController@configuration')->name('daemon.configuration'); Route::post('/download', 'ActionController@authenticateDownload')->name('daemon.download');