2019-11-24 20:50:16 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Middleware\Admin\Servers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Http\Response;
|
|
|
|
use Pterodactyl\Models\Server;
|
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
|
|
|
|
|
|
class ServerInstalled
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Checks that the server is installed before allowing access through the route.
|
|
|
|
*/
|
2023-02-23 19:30:16 +00:00
|
|
|
public function handle(Request $request, \Closure $next): mixed
|
2019-11-24 20:50:16 +00:00
|
|
|
{
|
|
|
|
/** @var \Pterodactyl\Models\Server|null $server */
|
|
|
|
$server = $request->route()->parameter('server');
|
|
|
|
|
2021-01-23 20:33:34 +00:00
|
|
|
if (!$server instanceof Server) {
|
|
|
|
throw new NotFoundHttpException('No server resource was located in the request parameters.');
|
2019-11-24 20:50:16 +00:00
|
|
|
}
|
|
|
|
|
2021-01-26 03:20:51 +00:00
|
|
|
if (!$server->isInstalled()) {
|
|
|
|
throw new HttpException(Response::HTTP_FORBIDDEN, 'Access to this resource is not allowed due to the current installation state.');
|
2019-11-24 20:50:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|