Path: blob/1.0-develop/app/Http/Controllers/Api/Client/Servers/CommandController.php
10280 views
<?php12namespace Pterodactyl\Http\Controllers\Api\Client\Servers;34use Illuminate\Http\Response;5use Pterodactyl\Models\Server;6use Pterodactyl\Facades\Activity;7use GuzzleHttp\Exception\BadResponseException;8use Symfony\Component\HttpKernel\Exception\HttpException;9use Pterodactyl\Repositories\Wings\DaemonCommandRepository;10use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;11use Pterodactyl\Http\Requests\Api\Client\Servers\SendCommandRequest;12use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;1314class CommandController extends ClientApiController15{16/**17* CommandController constructor.18*/19public function __construct(private DaemonCommandRepository $repository)20{21parent::__construct();22}2324/**25* Send a command to a running server.26*27* @throws DaemonConnectionException28*/29public function index(SendCommandRequest $request, Server $server): Response30{31try {32$this->repository->setServer($server)->send($request->input('command'));33} catch (DaemonConnectionException $exception) {34$previous = $exception->getPrevious();3536if ($previous instanceof BadResponseException) {37if ($previous->getResponse()->getStatusCode() === Response::HTTP_BAD_GATEWAY) {38throw new HttpException(Response::HTTP_BAD_GATEWAY, 'Server must be online in order to send commands.', $exception);39}40}4142throw $exception;43}4445Activity::event('server:console.command')->property('command', $request->input('command'))->log();4647return $this->returnNoContent();48}49}505152