Path: blob/1.0-develop/app/Http/Controllers/Api/Client/Servers/SettingsController.php
10280 views
<?php12namespace Pterodactyl\Http\Controllers\Api\Client\Servers;34use Illuminate\Http\Response;5use Pterodactyl\Models\Server;6use Illuminate\Http\JsonResponse;7use Pterodactyl\Facades\Activity;8use Pterodactyl\Repositories\Eloquent\ServerRepository;9use Pterodactyl\Services\Servers\ReinstallServerService;10use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;11use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;12use Pterodactyl\Http\Requests\Api\Client\Servers\Settings\RenameServerRequest;13use Pterodactyl\Http\Requests\Api\Client\Servers\Settings\SetDockerImageRequest;14use Pterodactyl\Http\Requests\Api\Client\Servers\Settings\ReinstallServerRequest;1516class SettingsController extends ClientApiController17{18/**19* SettingsController constructor.20*/21public function __construct(22private ServerRepository $repository,23private ReinstallServerService $reinstallServerService,24) {25parent::__construct();26}2728/**29* Renames a server.30*31* @throws \Pterodactyl\Exceptions\Model\DataValidationException32* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException33*/34public function rename(RenameServerRequest $request, Server $server): JsonResponse35{36$name = $request->input('name');37$description = $request->has('description') ? (string) $request->input('description') : $server->description;38$this->repository->update($server->id, [39'name' => $name,40'description' => $description,41]);4243if ($server->name !== $name) {44Activity::event('server:settings.rename')45->property(['old' => $server->name, 'new' => $name])46->log();47}4849if ($server->description !== $description) {50Activity::event('server:settings.description')51->property(['old' => $server->description, 'new' => $description])52->log();53}5455return new JsonResponse([], Response::HTTP_NO_CONTENT);56}5758/**59* Reinstalls the server on the daemon.60*61* @throws \Throwable62*/63public function reinstall(ReinstallServerRequest $request, Server $server): JsonResponse64{65$this->reinstallServerService->handle($server);6667Activity::event('server:reinstall')->log();6869return new JsonResponse([], Response::HTTP_ACCEPTED);70}7172/**73* Changes the Docker image in use by the server.74*75* @throws \Throwable76*/77public function dockerImage(SetDockerImageRequest $request, Server $server): JsonResponse78{79if (!in_array($server->image, array_values($server->egg->docker_images))) {80throw new BadRequestHttpException('This server\'s Docker image has been manually set by an administrator and cannot be updated.');81}8283$original = $server->image;84$server->forceFill(['image' => $request->input('docker_image')])->saveOrFail();8586if ($original !== $server->image) {87Activity::event('server:startup.image')88->property(['old' => $original, 'new' => $request->input('docker_image')])89->log();90}9192return new JsonResponse([], Response::HTTP_NO_CONTENT);93}94}959697