Add endpoints to return a server's egg configuration

This commit is contained in:
Dane Everitt 2019-09-22 15:30:53 -07:00
parent 5df46b23d2
commit 67ff67a1bd
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
10 changed files with 309 additions and 106 deletions

View file

@ -1,74 +0,0 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Http\Controllers\Api\Remote;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Services\Eggs\EggConfigurationService;
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
class EggRetrievalController extends Controller
{
/**
* @var \Pterodactyl\Services\Eggs\EggConfigurationService
*/
protected $configurationFileService;
/**
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
*/
protected $repository;
/**
* OptionUpdateController constructor.
*
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
* @param \Pterodactyl\Services\Eggs\EggConfigurationService $configurationFileService
*/
public function __construct(
EggRepositoryInterface $repository,
EggConfigurationService $configurationFileService
) {
$this->configurationFileService = $configurationFileService;
$this->repository = $repository;
}
/**
* Return a JSON array of Eggs and the SHA1 hash of their configuration file.
*
* @return \Illuminate\Http\JsonResponse
*/
public function index(): JsonResponse
{
$eggs = $this->repository->getAllWithCopyAttributes();
$response = [];
$eggs->each(function ($egg) use (&$response) {
$response[$egg->uuid] = sha1(json_encode($this->configurationFileService->handle($egg)));
});
return response()->json($response);
}
/**
* Return the configuration file for a single Egg for the Daemon.
*
* @param string $uuid
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function download(string $uuid): JsonResponse
{
$option = $this->repository->getWithCopyAttributes($uuid, 'uuid');
return response()->json($this->configurationFileService->handle($option));
}
}

View file

@ -0,0 +1,50 @@
<?php
namespace Pterodactyl\Http\Controllers\Api\Remote\Servers;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Services\Eggs\EggConfigurationService;
use Pterodactyl\Repositories\Eloquent\ServerRepository;
class ServerConfigurationController extends Controller
{
/**
* @var \Pterodactyl\Services\Eggs\EggConfigurationService
*/
private $eggConfigurationService;
/**
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository
*/
private $repository;
/**
* ServerConfigurationController constructor.
*
* @param \Pterodactyl\Repositories\Eloquent\ServerRepository $repository
* @param \Pterodactyl\Services\Eggs\EggConfigurationService $eggConfigurationService
*/
public function __construct(ServerRepository $repository, EggConfigurationService $eggConfigurationService)
{
$this->eggConfigurationService = $eggConfigurationService;
$this->repository = $repository;
}
/**
* @param \Illuminate\Http\Request $request
* @param $uuid
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function __invoke(Request $request, $uuid)
{
$server = $this->repository->getByUuid($uuid);
return JsonResponse::create(
$this->eggConfigurationService->handle($server)
);
}
}