Files
pterodactyl-panel/app/Http/Controllers/Api/Client/Servers/PowerController.php
T

38 lines
1.4 KiB
PHP
Raw Normal View History

2018-02-28 22:51:04 -06:00
<?php
2026-10-05 18:10:18 -04:00
declare(strict_types=1);
2018-02-28 22:51:04 -06:00
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
use Illuminate\Http\Response;
2026-10-05 18:10:18 -04:00
use Knuckles\Scribe\Attributes\Endpoint;
use Knuckles\Scribe\Attributes\Group;
use Knuckles\Scribe\Attributes\Response as ScribeResponse;
use Knuckles\Scribe\Attributes\Subgroup;
use Pterodactyl\Contracts\Servers\SendsServerPower;
use Pterodactyl\Facades\Activity;
2018-02-28 22:51:04 -06:00
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
use Pterodactyl\Http\Requests\Api\Client\Servers\SendPowerRequest;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Models\Server;
use Pterodactyl\Support\JsonValueGuard;
2018-02-28 22:51:04 -06:00
2026-10-05 18:10:18 -04:00
#[Group('Client API', 'Endpoints authenticated as a panel user using a client API token.')]
#[Subgroup('Server Overview', 'Inspect and control an accessible server.')]
2018-02-28 22:51:04 -06:00
class PowerController extends ClientApiController
{
/**
* Send a power action to a server.
*/
2026-10-05 18:10:18 -04:00
#[Endpoint('Send power action', 'Sends a power signal to the server through Wings.')]
#[ScribeResponse(status: 204, description: 'Power signal accepted by Wings.')]
public function index(SendPowerRequest $request, SendsServerPower $power, Server $server): Response
2018-02-28 22:51:04 -06:00
{
2026-10-05 18:10:18 -04:00
$signal = JsonValueGuard::string($request->validated('signal'));
$power->send($server, $signal);
2018-02-28 22:51:04 -06:00
2026-10-05 18:10:18 -04:00
Activity::event(mb_strtolower("server:power.{$signal}"))->log();
2018-02-28 22:51:04 -06:00
return $this->returnNoContent();
}
}