2018-02-27 22:09:34 -06:00
|
|
|
<?php
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2018-02-27 22:09:34 -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\SendsServerCommands;
|
|
|
|
|
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
2022-07-04 18:11:53 -04:00
|
|
|
use Pterodactyl\Facades\Activity;
|
2018-02-27 22:09:34 -06:00
|
|
|
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
|
|
|
|
use Pterodactyl\Http\Requests\Api\Client\Servers\SendCommandRequest;
|
2026-10-05 18:10:18 -04:00
|
|
|
use Pterodactyl\Models\Server;
|
|
|
|
|
use Pterodactyl\Support\JsonValueGuard;
|
2018-02-27 22:09:34 -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-27 22:09:34 -06:00
|
|
|
class CommandController extends ClientApiController
|
|
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
private const array OFFLINE_ERROR = [
|
|
|
|
|
'errors' => [
|
|
|
|
|
[
|
|
|
|
|
'code' => 'HttpException',
|
|
|
|
|
'status' => '502',
|
|
|
|
|
'detail' => 'Server must be online in order to send commands.',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
2018-02-27 22:09:34 -06:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Send a command to a running server.
|
|
|
|
|
*
|
2024-10-21 19:18:20 -06:00
|
|
|
* @throws DaemonConnectionException
|
2018-02-27 22:09:34 -06:00
|
|
|
*/
|
2026-10-05 18:10:18 -04:00
|
|
|
#[Endpoint('Send server command', 'Sends a console command to the running server through Wings.')]
|
|
|
|
|
#[ScribeResponse(status: 204, description: 'Command accepted by Wings.')]
|
|
|
|
|
#[ScribeResponse(self::OFFLINE_ERROR, status: 502, description: 'The server is not online or Wings rejected the command.')]
|
|
|
|
|
public function index(SendCommandRequest $request, SendsServerCommands $commands, Server $server): Response
|
2018-02-27 22:09:34 -06:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
$command = JsonValueGuard::string($request->validated('command'));
|
|
|
|
|
$commands->send($server, $command);
|
2018-02-27 22:09:34 -06:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
Activity::event('server:console.command')->property('command', $command)->log();
|
2022-07-04 18:11:53 -04:00
|
|
|
|
2018-02-27 22:09:34 -06:00
|
|
|
return $this->returnNoContent();
|
|
|
|
|
}
|
|
|
|
|
}
|