Update server listing and associated logic to pull from the panel dynamiacally

This commit is contained in:
Dane Everitt 2019-08-17 16:03:10 -07:00
parent 952dff854e
commit fb9c106448
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
26 changed files with 384 additions and 239 deletions

View file

@ -5,6 +5,7 @@ namespace Pterodactyl\Http\Controllers\Api\Application;
use Illuminate\Http\Request;
use Webmozart\Assert\Assert;
use Illuminate\Http\Response;
use Illuminate\Support\Collection;
use Illuminate\Container\Container;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Extensions\Spatie\Fractalistic\Fractal;
@ -30,7 +31,10 @@ abstract class ApplicationApiController extends Controller
Container::getInstance()->call([$this, 'loadDependencies']);
// Parse all of the includes to use on this request.
$includes = collect(explode(',', $this->request->input('include', '')))->map(function ($value) {
$input = $this->request->input('include', []);
$input = is_array($input) ? $input : explode(',', $input);
$includes = (new Collection($input))->map(function ($value) {
return trim($value);
})->filter()->toArray();

View file

@ -52,7 +52,7 @@ class ClientController extends ClientApiController
break;
}
$servers = $this->repository->
$servers = $this->repository
->setSearchTerm($request->input('query'))
->filterUserAccessServers(
$request->user(), $filter, config('pterodactyl.paginate.frontend.servers')

View file

@ -3,21 +3,45 @@
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
use Pterodactyl\Models\Server;
use Pterodactyl\Repositories\Wings\WingsServerRepository;
use Pterodactyl\Transformers\Api\Client\StatsTransformer;
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
use Pterodactyl\Http\Requests\Api\Client\Servers\GetServerRequest;
class ResourceUtilizationController extends ClientApiController
{
/**
* @var \Pterodactyl\Repositories\Wings\WingsServerRepository
*/
private $repository;
/**
* ResourceUtilizationController constructor.
*
* @param \Pterodactyl\Repositories\Wings\WingsServerRepository $repository
*/
public function __construct(WingsServerRepository $repository)
{
parent::__construct();
$this->repository = $repository;
}
/**
* Return the current resource utilization for a server.
*
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\GetServerRequest $request
* @return array
*
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
*/
public function index(GetServerRequest $request): array
public function __invoke(GetServerRequest $request): array
{
return $this->fractal->item($request->getModel(Server::class))
$stats = $this->repository
->setServer($request->getModel(Server::class))
->getDetails();
return $this->fractal->item($stats)
->transformWith($this->getTransformer(StatsTransformer::class))
->toArray();
}

View file

@ -4,27 +4,11 @@ namespace Pterodactyl\Http\Controllers\Base;
use Illuminate\Http\Request;
use Pterodactyl\Models\User;
use Illuminate\Http\Response;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\RequestException;
use Pterodactyl\Http\Controllers\Controller;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Pterodactyl\Services\DaemonKeys\DaemonKeyProviderService;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface as DaemonServerRepositoryInterface;
class IndexController extends Controller
{
/**
* @var \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface
*/
protected $daemonRepository;
/**
* @var \Pterodactyl\Services\DaemonKeys\DaemonKeyProviderService
*/
protected $keyProviderService;
/**
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
*/
@ -33,17 +17,10 @@ class IndexController extends Controller
/**
* IndexController constructor.
*
* @param \Pterodactyl\Services\DaemonKeys\DaemonKeyProviderService $keyProviderService
* @param \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface $daemonRepository
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
*/
public function __construct(
DaemonKeyProviderService $keyProviderService,
DaemonServerRepositoryInterface $daemonRepository,
ServerRepositoryInterface $repository
) {
$this->daemonRepository = $daemonRepository;
$this->keyProviderService = $keyProviderService;
public function __construct(ServerRepositoryInterface $repository)
{
$this->repository = $repository;
}
@ -61,34 +38,4 @@ class IndexController extends Controller
return view('templates/base.core', ['servers' => $servers]);
}
/**
* Returns status of the server in a JSON response used for populating active status list.
*
* @param \Illuminate\Http\Request $request
* @param string $uuid
* @return \Illuminate\Http\JsonResponse
* @throws \Exception
*/
public function status(Request $request, $uuid)
{
$server = $this->repository->findFirstWhere([['uuidShort', '=', $uuid]]);
$token = $this->keyProviderService->handle($server, $request->user());
if (! $server->installed) {
return response()->json(['status' => 20]);
} elseif ($server->suspended) {
return response()->json(['status' => 30]);
}
try {
$response = $this->daemonRepository->setServer($server)->setToken($token)->details();
} catch (ConnectException $exception) {
throw new HttpException(Response::HTTP_GATEWAY_TIMEOUT, $exception->getMessage());
} catch (RequestException $exception) {
throw new HttpException(500, $exception->getMessage());
}
return response()->json(json_decode($response->getBody()));
}
}