|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Pterodactyl\Http\Controllers\API\Remote; |
| 4 | + |
| 5 | +use Illuminate\Http\Request; |
| 6 | +use Illuminate\Http\JsonResponse; |
| 7 | +use Pterodactyl\Http\Controllers\Controller; |
| 8 | +use Pterodactyl\Services\Servers\EnvironmentService; |
| 9 | +use Pterodactyl\Contracts\Repository\ServerRepositoryInterface; |
| 10 | + |
| 11 | +class EggInstallController extends Controller |
| 12 | +{ |
| 13 | + /** |
| 14 | + * @var \Pterodactyl\Services\Servers\EnvironmentService |
| 15 | + */ |
| 16 | + private $environment; |
| 17 | + |
| 18 | + /** |
| 19 | + * @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface |
| 20 | + */ |
| 21 | + private $repository; |
| 22 | + |
| 23 | + /** |
| 24 | + * EggInstallController constructor. |
| 25 | + * |
| 26 | + * @param \Pterodactyl\Services\Servers\EnvironmentService $environment |
| 27 | + * @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository |
| 28 | + */ |
| 29 | + public function __construct(EnvironmentService $environment, ServerRepositoryInterface $repository) |
| 30 | + { |
| 31 | + $this->environment = $environment; |
| 32 | + $this->repository = $repository; |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * Handle request to get script and installation information for a server |
| 37 | + * that is being created on the node. |
| 38 | + * |
| 39 | + * @param \Illuminate\Http\Request $request |
| 40 | + * @param string $uuid |
| 41 | + * @return \Illuminate\Http\JsonResponse |
| 42 | + * |
| 43 | + * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException |
| 44 | + */ |
| 45 | + public function index(Request $request, string $uuid): JsonResponse |
| 46 | + { |
| 47 | + $node = $request->attributes->get('node'); |
| 48 | + |
| 49 | + /** @var \Pterodactyl\Models\Server $server */ |
| 50 | + $server = $this->repository->findFirstWhere([ |
| 51 | + ['uuid', '=', $uuid], |
| 52 | + ['node_id', '=', $node->id], |
| 53 | + ]); |
| 54 | + |
| 55 | + $this->repository->loadEggRelations($server); |
| 56 | + $egg = $server->getRelation('egg'); |
| 57 | + |
| 58 | + return response()->json([ |
| 59 | + 'scripts' => [ |
| 60 | + 'install' => ! $egg->copy_script_install ? null : str_replace(["\r\n", "\n", "\r"], "\n", $egg->copy_script_install), |
| 61 | + 'privileged' => $egg->script_is_privileged, |
| 62 | + ], |
| 63 | + 'config' => [ |
| 64 | + 'container' => $egg->copy_script_container, |
| 65 | + 'entry' => $egg->copy_script_entry, |
| 66 | + ], |
| 67 | + 'env' => $this->environment->handle($server), |
| 68 | + ]); |
| 69 | + } |
| 70 | +} |
0 commit comments