2019-09-22 22:30:53 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Api\Remote\Servers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
2020-10-31 18:14:28 +00:00
|
|
|
use Pterodactyl\Models\Server;
|
2019-09-22 22:30:53 +00:00
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
2020-04-10 19:04:11 +00:00
|
|
|
use Pterodactyl\Repositories\Eloquent\NodeRepository;
|
2019-09-22 22:30:53 +00:00
|
|
|
use Pterodactyl\Services\Eggs\EggConfigurationService;
|
|
|
|
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
2020-10-31 18:14:28 +00:00
|
|
|
use Pterodactyl\Http\Resources\Wings\ServerConfigurationCollection;
|
2019-12-22 21:28:51 +00:00
|
|
|
use Pterodactyl\Services\Servers\ServerConfigurationStructureService;
|
2019-09-22 22:30:53 +00:00
|
|
|
|
2019-12-22 21:28:51 +00:00
|
|
|
class ServerDetailsController extends Controller
|
2019-09-22 22:30:53 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Eggs\EggConfigurationService
|
|
|
|
*/
|
|
|
|
private $eggConfigurationService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository
|
|
|
|
*/
|
|
|
|
private $repository;
|
|
|
|
|
2019-12-22 21:28:51 +00:00
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Servers\ServerConfigurationStructureService
|
|
|
|
*/
|
|
|
|
private $configurationStructureService;
|
|
|
|
|
2019-09-22 22:30:53 +00:00
|
|
|
/**
|
|
|
|
* ServerConfigurationController constructor.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Repositories\Eloquent\ServerRepository $repository
|
2019-12-22 21:28:51 +00:00
|
|
|
* @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $configurationStructureService
|
2019-09-22 22:30:53 +00:00
|
|
|
* @param \Pterodactyl\Services\Eggs\EggConfigurationService $eggConfigurationService
|
2020-04-10 19:04:11 +00:00
|
|
|
* @param \Pterodactyl\Repositories\Eloquent\NodeRepository $nodeRepository
|
2019-09-22 22:30:53 +00:00
|
|
|
*/
|
2019-12-22 21:28:51 +00:00
|
|
|
public function __construct(
|
|
|
|
ServerRepository $repository,
|
|
|
|
ServerConfigurationStructureService $configurationStructureService,
|
2020-04-10 19:04:11 +00:00
|
|
|
EggConfigurationService $eggConfigurationService,
|
|
|
|
NodeRepository $nodeRepository
|
2019-12-22 21:28:51 +00:00
|
|
|
) {
|
2019-09-22 22:30:53 +00:00
|
|
|
$this->eggConfigurationService = $eggConfigurationService;
|
|
|
|
$this->repository = $repository;
|
2019-12-22 21:28:51 +00:00
|
|
|
$this->configurationStructureService = $configurationStructureService;
|
2019-09-22 22:30:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-12-22 21:28:51 +00:00
|
|
|
* Returns details about the server that allows Wings to self-recover and ensure
|
|
|
|
* that the state of the server matches the Panel at all times.
|
|
|
|
*
|
2019-09-22 22:30:53 +00:00
|
|
|
* @param \Illuminate\Http\Request $request
|
2019-12-22 21:28:51 +00:00
|
|
|
* @param string $uuid
|
2019-09-22 22:30:53 +00:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
*/
|
|
|
|
public function __invoke(Request $request, $uuid)
|
|
|
|
{
|
|
|
|
$server = $this->repository->getByUuid($uuid);
|
|
|
|
|
2020-10-31 18:14:28 +00:00
|
|
|
return new JsonResponse([
|
2019-12-22 21:28:51 +00:00
|
|
|
'settings' => $this->configurationStructureService->handle($server),
|
|
|
|
'process_configuration' => $this->eggConfigurationService->handle($server),
|
|
|
|
]);
|
2019-09-22 22:30:53 +00:00
|
|
|
}
|
2020-04-10 19:04:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Lists all servers with their configurations that are assigned to the requesting node.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
2020-10-31 18:14:28 +00:00
|
|
|
* @return \Pterodactyl\Http\Resources\Wings\ServerConfigurationCollection
|
2020-04-10 19:04:11 +00:00
|
|
|
*/
|
|
|
|
public function list(Request $request)
|
|
|
|
{
|
2020-10-31 18:14:28 +00:00
|
|
|
/** @var \Pterodactyl\Models\Node $node */
|
2020-04-10 23:54:50 +00:00
|
|
|
$node = $request->attributes->get('node');
|
2020-04-10 19:04:11 +00:00
|
|
|
|
2020-10-31 18:14:28 +00:00
|
|
|
// Avoid run-away N+1 SQL queries by pre-loading the relationships that are used
|
|
|
|
// within each of the services called below.
|
2020-10-31 18:28:31 +00:00
|
|
|
$servers = Server::query()->with('allocations', 'egg', 'mounts', 'variables', 'location')
|
2020-10-31 18:14:28 +00:00
|
|
|
->where('node_id', $node->id)
|
2020-11-01 22:27:14 +00:00
|
|
|
// If you don't cast this to a string you'll end up with a stringified per_page returned in
|
|
|
|
// the metadata, and then Wings will panic crash as a result.
|
|
|
|
->paginate((int)$request->input('per_page', 50));
|
2020-04-10 19:04:11 +00:00
|
|
|
|
2020-10-31 18:14:28 +00:00
|
|
|
return new ServerConfigurationCollection($servers);
|
2020-04-10 19:04:11 +00:00
|
|
|
}
|
2019-09-22 22:30:53 +00:00
|
|
|
}
|