Merge branch 'develop' into dane/restore-backups
This commit is contained in:
commit
663143de0b
575 changed files with 6080 additions and 6864 deletions
|
@ -31,8 +31,6 @@ class BuildModificationService
|
|||
* BuildModificationService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $structureService
|
||||
* @param \Illuminate\Database\ConnectionInterface $connection
|
||||
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository
|
||||
*/
|
||||
public function __construct(
|
||||
ServerConfigurationStructureService $structureService,
|
||||
|
@ -47,8 +45,6 @@ class BuildModificationService
|
|||
/**
|
||||
* Change the build details for a specified server.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @param array $data
|
||||
* @return \Pterodactyl\Models\Server
|
||||
*
|
||||
* @throws \Throwable
|
||||
|
@ -96,9 +92,6 @@ class BuildModificationService
|
|||
/**
|
||||
* Process the allocations being assigned in the data and ensure they are available for a server.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @param array $data
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
*/
|
||||
private function processAllocations(Server $server, array &$data)
|
||||
|
@ -109,7 +102,7 @@ class BuildModificationService
|
|||
|
||||
// Handle the addition of allocations to this server. Only assign allocations that are not currently
|
||||
// assigned to a different server, and only allocations on the same node as the server.
|
||||
if (! empty($data['add_allocations'])) {
|
||||
if (!empty($data['add_allocations'])) {
|
||||
$query = Allocation::query()
|
||||
->where('node_id', $server->node_id)
|
||||
->whereIn('id', $data['add_allocations'])
|
||||
|
@ -122,16 +115,14 @@ class BuildModificationService
|
|||
$query->update(['server_id' => $server->id, 'notes' => null]);
|
||||
}
|
||||
|
||||
if (! empty($data['remove_allocations'])) {
|
||||
if (!empty($data['remove_allocations'])) {
|
||||
foreach ($data['remove_allocations'] as $allocation) {
|
||||
// If we are attempting to remove the default allocation for the server, see if we can reassign
|
||||
// to the first provided value in add_allocations. If there is no new first allocation then we
|
||||
// will throw an exception back.
|
||||
if ($allocation === ($data['allocation_id'] ?? $server->allocation_id)) {
|
||||
if (empty($freshlyAllocated)) {
|
||||
throw new DisplayException(
|
||||
'You are attempting to delete the default allocation for this server but there is no fallback allocation to use.'
|
||||
);
|
||||
throw new DisplayException('You are attempting to delete the default allocation for this server but there is no fallback allocation to use.');
|
||||
}
|
||||
|
||||
// Update the default allocation to be the first allocation that we are creating.
|
||||
|
|
|
@ -25,9 +25,6 @@ class DetailsModificationService
|
|||
|
||||
/**
|
||||
* DetailsModificationService constructor.
|
||||
*
|
||||
* @param \Illuminate\Database\ConnectionInterface $connection
|
||||
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $serverRepository
|
||||
*/
|
||||
public function __construct(ConnectionInterface $connection, DaemonServerRepository $serverRepository)
|
||||
{
|
||||
|
@ -38,10 +35,6 @@ class DetailsModificationService
|
|||
/**
|
||||
* Update the details for a single server instance.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @param array $data
|
||||
* @return \Pterodactyl\Models\Server
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function handle(Server $server, array $data): Server
|
||||
|
|
|
@ -15,9 +15,6 @@ class EnvironmentService
|
|||
/**
|
||||
* Dynamically configure additional environment variables to be assigned
|
||||
* with a specific server.
|
||||
*
|
||||
* @param string $key
|
||||
* @param callable $closure
|
||||
*/
|
||||
public function setEnvironmentKey(string $key, callable $closure)
|
||||
{
|
||||
|
@ -26,8 +23,6 @@ class EnvironmentService
|
|||
|
||||
/**
|
||||
* Return the dynamically added additional keys.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getEnvironmentKeys(): array
|
||||
{
|
||||
|
@ -37,9 +32,6 @@ class EnvironmentService
|
|||
/**
|
||||
* Take all of the environment variables configured for this server and return
|
||||
* them in an easy to process format.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @return array
|
||||
*/
|
||||
public function handle(Server $server): array
|
||||
{
|
||||
|
@ -57,7 +49,8 @@ class EnvironmentService
|
|||
// Process variables set in the configuration file.
|
||||
foreach (config('pterodactyl.environment_variables', []) as $key => $object) {
|
||||
$variables->put(
|
||||
$key, is_callable($object) ? call_user_func($object, $server) : object_get($server, $object)
|
||||
$key,
|
||||
is_callable($object) ? call_user_func($object, $server) : object_get($server, $object)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -71,8 +64,6 @@ class EnvironmentService
|
|||
|
||||
/**
|
||||
* Return a mapping of Panel default environment variables.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getEnvironmentMappings(): array
|
||||
{
|
||||
|
|
|
@ -12,8 +12,6 @@ class GetUserPermissionsService
|
|||
* if they are an admin or a subuser for the server. If no permissions are
|
||||
* found, an empty array is returned.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @param \Pterodactyl\Models\User $user
|
||||
* @return string[]
|
||||
*/
|
||||
public function handle(Server $server, User $user)
|
||||
|
|
|
@ -4,7 +4,6 @@ namespace Pterodactyl\Services\Servers;
|
|||
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
||||
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
||||
|
||||
class ReinstallServerService
|
||||
|
@ -21,9 +20,6 @@ class ReinstallServerService
|
|||
|
||||
/**
|
||||
* ReinstallService constructor.
|
||||
*
|
||||
* @param \Illuminate\Database\ConnectionInterface $connection
|
||||
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository
|
||||
*/
|
||||
public function __construct(
|
||||
ConnectionInterface $connection,
|
||||
|
@ -36,7 +32,6 @@ class ReinstallServerService
|
|||
/**
|
||||
* Reinstall a server on the remote daemon.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @return \Pterodactyl\Models\Server
|
||||
*
|
||||
* @throws \Throwable
|
||||
|
|
|
@ -7,15 +7,10 @@ use Pterodactyl\Models\Server;
|
|||
|
||||
class ServerConfigurationStructureService
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Servers\EnvironmentService
|
||||
*/
|
||||
private $environment;
|
||||
private EnvironmentService $environment;
|
||||
|
||||
/**
|
||||
* ServerConfigurationStructureService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Services\Servers\EnvironmentService $environment
|
||||
*/
|
||||
public function __construct(EnvironmentService $environment)
|
||||
{
|
||||
|
@ -27,11 +22,6 @@ class ServerConfigurationStructureService
|
|||
*
|
||||
* DO NOT MODIFY THIS FUNCTION. This powers legacy code handling for the new Wings
|
||||
* daemon, if you modify the structure eggs will break unexpectedly.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @param array $override
|
||||
* @param bool $legacy deprecated
|
||||
* @return array
|
||||
*/
|
||||
public function handle(Server $server, array $override = [], bool $legacy = false): array
|
||||
{
|
||||
|
@ -52,11 +42,8 @@ class ServerConfigurationStructureService
|
|||
|
||||
/**
|
||||
* Returns the new data format used for the Wings daemon.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @return array
|
||||
*/
|
||||
protected function returnCurrentFormat(Server $server)
|
||||
protected function returnCurrentFormat(Server $server): array
|
||||
{
|
||||
return [
|
||||
'uuid' => $server->uuid,
|
||||
|
@ -93,12 +80,8 @@ class ServerConfigurationStructureService
|
|||
}),
|
||||
'egg' => [
|
||||
'id' => $server->egg->uuid,
|
||||
'file_denylist' => [
|
||||
'config.yml',
|
||||
'**/*.json'
|
||||
]
|
||||
// 'file_denylist' => explode(PHP_EOL, $server->egg->inherit_file_denylist),
|
||||
]
|
||||
'file_denylist' => explode(PHP_EOL, $server->egg->inherit_file_denylist),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -106,11 +89,9 @@ class ServerConfigurationStructureService
|
|||
* Returns the legacy server data format to continue support for old egg configurations
|
||||
* that have not yet been updated.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @return array
|
||||
* @deprecated
|
||||
*/
|
||||
protected function returnLegacyFormat(Server $server)
|
||||
protected function returnLegacyFormat(Server $server): array
|
||||
{
|
||||
return [
|
||||
'uuid' => $server->uuid,
|
||||
|
@ -124,12 +105,12 @@ class ServerConfigurationStructureService
|
|||
})->toArray(),
|
||||
'env' => $this->environment->handle($server),
|
||||
'oom_disabled' => $server->oom_disabled,
|
||||
'memory' => (int)$server->memory,
|
||||
'swap' => (int)$server->swap,
|
||||
'io' => (int)$server->io,
|
||||
'cpu' => (int)$server->cpu,
|
||||
'memory' => (int) $server->memory,
|
||||
'swap' => (int) $server->swap,
|
||||
'io' => (int) $server->io,
|
||||
'cpu' => (int) $server->cpu,
|
||||
'threads' => $server->threads,
|
||||
'disk' => (int)$server->disk,
|
||||
'disk' => (int) $server->disk,
|
||||
'image' => $server->image,
|
||||
],
|
||||
'service' => [
|
||||
|
|
|
@ -75,16 +75,9 @@ class ServerCreationService
|
|||
/**
|
||||
* CreationService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Services\Deployment\AllocationSelectionService $allocationSelectionService
|
||||
* @param \Illuminate\Database\ConnectionInterface $connection
|
||||
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository
|
||||
* @param \Pterodactyl\Repositories\Eloquent\EggRepository $eggRepository
|
||||
* @param \Pterodactyl\Services\Deployment\FindViableNodesService $findViableNodesService
|
||||
* @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $configurationStructureService
|
||||
* @param \Pterodactyl\Services\Servers\ServerDeletionService $serverDeletionService
|
||||
* @param \Pterodactyl\Repositories\Eloquent\ServerRepository $repository
|
||||
* @param \Pterodactyl\Repositories\Eloquent\ServerVariableRepository $serverVariableRepository
|
||||
* @param \Pterodactyl\Services\Servers\VariableValidatorService $validatorService
|
||||
* @param \Pterodactyl\Services\Servers\ServerDeletionService $serverDeletionService
|
||||
* @param \Pterodactyl\Services\Servers\VariableValidatorService $validatorService
|
||||
*/
|
||||
public function __construct(
|
||||
AllocationSelectionService $allocationSelectionService,
|
||||
|
@ -116,10 +109,6 @@ class ServerCreationService
|
|||
* as possible given the input data. For example, if an allocation_id is passed with
|
||||
* no node_id the node_is will be picked from the allocation.
|
||||
*
|
||||
* @param array $data
|
||||
* @param \Pterodactyl\Models\Objects\DeploymentObject|null $deployment
|
||||
* @return \Pterodactyl\Models\Server
|
||||
*
|
||||
* @throws \Throwable
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
|
@ -187,10 +176,6 @@ class ServerCreationService
|
|||
/**
|
||||
* Gets an allocation to use for automatic deployment.
|
||||
*
|
||||
* @param array $data
|
||||
* @param \Pterodactyl\Models\Objects\DeploymentObject $deployment
|
||||
*
|
||||
* @return \Pterodactyl\Models\Allocation
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Pterodactyl\Exceptions\Service\Deployment\NoViableAllocationException
|
||||
* @throws \Pterodactyl\Exceptions\Service\Deployment\NoViableNodeException
|
||||
|
@ -212,9 +197,6 @@ class ServerCreationService
|
|||
/**
|
||||
* Store the server in the database and return the model.
|
||||
*
|
||||
* @param array $data
|
||||
* @return \Pterodactyl\Models\Server
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
*/
|
||||
private function createModel(array $data): Server
|
||||
|
@ -254,9 +236,6 @@ class ServerCreationService
|
|||
|
||||
/**
|
||||
* Configure the allocations assigned to this server.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @param array $data
|
||||
*/
|
||||
private function storeAssignedAllocations(Server $server, array $data)
|
||||
{
|
||||
|
@ -272,9 +251,6 @@ class ServerCreationService
|
|||
|
||||
/**
|
||||
* Process environment variables passed for this server and store them in the database.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @param \Illuminate\Support\Collection $variables
|
||||
*/
|
||||
private function storeEggVariables(Server $server, Collection $variables)
|
||||
{
|
||||
|
@ -286,21 +262,19 @@ class ServerCreationService
|
|||
];
|
||||
})->toArray();
|
||||
|
||||
if (! empty($records)) {
|
||||
if (!empty($records)) {
|
||||
$this->serverVariableRepository->insert($records);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a unique UUID and UUID-Short combo for a server.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function generateUniqueUuidCombo(): string
|
||||
{
|
||||
$uuid = Uuid::uuid4()->toString();
|
||||
|
||||
if (! $this->repository->isUniqueUuidCombo($uuid, substr($uuid, 0, 8))) {
|
||||
if (!$this->repository->isUniqueUuidCombo($uuid, substr($uuid, 0, 8))) {
|
||||
return $this->generateUniqueUuidCombo();
|
||||
}
|
||||
|
||||
|
|
|
@ -35,10 +35,6 @@ class ServerDeletionService
|
|||
|
||||
/**
|
||||
* DeletionService constructor.
|
||||
*
|
||||
* @param \Illuminate\Database\ConnectionInterface $connection
|
||||
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository
|
||||
* @param \Pterodactyl\Services\Databases\DatabaseManagementService $databaseManagementService
|
||||
*/
|
||||
public function __construct(
|
||||
ConnectionInterface $connection,
|
||||
|
@ -54,6 +50,7 @@ class ServerDeletionService
|
|||
* Set if the server should be forcibly deleted from the panel (ignoring daemon errors) or not.
|
||||
*
|
||||
* @param bool $bool
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function withForce($bool = true)
|
||||
|
@ -66,8 +63,6 @@ class ServerDeletionService
|
|||
/**
|
||||
* Delete a server from the panel and remove any associated databases from hosts.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
*
|
||||
* @throws \Throwable
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
*/
|
||||
|
@ -80,7 +75,7 @@ class ServerDeletionService
|
|||
// go ahead and bail out. We specifically ignore a 404 since that can be assumed
|
||||
// to be a safe error, meaning the server doesn't exist at all on Wings so there
|
||||
// is no reason we need to bail out from that.
|
||||
if (! $this->force && $exception->getStatusCode() !== Response::HTTP_NOT_FOUND) {
|
||||
if (!$this->force && $exception->getStatusCode() !== Response::HTTP_NOT_FOUND) {
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,10 +8,6 @@ class StartupCommandService
|
|||
{
|
||||
/**
|
||||
* Generates a startup command for a given server instance.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @param bool $hideAllValues
|
||||
* @return string
|
||||
*/
|
||||
public function handle(Server $server, bool $hideAllValues = false): string
|
||||
{
|
||||
|
|
|
@ -27,7 +27,6 @@ class StartupModificationService
|
|||
/**
|
||||
* StartupModificationService constructor.
|
||||
*
|
||||
* @param \Illuminate\Database\ConnectionInterface $connection
|
||||
* @param \Pterodactyl\Services\Servers\VariableValidatorService $validatorService
|
||||
*/
|
||||
public function __construct(ConnectionInterface $connection, VariableValidatorService $validatorService)
|
||||
|
@ -39,16 +38,12 @@ class StartupModificationService
|
|||
/**
|
||||
* Process startup modification for a server.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @param array $data
|
||||
* @return \Pterodactyl\Models\Server
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function handle(Server $server, array $data): Server
|
||||
{
|
||||
return $this->connection->transaction(function () use ($server, $data) {
|
||||
if (! empty($data['environment'])) {
|
||||
if (!empty($data['environment'])) {
|
||||
$egg = $this->isUserLevel(User::USER_LEVEL_ADMIN) ? ($data['egg_id'] ?? $server->egg_id) : $server->egg_id;
|
||||
|
||||
$results = $this->validatorService
|
||||
|
@ -83,15 +78,12 @@ class StartupModificationService
|
|||
|
||||
/**
|
||||
* Update certain administrative settings for a server in the DB.
|
||||
*
|
||||
* @param array $data
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
*/
|
||||
protected function updateAdministrativeSettings(array $data, Server &$server)
|
||||
{
|
||||
$eggId = Arr::get($data, 'egg_id');
|
||||
|
||||
if (is_digit($eggId) && $server->egg_id !== (int)$eggId) {
|
||||
if (is_digit($eggId) && $server->egg_id !== (int) $eggId) {
|
||||
/** @var \Pterodactyl\Models\Egg $egg */
|
||||
$egg = Egg::query()->findOrFail($data['egg_id']);
|
||||
|
||||
|
|
|
@ -10,8 +10,8 @@ use Pterodactyl\Exceptions\Http\Server\ServerTransferringException;
|
|||
|
||||
class SuspensionService
|
||||
{
|
||||
const ACTION_SUSPEND = 'suspend';
|
||||
const ACTION_UNSUSPEND = 'unsuspend';
|
||||
public const ACTION_SUSPEND = 'suspend';
|
||||
public const ACTION_UNSUSPEND = 'unsuspend';
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\ConnectionInterface
|
||||
|
@ -25,9 +25,6 @@ class SuspensionService
|
|||
|
||||
/**
|
||||
* SuspensionService constructor.
|
||||
*
|
||||
* @param \Illuminate\Database\ConnectionInterface $connection
|
||||
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository
|
||||
*/
|
||||
public function __construct(
|
||||
ConnectionInterface $connection,
|
||||
|
@ -40,7 +37,6 @@ class SuspensionService
|
|||
/**
|
||||
* Suspends a server on the system.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @param string $action
|
||||
*
|
||||
* @throws \Throwable
|
||||
|
@ -58,8 +54,8 @@ class SuspensionService
|
|||
}
|
||||
|
||||
// Check if the server is currently being transferred.
|
||||
if (! is_null($server->transfer)) {
|
||||
throw new ServerTransferringException;
|
||||
if (!is_null($server->transfer)) {
|
||||
throw new ServerTransferringException();
|
||||
}
|
||||
|
||||
$this->connection->transaction(function () use ($action, $server, $isSuspending) {
|
||||
|
|
|
@ -20,9 +20,6 @@ class TransferService
|
|||
|
||||
/**
|
||||
* TransferService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository
|
||||
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
|
||||
*/
|
||||
public function __construct(
|
||||
DaemonServerRepository $daemonServerRepository,
|
||||
|
|
|
@ -27,8 +27,6 @@ class VariableValidatorService
|
|||
|
||||
/**
|
||||
* VariableValidatorService constructor.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Validation\Factory $validator
|
||||
*/
|
||||
public function __construct(ValidationFactory $validator)
|
||||
{
|
||||
|
@ -38,15 +36,12 @@ class VariableValidatorService
|
|||
/**
|
||||
* Validate all of the passed data against the given service option variables.
|
||||
*
|
||||
* @param int $egg
|
||||
* @param array $fields
|
||||
* @return \Illuminate\Support\Collection
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function handle(int $egg, array $fields = []): Collection
|
||||
{
|
||||
$query = EggVariable::query()->where('egg_id', $egg);
|
||||
if (! $this->isUserLevel(User::USER_LEVEL_ADMIN)) {
|
||||
if (!$this->isUserLevel(User::USER_LEVEL_ADMIN)) {
|
||||
// Don't attempt to validate variables if they aren't user editable
|
||||
// and we're not running this at an admin level.
|
||||
$query = $query->where('user_editable', true)->where('user_viewable', true);
|
||||
|
@ -68,7 +63,7 @@ class VariableValidatorService
|
|||
}
|
||||
|
||||
return Collection::make($variables)->map(function ($item) use ($fields) {
|
||||
return (object)[
|
||||
return (object) [
|
||||
'id' => $item->id,
|
||||
'key' => $item->env_variable,
|
||||
'value' => $fields[$item->env_variable] ?? null,
|
||||
|
|
Reference in a new issue