* Fix these * Update phpstan * Transform these into their identifiers instead * Fix custom rule * License is wrong * Update these * Pint fixes * Fix this * Consolidate these * Never supported PHP 7 * Better evaluation * Fixes * Don’t need ignore * Replace trait with service * Subusers are simply the many to many relationship between Servers and Users * Adjust to remove ignores * Use new query builder instead! * wip * Update composer * Quick fixes * Use realtime facade * Small fixes * Convert to static to avoid new * Update to statics * Don’t modify protected properties directly * Run pint * Change to correct method * Give up and use the facade * Make sure this route is available * Filament hasn’t been loaded yet * This can be readonly * Typehint * These are no longer used * Quick fixes * Need doc block help * Always true * We use caddy with docker * Pint * Fix phpstan issues * Remove unused import --------- Co-authored-by: MartinOscar <40749467+RMartinOscar@users.noreply.github.com>
		
			
				
	
	
		
			45 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			45 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace App\Http\Controllers\Api\Client\Servers;
 | 
						|
 | 
						|
use Illuminate\Http\Response;
 | 
						|
use App\Models\Server;
 | 
						|
use App\Facades\Activity;
 | 
						|
use GuzzleHttp\Exception\BadResponseException;
 | 
						|
use Symfony\Component\HttpKernel\Exception\HttpException;
 | 
						|
use App\Http\Controllers\Api\Client\ClientApiController;
 | 
						|
use App\Http\Requests\Api\Client\Servers\SendCommandRequest;
 | 
						|
use Exception;
 | 
						|
use Illuminate\Http\Client\ConnectionException;
 | 
						|
 | 
						|
class CommandController extends ClientApiController
 | 
						|
{
 | 
						|
    /**
 | 
						|
     * Send a command to a running server.
 | 
						|
     *
 | 
						|
     * @throws ConnectionException
 | 
						|
     */
 | 
						|
    public function index(SendCommandRequest $request, Server $server): Response
 | 
						|
    {
 | 
						|
        try {
 | 
						|
            $server->send($request->input('command'));
 | 
						|
        } catch (Exception $exception) {
 | 
						|
            $previous = $exception->getPrevious();
 | 
						|
 | 
						|
            if ($previous instanceof BadResponseException) {
 | 
						|
                if ($previous->getResponse()->getStatusCode() === Response::HTTP_BAD_GATEWAY) {
 | 
						|
                    throw new HttpException(Response::HTTP_BAD_GATEWAY, 'Server must be online in order to send commands.', $exception);
 | 
						|
                }
 | 
						|
            }
 | 
						|
 | 
						|
            throw $exception;
 | 
						|
        }
 | 
						|
 | 
						|
        Activity::event('server:console.command')
 | 
						|
            ->property('command', $request->input('command'))
 | 
						|
            ->log();
 | 
						|
 | 
						|
        return $this->returnNoContent();
 | 
						|
    }
 | 
						|
}
 |