Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Jobs/RevokeSftpAccessJob.php
14037 views
1
<?php
2
3
namespace Pterodactyl\Jobs;
4
5
use Pterodactyl\Models\Node;
6
use Pterodactyl\Models\Server;
7
use Illuminate\Foundation\Queue\Queueable;
8
use Illuminate\Contracts\Queue\ShouldQueue;
9
use Illuminate\Contracts\Queue\ShouldBeUnique;
10
use Illuminate\Queue\Attributes\WithoutRelations;
11
use Illuminate\Queue\Attributes\DeleteWhenMissingModels;
12
use Pterodactyl\Repositories\Wings\DaemonRevocationRepository;
13
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
14
15
/**
16
* Revokes all SFTP access for a user on a given node or for a specific server.
17
*/
18
#[DeleteWhenMissingModels]
19
class RevokeSftpAccessJob implements ShouldQueue, ShouldBeUnique
20
{
21
use Queueable;
22
23
public int $tries = 3;
24
25
public int $maxExceptions = 1;
26
27
public function __construct(
28
public readonly string $user,
29
#[WithoutRelations]
30
public readonly Server|Node $target,
31
) {
32
}
33
34
public function uniqueId(): string
35
{
36
$target = $this->target instanceof Node ? "node:{$this->target->uuid}" : "server:{$this->target->uuid}";
37
38
return "revoke-sftp:{$this->user}:{$target}";
39
}
40
41
public function handle(DaemonRevocationRepository $repository): void
42
{
43
$node = $this->target instanceof Node ? $this->target : $this->target->node;
44
45
try {
46
$repository->setNode($node)->deauthorize(
47
$this->user,
48
$this->target instanceof Server ? [$this->target->uuid] : []
49
);
50
} catch (DaemonConnectionException) {
51
// Keep retrying this job with a longer and longer backoff until we hit three
52
// attempts at which point we stop and will assume the node is fully offline
53
// and we are just wasting time.
54
$this->release($this->attempts() * 10);
55
}
56
}
57
}
58
59