misc_pterodactyl-panel/app/Http/Controllers/Api/Client/Servers/PowerController.php

48 lines
1.4 KiB
PHP
Raw Normal View History

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
*/
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);
$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();
}
}