diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php
index d28a399b9..03d479400 100644
--- a/app/Console/Kernel.php
+++ b/app/Console/Kernel.php
@@ -7,7 +7,6 @@ use App\Jobs\CleanupInstanceStuffsJob;
use App\Jobs\CleanupStaleMultiplexedConnections;
use App\Jobs\DatabaseBackupJob;
use App\Jobs\DockerCleanupJob;
-use App\Jobs\CleanupSshKeysJob;
use App\Jobs\PullHelperImageJob;
use App\Jobs\PullSentinelImageJob;
use App\Jobs\PullTemplatesFromCDN;
@@ -45,7 +44,7 @@ class Kernel extends ConsoleKernel
$schedule->command('telescope:prune')->daily();
- $schedule->job(new CleanupSshKeysJob)->weekly()->onOneServer();
+ $schedule->job(new PullHelperImageJob)->everyFiveMinutes()->onOneServer();
} else {
// Instance Jobs
$schedule->command('horizon:snapshot')->everyFiveMinutes();
@@ -62,8 +61,6 @@ class Kernel extends ConsoleKernel
$schedule->command('cleanup:database --yes')->daily();
$schedule->command('uploads:clear')->everyTwoMinutes();
-
- $schedule->job(new CleanupSshKeysJob)->weekly()->onOneServer();
}
}
@@ -82,11 +79,11 @@ class Kernel extends ConsoleKernel
}
})->cron($settings->update_check_frequency)->timezone($settings->instance_timezone)->onOneServer();
}
- $schedule->job(new PullHelperImageJob($server))
- ->cron($settings->update_check_frequency)
- ->timezone($settings->instance_timezone)
- ->onOneServer();
}
+ $schedule->job(new PullHelperImageJob)
+ ->cron($settings->update_check_frequency)
+ ->timezone($settings->instance_timezone)
+ ->onOneServer();
}
private function schedule_updates($schedule)
diff --git a/app/Helpers/SshMultiplexingHelper.php b/app/Helpers/SshMultiplexingHelper.php
index 57d4c88a4..71be77506 100644
--- a/app/Helpers/SshMultiplexingHelper.php
+++ b/app/Helpers/SshMultiplexingHelper.php
@@ -2,10 +2,10 @@
namespace App\Helpers;
-use App\Models\Server;
use App\Models\PrivateKey;
-use Illuminate\Support\Facades\Process;
+use App\Models\Server;
use Illuminate\Support\Facades\Hash;
+use Illuminate\Support\Facades\Process;
class SshMultiplexingHelper
{
@@ -13,7 +13,7 @@ class SshMultiplexingHelper
{
$privateKey = PrivateKey::findOrFail($server->private_key_id);
$sshKeyLocation = $privateKey->getKeyLocation();
- $muxFilename = '/var/www/html/storage/app/ssh/mux/mux_' . $server->uuid;
+ $muxFilename = '/var/www/html/storage/app/ssh/mux/mux_'.$server->uuid;
return [
'sshKeyLocation' => $sshKeyLocation,
@@ -23,7 +23,7 @@ class SshMultiplexingHelper
public static function ensureMultiplexedConnection(Server $server)
{
- if (!self::isMultiplexingEnabled()) {
+ if (! self::isMultiplexingEnabled()) {
// ray('SSH Multiplexing: DISABLED')->red();
return;
}
@@ -64,8 +64,8 @@ class SshMultiplexingHelper
$muxPersistTime = config('constants.ssh.mux_persist_time');
$establishCommand = "ssh -fNM -o ControlMaster=auto -o ControlPath=$muxSocket -o ControlPersist={$muxPersistTime} "
- . self::getCommonSshOptions($server, $sshKeyLocation, $connectionTimeout, $serverInterval)
- . "{$server->user}@{$server->ip}";
+ .self::getCommonSshOptions($server, $sshKeyLocation, $connectionTimeout, $serverInterval)
+ ."{$server->user}@{$server->ip}";
// ray('Establish Command:', $establishCommand);
@@ -77,13 +77,13 @@ class SshMultiplexingHelper
if ($establishProcess->exitCode() !== 0) {
// ray('Failed to establish multiplexed connection')->red();
- throw new \RuntimeException('Failed to establish multiplexed connection: ' . $establishProcess->errorOutput());
+ throw new \RuntimeException('Failed to establish multiplexed connection: '.$establishProcess->errorOutput());
}
// ray('Successfully established multiplexed connection')->green();
// Check if the mux socket file was created
- if (!file_exists($muxSocket)) {
+ if (! file_exists($muxSocket)) {
// ray('Mux socket file not found after connection establishment')->orange();
}
}
@@ -92,10 +92,10 @@ class SshMultiplexingHelper
{
$sshConfig = self::serverSshConfiguration($server);
$muxSocket = $sshConfig['muxFilename'];
-
+
$closeCommand = "ssh -O exit -o ControlPath=$muxSocket {$server->user}@{$server->ip}";
$process = Process::run($closeCommand);
-
+
// ray('Closing multiplexed connection')->blue();
// ray('Close command:', $closeCommand);
// ray('Close process exit code:', $process->exitCode());
@@ -127,7 +127,7 @@ class SshMultiplexingHelper
self::addCloudflareProxyCommand($scp_command, $server);
- $scp_command .= self::getCommonSshOptions($server, $sshKeyLocation, config('constants.ssh.connection_timeout'), config('constants.ssh.server_interval'));
+ $scp_command .= self::getCommonSshOptions($server, $sshKeyLocation, config('constants.ssh.connection_timeout'), config('constants.ssh.server_interval'), isScp: true);
$scp_command .= "{$source} {$server->user}@{$server->ip}:{$dest}";
return $scp_command;
@@ -170,7 +170,7 @@ class SshMultiplexingHelper
private static function isMultiplexingEnabled(): bool
{
- return config('constants.ssh.mux_enabled') && !config('coolify.is_windows_docker_desktop');
+ return config('constants.ssh.mux_enabled') && ! config('coolify.is_windows_docker_desktop');
}
private static function validateSshKey(string $sshKeyLocation): void
@@ -190,15 +190,23 @@ class SshMultiplexingHelper
}
}
- private static function getCommonSshOptions(Server $server, string $sshKeyLocation, int $connectionTimeout, int $serverInterval): string
+ private static function getCommonSshOptions(Server $server, string $sshKeyLocation, int $connectionTimeout, int $serverInterval, bool $isScp = false): string
{
- return "-i {$sshKeyLocation} "
+ $options = "-i {$sshKeyLocation} "
.'-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null '
.'-o PasswordAuthentication=no '
."-o ConnectTimeout=$connectionTimeout "
."-o ServerAliveInterval=$serverInterval "
.'-o RequestTTY=no '
- .'-o LogLevel=ERROR '
- ."-p {$server->port} ";
+ .'-o LogLevel=ERROR ';
+
+ // Bruh
+ if ($isScp) {
+ $options .= "-P {$server->port} ";
+ } else {
+ $options .= "-p {$server->port} ";
+ }
+
+ return $options;
}
-}
\ No newline at end of file
+}
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php
index 5ee0ef189..96313d285 100644
--- a/app/Jobs/ApplicationDeploymentJob.php
+++ b/app/Jobs/ApplicationDeploymentJob.php
@@ -969,7 +969,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
}
}
if ($this->application->environment_variables->where('key', 'COOLIFY_URL')->isEmpty()) {
- $url = str($this->application->fqdn)->replace('http://', '').replace('https://', '');
+ $url = str($this->application->fqdn)->replace('http://', '')->replace('https://', '');
if ($this->application->compose_parsing_version === '3') {
$envs->push("COOLIFY_FQDN={$url}");
} else {
@@ -1442,7 +1442,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
if ($this->pull_request_id !== 0) {
$local_branch = "pull/{$this->pull_request_id}/head";
}
- $private_key = $this->application->privateKey->getKeyLocation();
+ $private_key = $this->application->privateKey?->getKeyLocation();
if ($private_key) {
$this->execute_remote_command(
[
diff --git a/app/Jobs/PullHelperImageJob.php b/app/Jobs/PullHelperImageJob.php
index 63b7fa920..ef1659680 100644
--- a/app/Jobs/PullHelperImageJob.php
+++ b/app/Jobs/PullHelperImageJob.php
@@ -9,7 +9,6 @@ use Illuminate\Contracts\Queue\ShouldBeEncrypted;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
-use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Http;
@@ -19,17 +18,7 @@ class PullHelperImageJob implements ShouldBeEncrypted, ShouldQueue
public $timeout = 1000;
- public function middleware(): array
- {
- return [(new WithoutOverlapping($this->server->uuid))];
- }
-
- public function uniqueId(): string
- {
- return $this->server->uuid;
- }
-
- public function __construct(public Server $server) {}
+ public function __construct() {}
public function handle(): void
{
diff --git a/app/Livewire/Project/Shared/Terminal.php b/app/Livewire/Project/Shared/Terminal.php
index 802e65a30..5fd098e9f 100644
--- a/app/Livewire/Project/Shared/Terminal.php
+++ b/app/Livewire/Project/Shared/Terminal.php
@@ -2,6 +2,7 @@
namespace App\Livewire\Project\Shared;
+use App\Helpers\SshMultiplexingHelper;
use App\Models\Server;
use Livewire\Attributes\On;
use Livewire\Component;
@@ -19,9 +20,9 @@ class Terminal extends Component
if ($status !== 'running') {
return;
}
- $command = generateSshCommand($server, "docker exec -it {$identifier} sh -c 'if [ -f ~/.profile ]; then . ~/.profile; fi; if [ -n \"\$SHELL\" ]; then exec \$SHELL; else sh; fi'");
+ $command = SshMultiplexingHelper::generateSshCommand($server, "docker exec -it {$identifier} sh -c 'if [ -f ~/.profile ]; then . ~/.profile; fi; if [ -n \"\$SHELL\" ]; then exec \$SHELL; else sh; fi'");
} else {
- $command = generateSshCommand($server, "sh -c 'if [ -f ~/.profile ]; then . ~/.profile; fi; if [ -n \"\$SHELL\" ]; then exec \$SHELL; else sh; fi'");
+ $command = SshMultiplexingHelper::generateSshCommand($server, "sh -c 'if [ -f ~/.profile ]; then . ~/.profile; fi; if [ -n \"\$SHELL\" ]; then exec \$SHELL; else sh; fi'");
}
// ssh command is sent back to frontend then to websocket
diff --git a/app/Livewire/Security/PrivateKey/Show.php b/app/Livewire/Security/PrivateKey/Show.php
index 14d2ed767..249c84f14 100644
--- a/app/Livewire/Security/PrivateKey/Show.php
+++ b/app/Livewire/Security/PrivateKey/Show.php
@@ -29,7 +29,7 @@ class Show extends Component
try {
$this->private_key = PrivateKey::ownedByCurrentTeam(['name', 'description', 'private_key', 'is_git_related'])->whereUuid(request()->private_key_uuid)->firstOrFail();
} catch (\Throwable $e) {
- return handleError($e, $this);
+ abort(404);
}
}
@@ -46,6 +46,7 @@ class Show extends Component
try {
$this->private_key->safeDelete();
currentTeam()->privateKeys = PrivateKey::where('team_id', currentTeam()->id)->get();
+
return redirect()->route('security.private-key.index');
} catch (\Exception $e) {
$this->dispatch('error', $e->getMessage());
@@ -58,7 +59,7 @@ class Show extends Component
{
try {
$this->private_key->updatePrivateKey([
- 'private_key' => formatPrivateKey($this->private_key->private_key)
+ 'private_key' => formatPrivateKey($this->private_key->private_key),
]);
refresh_server_connection($this->private_key);
$this->dispatch('success', 'Private key updated.');
diff --git a/app/Livewire/Server/Proxy.php b/app/Livewire/Server/Proxy.php
index 123b29d70..55d0c4966 100644
--- a/app/Livewire/Server/Proxy.php
+++ b/app/Livewire/Server/Proxy.php
@@ -39,6 +39,7 @@ class Proxy extends Component
{
$this->server->proxy = null;
$this->server->save();
+ $this->dispatch('proxyChanged');
}
public function selectProxy($proxy_type)
@@ -47,7 +48,7 @@ class Proxy extends Component
$this->server->proxy->set('type', $proxy_type);
$this->server->save();
$this->selectedProxy = $this->server->proxy->type;
- if ($this->selectedProxy !== 'NONE') {
+ if ($this->server->proxySet()) {
StartProxy::run($this->server, false);
}
$this->dispatch('proxyStatusUpdated');
diff --git a/app/Livewire/Server/Proxy/Deploy.php b/app/Livewire/Server/Proxy/Deploy.php
index f7318c8f4..c66ed1795 100644
--- a/app/Livewire/Server/Proxy/Deploy.php
+++ b/app/Livewire/Server/Proxy/Deploy.php
@@ -31,6 +31,7 @@ class Deploy extends Component
'serverRefresh' => 'proxyStatusUpdated',
'checkProxy',
'startProxy',
+ 'proxyChanged' => 'proxyStatusUpdated',
];
}
diff --git a/app/Livewire/Server/Proxy/Show.php b/app/Livewire/Server/Proxy/Show.php
index cef909a45..d70e44e55 100644
--- a/app/Livewire/Server/Proxy/Show.php
+++ b/app/Livewire/Server/Proxy/Show.php
@@ -11,7 +11,7 @@ class Show extends Component
public $parameters = [];
- protected $listeners = ['proxyStatusUpdated'];
+ protected $listeners = ['proxyStatusUpdated', 'proxyChanged' => 'proxyStatusUpdated'];
public function proxyStatusUpdated()
{
diff --git a/app/Livewire/Server/ShowPrivateKey.php b/app/Livewire/Server/ShowPrivateKey.php
index 8e9b59157..92869c44b 100644
--- a/app/Livewire/Server/ShowPrivateKey.php
+++ b/app/Livewire/Server/ShowPrivateKey.php
@@ -2,9 +2,9 @@
namespace App\Livewire\Server;
+use App\Models\PrivateKey;
use App\Models\Server;
use Livewire\Component;
-use App\Models\PrivateKey;
class ShowPrivateKey extends Component
{
@@ -22,7 +22,7 @@ class ShowPrivateKey extends Component
$this->server->refresh();
$this->dispatch('success', 'Private key updated successfully.');
} catch (\Exception $e) {
- $this->dispatch('error', 'Failed to update private key: ' . $e->getMessage());
+ $this->dispatch('error', 'Failed to update private key: '.$e->getMessage());
}
}
@@ -34,7 +34,7 @@ class ShowPrivateKey extends Component
$this->dispatch('success', 'Server is reachable.');
} else {
ray($error);
- $this->dispatch('error', 'Server is not reachable.
Please validate your configuration and connection.
Check this documentation for further help.');
+ $this->dispatch('error', 'Server is not reachable.
Check this documentation for further help.
Error: '.$error);
return;
}
diff --git a/app/Models/Server.php b/app/Models/Server.php
index 1d12c0931..61c670dcc 100644
--- a/app/Models/Server.php
+++ b/app/Models/Server.php
@@ -5,7 +5,6 @@ namespace App\Models;
use App\Actions\Server\InstallDocker;
use App\Enums\ProxyTypes;
use App\Jobs\PullSentinelImageJob;
-use App\Notifications\Server\Revived;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Support\Collection;
@@ -156,11 +155,17 @@ class Server extends BaseModel
return $this->hasOne(ServerSetting::class);
}
+ public function proxySet()
+ {
+ return $this->proxyType() && $this->proxyType() !== 'NONE' && $this->isFunctional() && ! $this->isSwarmWorker() && ! $this->settings->is_build_server;
+ }
+
public function setupDefault404Redirect()
{
$dynamic_conf_path = $this->proxyPath().'/dynamic';
$proxy_type = $this->proxyType();
$redirect_url = $this->proxy->redirect_url;
+ ray($proxy_type);
if ($proxy_type === ProxyTypes::TRAEFIK->value) {
$default_redirect_file = "$dynamic_conf_path/default_redirect_404.yaml";
} elseif ($proxy_type === 'CADDY') {
@@ -950,12 +955,12 @@ $schema://$host {
public function isFunctional()
{
- $isFunctional = $this->settings->is_reachable && $this->settings->is_usable && !$this->settings->force_disabled;
-
- if (!$isFunctional) {
+ $isFunctional = $this->settings->is_reachable && $this->settings->is_usable && ! $this->settings->force_disabled;
+
+ if (! $isFunctional) {
Storage::disk('ssh-mux')->delete($this->muxFilename());
}
-
+
return $isFunctional;
}
@@ -1007,7 +1012,7 @@ $schema://$host {
public function validateConnection($isManualCheck = true)
{
- config()->set('constants.ssh.mux_enabled', !$isManualCheck);
+ config()->set('constants.ssh.mux_enabled', ! $isManualCheck);
// ray('Manual Check: ' . ($isManualCheck ? 'true' : 'false'));
$server = Server::find($this->id);
@@ -1160,16 +1165,18 @@ $schema://$host {
$server = new self($data);
$server->privateKey()->associate($privateKey);
$server->save();
+
return $server;
}
- public function updateWithPrivateKey(array $data, PrivateKey $privateKey = null)
+ public function updateWithPrivateKey(array $data, ?PrivateKey $privateKey = null)
{
$this->update($data);
if ($privateKey) {
$this->privateKey()->associate($privateKey);
$this->save();
}
+
return $this;
}
}
diff --git a/bootstrap/helpers/remoteProcess.php b/bootstrap/helpers/remoteProcess.php
index ebc8420c6..67b60d6b7 100644
--- a/bootstrap/helpers/remoteProcess.php
+++ b/bootstrap/helpers/remoteProcess.php
@@ -11,8 +11,8 @@ use App\Models\Server;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
-use Illuminate\Support\Facades\Process;
use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Facades\Process;
use Illuminate\Support\Str;
use Spatie\Activitylog\Contracts\Activity;
@@ -28,16 +28,16 @@ function remote_process(
): Activity {
$type = $type ?? ActivityTypes::INLINE->value;
$command = $command instanceof Collection ? $command->toArray() : $command;
-
+
if ($server->isNonRoot()) {
$command = parseCommandsByLineForSudo(collect($command), $server);
}
-
+
$command_string = implode("\n", $command);
-
+
if (Auth::check()) {
$teams = Auth::user()->teams->pluck('id');
- if (!$teams->contains($server->team_id) && !$teams->contains(0)) {
+ if (! $teams->contains($server->team_id) && ! $teams->contains(0)) {
throw new \Exception('User is not part of the team that owns this server');
}
}
@@ -67,13 +67,14 @@ function instant_scp(string $source, string $dest, Server $server, $throwError =
if ($exitCode !== 0) {
return $throwError ? excludeCertainErrors($process->errorOutput(), $exitCode) : null;
}
+
return $output === 'null' ? null : $output;
}
function instant_remote_process(Collection|array $command, Server $server, bool $throwError = true, bool $no_sudo = false): ?string
{
$command = $command instanceof Collection ? $command->toArray() : $command;
- if ($server->isNonRoot() && !$no_sudo) {
+ if ($server->isNonRoot() && ! $no_sudo) {
$command = parseCommandsByLineForSudo(collect($command), $server);
}
$command_string = implode("\n", $command);
@@ -92,6 +93,7 @@ function instant_remote_process(Collection|array $command, Server $server, bool
if ($exitCode !== 0) {
return $throwError ? excludeCertainErrors($process->errorOutput(), $exitCode) : null;
}
+
return $output === 'null' ? null : $output;
}
@@ -101,7 +103,7 @@ function excludeCertainErrors(string $errorOutput, ?int $exitCode = null)
'Permission denied (publickey',
'Could not resolve hostname',
]);
- $ignored = $ignoredErrors->contains(fn($error) => Str::contains($errorOutput, $error));
+ $ignored = $ignoredErrors->contains(fn ($error) => Str::contains($errorOutput, $error));
if ($ignored) {
// TODO: Create new exception and disable in sentry
throw new \RuntimeException($errorOutput, $exitCode);
@@ -127,19 +129,21 @@ function decode_remote_command_output(?ApplicationDeploymentQueue $application_d
}
$seenCommands = collect();
$formatted = collect($decoded);
- if (!$is_debug_enabled) {
+ if (! $is_debug_enabled) {
$formatted = $formatted->filter(fn ($i) => $i['hidden'] === false ?? false);
}
+
return $formatted
->sortBy(fn ($i) => data_get($i, 'order'))
->map(function ($i) {
data_set($i, 'timestamp', Carbon::parse(data_get($i, 'timestamp'))->format('Y-M-d H:i:s.u'));
+
return $i;
})
->reduce(function ($deploymentLogLines, $logItem) use ($seenCommands) {
$command = data_get($logItem, 'command');
$isStderr = data_get($logItem, 'type') === 'stderr';
- $isNewCommand = !is_null($command) && !$seenCommands->first(function ($seenCommand) use ($logItem) {
+ $isNewCommand = ! is_null($command) && ! $seenCommands->first(function ($seenCommand) use ($logItem) {
return data_get($seenCommand, 'command') === data_get($logItem, 'command') && data_get($seenCommand, 'batch') === data_get($logItem, 'batch');
});
@@ -176,6 +180,7 @@ function decode_remote_command_output(?ApplicationDeploymentQueue $application_d
function remove_iip($text)
{
$text = preg_replace('/x-access-token:.*?(?=@)/', 'x-access-token:'.REDACTED, $text);
+
return preg_replace('/\x1b\[[0-9;]*m/', '', $text);
}
@@ -203,7 +208,7 @@ function checkRequiredCommands(Server $server)
break;
}
$commandFound = instant_remote_process(["docker run --rm --privileged --net=host --pid=host --ipc=host --volume /:/host busybox chroot /host bash -c 'command -v {$command}'"], $server, false);
- if (!$commandFound) {
+ if (! $commandFound) {
break;
}
}
diff --git a/resources/views/components/server/navbar.blade.php b/resources/views/components/server/navbar.blade.php
index c24787e97..a73f6865e 100644
--- a/resources/views/components/server/navbar.blade.php
+++ b/resources/views/components/server/navbar.blade.php
@@ -2,7 +2,9 @@