2017-10-06 04:09:43 +00:00
|
|
|
<?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
|
|
|
|
*/
|
|
|
|
|
2018-01-20 01:58:57 +00:00
|
|
|
namespace Pterodactyl\Http\Controllers\Api\Remote;
|
2017-10-06 04:09:43 +00:00
|
|
|
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
2017-10-07 22:21:41 +00:00
|
|
|
use Pterodactyl\Services\Eggs\EggConfigurationService;
|
2017-10-07 04:57:53 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
2017-10-06 04:09:43 +00:00
|
|
|
|
2017-10-07 22:21:41 +00:00
|
|
|
class EggRetrievalController extends Controller
|
2017-10-06 04:09:43 +00:00
|
|
|
{
|
|
|
|
/**
|
2017-10-07 22:21:41 +00:00
|
|
|
* @var \Pterodactyl\Services\Eggs\EggConfigurationService
|
2017-10-06 04:09:43 +00:00
|
|
|
*/
|
|
|
|
protected $configurationFileService;
|
|
|
|
|
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
|
2017-10-06 04:09:43 +00:00
|
|
|
*/
|
|
|
|
protected $repository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* OptionUpdateController constructor.
|
|
|
|
*
|
2017-10-07 22:21:41 +00:00
|
|
|
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
|
|
|
|
* @param \Pterodactyl\Services\Eggs\EggConfigurationService $configurationFileService
|
2017-10-06 04:09:43 +00:00
|
|
|
*/
|
|
|
|
public function __construct(
|
2017-10-07 04:57:53 +00:00
|
|
|
EggRepositoryInterface $repository,
|
2017-10-07 21:16:51 +00:00
|
|
|
EggConfigurationService $configurationFileService
|
2017-10-06 04:09:43 +00:00
|
|
|
) {
|
|
|
|
$this->configurationFileService = $configurationFileService;
|
|
|
|
$this->repository = $repository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-07 22:21:41 +00:00
|
|
|
* Return a JSON array of Eggs and the SHA1 hash of thier configuration file.
|
2017-10-06 04:09:43 +00:00
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
|
|
|
public function index(): JsonResponse
|
|
|
|
{
|
2017-10-09 02:36:22 +00:00
|
|
|
$eggs = $this->repository->getAllWithCopyAttributes();
|
2017-10-06 04:09:43 +00:00
|
|
|
|
|
|
|
$response = [];
|
2017-10-09 02:36:22 +00:00
|
|
|
$eggs->each(function ($egg) use (&$response) {
|
|
|
|
$response[$egg->uuid] = sha1(json_encode($this->configurationFileService->handle($egg)));
|
2017-10-06 04:09:43 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return response()->json($response);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-07 22:21:41 +00:00
|
|
|
* Return the configuration file for a single Egg for the Daemon.
|
2017-10-06 04:09:43 +00:00
|
|
|
*
|
|
|
|
* @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));
|
|
|
|
}
|
|
|
|
}
|