2018-01-20 19:48:02 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Api\Application\Servers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Response;
|
|
|
|
use Pterodactyl\Models\Server;
|
|
|
|
use Pterodactyl\Services\Servers\SuspensionService;
|
|
|
|
use Pterodactyl\Services\Servers\ReinstallServerService;
|
|
|
|
use Pterodactyl\Services\Servers\ContainerRebuildService;
|
|
|
|
use Pterodactyl\Http\Requests\Api\Application\Servers\ServerWriteRequest;
|
|
|
|
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
|
|
|
|
|
|
|
|
class ServerManagementController extends ApplicationApiController
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Servers\ContainerRebuildService
|
|
|
|
*/
|
|
|
|
private $rebuildService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Servers\ReinstallServerService
|
|
|
|
*/
|
|
|
|
private $reinstallServerService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Servers\SuspensionService
|
|
|
|
*/
|
|
|
|
private $suspensionService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SuspensionController constructor.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Services\Servers\ContainerRebuildService $rebuildService
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param \Pterodactyl\Services\Servers\ReinstallServerService $reinstallServerService
|
|
|
|
* @param \Pterodactyl\Services\Servers\SuspensionService $suspensionService
|
2018-01-20 19:48:02 +00:00
|
|
|
*/
|
2018-01-27 18:38:56 +00:00
|
|
|
public function __construct(
|
|
|
|
ContainerRebuildService $rebuildService,
|
|
|
|
ReinstallServerService $reinstallServerService,
|
|
|
|
SuspensionService $suspensionService
|
|
|
|
) {
|
2018-01-20 19:48:02 +00:00
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->rebuildService = $rebuildService;
|
|
|
|
$this->reinstallServerService = $reinstallServerService;
|
|
|
|
$this->suspensionService = $suspensionService;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Suspend a server on the Panel.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\ServerWriteRequest $request
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
*/
|
2018-01-27 18:38:56 +00:00
|
|
|
public function suspend(ServerWriteRequest $request): Response
|
2018-01-20 19:48:02 +00:00
|
|
|
{
|
2018-01-27 18:38:56 +00:00
|
|
|
$this->suspensionService->toggle($request->getModel(Server::class), SuspensionService::ACTION_SUSPEND);
|
2018-01-20 19:48:02 +00:00
|
|
|
|
|
|
|
return $this->returnNoContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unsuspend a server on the Panel.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\ServerWriteRequest $request
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
*/
|
2018-01-27 18:38:56 +00:00
|
|
|
public function unsuspend(ServerWriteRequest $request): Response
|
2018-01-20 19:48:02 +00:00
|
|
|
{
|
2018-01-27 18:38:56 +00:00
|
|
|
$this->suspensionService->toggle($request->getModel(Server::class), SuspensionService::ACTION_UNSUSPEND);
|
2018-01-20 19:48:02 +00:00
|
|
|
|
|
|
|
return $this->returnNoContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mark a server as needing to be reinstalled.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\ServerWriteRequest $request
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
*/
|
2018-01-27 18:38:56 +00:00
|
|
|
public function reinstall(ServerWriteRequest $request): Response
|
2018-01-20 19:48:02 +00:00
|
|
|
{
|
2018-01-27 18:38:56 +00:00
|
|
|
$this->reinstallServerService->reinstall($request->getModel(Server::class));
|
2018-01-20 19:48:02 +00:00
|
|
|
|
|
|
|
return $this->returnNoContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mark a server as needing its container rebuilt the next time it is started.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\ServerWriteRequest $request
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
|
|
|
*/
|
2018-01-27 18:38:56 +00:00
|
|
|
public function rebuild(ServerWriteRequest $request): Response
|
2018-01-20 19:48:02 +00:00
|
|
|
{
|
2018-01-27 18:38:56 +00:00
|
|
|
$this->rebuildService->handle($request->getModel(Server::class));
|
2018-01-20 19:48:02 +00:00
|
|
|
|
|
|
|
return $this->returnNoContent();
|
|
|
|
}
|
|
|
|
}
|