Merge branch 'develop' into feature/vuejs
This commit is contained in:
commit
a66d7a3417
73 changed files with 1867 additions and 558 deletions
|
@ -178,9 +178,7 @@ class AppSettingsCommand extends Command
|
|||
if ($askForRedisPassword) {
|
||||
$this->output->comment(trans('command/messages.environment.app.redis_pass_help'));
|
||||
$this->variables['REDIS_PASSWORD'] = $this->option('redis-pass') ?? $this->output->askHidden(
|
||||
trans('command/messages.environment.app.redis_password'), function () {
|
||||
return '';
|
||||
}
|
||||
trans('command/messages.environment.app.redis_password')
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -55,16 +55,6 @@ interface NodeRepositoryInterface extends RepositoryInterface, SearchableInterfa
|
|||
*/
|
||||
public function loadNodeAllocations(Node $node, bool $refresh = false): Node;
|
||||
|
||||
/**
|
||||
* Return a node with all of the servers attached to that node.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Pterodactyl\Models\Node
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function getNodeServers(int $id): Node;
|
||||
|
||||
/**
|
||||
* Return a collection of nodes for all locations to use in server creation UI.
|
||||
*
|
||||
|
|
|
@ -152,4 +152,14 @@ interface ServerRepositoryInterface extends RepositoryInterface, SearchableInter
|
|||
* @return int
|
||||
*/
|
||||
public function getSuspendedServersCount(): int;
|
||||
|
||||
/**
|
||||
* Returns all of the servers that exist for a given node in a paginated response.
|
||||
*
|
||||
* @param int $node
|
||||
* @param int $limit
|
||||
*
|
||||
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
|
||||
*/
|
||||
public function loadAllServersForNode(int $node, int $limit): LengthAwarePaginator;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ use Exception;
|
|||
use PDOException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Database\Connection;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Session\TokenMismatchException;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
@ -14,6 +15,7 @@ use Illuminate\Database\Eloquent\ModelNotFoundException;
|
|||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
|
@ -137,6 +139,41 @@ class Handler extends ExceptionHandler
|
|||
*/
|
||||
public function render($request, Exception $exception)
|
||||
{
|
||||
$connections = Container::getInstance()->make(Connection::class);
|
||||
|
||||
// If we are currently wrapped up inside a transaction, we will roll all the way
|
||||
// back to the beginning. This needs to happen, otherwise session data does not
|
||||
// get properly persisted.
|
||||
//
|
||||
// This is kind of a hack, and ideally things like this should be handled as
|
||||
// much as possible at the code level, but there are a lot of spots that do a
|
||||
// ton of actions and were written before this bug discovery was made.
|
||||
//
|
||||
// @see https://github.com/pterodactyl/panel/pull/1468
|
||||
if ($connections->transactionLevel()) {
|
||||
$connections->rollBack(0);
|
||||
}
|
||||
|
||||
// Because of some breaking change snuck into a Laravel update that didn't get caught
|
||||
// by any of the tests, exceptions implementing the HttpExceptionInterface get marked
|
||||
// as being HttpExceptions, but aren't actually implementing the HttpException abstract.
|
||||
//
|
||||
// This is incredibly annoying because we can't just temporarily override the handler to
|
||||
// allow these (at least without taking on a high maintenance cost). Laravel 5.8 fixes this,
|
||||
// so when we update (or have updated) this code can be removed.
|
||||
//
|
||||
// @see https://github.com/laravel/framework/pull/25975
|
||||
// @todo remove this code when upgrading to Laravel 5.8
|
||||
if ($exception instanceof HttpExceptionInterface && ! $exception instanceof HttpException) {
|
||||
$exception = new HttpException(
|
||||
$exception->getStatusCode(),
|
||||
$exception->getMessage(),
|
||||
$exception,
|
||||
$exception->getHeaders(),
|
||||
$exception->getCode()
|
||||
);
|
||||
}
|
||||
|
||||
return parent::render($request, $exception);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,19 +2,28 @@
|
|||
|
||||
namespace Pterodactyl\Exceptions\Repository;
|
||||
|
||||
class RecordNotFoundException extends RepositoryException
|
||||
use Illuminate\Http\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
|
||||
|
||||
class RecordNotFoundException extends RepositoryException implements HttpExceptionInterface
|
||||
{
|
||||
/**
|
||||
* Handle request to render this exception to a user. Returns the default
|
||||
* 404 page view.
|
||||
* Returns the status code.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return int
|
||||
*/
|
||||
public function render($request)
|
||||
public function getStatusCode()
|
||||
{
|
||||
if (! config('app.debug')) {
|
||||
return response()->view('errors.404', [], 404);
|
||||
}
|
||||
return Response::HTTP_NOT_FOUND;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns response headers.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getHeaders()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ use Pterodactyl\Services\Allocations\AssignmentService;
|
|||
use Pterodactyl\Services\Helpers\SoftwareVersionService;
|
||||
use Pterodactyl\Http\Requests\Admin\Node\NodeFormRequest;
|
||||
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
use Pterodactyl\Http\Requests\Admin\Node\AllocationFormRequest;
|
||||
use Pterodactyl\Services\Allocations\AllocationDeletionService;
|
||||
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
|
||||
|
@ -32,6 +33,11 @@ use Pterodactyl\Http\Requests\Admin\Node\AllocationAliasFormRequest;
|
|||
|
||||
class NodesController extends Controller
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Allocations\AllocationDeletionService
|
||||
*/
|
||||
protected $allocationDeletionService;
|
||||
|
||||
/**
|
||||
* @var \Prologue\Alerts\AlertsMessageBag
|
||||
*/
|
||||
|
@ -72,6 +78,11 @@ class NodesController extends Controller
|
|||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
|
||||
*/
|
||||
protected $serverRepository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Nodes\NodeUpdateService
|
||||
*/
|
||||
|
@ -81,10 +92,6 @@ class NodesController extends Controller
|
|||
* @var \Pterodactyl\Services\Helpers\SoftwareVersionService
|
||||
*/
|
||||
protected $versionService;
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Allocations\AllocationDeletionService
|
||||
*/
|
||||
private $allocationDeletionService;
|
||||
|
||||
/**
|
||||
* NodesController constructor.
|
||||
|
@ -98,6 +105,7 @@ class NodesController extends Controller
|
|||
* @param \Pterodactyl\Services\Nodes\NodeDeletionService $deletionService
|
||||
* @param \Pterodactyl\Contracts\Repository\LocationRepositoryInterface $locationRepository
|
||||
* @param \Pterodactyl\Contracts\Repository\NodeRepositoryInterface $repository
|
||||
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $serverRepository
|
||||
* @param \Pterodactyl\Services\Nodes\NodeUpdateService $updateService
|
||||
* @param \Pterodactyl\Services\Helpers\SoftwareVersionService $versionService
|
||||
*/
|
||||
|
@ -111,6 +119,7 @@ class NodesController extends Controller
|
|||
NodeDeletionService $deletionService,
|
||||
LocationRepositoryInterface $locationRepository,
|
||||
NodeRepositoryInterface $repository,
|
||||
ServerRepositoryInterface $serverRepository,
|
||||
NodeUpdateService $updateService,
|
||||
SoftwareVersionService $versionService
|
||||
) {
|
||||
|
@ -123,6 +132,7 @@ class NodesController extends Controller
|
|||
$this->deletionService = $deletionService;
|
||||
$this->locationRepository = $locationRepository;
|
||||
$this->repository = $repository;
|
||||
$this->serverRepository = $serverRepository;
|
||||
$this->updateService = $updateService;
|
||||
$this->versionService = $versionService;
|
||||
}
|
||||
|
@ -178,8 +188,6 @@ class NodesController extends Controller
|
|||
*
|
||||
* @param \Pterodactyl\Models\Node $node
|
||||
* @return \Illuminate\View\View
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function viewIndex(Node $node)
|
||||
{
|
||||
|
@ -235,19 +243,17 @@ class NodesController extends Controller
|
|||
/**
|
||||
* Shows the server listing page for a specific node.
|
||||
*
|
||||
* @param int $node
|
||||
* @param \Pterodactyl\Models\Node $node
|
||||
* @return \Illuminate\View\View
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function viewServers($node)
|
||||
public function viewServers(Node $node)
|
||||
{
|
||||
$node = $this->repository->getNodeServers($node);
|
||||
$servers = $this->serverRepository->loadAllServersForNode($node->id, 25);
|
||||
Javascript::put([
|
||||
'node' => collect($node->makeVisible('daemonSecret'))->only(['scheme', 'fqdn', 'daemonListen', 'daemonSecret']),
|
||||
]);
|
||||
|
||||
return view('admin.nodes.view.servers', ['node' => $node]);
|
||||
return view('admin.nodes.view.servers', ['node' => $node, 'servers' => $servers]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -13,8 +13,8 @@ use Pterodactyl\Transformers\Api\Application\LocationTransformer;
|
|||
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Locations\GetLocationRequest;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Locations\GetLocationsRequest;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Locations\DeleteLocationRequest;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Locations\StoreLocationRequest;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Locations\DeleteLocationRequest;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Locations\UpdateLocationRequest;
|
||||
|
||||
class LocationController extends ApplicationApiController
|
||||
|
|
|
@ -5,10 +5,14 @@ namespace Pterodactyl\Http\Controllers\Daemon;
|
|||
use Cache;
|
||||
use Illuminate\Http\Request;
|
||||
use Pterodactyl\Models\Node;
|
||||
use Illuminate\Http\Response;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
||||
use Pterodactyl\Events\Server\Installed as ServerInstalled;
|
||||
use Illuminate\Contracts\Events\Dispatcher as EventDispatcher;
|
||||
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
||||
|
||||
class ActionController extends Controller
|
||||
{
|
||||
|
@ -16,15 +20,21 @@ class ActionController extends Controller
|
|||
* @var \Illuminate\Contracts\Events\Dispatcher
|
||||
*/
|
||||
private $eventDispatcher;
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* ActionController constructor.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Events\Dispatcher $eventDispatcher
|
||||
* @param \Pterodactyl\Repositories\Eloquent\ServerRepository $repository
|
||||
* @param \Illuminate\Contracts\Events\Dispatcher $eventDispatcher
|
||||
*/
|
||||
public function __construct(EventDispatcher $eventDispatcher)
|
||||
public function __construct(ServerRepository $repository, EventDispatcher $eventDispatcher)
|
||||
{
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -32,34 +42,47 @@ class ActionController extends Controller
|
|||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function markInstall(Request $request)
|
||||
public function markInstall(Request $request): JsonResponse
|
||||
{
|
||||
$server = Server::where('uuid', $request->input('server'))->with('node')->first();
|
||||
if (! $server) {
|
||||
return response()->json([
|
||||
try {
|
||||
/** @var \Pterodactyl\Models\Server $server */
|
||||
$server = $this->repository->findFirstWhere([
|
||||
'uuid' => $request->input('server'),
|
||||
]);
|
||||
} catch (RecordNotFoundException $exception) {
|
||||
return JsonResponse::create([
|
||||
'error' => 'No server by that ID was found on the system.',
|
||||
], 422);
|
||||
], Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
if (! $server->relationLoaded('node')) {
|
||||
$server->load('node');
|
||||
}
|
||||
|
||||
$hmac = $request->input('signed');
|
||||
$status = $request->input('installed');
|
||||
|
||||
if (! hash_equals(base64_decode($hmac), hash_hmac('sha256', $server->uuid, $server->node->daemonSecret, true))) {
|
||||
return response()->json([
|
||||
if (! hash_equals(base64_decode($hmac), hash_hmac('sha256', $server->uuid, $server->getRelation('node')->daemonSecret, true))) {
|
||||
return JsonResponse::create([
|
||||
'error' => 'Signed HMAC was invalid.',
|
||||
], 403);
|
||||
], Response::HTTP_FORBIDDEN);
|
||||
}
|
||||
|
||||
$server->installed = ($status === 'installed') ? 1 : 2;
|
||||
$server->save();
|
||||
$this->repository->update($server->id, [
|
||||
'installed' => ($status === 'installed') ? 1 : 2,
|
||||
], true, true);
|
||||
|
||||
// Only fire event if server installed successfully.
|
||||
if ($server->installed === 1) {
|
||||
if ($status === 'installed') {
|
||||
$this->eventDispatcher->dispatch(new ServerInstalled($server));
|
||||
}
|
||||
|
||||
return response()->json([]);
|
||||
// Don't use a 204 here, the daemon is hard-checking for a 200 code.
|
||||
return JsonResponse::create([]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Pterodactyl\Http\Requests\Admin\Servers\Databases;
|
||||
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Pterodactyl\Http\Requests\Admin\AdminFormRequest;
|
||||
|
||||
class StoreServerDatabaseRequest extends AdminFormRequest
|
||||
|
@ -14,7 +16,15 @@ class StoreServerDatabaseRequest extends AdminFormRequest
|
|||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'database' => 'required|string|min:1|max:24',
|
||||
'database' => [
|
||||
'required',
|
||||
'string',
|
||||
'min:1',
|
||||
'max:24',
|
||||
Rule::unique('databases')->where(function (Builder $query) {
|
||||
$query->where('database_host_id', $this->input('database_host_id') ?? 0);
|
||||
}),
|
||||
],
|
||||
'remote' => 'required|string|regex:/^[0-9%.]{1,15}$/',
|
||||
'database_host_id' => 'required|integer|exists:database_hosts,id',
|
||||
];
|
||||
|
|
|
@ -30,6 +30,6 @@ class UpdateLocationRequest extends StoreLocationRequest
|
|||
return collect(Location::getUpdateRulesForId($locationId))->only([
|
||||
'short',
|
||||
'long',
|
||||
]);
|
||||
])->toArray();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ class StoreNodeRequest extends ApplicationApiRequest
|
|||
'memory',
|
||||
'memory_overallocate',
|
||||
'disk',
|
||||
'disk_overallocation',
|
||||
'disk_overallocate',
|
||||
'upload_size',
|
||||
'daemonListen',
|
||||
'daemonSFTP',
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Pterodactyl\Http\Requests\Api\Application\Servers\Databases;
|
||||
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
|
@ -25,7 +27,15 @@ class StoreServerDatabaseRequest extends ApplicationApiRequest
|
|||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'database' => 'required|string|min:1|max:24',
|
||||
'database' => [
|
||||
'required',
|
||||
'string',
|
||||
'min:1',
|
||||
'max:24',
|
||||
Rule::unique('databases')->where(function (Builder $query) {
|
||||
$query->where('database_host_id', $this->input('host') ?? 0);
|
||||
}),
|
||||
],
|
||||
'remote' => 'required|string|regex:/^[0-9%.]{1,15}$/',
|
||||
'host' => 'required|integer|exists:database_hosts,id',
|
||||
];
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Pterodactyl\Http\Requests\Api\Application\Servers;
|
||||
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class UpdateServerBuildConfigurationRequest extends ServerWriteRequest
|
||||
{
|
||||
|
@ -17,15 +18,29 @@ class UpdateServerBuildConfigurationRequest extends ServerWriteRequest
|
|||
|
||||
return [
|
||||
'allocation' => $rules['allocation_id'],
|
||||
'memory' => $rules['memory'],
|
||||
'swap' => $rules['swap'],
|
||||
'io' => $rules['io'],
|
||||
'cpu' => $rules['cpu'],
|
||||
'disk' => $rules['disk'],
|
||||
|
||||
'limits' => 'sometimes|array',
|
||||
'limits.memory' => $this->requiredToOptional('memory', $rules['memory'], true),
|
||||
'limits.swap' => $this->requiredToOptional('swap', $rules['swap'], true),
|
||||
'limits.io' => $this->requiredToOptional('io', $rules['io'], true),
|
||||
'limits.cpu' => $this->requiredToOptional('cpu', $rules['cpu'], true),
|
||||
'limits.disk' => $this->requiredToOptional('disk', $rules['disk'], true),
|
||||
|
||||
// Legacy rules to maintain backwards compatable API support without requiring
|
||||
// a major version bump.
|
||||
//
|
||||
// @see https://github.com/pterodactyl/panel/issues/1500
|
||||
'memory' => $this->requiredToOptional('memory', $rules['memory']),
|
||||
'swap' => $this->requiredToOptional('swap', $rules['swap']),
|
||||
'io' => $this->requiredToOptional('io', $rules['io']),
|
||||
'cpu' => $this->requiredToOptional('cpu', $rules['cpu']),
|
||||
'disk' => $this->requiredToOptional('disk', $rules['disk']),
|
||||
|
||||
'add_allocations' => 'bail|array',
|
||||
'add_allocations.*' => 'integer',
|
||||
'remove_allocations' => 'bail|array',
|
||||
'remove_allocations.*' => 'integer',
|
||||
|
||||
'feature_limits' => 'required|array',
|
||||
'feature_limits.databases' => $rules['database_limit'],
|
||||
'feature_limits.allocations' => $rules['allocation_limit'],
|
||||
|
@ -46,6 +61,15 @@ class UpdateServerBuildConfigurationRequest extends ServerWriteRequest
|
|||
$data['allocation_limit'] = $data['feature_limits']['allocations'];
|
||||
unset($data['allocation'], $data['feature_limits']);
|
||||
|
||||
// Adjust the limits field to match what is expected by the model.
|
||||
if (! empty($data['limits'])) {
|
||||
foreach ($data['limits'] as $key => $value) {
|
||||
$data[$key] = $value;
|
||||
}
|
||||
|
||||
unset($data['limits']);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
@ -65,4 +89,30 @@ class UpdateServerBuildConfigurationRequest extends ServerWriteRequest
|
|||
'feature_limits.allocations' => 'Allocation Limit',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts existing rules for certain limits into a format that maintains backwards
|
||||
* compatability with the old API endpoint while also supporting a more correct API
|
||||
* call.
|
||||
*
|
||||
* @param string $field
|
||||
* @param array $rules
|
||||
* @param bool $limits
|
||||
* @return array
|
||||
*
|
||||
* @see https://github.com/pterodactyl/panel/issues/1500
|
||||
*/
|
||||
protected function requiredToOptional(string $field, array $rules, bool $limits = false)
|
||||
{
|
||||
if (! in_array('required', $rules)) {
|
||||
return $rules;
|
||||
}
|
||||
|
||||
return (new Collection($rules))
|
||||
->filter(function ($value) {
|
||||
return $value !== 'required';
|
||||
})
|
||||
->prepend($limits ? 'required_with:limits' : 'required_without:limits')
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ class AccountDataFormRequest extends FrontendUserFormRequest
|
|||
'name_first' => array_get($modelRules, 'name_first'),
|
||||
'name_last' => array_get($modelRules, 'name_last'),
|
||||
'username' => array_get($modelRules, 'username'),
|
||||
'language' => array_get($modelRules, 'language'),
|
||||
];
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -63,7 +63,7 @@ class Server extends Model implements CleansAttributes, ValidableContract
|
|||
'image' => 'required',
|
||||
'startup' => 'required',
|
||||
'database_limit' => 'present',
|
||||
'allocation_limit' => 'present',
|
||||
'allocation_limit' => 'sometimes',
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -87,7 +87,7 @@ class Server extends Model implements CleansAttributes, ValidableContract
|
|||
'startup' => 'string',
|
||||
'skip_scripts' => 'boolean',
|
||||
'image' => 'string|max:255',
|
||||
'installed' => 'boolean',
|
||||
'installed' => 'in:0,1,2',
|
||||
'database_limit' => 'nullable|integer|min:0',
|
||||
'allocation_limit' => 'nullable|integer|min:0',
|
||||
];
|
||||
|
|
|
@ -6,10 +6,8 @@ use Generator;
|
|||
use Pterodactyl\Models\Node;
|
||||
use Illuminate\Support\Collection;
|
||||
use Pterodactyl\Repositories\Concerns\Searchable;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
||||
|
||||
class NodeRepository extends EloquentRepository implements NodeRepositoryInterface
|
||||
{
|
||||
|
@ -140,25 +138,6 @@ class NodeRepository extends EloquentRepository implements NodeRepositoryInterfa
|
|||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a node with all of the servers attached to that node.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Pterodactyl\Models\Node
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function getNodeServers(int $id): Node
|
||||
{
|
||||
try {
|
||||
return $this->getBuilder()->with([
|
||||
'servers.user', 'servers.nest', 'servers.egg',
|
||||
])->findOrFail($id, $this->getColumns());
|
||||
} catch (ModelNotFoundException $exception) {
|
||||
throw new RecordNotFoundException;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a collection of nodes for all locations to use in server creation UI.
|
||||
*
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Pterodactyl\Repositories\Eloquent;
|
||||
|
||||
use Pterodactyl\Models\Node;
|
||||
use Pterodactyl\Models\User;
|
||||
use Webmozart\Assert\Assert;
|
||||
use Pterodactyl\Models\Server;
|
||||
|
@ -338,4 +339,20 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt
|
|||
{
|
||||
return $this->getBuilder()->where('suspended', true)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all of the servers that exist for a given node in a paginated response.
|
||||
*
|
||||
* @param int $node
|
||||
* @param int $limit
|
||||
*
|
||||
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
|
||||
*/
|
||||
public function loadAllServersForNode(int $node, int $limit): LengthAwarePaginator
|
||||
{
|
||||
return $this->getBuilder()
|
||||
->with(['user', 'nest', 'egg'])
|
||||
->where('node_id', '=', $node)
|
||||
->paginate($limit);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue