2019-12-10 06:03:10 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Response;
|
|
|
|
use Pterodactyl\Models\Server;
|
2020-04-03 21:43:24 +00:00
|
|
|
use Illuminate\Http\JsonResponse;
|
2022-05-29 23:26:28 +00:00
|
|
|
use Pterodactyl\Facades\Activity;
|
2019-12-10 06:03:10 +00:00
|
|
|
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
2020-04-03 21:43:24 +00:00
|
|
|
use Pterodactyl\Services\Servers\ReinstallServerService;
|
2019-12-10 06:03:10 +00:00
|
|
|
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
2020-12-13 19:07:29 +00:00
|
|
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
2019-12-10 06:03:10 +00:00
|
|
|
use Pterodactyl\Http\Requests\Api\Client\Servers\Settings\RenameServerRequest;
|
2020-12-13 19:07:29 +00:00
|
|
|
use Pterodactyl\Http\Requests\Api\Client\Servers\Settings\SetDockerImageRequest;
|
2020-04-03 21:43:24 +00:00
|
|
|
use Pterodactyl\Http\Requests\Api\Client\Servers\Settings\ReinstallServerRequest;
|
2019-12-10 06:03:10 +00:00
|
|
|
|
|
|
|
class SettingsController extends ClientApiController
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* SettingsController constructor.
|
|
|
|
*/
|
2020-04-03 21:43:24 +00:00
|
|
|
public function __construct(
|
2022-10-14 16:59:20 +00:00
|
|
|
private ServerRepository $repository,
|
|
|
|
private ReinstallServerService $reinstallServerService
|
2020-04-03 21:43:24 +00:00
|
|
|
) {
|
2019-12-10 06:03:10 +00:00
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renames a server.
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function rename(RenameServerRequest $request, Server $server): JsonResponse
|
2019-12-10 06:03:10 +00:00
|
|
|
{
|
|
|
|
$this->repository->update($server->id, [
|
|
|
|
'name' => $request->input('name'),
|
|
|
|
]);
|
|
|
|
|
2022-05-29 23:26:28 +00:00
|
|
|
if ($server->name !== $request->input('name')) {
|
|
|
|
Activity::event('server:settings.rename')
|
|
|
|
->property(['old' => $server->name, 'new' => $request->input('name')])
|
|
|
|
->log();
|
|
|
|
}
|
|
|
|
|
2020-06-28 17:40:41 +00:00
|
|
|
return new JsonResponse([], Response::HTTP_NO_CONTENT);
|
2020-04-03 21:43:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reinstalls the server on the daemon.
|
|
|
|
*
|
|
|
|
* @throws \Throwable
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function reinstall(ReinstallServerRequest $request, Server $server): JsonResponse
|
2020-04-03 21:43:24 +00:00
|
|
|
{
|
2020-10-06 04:54:29 +00:00
|
|
|
$this->reinstallServerService->handle($server);
|
2020-04-03 21:43:24 +00:00
|
|
|
|
2022-05-29 23:26:28 +00:00
|
|
|
Activity::event('server:reinstall')->log();
|
|
|
|
|
2020-06-28 17:40:41 +00:00
|
|
|
return new JsonResponse([], Response::HTTP_ACCEPTED);
|
2019-12-10 06:03:10 +00:00
|
|
|
}
|
2020-12-13 19:07:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes the Docker image in use by the server.
|
|
|
|
*
|
|
|
|
* @throws \Throwable
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function dockerImage(SetDockerImageRequest $request, Server $server): JsonResponse
|
2020-12-13 19:07:29 +00:00
|
|
|
{
|
2022-05-07 21:45:22 +00:00
|
|
|
if (!in_array($server->image, array_values($server->egg->docker_images))) {
|
2021-01-23 20:33:34 +00:00
|
|
|
throw new BadRequestHttpException('This server\'s Docker image has been manually set by an administrator and cannot be updated.');
|
2020-12-13 19:07:29 +00:00
|
|
|
}
|
|
|
|
|
2022-05-29 23:26:28 +00:00
|
|
|
$original = $server->image;
|
2020-12-13 19:07:29 +00:00
|
|
|
$server->forceFill(['image' => $request->input('docker_image')])->saveOrFail();
|
|
|
|
|
2022-05-29 23:26:28 +00:00
|
|
|
if ($original !== $server->image) {
|
|
|
|
Activity::event('server:startup.image')
|
|
|
|
->property(['old' => $original, 'new' => $request->input('docker_image')])
|
|
|
|
->log();
|
|
|
|
}
|
|
|
|
|
2020-12-13 19:07:29 +00:00
|
|
|
return new JsonResponse([], Response::HTTP_NO_CONTENT);
|
|
|
|
}
|
2019-12-10 06:03:10 +00:00
|
|
|
}
|