1
1
mirror of https://github.com/pterodactyl/panel.git synced 2024-10-26 21:02:28 +02:00

Fix inability to create a server

This commit is contained in:
Dane Everitt 2017-11-05 15:36:37 -06:00
parent 5170bcf41a
commit 88562b5cd6
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
8 changed files with 102 additions and 50 deletions

View File

@ -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

View File

@ -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.
*

View File

@ -0,0 +1,70 @@
<?php
namespace Pterodactyl\Http\Controllers\API\Remote;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Services\Servers\EnvironmentService;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
class EggInstallController extends Controller
{
/**
* @var \Pterodactyl\Services\Servers\EnvironmentService
*/
private $environment;
/**
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
*/
private $repository;
/**
* EggInstallController constructor.
*
* @param \Pterodactyl\Services\Servers\EnvironmentService $environment
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
*/
public function __construct(EnvironmentService $environment, ServerRepositoryInterface $repository)
{
$this->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),
]);
}
}

View File

@ -1,49 +0,0 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* 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(),
]);
}
}

View File

@ -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}
*/

View File

@ -184,6 +184,8 @@ return [
'remote/*',
],
'default_api_version' => 'application/vnd.pterodactyl.v1+json',
/*
|--------------------------------------------------------------------------
| Dynamic Environment Variables

View File

@ -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');
});

View File

@ -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');