mirror of
https://github.com/pterodactyl/panel.git
synced 2024-11-26 11:02:31 +01:00
Implement initial server and location API routes.
Also fixes a few exception handler issues causing incorrect HTTP status codes on authorization errors.
This commit is contained in:
parent
463f465dea
commit
c492446513
@ -47,6 +47,7 @@ class Handler extends ExceptionHandler
|
||||
public function render($request, Exception $exception)
|
||||
{
|
||||
if ($request->expectsJson() || $request->isJson() || $request->is(...config('pterodactyl.json_routes'))) {
|
||||
$exception = $this->prepareException($exception);
|
||||
|
||||
if (config('app.debug')) {
|
||||
$report = [
|
||||
|
51
app/Http/Controllers/API/Admin/LocationController.php
Normal file
51
app/Http/Controllers/API/Admin/LocationController.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Http\Controllers\API\Admin;
|
||||
|
||||
use Fractal;
|
||||
use Illuminate\Http\Request;
|
||||
use Pterodactyl\Models\Location;
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Pterodactyl\Transformers\Admin\LocationTransformer;
|
||||
|
||||
class LocationController extends Controller
|
||||
{
|
||||
/**
|
||||
* Controller to handle returning all locations on the system.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$this->authorize('location-list', $request->apiKey());
|
||||
|
||||
return Fractal::create()
|
||||
->collection(Location::all())
|
||||
->transformWith(new LocationTransformer($request))
|
||||
->withResourceName('location')
|
||||
->toArray();
|
||||
}
|
||||
}
|
@ -27,8 +27,12 @@ namespace Pterodactyl\Http\Controllers\API\Admin;
|
||||
use Fractal;
|
||||
use Illuminate\Http\Request;
|
||||
use Pterodactyl\Models\Server;
|
||||
use GuzzleHttp\Exception\TransferException;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Pterodactyl\Repositories\ServerRepository;
|
||||
use Pterodactyl\Transformers\Admin\ServerTransformer;
|
||||
use Pterodactyl\Exceptions\DisplayValidationException;
|
||||
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
||||
|
||||
class ServerController extends Controller
|
||||
@ -41,6 +45,8 @@ class ServerController extends Controller
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$this->authorize('server-list', $request->apiKey());
|
||||
|
||||
$servers = Server::paginate(20);
|
||||
|
||||
return Fractal::create()
|
||||
@ -59,6 +65,8 @@ class ServerController extends Controller
|
||||
*/
|
||||
public function view(Request $request, $id)
|
||||
{
|
||||
$this->authorize('server-view', $request->apiKey());
|
||||
|
||||
$server = Server::findOrFail($id);
|
||||
$fractal = Fractal::create()->item($server);
|
||||
|
||||
@ -70,4 +78,332 @@ class ServerController extends Controller
|
||||
->withResourceName('server')
|
||||
->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new server on the system.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\JsonResponse|array
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$this->authorize('server-create', $request->apiKey());
|
||||
|
||||
$repo = new ServerRepository;
|
||||
try {
|
||||
$server = $repo->create($request->all());
|
||||
|
||||
$fractal = Fractal::create()->item($server)->transformWith(new ServerTransformer($request));
|
||||
if ($request->input('include')) {
|
||||
$fractal->parseIncludes(explode(',', $request->input('include')));
|
||||
}
|
||||
|
||||
return $fractal->withResourceName('server')->toArray();
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return response()->json([
|
||||
'error' => json_decode($ex->getMessage()),
|
||||
], 400);
|
||||
} catch (DisplayException $ex) {
|
||||
return response()->json([
|
||||
'error' => $ex->getMessage(),
|
||||
], 400);
|
||||
} catch (TransferException $ex) {
|
||||
Log::warning($ex);
|
||||
return response()->json([
|
||||
'error' => 'A TransferException was encountered while trying to contact the daemon, please ensure it is online and accessible. This error has been logged.',
|
||||
], 504);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return response()->json([
|
||||
'error' => 'An unhandled exception occured while attemping to add this server. Please try again.',
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a server from the system.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function delete(Request $request, $id)
|
||||
{
|
||||
$this->authorize('server-delete', $request->apiKey());
|
||||
|
||||
$repo = new ServerRepository;
|
||||
try {
|
||||
$repo->delete($id, $request->has('force_delete'));
|
||||
|
||||
return response('', 204);
|
||||
} catch (DisplayException $ex) {
|
||||
return response()->json([
|
||||
'error' => $ex->getMessage(),
|
||||
], 400);
|
||||
} catch (TransferException $ex) {
|
||||
Log::warning($ex);
|
||||
return response()->json([
|
||||
'error' => 'A TransferException was encountered while trying to contact the daemon, please ensure it is online and accessible. This error has been logged.',
|
||||
], 504);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return response()->json([
|
||||
'error' => 'An unhandled exception occured while attemping to add this server. Please try again.',
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the details for a server.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\JsonResponse|array
|
||||
*/
|
||||
public function details(Request $request, $id)
|
||||
{
|
||||
$this->authorize('server-edit-details', $request->apiKey());
|
||||
|
||||
$repo = new ServerRepository;
|
||||
try {
|
||||
$server = $repo->updateDetails($id, $request->intersect([
|
||||
'owner_id', 'name', 'description', 'reset_token',
|
||||
]));
|
||||
|
||||
$fractal = Fractal::create()->item($server)->transformWith(new ServerTransformer($request));
|
||||
if ($request->input('include')) {
|
||||
$fractal->parseIncludes(explode(',', $request->input('include')));
|
||||
}
|
||||
|
||||
return $fractal->withResourceName('server')->toArray();
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return response()->json([
|
||||
'error' => json_decode($ex->getMessage()),
|
||||
], 400);
|
||||
} catch (DisplayException $ex) {
|
||||
return response()->json([
|
||||
'error' => $ex->getMessage(),
|
||||
], 400);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return response()->json([
|
||||
'error' => 'An unhandled exception occured while attemping to modify this server. Please try again.',
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the new docker container for a server.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\RedirectResponse|array
|
||||
*/
|
||||
public function container(Request $request, $id)
|
||||
{
|
||||
$this->authorize('server-edit-container', $request->apiKey());
|
||||
|
||||
$repo = new ServerRepository;
|
||||
try {
|
||||
$server = $repo->updateContainer($id, $request->intersect('docker_image'));
|
||||
|
||||
$fractal = Fractal::create()->item($server)->transformWith(new ServerTransformer($request));
|
||||
if ($request->input('include')) {
|
||||
$fractal->parseIncludes(explode(',', $request->input('include')));
|
||||
}
|
||||
|
||||
return $fractal->withResourceName('server')->toArray();
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return response()->json([
|
||||
'error' => json_decode($ex->getMessage()),
|
||||
], 400);
|
||||
} catch (TransferException $ex) {
|
||||
Log::warning($ex);
|
||||
return response()->json([
|
||||
'error' => 'A TransferException was encountered while trying to contact the daemon, please ensure it is online and accessible. This error has been logged.',
|
||||
], 504);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return response()->json([
|
||||
'error' => 'An unhandled exception occured while attemping to modify this server container. Please try again.',
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the install status for a server.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function install(Request $request, $id)
|
||||
{
|
||||
$this->authorize('server-install', $request->apiKey());
|
||||
|
||||
$repo = new ServerRepository;
|
||||
try {
|
||||
$repo->toggleInstall($id);
|
||||
|
||||
return response('', 204);
|
||||
} catch (DisplayException $ex) {
|
||||
return response()->json([
|
||||
'error' => $ex->getMessage(),
|
||||
], 400);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return response()->json([
|
||||
'error' => 'An unhandled exception occured while attemping to toggle the install status for this server. Please try again.',
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup a server to have a container rebuild.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function rebuild(Request $request, $id)
|
||||
{
|
||||
$this->authorize('server-rebuild', $request->apiKey());
|
||||
$server = Server::with('node')->findOrFail($id);
|
||||
|
||||
try {
|
||||
$server->node->guzzleClient([
|
||||
'X-Access-Server' => $server->uuid,
|
||||
'X-Access-Token' => $server->node->daemonSecret,
|
||||
])->request('POST', '/server/rebuild');
|
||||
|
||||
return response('', 204);
|
||||
} catch (TransferException $ex) {
|
||||
Log::warning($ex);
|
||||
return response()->json([
|
||||
'error' => 'A TransferException was encountered while trying to contact the daemon, please ensure it is online and accessible. This error has been logged.',
|
||||
], 504);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage the suspension status for a server.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function suspend(Request $request, $id)
|
||||
{
|
||||
$this->authorize('server-suspend', $request->apiKey());
|
||||
|
||||
$repo = new ServerRepository;
|
||||
$action = $request->input('action');
|
||||
if (! in_array($action, ['suspend', 'unsuspend'])) {
|
||||
return response()->json([
|
||||
'error' => 'The action provided was invalid. Action should be one of: suspend, unsuspend.',
|
||||
], 400);
|
||||
}
|
||||
|
||||
try {
|
||||
$repo->$action($id);
|
||||
|
||||
return response('', 204);
|
||||
} catch (DisplayException $ex) {
|
||||
return response()->json([
|
||||
'error' => $ex->getMessage(),
|
||||
], 400);
|
||||
} catch (TransferException $ex) {
|
||||
Log::warning($ex);
|
||||
return response()->json([
|
||||
'error' => 'A TransferException was encountered while trying to contact the daemon, please ensure it is online and accessible. This error has been logged.',
|
||||
], 504);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return response()->json([
|
||||
'error' => 'An unhandled exception occured while attemping to ' . $action . ' this server. Please try again.',
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the build configuration for a server.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\JsonResponse|array
|
||||
*/
|
||||
public function build(Request $request, $id)
|
||||
{
|
||||
$this->authorize('server-edit-build', $request->apiKey());
|
||||
|
||||
$repo = new ServerRepository;
|
||||
try {
|
||||
$server = $repo->changeBuild($id, $request->intersect([
|
||||
'allocation_id', 'add_allocations', 'remove_allocations',
|
||||
'memory', 'swap', 'io', 'cpu',
|
||||
]));
|
||||
|
||||
$fractal = Fractal::create()->item($server)->transformWith(new ServerTransformer($request));
|
||||
if ($request->input('include')) {
|
||||
$fractal->parseIncludes(explode(',', $request->input('include')));
|
||||
}
|
||||
|
||||
return $fractal->withResourceName('server')->toArray();
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return response()->json([
|
||||
'error' => json_decode($ex->getMessage()),
|
||||
], 400);
|
||||
} catch (DisplayException $ex) {
|
||||
return response()->json([
|
||||
'error' => $ex->getMessage(),
|
||||
], 400);
|
||||
} catch (TransferException $ex) {
|
||||
Log::warning($ex);
|
||||
return response()->json([
|
||||
'error' => 'A TransferException was encountered while trying to contact the daemon, please ensure it is online and accessible. This error has been logged.',
|
||||
], 504);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return response()->json([
|
||||
'error' => 'An unhandled exception occured while attemping to modify the build settings for this server. Please try again.',
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the startup command as well as variables.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function startup(Request $request, $id)
|
||||
{
|
||||
$this->authorize('server-edit-startup', $request->apiKey());
|
||||
|
||||
$repo = new ServerRepository;
|
||||
try {
|
||||
$repo->updateStartup($id, $request->all(), true);
|
||||
|
||||
return response('', 204);
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return response()->json([
|
||||
'error' => json_decode($ex->getMessage()),
|
||||
], 400);
|
||||
} catch (DisplayException $ex) {
|
||||
return response()->json([
|
||||
'error' => $ex->getMessage(),
|
||||
], 400);
|
||||
} catch (TransferException $ex) {
|
||||
Log::warning($ex);
|
||||
return response()->json([
|
||||
'error' => 'A TransferException was encountered while trying to contact the daemon, please ensure it is online and accessible. This error has been logged.',
|
||||
], 504);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return response()->json([
|
||||
'error' => 'An unhandled exception occured while attemping to modify the startup settings for this server. Please try again.',
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,6 +39,8 @@ class CoreController extends Controller
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$this->authorize('user-server-list', $request->apiKey());
|
||||
|
||||
$servers = $request->user()->access('service', 'node', 'allocation', 'option')->get();
|
||||
|
||||
return Fractal::collection($servers)
|
||||
|
@ -43,6 +43,8 @@ class ServerController extends Controller
|
||||
*/
|
||||
public function index(Request $request, $uuid)
|
||||
{
|
||||
$this->authorize('user-server-view', $request->apiKey());
|
||||
|
||||
$server = Server::byUuid($uuid);
|
||||
$fractal = Fractal::create()->item($server);
|
||||
|
||||
@ -64,6 +66,8 @@ class ServerController extends Controller
|
||||
*/
|
||||
public function power(Request $request, $uuid)
|
||||
{
|
||||
$this->authorize('user-server-power', $request->apiKey());
|
||||
|
||||
$server = Server::byUuid($uuid);
|
||||
$request->user()->can('power-' . $request->input('action'), $server);
|
||||
|
||||
@ -82,6 +86,8 @@ class ServerController extends Controller
|
||||
*/
|
||||
public function command(Request $request, $uuid)
|
||||
{
|
||||
$this->authorize('user-server-command', $request->apiKey());
|
||||
|
||||
$server = Server::byUuid($uuid);
|
||||
$request->user()->can('send-command', $server);
|
||||
|
||||
|
@ -97,6 +97,9 @@ class ServersController extends Controller
|
||||
return redirect()->route('admin.servers.new')->withErrors(json_decode($ex->getMessage()))->withInput();
|
||||
} catch (DisplayException $ex) {
|
||||
Alert::danger($ex->getMessage())->flash();
|
||||
} catch (TransferException $ex) {
|
||||
Log::warning($ex);
|
||||
Alert::danger('A TransferException was encountered while trying to contact the daemon, please ensure it is online and accessible. This error has been logged.')->flash();
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
Alert::danger('An unhandled exception occured while attemping to add this server. Please try again.')->flash();
|
||||
@ -284,8 +287,9 @@ class ServersController extends Controller
|
||||
Alert::success('Successfully updated this server\'s docker image.')->flash();
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return redirect()->route('admin.servers.view.details', $id)->withErrors(json_decode($ex->getMessage()))->withInput();
|
||||
} catch (DisplayException $ex) {
|
||||
Alert::danger($ex->getMessage())->flash();
|
||||
} catch (TransferException $ex) {
|
||||
Log::warning($ex);
|
||||
Alert::danger('A TransferException occured while attempting to update the container image. Is the daemon online? This error has been logged.');
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
Alert::danger('An unhandled exception occured while attemping to update this server\'s docker image. This error has been logged.')->flash();
|
||||
@ -366,8 +370,9 @@ class ServersController extends Controller
|
||||
$repo->$action($id);
|
||||
|
||||
Alert::success('Server has been ' . $action . 'ed.');
|
||||
} catch (DisplayException $ex) {
|
||||
Alert::danger($ex->getMessage())->flash();
|
||||
} catch (TransferException $ex) {
|
||||
Log::warning($ex);
|
||||
Alert::danger('A TransferException was encountered while trying to contact the daemon, please ensure it is online and accessible. This error has been logged.')->flash();
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
Alert::danger('An unhandled exception occured while attemping to ' . $action . ' this server. This error has been logged.')->flash();
|
||||
@ -398,6 +403,9 @@ class ServersController extends Controller
|
||||
return redirect()->route('admin.servers.view.build', $id)->withErrors(json_decode($ex->getMessage()))->withInput();
|
||||
} catch (DisplayException $ex) {
|
||||
Alert::danger($ex->getMessage())->flash();
|
||||
} catch (TransferException $ex) {
|
||||
Log::warning($ex);
|
||||
Alert::danger('A TransferException was encountered while trying to contact the daemon, please ensure it is online and accessible. This error has been logged.')->flash();
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
Alert::danger('An unhandled exception occured while attemping to add this server. This error has been logged.')->flash();
|
||||
|
@ -57,4 +57,46 @@ class APIPermission extends Model
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* List of permissions available for the API.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $permissions = [
|
||||
// Items within this block are available to non-adminitrative users.
|
||||
'_user' => [
|
||||
'server' => [
|
||||
'list',
|
||||
'view',
|
||||
'power',
|
||||
'command',
|
||||
]
|
||||
],
|
||||
|
||||
// All other pemissions below are administrative actions.
|
||||
'server' => [
|
||||
'list',
|
||||
'view',
|
||||
'delete',
|
||||
'create',
|
||||
'edit-details',
|
||||
'edit-container',
|
||||
'suspend',
|
||||
'install',
|
||||
'rebuild',
|
||||
'edit-build',
|
||||
'edit-startup',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Return permissions for API
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function permissions()
|
||||
{
|
||||
return self::$permissions;
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ namespace Pterodactyl\Models;
|
||||
use Auth;
|
||||
use Cache;
|
||||
use Carbon;
|
||||
use Schema;
|
||||
use Javascript;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
@ -203,6 +204,15 @@ class Server extends Model
|
||||
return Javascript::put($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the columns available for this table.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTableColumns() {
|
||||
return Schema::getColumnListing($this->getTable());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the user who owns the server.
|
||||
*
|
||||
|
@ -54,26 +54,162 @@ class APIKeyPolicy
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if API key is allowed to view all nodes.
|
||||
*
|
||||
* @param \Pterodactyl\Models\User $user
|
||||
* @param \Pterodactyl\Models\APIKey $key
|
||||
* @return bool
|
||||
*/
|
||||
public function listNodes(User $user, Key $key)
|
||||
public function locationList(User $user, Key $key)
|
||||
{
|
||||
return $this->checkPermission($user, $key, 'list-nodes');
|
||||
return $this->checkPermission($user, $key, 'location-list');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if API key is allowed to view a specific node.
|
||||
*
|
||||
* @param \Pterodactyl\Models\User $user
|
||||
* @param \Pterodactyl\Models\APIKey $key
|
||||
* @return bool
|
||||
*/
|
||||
public function viewNode(User $user, Key $key)
|
||||
public function serverList(User $user, Key $key)
|
||||
{
|
||||
return $this->checkPermission($user, $key, 'view-node');
|
||||
return $this->checkPermission($user, $key, 'server-list');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Pterodactyl\Models\User $user
|
||||
* @param \Pterodactyl\Models\APIKey $key
|
||||
* @return bool
|
||||
*/
|
||||
public function serverView(User $user, Key $key)
|
||||
{
|
||||
return $this->checkPermission($user, $key, 'server-view');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Pterodactyl\Models\User $user
|
||||
* @param \Pterodactyl\Models\APIKey $key
|
||||
* @return bool
|
||||
*/
|
||||
public function serverCreate(User $user, Key $key)
|
||||
{
|
||||
return $this->checkPermission($user, $key, 'server-create');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Pterodactyl\Models\User $user
|
||||
* @param \Pterodactyl\Models\APIKey $key
|
||||
* @return bool
|
||||
*/
|
||||
public function serverDelete(User $user, Key $key)
|
||||
{
|
||||
return $this->checkPermission($user, $key, 'server-delete');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Pterodactyl\Models\User $user
|
||||
* @param \Pterodactyl\Models\APIKey $key
|
||||
* @return bool
|
||||
*/
|
||||
public function serverEditDetails(User $user, Key $key)
|
||||
{
|
||||
return $this->checkPermission($user, $key, 'server-edit-details');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Pterodactyl\Models\User $user
|
||||
* @param \Pterodactyl\Models\APIKey $key
|
||||
* @return bool
|
||||
*/
|
||||
public function serverEditContainer(User $user, Key $key)
|
||||
{
|
||||
return $this->checkPermission($user, $key, 'server-edit-container');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Pterodactyl\Models\User $user
|
||||
* @param \Pterodactyl\Models\APIKey $key
|
||||
* @return bool
|
||||
*/
|
||||
public function serverEditBuild(User $user, Key $key)
|
||||
{
|
||||
return $this->checkPermission($user, $key, 'server-edit-build');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Pterodactyl\Models\User $user
|
||||
* @param \Pterodactyl\Models\APIKey $key
|
||||
* @return bool
|
||||
*/
|
||||
public function serverEditStartup(User $user, Key $key)
|
||||
{
|
||||
return $this->checkPermission($user, $key, 'server-edit-startup');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Pterodactyl\Models\User $user
|
||||
* @param \Pterodactyl\Models\APIKey $key
|
||||
* @return bool
|
||||
*/
|
||||
public function serverSuspend(User $user, Key $key)
|
||||
{
|
||||
return $this->checkPermission($user, $key, 'server-suspend');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Pterodactyl\Models\User $user
|
||||
* @param \Pterodactyl\Models\APIKey $key
|
||||
* @return bool
|
||||
*/
|
||||
public function servrerInstall(User $user, Key $key)
|
||||
{
|
||||
return $this->checkPermission($user, $key, 'server-install');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Pterodactyl\Models\User $user
|
||||
* @param \Pterodactyl\Models\APIKey $key
|
||||
* @return bool
|
||||
*/
|
||||
public function serverRebuild(User $user, Key $key)
|
||||
{
|
||||
return $this->checkPermission($user, $key, 'server-rebuild');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Pterodactyl\Models\User $user
|
||||
* @param \Pterodactyl\Models\APIKey $key
|
||||
* @return bool
|
||||
*/
|
||||
public function userServerList(User $user, Key $key)
|
||||
{
|
||||
return $this->checkPermission($user, $key, 'user-server-list');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Pterodactyl\Models\User $user
|
||||
* @param \Pterodactyl\Models\APIKey $key
|
||||
* @return bool
|
||||
*/
|
||||
public function userServerView(User $user, Key $key)
|
||||
{
|
||||
return $this->checkPermission($user, $key, 'user-server-view');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Pterodactyl\Models\User $user
|
||||
* @param \Pterodactyl\Models\APIKey $key
|
||||
* @return bool
|
||||
*/
|
||||
public function userServerPower(User $user, Key $key)
|
||||
{
|
||||
return $this->checkPermission($user, $key, 'user-server-power');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Pterodactyl\Models\User $user
|
||||
* @param \Pterodactyl\Models\APIKey $key
|
||||
* @return bool
|
||||
*/
|
||||
public function userServerCommand(User $user, Key $key)
|
||||
{
|
||||
return $this->checkPermission($user, $key, 'user-server-command');
|
||||
}
|
||||
}
|
||||
|
@ -337,9 +337,6 @@ class ServerRepository
|
||||
DB::commit();
|
||||
|
||||
return $server;
|
||||
} catch (TransferException $ex) {
|
||||
DB::rollBack();
|
||||
throw new DisplayException('There was an error while attempting to connect to the daemon to add this server.', $ex);
|
||||
} catch (\Exception $ex) {
|
||||
DB::rollBack();
|
||||
throw $ex;
|
||||
@ -351,7 +348,7 @@ class ServerRepository
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
* @return bool
|
||||
* @return \Pterodactyl\Models\Server
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Pterodactyl\Exceptions\DisplayValidationException
|
||||
@ -409,7 +406,9 @@ class ServerRepository
|
||||
]);
|
||||
|
||||
if ($res->getStatusCode() === 204) {
|
||||
return DB::commit();
|
||||
DB::commit();
|
||||
|
||||
return $server;
|
||||
} else {
|
||||
throw new DisplayException('Daemon returned a a non HTTP/204 error code. HTTP/' + $res->getStatusCode());
|
||||
}
|
||||
@ -424,9 +423,8 @@ class ServerRepository
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
* @return bool
|
||||
* @return \Pterodactyl\Models\Server
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Pterodactyl\Exceptions\DisplayValidationException
|
||||
*/
|
||||
public function updateContainer($id, array $data)
|
||||
@ -461,10 +459,7 @@ class ServerRepository
|
||||
|
||||
DB::commit();
|
||||
|
||||
return true;
|
||||
} catch (TransferException $ex) {
|
||||
DB::rollBack();
|
||||
throw new DisplayException('A TransferException occured while attempting to update the container image. Is the daemon online? This error has been logged.', $ex);
|
||||
return $server;
|
||||
} catch (\Exception $ex) {
|
||||
DB::rollBack();
|
||||
throw $ex;
|
||||
@ -609,9 +604,6 @@ class ServerRepository
|
||||
DB::commit();
|
||||
|
||||
return $server;
|
||||
} catch (TransferException $ex) {
|
||||
DB::rollBack();
|
||||
throw new DisplayException('A TransferException occured while attempting to update the server configuration, check that the daemon is online. This error has been logged.', $ex);
|
||||
} catch (\Exception $ex) {
|
||||
DB::rollBack();
|
||||
throw $ex;
|
||||
@ -799,8 +791,6 @@ class ServerRepository
|
||||
* @param int $id
|
||||
* @param bool $deleted
|
||||
* @return void
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
*/
|
||||
public function suspend($id, $deleted = false)
|
||||
{
|
||||
@ -824,9 +814,6 @@ class ServerRepository
|
||||
])->request('POST', '/server/suspend');
|
||||
|
||||
return DB::commit();
|
||||
} catch (TransferException $ex) {
|
||||
DB::rollBack();
|
||||
throw new DisplayException('An error occured while attempting to contact the remote daemon to suspend this server.', $ex);
|
||||
} catch (\Exception $ex) {
|
||||
DB::rollBack();
|
||||
throw $ex;
|
||||
@ -838,8 +825,6 @@ class ServerRepository
|
||||
*
|
||||
* @param int $id
|
||||
* @return void
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
*/
|
||||
public function unsuspend($id)
|
||||
{
|
||||
@ -848,7 +833,6 @@ class ServerRepository
|
||||
DB::beginTransaction();
|
||||
|
||||
try {
|
||||
|
||||
// Already unsuspended, no need to make more requests.
|
||||
if ($server->suspended === 0) {
|
||||
return true;
|
||||
@ -863,9 +847,6 @@ class ServerRepository
|
||||
])->request('POST', '/server/unsuspend');
|
||||
|
||||
return DB::commit();
|
||||
} catch (TransferException $ex) {
|
||||
DB::rollBack();
|
||||
throw new DisplayException('An error occured while attempting to contact the remote daemon to un-suspend this server.', $ex);
|
||||
} catch (\Exception $ex) {
|
||||
DB::rollBack();
|
||||
throw $ex;
|
||||
@ -879,7 +860,6 @@ class ServerRepository
|
||||
* @param string $password
|
||||
* @return void
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Pterodactyl\Exceptions\DisplayValidationException
|
||||
*/
|
||||
public function updateSFTPPassword($id, $password)
|
||||
@ -910,9 +890,6 @@ class ServerRepository
|
||||
DB::commit();
|
||||
|
||||
return true;
|
||||
} catch (TransferException $ex) {
|
||||
DB::rollBack();
|
||||
throw new DisplayException('There was an error while attmping to contact the remote service to change the password.', $ex);
|
||||
} catch (\Exception $ex) {
|
||||
DB::rollBack();
|
||||
throw $ex;
|
||||
|
@ -76,7 +76,7 @@ class ServerTransformer extends TransformerAbstract
|
||||
*/
|
||||
public function transform(Server $server)
|
||||
{
|
||||
return $server->toArray();
|
||||
return collect($server->toArray())->only($server->getTableColumns())->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -22,7 +22,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
Route::get('/', 'CoreController@index')->name('api.admin');
|
||||
Route::get('/', 'CoreController@index');
|
||||
|
||||
|
||||
/*
|
||||
@ -34,6 +34,31 @@ Route::get('/', 'CoreController@index')->name('api.admin');
|
||||
|
|
||||
*/
|
||||
Route::group(['prefix' => '/servers'], function () {
|
||||
Route::get('/', 'ServerController@index')->name('api.admin.servers.list');
|
||||
Route::get('/{id}', 'ServerController@view')->name('api.admin.servers.view');
|
||||
Route::get('/', 'ServerController@index');
|
||||
Route::get('/{id}', 'ServerController@view');
|
||||
|
||||
Route::post('/', 'ServerController@store');
|
||||
|
||||
Route::put('/{id}/details', 'ServerController@details');
|
||||
Route::put('/{id}/container', 'ServerController@container');
|
||||
Route::put('/{id}/build', 'ServerController@build');
|
||||
Route::put('/{id}/startup', 'ServerController@startup');
|
||||
|
||||
Route::patch('/{id}/install', 'ServerController@install');
|
||||
Route::patch('/{id}/rebuild', 'ServerController@rebuild');
|
||||
Route::patch('/{id}/suspend', 'ServerController@suspend');
|
||||
|
||||
Route::delete('/{id}', 'ServerController@delete');
|
||||
});
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Location Controller Routes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Endpoint: /api/admin/locations
|
||||
|
|
||||
*/
|
||||
Route::group(['prefix' => '/locations'], function () {
|
||||
Route::get('/', 'LocationController@index');
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user