Replace node repository
This commit is contained in:
parent
7266c66ebf
commit
aeb7590a6d
14 changed files with 101 additions and 250 deletions
|
@ -4,10 +4,9 @@ namespace Pterodactyl\Http\Middleware\Api\Daemon;
|
|||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Pterodactyl\Models\Node;
|
||||
use Illuminate\Contracts\Encryption\Encrypter;
|
||||
use Pterodactyl\Repositories\Eloquent\NodeRepository;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
|
||||
|
@ -23,14 +22,14 @@ class DaemonAuthenticate
|
|||
/**
|
||||
* DaemonAuthenticate constructor.
|
||||
*/
|
||||
public function __construct(private Encrypter $encrypter, private NodeRepository $repository)
|
||||
public function __construct(private Encrypter $encrypter)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a request from the daemon can be properly attributed back to a single node instance.
|
||||
*
|
||||
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
|
||||
* @throws HttpException
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): mixed
|
||||
{
|
||||
|
@ -43,24 +42,18 @@ class DaemonAuthenticate
|
|||
}
|
||||
|
||||
$parts = explode('.', $bearer);
|
||||
// Ensure that all of the correct parts are provided in the header.
|
||||
// Ensure that all the correct parts are provided in the header.
|
||||
if (count($parts) !== 2 || empty($parts[0]) || empty($parts[1])) {
|
||||
throw new BadRequestHttpException('The Authorization header provided was not in a valid format.');
|
||||
}
|
||||
|
||||
try {
|
||||
/** @var \Pterodactyl\Models\Node $node */
|
||||
$node = $this->repository->findFirstWhere([
|
||||
'daemon_token_id' => $parts[0],
|
||||
]);
|
||||
/** @var Node $node */
|
||||
$node = Node::query()->where('daemon_token_id', $parts[0])->firstOrFail();
|
||||
|
||||
if (hash_equals((string) $this->encrypter->decrypt($node->daemon_token), $parts[1])) {
|
||||
$request->attributes->set('node', $node);
|
||||
if (hash_equals((string) $this->encrypter->decrypt($node->daemon_token), $parts[1])) {
|
||||
$request->attributes->set('node', $node);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
} catch (RecordNotFoundException $exception) {
|
||||
// Do nothing, we don't want to expose a node not existing at all.
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
throw new AccessDeniedHttpException('You are not authorized to access this resource.');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue