mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-06 13:10:37 -04:00
- Rate limit the import check probe and refuse private, loopback, and link-local targets on Cloud. - Rate limit the SSH validation that an import starts, like other server validations. - Count only managed servers for the server limit, the limit check job, and the subscription page. Archives of transferred servers are left out. - Do not show the name of another team's archived server in the import check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
1.9 KiB
PHP
59 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Models\Team;
|
|
use App\Notifications\Server\ForceDisabled;
|
|
use App\Notifications\Server\ForceEnabled;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class ServerLimitCheckJob implements ShouldBeEncrypted, ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
public $tries = 4;
|
|
|
|
public function backoff(): int
|
|
{
|
|
return isDev() ? 1 : 3;
|
|
}
|
|
|
|
public function __construct(public Team $team)
|
|
{
|
|
$this->onQueue(webhooks_queue());
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
try {
|
|
$servers = $this->team->managedServers;
|
|
$servers_count = $servers->count();
|
|
$number_of_servers_to_disable = $servers_count - $this->team->limits;
|
|
if ($number_of_servers_to_disable > 0) {
|
|
$servers = $servers->sortbyDesc('created_at');
|
|
$servers_to_disable = $servers->take($number_of_servers_to_disable);
|
|
$servers_to_disable->each(function ($server) {
|
|
$server->forceDisableServer();
|
|
$this->team->notify(new ForceDisabled($server));
|
|
});
|
|
} elseif ($number_of_servers_to_disable <= 0) {
|
|
$servers->each(function ($server) {
|
|
if ($server->isForceDisabled()) {
|
|
$server->forceEnableServer();
|
|
$this->team->notify(new ForceEnabled($server));
|
|
}
|
|
});
|
|
}
|
|
} catch (\Throwable $e) {
|
|
send_internal_notification('ServerLimitCheckJob failed with: '.$e->getMessage());
|
|
|
|
return handleError($e);
|
|
}
|
|
}
|
|
}
|