Upgrade to Laravel 9 (#4413)

Co-authored-by: DaneEveritt <dane@daneeveritt.com>
This commit is contained in:
Matthew Penner 2022-10-14 10:59:20 -06:00 committed by GitHub
parent 95e15d2c8a
commit cbcf62086f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
573 changed files with 4387 additions and 9411 deletions

View file

@ -14,10 +14,8 @@ class TrackAPIKey
* API key, or it is just a cookie authenticated session. This data is set in a
* request singleton so that all tracked activity log events are properly associated
* with the given API key.
*
* @return mixed
*/
public function handle(Request $request, Closure $next)
public function handle(Request $request, Closure $next): mixed
{
if ($request->user()) {
$token = $request->user()->currentAccessToken();

View file

@ -13,10 +13,8 @@ class ServerInstalled
{
/**
* Checks that the server is installed before allowing access through the route.
*
* @return mixed
*/
public function handle(Request $request, Closure $next)
public function handle(Request $request, Closure $next): mixed
{
/** @var \Pterodactyl\Models\Server|null $server */
$server = $request->route()->parameter('server');

View file

@ -1,11 +1,4 @@
<?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\Http\Middleware;
@ -18,11 +11,9 @@ class AdminAuthenticate
/**
* Handle an incoming request.
*
* @return mixed
*
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
*/
public function handle(Request $request, Closure $next)
public function handle(Request $request, Closure $next): mixed
{
if (!$request->user() || !$request->user()->root_admin) {
throw new AccessDeniedHttpException();

View file

@ -11,10 +11,8 @@ class AuthenticateApplicationUser
/**
* Authenticate that the currently authenticated user is an administrator
* and should be allowed to proceed through the application API.
*
* @return mixed
*/
public function handle(Request $request, Closure $next)
public function handle(Request $request, Closure $next): mixed
{
/** @var \Pterodactyl\Models\User|null $user */
$user = $request->user();

View file

@ -15,12 +15,10 @@ class AuthenticateIPAccess
/**
* Determine if a request IP has permission to access the API.
*
* @return mixed
*
* @throws \Exception
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
*/
public function handle(Request $request, Closure $next)
public function handle(Request $request, Closure $next): mixed
{
/** @var \Laravel\Sanctum\TransientToken|\Pterodactyl\Models\ApiKey $token */
$token = $request->user()->currentAccessToken();

View file

@ -11,10 +11,8 @@ class RequireClientApiKey
/**
* Blocks a request to the Client API endpoints if the user is providing an API token
* that was created for the application API.
*
* @return mixed
*/
public function handle(Request $request, \Closure $next)
public function handle(Request $request, \Closure $next): mixed
{
$token = $request->user()->currentAccessToken();

View file

@ -5,40 +5,29 @@ namespace Pterodactyl\Http\Middleware\Api\Client\Server;
use Closure;
use Illuminate\Http\Request;
use Pterodactyl\Models\Server;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Pterodactyl\Exceptions\Http\Server\ServerStateConflictException;
class AuthenticateServerAccess
{
/**
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
*/
private $repository;
/**
* Routes that this middleware should not apply to if the user is an admin.
*
* @var string[]
*/
protected $except = [
protected array $except = [
'api:client:server.ws',
];
/**
* AuthenticateServerAccess constructor.
*/
public function __construct(ServerRepositoryInterface $repository)
public function __construct()
{
$this->repository = $repository;
}
/**
* Authenticate that this server exists and is not suspended or marked as installing.
*
* @return mixed
*/
public function handle(Request $request, Closure $next)
public function handle(Request $request, Closure $next): mixed
{
/** @var \Pterodactyl\Models\User $user */
$user = $request->user();

View file

@ -25,10 +25,8 @@ class ResourceBelongsToServer
* This is critical to ensuring that all subsequent logic is using exactly the
* server that is expected, and that we're not accessing a resource completely
* unrelated to the server provided in the request.
*
* @return mixed
*/
public function handle(Request $request, Closure $next)
public function handle(Request $request, Closure $next): mixed
{
$params = $request->route()->parameters();
if (is_null($params) || !$params['server'] instanceof Server) {
@ -59,8 +57,8 @@ class ResourceBelongsToServer
throw $exception;
}
break;
// Regular users are a special case here as we need to make sure they're
// currently assigned as a subuser on the server.
// Regular users are a special case here as we need to make sure they're
// currently assigned as a subuser on the server.
case User::class:
$subuser = $server->subusers()->where('user_id', $model->id)->first();
if (is_null($subuser)) {
@ -70,8 +68,8 @@ class ResourceBelongsToServer
// in the underlying logic.
$request->attributes->set('subuser', $subuser);
break;
// Tasks are special since they're (currently) the only item in the API
// that requires something in addition to the server in order to be accessed.
// Tasks are special since they're (currently) the only item in the API
// that requires something in addition to the server in order to be accessed.
case Task::class:
$schedule = $request->route()->parameter('schedule');
if ($model->schedule_id !== $schedule->id || $schedule->server_id !== $server->id) {

View file

@ -10,10 +10,8 @@ class SubstituteClientBindings extends SubstituteBindings
{
/**
* @param \Illuminate\Http\Request $request
*
* @return mixed
*/
public function handle($request, Closure $next)
public function handle($request, Closure $next): mixed
{
// Override default behavior of the model binding to use a specific table
// column rather than the default 'id'.

View file

@ -13,42 +13,26 @@ use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
class DaemonAuthenticate
{
/**
* @var \Pterodactyl\Repositories\Eloquent\NodeRepository
*/
private $repository;
/**
* @var \Illuminate\Contracts\Encryption\Encrypter
*/
private $encrypter;
/**
* Daemon routes that this middleware should be skipped on.
*
* @var array
*/
protected $except = [
protected array $except = [
'daemon.configuration',
];
/**
* DaemonAuthenticate constructor.
*/
public function __construct(Encrypter $encrypter, NodeRepository $repository)
public function __construct(private Encrypter $encrypter, private NodeRepository $repository)
{
$this->repository = $repository;
$this->encrypter = $encrypter;
}
/**
* Check if a request from the daemon can be properly attributed back to a single node instance.
*
* @return mixed
*
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
*/
public function handle(Request $request, Closure $next)
public function handle(Request $request, Closure $next): mixed
{
if (in_array($request->route()->getName(), $this->except)) {
return $next($request);

View file

@ -13,10 +13,8 @@ class IsValidJson
* Throw an exception if the request should be valid JSON data but there is an error while
* parsing the data. This avoids confusing validation errors where every field is flagged and
* it is not immediately clear that there is an issue with the JSON being passed.
*
* @return mixed
*/
public function handle(Request $request, Closure $next)
public function handle(Request $request, Closure $next): mixed
{
if ($request->isJson() && !empty($request->getContent())) {
try {

View file

@ -8,8 +8,6 @@ class EncryptCookies extends BaseEncrypter
{
/**
* The names of the cookies that should not be encrypted.
*
* @var array
*/
protected $except = [];
}

View file

@ -8,25 +8,17 @@ use Illuminate\Foundation\Application;
class LanguageMiddleware
{
/**
* @var \Illuminate\Foundation\Application
*/
private $app;
/**
* LanguageMiddleware constructor.
*/
public function __construct(Application $app)
public function __construct(private Application $app)
{
$this->app = $app;
}
/**
* Handle an incoming request and set the user's preferred language.
*
* @return mixed
*/
public function handle(Request $request, Closure $next)
public function handle(Request $request, Closure $next): mixed
{
$this->app->setLocale($request->user()->language ?? config('app.locale', 'en'));

View file

@ -3,31 +3,22 @@
namespace Pterodactyl\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Contracts\Routing\ResponseFactory;
class MaintenanceMiddleware
{
/**
* @var \Illuminate\Contracts\Routing\ResponseFactory
*/
private $response;
/**
* MaintenanceMiddleware constructor.
*/
public function __construct(ResponseFactory $response)
public function __construct(private ResponseFactory $response)
{
$this->response = $response;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
*
* @return mixed
*/
public function handle($request, Closure $next)
public function handle(Request $request, Closure $next): mixed
{
/** @var \Pterodactyl\Models\Server $server */
$server = $request->attributes->get('server');

View file

@ -8,25 +8,17 @@ use Illuminate\Auth\AuthManager;
class RedirectIfAuthenticated
{
/**
* @var \Illuminate\Auth\AuthManager
*/
private $authManager;
/**
* RedirectIfAuthenticated constructor.
*/
public function __construct(AuthManager $authManager)
public function __construct(private AuthManager $authManager)
{
$this->authManager = $authManager;
}
/**
* Handle an incoming request.
*
* @return mixed
*/
public function handle(Request $request, Closure $next, string $guard = null)
public function handle(Request $request, Closure $next, string $guard = null): mixed
{
if ($this->authManager->guard($guard)->check()) {
return redirect()->route('index');

View file

@ -15,23 +15,15 @@ class RequireTwoFactorAuthentication
public const LEVEL_ALL = 2;
/**
* @var \Prologue\Alerts\AlertsMessageBag
* The route to redirect a user to enable 2FA.
*/
private $alert;
/**
* The route to redirect a user to to enable 2FA.
*
* @var string
*/
protected $redirectRoute = '/account';
protected string $redirectRoute = '/account';
/**
* RequireTwoFactorAuthentication constructor.
*/
public function __construct(AlertsMessageBag $alert)
public function __construct(private AlertsMessageBag $alert)
{
$this->alert = $alert;
}
/**
@ -40,11 +32,9 @@ class RequireTwoFactorAuthentication
* order to perform actions. If so, we check the level at which it is required (all users
* or just admins) and then check if the user has enabled it for their account.
*
* @return mixed
*
* @throws \Pterodactyl\Exceptions\Http\TwoFactorAuthRequiredException
*/
public function handle(Request $request, Closure $next)
public function handle(Request $request, Closure $next): mixed
{
/** @var \Pterodactyl\Models\User $user */
$user = $request->user();

View file

@ -8,8 +8,6 @@ class TrimStrings extends BaseTrimmer
{
/**
* The names of the attributes that should not be trimmed.
*
* @var array
*/
protected $except = [
'password',

View file

@ -10,8 +10,6 @@ class VerifyCsrfToken extends BaseVerifier
* The URIs that should be excluded from CSRF verification. These are
* never hit by the front-end, and require specific token validation
* to work.
*
* @var string[]
*/
protected $except = ['remote/*', 'daemon/*'];
}

View file

@ -14,33 +14,17 @@ use Symfony\Component\HttpKernel\Exception\HttpException;
class VerifyReCaptcha
{
/**
* @var \Illuminate\Contracts\Config\Repository
*/
private $config;
/**
* @var \Illuminate\Contracts\Events\Dispatcher
*/
private $dispatcher;
/**
* VerifyReCaptcha constructor.
*/
public function __construct(Dispatcher $dispatcher, Repository $config)
public function __construct(private Dispatcher $dispatcher, private Repository $config)
{
$this->config = $config;
$this->dispatcher = $dispatcher;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\RedirectResponse|mixed
*/
public function handle($request, Closure $next)
public function handle(Request $request, Closure $next): mixed
{
if (!$this->config->get('recaptcha.enabled')) {
return $next($request);