Path: blob/1.0-develop/app/Jobs/RevokeSftpAccessJob.php
14037 views
<?php12namespace Pterodactyl\Jobs;34use Pterodactyl\Models\Node;5use Pterodactyl\Models\Server;6use Illuminate\Foundation\Queue\Queueable;7use Illuminate\Contracts\Queue\ShouldQueue;8use Illuminate\Contracts\Queue\ShouldBeUnique;9use Illuminate\Queue\Attributes\WithoutRelations;10use Illuminate\Queue\Attributes\DeleteWhenMissingModels;11use Pterodactyl\Repositories\Wings\DaemonRevocationRepository;12use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;1314/**15* Revokes all SFTP access for a user on a given node or for a specific server.16*/17#[DeleteWhenMissingModels]18class RevokeSftpAccessJob implements ShouldQueue, ShouldBeUnique19{20use Queueable;2122public int $tries = 3;2324public int $maxExceptions = 1;2526public function __construct(27public readonly string $user,28#[WithoutRelations]29public readonly Server|Node $target,30) {31}3233public function uniqueId(): string34{35$target = $this->target instanceof Node ? "node:{$this->target->uuid}" : "server:{$this->target->uuid}";3637return "revoke-sftp:{$this->user}:{$target}";38}3940public function handle(DaemonRevocationRepository $repository): void41{42$node = $this->target instanceof Node ? $this->target : $this->target->node;4344try {45$repository->setNode($node)->deauthorize(46$this->user,47$this->target instanceof Server ? [$this->target->uuid] : []48);49} catch (DaemonConnectionException) {50// Keep retrying this job with a longer and longer backoff until we hit three51// attempts at which point we stop and will assume the node is fully offline52// and we are just wasting time.53$this->release($this->attempts() * 10);54}55}56}575859