2018-03-01 04:51:04 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Response;
|
|
|
|
use Pterodactyl\Models\Server;
|
|
|
|
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
|
|
|
use Pterodactyl\Http\Requests\Api\Client\Servers\SendPowerRequest;
|
|
|
|
use Pterodactyl\Contracts\Repository\Daemon\PowerRepositoryInterface;
|
|
|
|
|
|
|
|
class PowerController extends ClientApiController
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\Daemon\PowerRepositoryInterface
|
|
|
|
*/
|
|
|
|
private $repository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PowerController constructor.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Contracts\Repository\Daemon\PowerRepositoryInterface $repository
|
|
|
|
*/
|
2018-11-10 23:27:50 +00:00
|
|
|
public function __construct(PowerRepositoryInterface $repository)
|
2018-03-01 04:51:04 +00:00
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->repository = $repository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a power action to a server.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\SendPowerRequest $request
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\Daemon\InvalidPowerSignalException
|
|
|
|
*/
|
|
|
|
public function index(SendPowerRequest $request): Response
|
|
|
|
{
|
|
|
|
$server = $request->getModel(Server::class);
|
2018-11-10 23:27:50 +00:00
|
|
|
$token = $request->attributes->get('server_token');
|
2018-03-01 04:51:04 +00:00
|
|
|
|
|
|
|
$this->repository->setServer($server)->setToken($token)->sendSignal($request->input('signal'));
|
|
|
|
|
|
|
|
return $this->returnNoContent();
|
|
|
|
}
|
|
|
|
}
|