Better middleware for routes, cleaned up API, removed old API calls
New API routes for Server allow specifying which fractal objects to load into the request, thus making it possible to fine-tune what data is returned.
This commit is contained in:
parent
ddb82ac3ca
commit
97773300ed
15 changed files with 304 additions and 747 deletions
|
@ -28,9 +28,26 @@ use Auth;
|
|||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
|
||||
class CheckServer
|
||||
{
|
||||
/**
|
||||
* The elquent model for the server.
|
||||
*
|
||||
* @var \Pterodactyl\Models\Server
|
||||
*/
|
||||
protected $server;
|
||||
|
||||
/**
|
||||
* The request object.
|
||||
*
|
||||
* @var \Illuminate\Http\Request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
|
@ -41,22 +58,72 @@ class CheckServer
|
|||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
if (! Auth::user()) {
|
||||
return redirect()->guest('auth/login');
|
||||
throw new AuthenticationException();
|
||||
}
|
||||
|
||||
$server = Server::byUuid($request->route()->server);
|
||||
if (! $server) {
|
||||
$this->request = $request;
|
||||
$this->server = Server::byUuid($request->route()->server);
|
||||
|
||||
if(! $this->exists()) {
|
||||
return response()->view('errors.404', [], 404);
|
||||
}
|
||||
|
||||
if ($server->suspended) {
|
||||
if ($this->suspended()) {
|
||||
return response()->view('errors.suspended', [], 403);
|
||||
}
|
||||
|
||||
if (! $server->installed) {
|
||||
if (! $this->installed()) {
|
||||
return response()->view('errors.installing', [], 403);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the server was found on the system.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function exists()
|
||||
{
|
||||
if (! $this->server) {
|
||||
if ($this->request->expectsJson() || $this->request->is(...config('pterodactyl.json_routes'))) {
|
||||
throw new NotFoundHttpException('The requested server was not found on the system.');
|
||||
}
|
||||
}
|
||||
|
||||
return (! $this->server) ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the server is suspended.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function suspended()
|
||||
{
|
||||
if ($this->server->suspended) {
|
||||
if ($this->request->expectsJson() || $this->request->is(...config('pterodactyl.json_routes'))) {
|
||||
throw new AccessDeniedHttpException('Server is suspended.');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->server->suspended;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the server is installed.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function installed()
|
||||
{
|
||||
if ($this->server->installed !== 1) {
|
||||
if ($this->request->expectsJson() || $this->request->is(...config('pterodactyl.json_routes'))) {
|
||||
throw new AccessDeniedHttpException('Server is completing install process.');
|
||||
}
|
||||
}
|
||||
|
||||
return ($this->server->installed === 1);
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue