Path: blob/1.0-develop/app/Http/Controllers/Api/Remote/Servers/ServerInstallController.php
10284 views
<?php12namespace Pterodactyl\Http\Controllers\Api\Remote\Servers;34use Carbon\CarbonImmutable;5use Illuminate\Http\Request;6use Illuminate\Http\Response;7use Pterodactyl\Models\Server;8use Illuminate\Http\JsonResponse;9use Pterodactyl\Http\Controllers\Controller;10use Pterodactyl\Repositories\Eloquent\ServerRepository;11use Pterodactyl\Events\Server\Installed as ServerInstalled;12use Illuminate\Contracts\Events\Dispatcher as EventDispatcher;13use Pterodactyl\Http\Requests\Api\Remote\InstallationDataRequest;1415class ServerInstallController extends Controller16{17/**18* ServerInstallController constructor.19*/20public function __construct(private ServerRepository $repository, private EventDispatcher $eventDispatcher)21{22}2324/**25* Returns installation information for a server.26*27* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException28*/29public function index(Request $request, string $uuid): JsonResponse30{31$server = $this->repository->getByUuid($uuid);32$egg = $server->egg;3334return new JsonResponse([35'container_image' => $egg->copy_script_container,36'entrypoint' => $egg->copy_script_entry,37'script' => $egg->copy_script_install,38]);39}4041/**42* Updates the installation state of a server.43*44* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException45* @throws \Pterodactyl\Exceptions\Model\DataValidationException46*/47public function store(InstallationDataRequest $request, string $uuid): JsonResponse48{49$server = $this->repository->getByUuid($uuid);50$status = null;5152// Make sure the type of failure is accurate53if (!$request->boolean('successful')) {54$status = Server::STATUS_INSTALL_FAILED;5556if ($request->boolean('reinstall')) {57$status = Server::STATUS_REINSTALL_FAILED;58}59}6061// Keep the server suspended if it's already suspended62if ($server->status === Server::STATUS_SUSPENDED) {63$status = Server::STATUS_SUSPENDED;64}6566$this->repository->update($server->id, ['status' => $status, 'installed_at' => CarbonImmutable::now()], true, true);6768// If the server successfully installed, fire installed event.69// This logic allows individually disabling install and reinstall notifications separately.70$isInitialInstall = is_null($server->installed_at);71if ($isInitialInstall && config()->get('pterodactyl.email.send_install_notification', true)) {72$this->eventDispatcher->dispatch(new ServerInstalled($server));73} elseif (!$isInitialInstall && config()->get('pterodactyl.email.send_reinstall_notification', true)) {74$this->eventDispatcher->dispatch(new ServerInstalled($server));75}7677return new JsonResponse([], Response::HTTP_NO_CONTENT);78}79}808182