Files
pterodactyl-panel/app/Http/Middleware/Activity/ServerSubject.php
T

41 lines
1.2 KiB
PHP
Raw Normal View History

<?php
2026-10-05 18:10:18 -04:00
declare(strict_types=1);
2022-06-18 12:07:32 -04:00
namespace Pterodactyl\Http\Middleware\Activity;
2026-10-05 18:10:18 -04:00
use Closure;
use Illuminate\Http\Request;
use Pterodactyl\Facades\LogTarget;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Http\Concerns\ResolvesRequestContext;
use Pterodactyl\Models\Server;
use Symfony\Component\HttpFoundation\Response;
2022-06-18 12:07:32 -04:00
class ServerSubject
{
2026-10-05 18:10:18 -04:00
use ResolvesRequestContext;
/**
* Attempts to automatically scope all of the activity log events registered
* within the request instance to the given user and server. This only sets
* the actor and subject if there is a server present on the request.
*
* If no server is found this is a no-op as the activity log service can always
* set the user based on the authmanager response.
*/
2026-10-05 18:10:18 -04:00
/**
* @param Closure(Request):Response $next
* @return Response
*/
public function handle(Request $request, Closure $next): mixed
{
2026-10-05 18:10:18 -04:00
$server = $this->resolvedRoute($request)->parameter('server');
if ($server instanceof Server) {
2026-10-05 18:10:18 -04:00
LogTarget::setActor($this->authenticatedUser($request));
LogTarget::setSubject($server);
}
return $next($request);
}
}