mirror of
https://github.com/pterodactyl/panel.git
synced 2026-12-01 11:55:51 -05:00
This expands upon previous work done to better disconnect users from SFTP when different events occur within Pterodactyl. This new logic also accounts for password changes and their account being deleted entirely from the system. These events now trigger background jobs that will reach out to every node they are associated with to ensure they're disconnected if currently connected.
55 lines
1.7 KiB
PHP
55 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Pterodactyl\Services\Servers;
|
|
|
|
use Illuminate\Support\Arr;
|
|
use Pterodactyl\Models\Server;
|
|
use Pterodactyl\Jobs\RevokeSftpAccessJob;
|
|
use Illuminate\Database\ConnectionInterface;
|
|
use Pterodactyl\Traits\Services\ReturnsUpdatedModels;
|
|
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
|
use Pterodactyl\Repositories\Wings\DaemonRevocationRepository;
|
|
|
|
class DetailsModificationService
|
|
{
|
|
use ReturnsUpdatedModels;
|
|
|
|
/**
|
|
* DetailsModificationService constructor.
|
|
*/
|
|
public function __construct(
|
|
private ConnectionInterface $connection,
|
|
private DaemonServerRepository $serverRepository,
|
|
private DaemonRevocationRepository $revocationRepository,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* Update the details for a single server instance.
|
|
*
|
|
* @throws \Throwable
|
|
*/
|
|
public function handle(Server $server, array $data): Server
|
|
{
|
|
return $this->connection->transaction(function () use ($data, $server) {
|
|
$original = $server->user;
|
|
|
|
$server->forceFill([
|
|
'external_id' => Arr::get($data, 'external_id'),
|
|
'owner_id' => Arr::get($data, 'owner_id'),
|
|
'name' => Arr::get($data, 'name'),
|
|
'description' => Arr::get($data, 'description') ?? '',
|
|
])->saveOrFail();
|
|
|
|
// If the owner_id value is changed we need to revoke any tokens that exist for the server
|
|
// on the Wings instance so that the old owner no longer has any permission to access the
|
|
// websockets.
|
|
if (! $server->refresh()->user->is($original)) {
|
|
RevokeSftpAccessJob::dispatch($original->uuid, $server);
|
|
}
|
|
|
|
return $server;
|
|
});
|
|
}
|
|
}
|