Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Http/Middleware/Admin/Servers/ServerInstalled.php
10284 views
1
<?php
2
3
namespace Pterodactyl\Http\Middleware\Admin\Servers;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Http\Response;
7
use Pterodactyl\Models\Server;
8
use Symfony\Component\HttpKernel\Exception\HttpException;
9
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
10
11
class ServerInstalled
12
{
13
/**
14
* Checks that the server is installed before allowing access through the route.
15
*/
16
public function handle(Request $request, \Closure $next): mixed
17
{
18
/** @var Server|null $server */
19
$server = $request->route()->parameter('server');
20
21
if (!$server instanceof Server) {
22
throw new NotFoundHttpException('No server resource was located in the request parameters.');
23
}
24
25
if (!$server->isInstalled()) {
26
throw new HttpException(Response::HTTP_FORBIDDEN, 'Access to this resource is not allowed due to the current installation state.');
27
}
28
29
return $next($request);
30
}
31
}
32
33