2018-02-25 21:30:56 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Api\Client;
|
|
|
|
|
2018-02-28 03:28:43 +00:00
|
|
|
use Pterodactyl\Models\User;
|
2019-11-04 01:37:06 +00:00
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
use Pterodactyl\Models\Permission;
|
2019-09-06 04:41:20 +00:00
|
|
|
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
2018-02-28 03:28:43 +00:00
|
|
|
use Pterodactyl\Transformers\Api\Client\ServerTransformer;
|
|
|
|
use Pterodactyl\Http\Requests\Api\Client\GetServersRequest;
|
2018-02-25 21:30:56 +00:00
|
|
|
|
|
|
|
class ClientController extends ClientApiController
|
|
|
|
{
|
2018-02-28 03:28:43 +00:00
|
|
|
/**
|
2019-09-06 04:41:20 +00:00
|
|
|
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository
|
2018-02-28 03:28:43 +00:00
|
|
|
*/
|
|
|
|
private $repository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ClientController constructor.
|
|
|
|
*
|
2019-09-06 04:41:20 +00:00
|
|
|
* @param \Pterodactyl\Repositories\Eloquent\ServerRepository $repository
|
2018-02-28 03:28:43 +00:00
|
|
|
*/
|
2019-09-06 04:41:20 +00:00
|
|
|
public function __construct(ServerRepository $repository)
|
2018-02-28 03:28:43 +00:00
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->repository = $repository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return all of the servers available to the client making the API
|
|
|
|
* request, including servers the user has access to as a subuser.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Http\Requests\Api\Client\GetServersRequest $request
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function index(GetServersRequest $request): array
|
|
|
|
{
|
2019-08-03 19:44:15 +00:00
|
|
|
// Check for the filter parameter on the request.
|
|
|
|
switch ($request->input('filter')) {
|
|
|
|
case 'all':
|
|
|
|
$filter = User::FILTER_LEVEL_ALL;
|
|
|
|
break;
|
|
|
|
case 'admin':
|
|
|
|
$filter = User::FILTER_LEVEL_ADMIN;
|
|
|
|
break;
|
|
|
|
case 'owner':
|
|
|
|
$filter = User::FILTER_LEVEL_OWNER;
|
|
|
|
break;
|
|
|
|
case 'subuser-of':
|
|
|
|
default:
|
|
|
|
$filter = User::FILTER_LEVEL_SUBUSER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-08-17 23:03:10 +00:00
|
|
|
$servers = $this->repository
|
2018-05-28 20:23:40 +00:00
|
|
|
->setSearchTerm($request->input('query'))
|
2019-08-04 20:49:26 +00:00
|
|
|
->filterUserAccessServers(
|
|
|
|
$request->user(), $filter, config('pterodactyl.paginate.frontend.servers')
|
|
|
|
);
|
2018-02-28 03:28:43 +00:00
|
|
|
|
|
|
|
return $this->fractal->collection($servers)
|
|
|
|
->transformWith($this->getTransformer(ServerTransformer::class))
|
|
|
|
->toArray();
|
|
|
|
}
|
2019-11-04 01:37:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns all of the subuser permissions available on the system.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function permissions()
|
|
|
|
{
|
|
|
|
$permissions = Permission::permissions()->map(function ($values, $key) {
|
|
|
|
return Collection::make($values)->map(function ($permission) use ($key) {
|
|
|
|
return $key . '.' . $permission;
|
|
|
|
})->values()->toArray();
|
|
|
|
})->flatten();
|
|
|
|
|
|
|
|
return [
|
|
|
|
'object' => 'system_permissions',
|
|
|
|
'attributes' => [
|
|
|
|
'permissions' => $permissions,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
2018-02-25 21:30:56 +00:00
|
|
|
}
|