Update to Laravel 8
Co-authored-by: Matthew Penner <me@matthewp.io>
This commit is contained in:
parent
028921b42a
commit
a043071e3c
211 changed files with 4394 additions and 2933 deletions
|
@ -2,13 +2,14 @@
|
|||
|
||||
namespace Pterodactyl\Services\Nodes;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Lcobucci\JWT\Builder;
|
||||
use DateTimeImmutable;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Support\Str;
|
||||
use Lcobucci\JWT\Signer\Key;
|
||||
use Pterodactyl\Models\Node;
|
||||
use Lcobucci\JWT\Configuration;
|
||||
use Lcobucci\JWT\Signer\Hmac\Sha256;
|
||||
use Lcobucci\JWT\Signer\Key\InMemory;
|
||||
use Pterodactyl\Extensions\Lcobucci\JWT\Encoding\TimestampDates;
|
||||
|
||||
class NodeJWTService
|
||||
{
|
||||
|
@ -18,7 +19,7 @@ class NodeJWTService
|
|||
private $claims = [];
|
||||
|
||||
/**
|
||||
* @var int|null
|
||||
* @var \DateTimeImmutable|null
|
||||
*/
|
||||
private $expiresAt;
|
||||
|
||||
|
@ -41,12 +42,12 @@ class NodeJWTService
|
|||
}
|
||||
|
||||
/**
|
||||
* @param \DateTimeInterface $date
|
||||
* @param \DateTimeImmutable $date
|
||||
* @return $this
|
||||
*/
|
||||
public function setExpiresAt(DateTimeInterface $date)
|
||||
public function setExpiresAt(DateTimeImmutable $date)
|
||||
{
|
||||
$this->expiresAt = $date->getTimestamp();
|
||||
$this->expiresAt = $date;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -68,24 +69,27 @@ class NodeJWTService
|
|||
* @param \Pterodactyl\Models\Node $node
|
||||
* @param string|null $identifiedBy
|
||||
* @param string $algo
|
||||
* @return \Lcobucci\JWT\Token
|
||||
* @return \Lcobucci\JWT\Token\Plain
|
||||
*/
|
||||
public function handle(Node $node, string $identifiedBy, string $algo = 'md5')
|
||||
{
|
||||
$signer = new Sha256;
|
||||
$identifier = hash($algo, $identifiedBy);
|
||||
$config = Configuration::forSymmetricSigner(new Sha256, InMemory::plainText($node->getDecryptedKey()));
|
||||
|
||||
$builder = (new Builder)->issuedBy(config('app.url'))
|
||||
$builder = $config->builder(new TimestampDates)
|
||||
->issuedBy(config('app.url'))
|
||||
->permittedFor($node->getConnectionAddress())
|
||||
->identifiedBy(hash($algo, $identifiedBy), true)
|
||||
->issuedAt(CarbonImmutable::now()->getTimestamp())
|
||||
->canOnlyBeUsedAfter(CarbonImmutable::now()->subMinutes(5)->getTimestamp());
|
||||
->identifiedBy($identifier)
|
||||
->withHeader('jti', $identifier)
|
||||
->issuedAt(CarbonImmutable::now())
|
||||
->canOnlyBeUsedAfter(CarbonImmutable::now()->subMinutes(5));
|
||||
|
||||
if ($this->expiresAt) {
|
||||
$builder = $builder->expiresAt($this->expiresAt);
|
||||
}
|
||||
|
||||
if (!empty($this->subject)) {
|
||||
$builder = $builder->relatedTo($this->subject, true);
|
||||
if (! empty($this->subject)) {
|
||||
$builder = $builder->relatedTo($this->subject)->withHeader('sub', $this->subject);
|
||||
}
|
||||
|
||||
foreach ($this->claims as $key => $value) {
|
||||
|
@ -94,6 +98,6 @@ class NodeJWTService
|
|||
|
||||
return $builder
|
||||
->withClaim('unique_id', Str::random(16))
|
||||
->getToken($signer, new Key($node->getDecryptedKey()));
|
||||
->getToken($config->signer(), $config->signingKey());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,11 +5,9 @@ namespace Pterodactyl\Services\Nodes;
|
|||
use Illuminate\Support\Str;
|
||||
use Pterodactyl\Models\Node;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use GuzzleHttp\Exception\ConnectException;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Illuminate\Contracts\Encryption\Encrypter;
|
||||
use Pterodactyl\Repositories\Eloquent\NodeRepository;
|
||||
use Pterodactyl\Repositories\Daemon\ConfigurationRepository;
|
||||
use Pterodactyl\Repositories\Wings\DaemonConfigurationRepository;
|
||||
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
||||
use Pterodactyl\Exceptions\Service\Node\ConfigurationNotPersistedException;
|
||||
|
@ -101,7 +99,7 @@ class NodeUpdateService
|
|||
// inject their own response pages, causing this logic to get fucked up.
|
||||
//
|
||||
// @see https://github.com/pterodactyl/panel/issues/2712
|
||||
return [ $updated, true ];
|
||||
return [$updated, true];
|
||||
}
|
||||
|
||||
return [$updated, false];
|
||||
|
|
Reference in a new issue