Upgrade to Laravel 9 (#4413)
Co-authored-by: DaneEveritt <dane@daneeveritt.com>
This commit is contained in:
parent
95e15d2c8a
commit
cbcf62086f
573 changed files with 4387 additions and 9411 deletions
|
@ -11,32 +11,18 @@ use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
|
|||
class NodeCreationService
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\NodeRepositoryInterface
|
||||
* NodeCreationService constructor.
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Encryption\Encrypter
|
||||
*/
|
||||
private $encrypter;
|
||||
|
||||
/**
|
||||
* CreationService constructor.
|
||||
*/
|
||||
public function __construct(Encrypter $encrypter, NodeRepositoryInterface $repository)
|
||||
public function __construct(private Encrypter $encrypter, protected NodeRepositoryInterface $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
$this->encrypter = $encrypter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new node on the panel.
|
||||
*
|
||||
* @return \Pterodactyl\Models\Node
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
*/
|
||||
public function handle(array $data)
|
||||
public function handle(array $data): Node
|
||||
{
|
||||
$data['uuid'] = Uuid::uuid4()->toString();
|
||||
$data['daemon_token'] = $this->encrypter->encrypt(Str::random(Node::DAEMON_TOKEN_LENGTH));
|
||||
|
|
|
@ -1,13 +1,5 @@
|
|||
<?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\Services\Nodes;
|
||||
|
||||
use Pterodactyl\Models\Node;
|
||||
|
@ -19,43 +11,21 @@ use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
|||
class NodeDeletionService
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\NodeRepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
|
||||
*/
|
||||
protected $serverRepository;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Translation\Translator
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
/**
|
||||
* DeletionService constructor.
|
||||
* NodeDeletionService constructor.
|
||||
*/
|
||||
public function __construct(
|
||||
NodeRepositoryInterface $repository,
|
||||
ServerRepositoryInterface $serverRepository,
|
||||
Translator $translator
|
||||
protected NodeRepositoryInterface $repository,
|
||||
protected ServerRepositoryInterface $serverRepository,
|
||||
protected Translator $translator
|
||||
) {
|
||||
$this->repository = $repository;
|
||||
$this->serverRepository = $serverRepository;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a node from the panel if no servers are attached to it.
|
||||
*
|
||||
* @param int|\Pterodactyl\Models\Node $node
|
||||
*
|
||||
* @return bool|null
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
|
||||
*/
|
||||
public function handle($node)
|
||||
public function handle(int|Node $node): int
|
||||
{
|
||||
if ($node instanceof Node) {
|
||||
$node = $node->id;
|
||||
|
|
|
@ -7,6 +7,7 @@ use Carbon\CarbonImmutable;
|
|||
use Illuminate\Support\Str;
|
||||
use Pterodactyl\Models\Node;
|
||||
use Pterodactyl\Models\User;
|
||||
use Lcobucci\JWT\Token\Plain;
|
||||
use Lcobucci\JWT\Configuration;
|
||||
use Lcobucci\JWT\Signer\Hmac\Sha256;
|
||||
use Lcobucci\JWT\Signer\Key\InMemory;
|
||||
|
@ -18,19 +19,14 @@ class NodeJWTService
|
|||
|
||||
private ?User $user = null;
|
||||
|
||||
/**
|
||||
* @var \DateTimeImmutable|null
|
||||
*/
|
||||
private $expiresAt;
|
||||
private ?DateTimeImmutable $expiresAt;
|
||||
|
||||
private ?string $subject = null;
|
||||
|
||||
/**
|
||||
* Set the claims to include in this JWT.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setClaims(array $claims)
|
||||
public function setClaims(array $claims): self
|
||||
{
|
||||
$this->claims = $claims;
|
||||
|
||||
|
@ -48,20 +44,14 @@ class NodeJWTService
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setExpiresAt(DateTimeImmutable $date)
|
||||
public function setExpiresAt(DateTimeImmutable $date): self
|
||||
{
|
||||
$this->expiresAt = $date;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setSubject(string $subject)
|
||||
public function setSubject(string $subject): self
|
||||
{
|
||||
$this->subject = $subject;
|
||||
|
||||
|
@ -70,12 +60,8 @@ class NodeJWTService
|
|||
|
||||
/**
|
||||
* Generate a new JWT for a given node.
|
||||
*
|
||||
* @param string|null $identifiedBy
|
||||
*
|
||||
* @return \Lcobucci\JWT\Token\Plain
|
||||
*/
|
||||
public function handle(Node $node, string $identifiedBy, string $algo = 'md5')
|
||||
public function handle(Node $node, ?string $identifiedBy, string $algo = 'md5'): Plain
|
||||
{
|
||||
$identifier = hash($algo, $identifiedBy);
|
||||
$config = Configuration::forSymmetricSigner(new Sha256(), InMemory::plainText($node->getDecryptedKey()));
|
||||
|
@ -112,7 +98,7 @@ class NodeJWTService
|
|||
}
|
||||
|
||||
return $builder
|
||||
->withClaim('unique_id', Str::random(16))
|
||||
->withClaim('unique_id', Str::random())
|
||||
->getToken($config->signer(), $config->signingKey());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,48 +15,22 @@ use Pterodactyl\Exceptions\Service\Node\ConfigurationNotPersistedException;
|
|||
class NodeUpdateService
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Database\ConnectionInterface
|
||||
*/
|
||||
private $connection;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Wings\DaemonConfigurationRepository
|
||||
*/
|
||||
private $configurationRepository;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Encryption\Encrypter
|
||||
*/
|
||||
private $encrypter;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Eloquent\NodeRepository
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* UpdateService constructor.
|
||||
* NodeUpdateService constructor.
|
||||
*/
|
||||
public function __construct(
|
||||
ConnectionInterface $connection,
|
||||
Encrypter $encrypter,
|
||||
DaemonConfigurationRepository $configurationRepository,
|
||||
NodeRepository $repository
|
||||
private ConnectionInterface $connection,
|
||||
private DaemonConfigurationRepository $configurationRepository,
|
||||
private Encrypter $encrypter,
|
||||
private NodeRepository $repository
|
||||
) {
|
||||
$this->connection = $connection;
|
||||
$this->configurationRepository = $configurationRepository;
|
||||
$this->encrypter = $encrypter;
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the configuration values for a given node on the machine.
|
||||
*
|
||||
* @return \Pterodactyl\Models\Node
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function handle(Node $node, array $data, bool $resetToken = false)
|
||||
public function handle(Node $node, array $data, bool $resetToken = false): Node
|
||||
{
|
||||
if ($resetToken) {
|
||||
$data['daemon_token'] = $this->encrypter->encrypt(Str::random(Node::DAEMON_TOKEN_LENGTH));
|
||||
|
@ -87,7 +61,7 @@ class NodeUpdateService
|
|||
// but something went wrong with Wings we just want to store the update and let the user manually
|
||||
// make changes as needed.
|
||||
//
|
||||
// This avoids issues with proxies such as CloudFlare which will see Wings as offline and then
|
||||
// This avoids issues with proxies such as Cloudflare which will see Wings as offline and then
|
||||
// inject their own response pages, causing this logic to get fucked up.
|
||||
//
|
||||
// @see https://github.com/pterodactyl/panel/issues/2712
|
||||
|
|
Reference in a new issue