From a18c2e0f55d8ca36b35f8f3e688f4202fde69728 Mon Sep 17 00:00:00 2001
From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com>
Date: Mon, 23 Dec 2024 15:25:07 +0100
Subject: [PATCH 01/11] feat: migrate to new encryption options
---
..._142402_update_email_encryption_values.php | 130 ++++++++++++++++++
1 file changed, 130 insertions(+)
create mode 100644 database/migrations/2024_12_23_142402_update_email_encryption_values.php
diff --git a/database/migrations/2024_12_23_142402_update_email_encryption_values.php b/database/migrations/2024_12_23_142402_update_email_encryption_values.php
new file mode 100644
index 000000000..c21c910d1
--- /dev/null
+++ b/database/migrations/2024_12_23_142402_update_email_encryption_values.php
@@ -0,0 +1,130 @@
+ 'starttls',
+ 'ssl' => 'tls',
+ '' => 'none',
+ ];
+
+ /**
+ * Run the migrations.
+ */
+ public function up(): void
+ {
+ try {
+ DB::beginTransaction();
+
+ $instanceSettings = DB::table('instance_settings')->get();
+ foreach ($instanceSettings as $setting) {
+ try {
+ if (array_key_exists($setting->smtp_encryption, $this->encryptionMappings)) {
+ DB::table('instance_settings')
+ ->where('id', $setting->id)
+ ->update([
+ 'smtp_encryption' => $this->encryptionMappings[$setting->smtp_encryption],
+ ]);
+ }
+ } catch (\Exception $e) {
+ \Log::error('Failed to update instance_settings encryption for ID: '.$setting->id, [
+ 'error' => $e->getMessage(),
+ 'old_value' => $setting->smtp_encryption,
+ ]);
+ }
+ }
+
+ $emailSettings = DB::table('email_notification_settings')->get();
+ foreach ($emailSettings as $setting) {
+ try {
+ if (array_key_exists($setting->smtp_encryption, $this->encryptionMappings)) {
+ DB::table('email_notification_settings')
+ ->where('id', $setting->id)
+ ->update([
+ 'smtp_encryption' => $this->encryptionMappings[$setting->smtp_encryption],
+ ]);
+ }
+ } catch (\Exception $e) {
+ \Log::error('Failed to update email_notification_settings encryption for ID: '.$setting->id, [
+ 'error' => $e->getMessage(),
+ 'old_value' => $setting->smtp_encryption,
+ ]);
+ }
+ }
+
+ DB::commit();
+ } catch (\Exception $e) {
+ DB::rollBack();
+ \Log::error('Failed to complete email encryption migration', [
+ 'error' => $e->getMessage(),
+ ]);
+ throw $e;
+ }
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ try {
+ DB::beginTransaction();
+
+ $reverseMapping = [
+ 'starttls' => 'tls',
+ 'tls' => 'ssl',
+ 'none' => '',
+ ];
+
+ $instanceSettings = DB::table('instance_settings')->get();
+ foreach ($instanceSettings as $setting) {
+ try {
+ if (array_key_exists($setting->smtp_encryption, $reverseMapping)) {
+ DB::table('instance_settings')
+ ->where('id', $setting->id)
+ ->update([
+ 'smtp_encryption' => $reverseMapping[$setting->smtp_encryption],
+ ]);
+ }
+ } catch (\Exception $e) {
+ \Log::error('Failed to reverse instance_settings encryption for ID: '.$setting->id, [
+ 'error' => $e->getMessage(),
+ 'old_value' => $setting->smtp_encryption,
+ ]);
+ }
+ }
+
+ $emailSettings = DB::table('email_notification_settings')->get();
+ foreach ($emailSettings as $setting) {
+ try {
+ if (array_key_exists($setting->smtp_encryption, $reverseMapping)) {
+ DB::table('email_notification_settings')
+ ->where('id', $setting->id)
+ ->update([
+ 'smtp_encryption' => $reverseMapping[$setting->smtp_encryption],
+ ]);
+ }
+ } catch (\Exception $e) {
+ \Log::error('Failed to reverse email_notification_settings encryption for ID: '.$setting->id, [
+ 'error' => $e->getMessage(),
+ 'old_value' => $setting->smtp_encryption,
+ ]);
+ }
+ }
+
+ DB::commit();
+ } catch (\Exception $e) {
+ DB::rollBack();
+ \Log::error('Failed to complete email encryption rollback migration', [
+ 'error' => $e->getMessage(),
+ ]);
+ throw $e;
+ }
+ }
+}
From f2cb040ba9c7308d4446a1198eeedd28af5f3d05 Mon Sep 17 00:00:00 2001
From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com>
Date: Mon, 23 Dec 2024 15:26:26 +0100
Subject: [PATCH 02/11] feat: new encryption options
---
app/Livewire/Notifications/Email.php | 6 +++---
app/Livewire/SettingsEmail.php | 6 +++---
resources/views/livewire/notifications/email.blade.php | 6 +++---
resources/views/livewire/settings-email.blade.php | 6 +++---
4 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/app/Livewire/Notifications/Email.php b/app/Livewire/Notifications/Email.php
index eac48cf77..3ed20f907 100644
--- a/app/Livewire/Notifications/Email.php
+++ b/app/Livewire/Notifications/Email.php
@@ -41,8 +41,8 @@ class Email extends Component
#[Validate(['nullable', 'numeric', 'min:1', 'max:65535'])]
public ?int $smtpPort = null;
- #[Validate(['nullable', 'string', 'in:tls,ssl,none'])]
- public ?string $smtpEncryption = 'tls';
+ #[Validate(['nullable', 'string', 'in:starttls,tls,none'])]
+ public ?string $smtpEncryption = null;
#[Validate(['nullable', 'string'])]
public ?string $smtpUsername = null;
@@ -235,7 +235,7 @@ class Email extends Component
'smtpFromName' => 'required|string',
'smtpHost' => 'required|string',
'smtpPort' => 'required|numeric',
- 'smtpEncryption' => 'required|string|in:tls,ssl,none',
+ 'smtpEncryption' => 'required|string|in:starttls,tls,none',
'smtpUsername' => 'nullable|string',
'smtpPassword' => 'nullable|string',
'smtpTimeout' => 'nullable|numeric',
diff --git a/app/Livewire/SettingsEmail.php b/app/Livewire/SettingsEmail.php
index 1c5edb108..058f080e4 100644
--- a/app/Livewire/SettingsEmail.php
+++ b/app/Livewire/SettingsEmail.php
@@ -35,8 +35,8 @@ class SettingsEmail extends Component
#[Validate(['nullable', 'numeric', 'min:1', 'max:65535'])]
public ?int $smtpPort = null;
- #[Validate(['nullable', 'string', 'in:tls,ssl,none'])]
- public ?string $smtpEncryption = 'tls';
+ #[Validate(['nullable', 'string', 'in:starttls,tls,none'])]
+ public ?string $smtpEncryption = null;
#[Validate(['nullable', 'string'])]
public ?string $smtpUsername = null;
@@ -142,7 +142,7 @@ class SettingsEmail extends Component
'smtpFromName' => 'required|string',
'smtpHost' => 'required|string',
'smtpPort' => 'required|numeric',
- 'smtpEncryption' => 'required|string|in:tls,ssl,none',
+ 'smtpEncryption' => 'required|string|in:starttls,tls,none',
'smtpUsername' => 'nullable|string',
'smtpPassword' => 'nullable|string',
'smtpTimeout' => 'nullable|numeric',
diff --git a/resources/views/livewire/notifications/email.blade.php b/resources/views/livewire/notifications/email.blade.php
index 1977df516..7b0878b25 100644
--- a/resources/views/livewire/notifications/email.blade.php
+++ b/resources/views/livewire/notifications/email.blade.php
@@ -70,9 +70,9 @@
-
-
-
+
+
+
diff --git a/resources/views/livewire/settings-email.blade.php b/resources/views/livewire/settings-email.blade.php
index 19c77971c..02523bbcc 100644
--- a/resources/views/livewire/settings-email.blade.php
+++ b/resources/views/livewire/settings-email.blade.php
@@ -43,9 +43,9 @@
-
-
-
+
+
+
From 1f6c6140bafd499f4af42b8d77ae16ae58a1ab88 Mon Sep 17 00:00:00 2001
From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com>
Date: Mon, 23 Dec 2024 15:28:35 +0100
Subject: [PATCH 03/11] fix: smtp encryption
---
app/Notifications/Channels/EmailChannel.php | 11 +++++++++--
bootstrap/helpers/notifications.php | 11 ++++++++++-
2 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/app/Notifications/Channels/EmailChannel.php b/app/Notifications/Channels/EmailChannel.php
index 0985f4393..6ffe5c4d7 100644
--- a/app/Notifications/Channels/EmailChannel.php
+++ b/app/Notifications/Channels/EmailChannel.php
@@ -66,17 +66,24 @@ class EmailChannel
}
if ($emailSettings->smtp_enabled) {
+ $encryption = match (strtolower($emailSettings->smtp_encryption)) {
+ 'starttls' => null,
+ 'tls' => 'tls',
+ 'none' => null,
+ default => null,
+ };
+
config()->set('mail.default', 'smtp');
config()->set('mail.mailers.smtp', [
'transport' => 'smtp',
'host' => $emailSettings->smtp_host,
'port' => $emailSettings->smtp_port,
- 'encryption' => $emailSettings->smtp_encryption === 'none' ? null : $emailSettings->smtp_encryption,
+ 'encryption' => $encryption,
'username' => $emailSettings->smtp_username,
'password' => $emailSettings->smtp_password,
'timeout' => $emailSettings->smtp_timeout,
'local_domain' => null,
- 'auto_tls' => $emailSettings->smtp_encryption === 'none' ? '0' : '',
+ 'auto_tls' => $emailSettings->smtp_encryption === 'none' ? '0' : '', // If encryption is "none", it will not try to upgrade to TLS via StartTLS to make sure it is unencrypted.
]);
}
}
diff --git a/bootstrap/helpers/notifications.php b/bootstrap/helpers/notifications.php
index 3b1eb758b..46f0ebca7 100644
--- a/bootstrap/helpers/notifications.php
+++ b/bootstrap/helpers/notifications.php
@@ -67,17 +67,26 @@ function set_transanctional_email_settings(?InstanceSettings $settings = null):
return 'resend';
}
+
+ $encryption = match (strtolower(data_get($settings, 'smtp_encryption'))) {
+ 'starttls' => null,
+ 'tls' => 'tls',
+ 'none' => null,
+ default => null,
+ };
+
if (data_get($settings, 'smtp_enabled')) {
config()->set('mail.default', 'smtp');
config()->set('mail.mailers.smtp', [
'transport' => 'smtp',
'host' => data_get($settings, 'smtp_host'),
'port' => data_get($settings, 'smtp_port'),
- 'encryption' => data_get($settings, 'smtp_encryption'),
+ 'encryption' => $encryption,
'username' => data_get($settings, 'smtp_username'),
'password' => data_get($settings, 'smtp_password'),
'timeout' => data_get($settings, 'smtp_timeout'),
'local_domain' => null,
+ 'auto_tls' => data_get($settings, 'smtp_encryption') === 'none' ? '0' : '', // If encryption is "none", it will not try to upgrade to TLS via StartTLS to make sure it is unencrypted.
]);
return 'smtp';
From e51207a35e5402b306b53061f8bde7b75b935bbe Mon Sep 17 00:00:00 2001
From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com>
Date: Mon, 23 Dec 2024 15:33:12 +0100
Subject: [PATCH 04/11] fix: bind() to 0.0.0.0:80 failed
---
config/constants.php | 2 +-
docker-compose.dev.yml | 2 +-
docker-compose.prod.yml | 4 ++--
docker/coolify-realtime/terminal-server.js | 2 +-
docker/development/etc/nginx/site-opts.d/http.conf | 2 --
docker/production/etc/nginx/site-opts.d/http.conf | 2 --
other/nightly/docker-compose.prod.yml | 4 ++--
versions.json | 4 ++--
8 files changed, 9 insertions(+), 13 deletions(-)
diff --git a/config/constants.php b/config/constants.php
index a8a70235b..99859ffb8 100644
--- a/config/constants.php
+++ b/config/constants.php
@@ -2,7 +2,7 @@
return [
'coolify' => [
- 'version' => '4.0.0-beta.379',
+ 'version' => '4.0.0-beta.380',
'self_hosted' => env('SELF_HOSTED', true),
'autoupdate' => env('AUTOUPDATE'),
'base_config_path' => env('BASE_CONFIG_PATH', '/data/coolify'),
diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml
index 76f8e9ca6..3fadd914c 100644
--- a/docker-compose.dev.yml
+++ b/docker-compose.dev.yml
@@ -7,7 +7,7 @@ services:
- USER_ID=${USERID:-1000}
- GROUP_ID=${GROUPID:-1000}
ports:
- - "${APP_PORT:-8000}:80"
+ - "${APP_PORT:-8000}:8080"
environment:
AUTORUN_ENABLED: false
PUSHER_HOST: "${PUSHER_HOST}"
diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml
index d86b2336b..cb8f6b326 100644
--- a/docker-compose.prod.yml
+++ b/docker-compose.prod.yml
@@ -54,7 +54,7 @@ services:
- SSH_MUX_ENABLED
- SSH_MUX_PERSIST_TIME
ports:
- - "${APP_PORT:-8000}:80"
+ - "${APP_PORT:-8000}:8080"
expose:
- "${APP_PORT:-8000}"
healthcheck:
@@ -93,7 +93,7 @@ services:
retries: 10
timeout: 2s
soketi:
- image: 'ghcr.io/coollabsio/coolify-realtime:1.0.4'
+ image: 'ghcr.io/coollabsio/coolify-realtime:1.0.5'
ports:
- "${SOKETI_PORT:-6001}:6001"
- "6002:6002"
diff --git a/docker/coolify-realtime/terminal-server.js b/docker/coolify-realtime/terminal-server.js
index 6633204b2..6649f866c 100755
--- a/docker/coolify-realtime/terminal-server.js
+++ b/docker/coolify-realtime/terminal-server.js
@@ -33,7 +33,7 @@ const verifyClient = async (info, callback) => {
try {
// Authenticate with Laravel backend
- const response = await axios.post(`http://coolify/terminal/auth`, null, {
+ const response = await axios.post(`http://coolify:8080/terminal/auth`, null, {
headers: {
'Cookie': `${sessionCookieName}=${laravelSession}`,
'X-XSRF-TOKEN': xsrfToken
diff --git a/docker/development/etc/nginx/site-opts.d/http.conf b/docker/development/etc/nginx/site-opts.d/http.conf
index 41735cf06..e740918a5 100644
--- a/docker/development/etc/nginx/site-opts.d/http.conf
+++ b/docker/development/etc/nginx/site-opts.d/http.conf
@@ -1,5 +1,3 @@
-listen 80 default_server;
-listen [::]:80 default_server;
listen 8080 default_server;
listen [::]:8080 default_server;
diff --git a/docker/production/etc/nginx/site-opts.d/http.conf b/docker/production/etc/nginx/site-opts.d/http.conf
index 41735cf06..e740918a5 100644
--- a/docker/production/etc/nginx/site-opts.d/http.conf
+++ b/docker/production/etc/nginx/site-opts.d/http.conf
@@ -1,5 +1,3 @@
-listen 80 default_server;
-listen [::]:80 default_server;
listen 8080 default_server;
listen [::]:8080 default_server;
diff --git a/other/nightly/docker-compose.prod.yml b/other/nightly/docker-compose.prod.yml
index d86b2336b..cb8f6b326 100644
--- a/other/nightly/docker-compose.prod.yml
+++ b/other/nightly/docker-compose.prod.yml
@@ -54,7 +54,7 @@ services:
- SSH_MUX_ENABLED
- SSH_MUX_PERSIST_TIME
ports:
- - "${APP_PORT:-8000}:80"
+ - "${APP_PORT:-8000}:8080"
expose:
- "${APP_PORT:-8000}"
healthcheck:
@@ -93,7 +93,7 @@ services:
retries: 10
timeout: 2s
soketi:
- image: 'ghcr.io/coollabsio/coolify-realtime:1.0.4'
+ image: 'ghcr.io/coollabsio/coolify-realtime:1.0.5'
ports:
- "${SOKETI_PORT:-6001}:6001"
- "6002:6002"
diff --git a/versions.json b/versions.json
index c5f41a4db..d00272987 100644
--- a/versions.json
+++ b/versions.json
@@ -1,10 +1,10 @@
{
"coolify": {
"v4": {
- "version": "4.0.0-beta.379"
+ "version": "4.0.0-beta.380"
},
"nightly": {
- "version": "4.0.0-beta.380"
+ "version": "4.0.0-beta.381"
},
"helper": {
"version": "1.0.4"
From 68362d05b3504db9a2d70b20888d7efa9d576c75 Mon Sep 17 00:00:00 2001
From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com>
Date: Mon, 23 Dec 2024 16:08:10 +0100
Subject: [PATCH 05/11] fix: Oauth seeder
---
database/seeders/OauthSettingSeeder.php | 80 +++++++++++--------------
1 file changed, 36 insertions(+), 44 deletions(-)
diff --git a/database/seeders/OauthSettingSeeder.php b/database/seeders/OauthSettingSeeder.php
index bf902175f..df7619fec 100644
--- a/database/seeders/OauthSettingSeeder.php
+++ b/database/seeders/OauthSettingSeeder.php
@@ -4,6 +4,7 @@ namespace Database\Seeders;
use App\Models\OauthSetting;
use Illuminate\Database\Seeder;
+use Illuminate\Support\Facades\Log;
class OauthSettingSeeder extends Seeder
{
@@ -12,62 +13,53 @@ class OauthSettingSeeder extends Seeder
*/
public function run(): void
{
- $providers = collect([
- 'azure',
- 'bitbucket',
- 'github',
- 'gitlab',
- 'google',
- 'authentik',
- ]);
+ try {
+ $providers = collect([
+ 'azure',
+ 'bitbucket',
+ 'github',
+ 'gitlab',
+ 'google',
+ 'authentik',
+ ]);
- $isOauthSeeded = OauthSetting::count() > 0;
+ $isOauthSeeded = OauthSetting::count() > 0;
- // We changed how providers are defined in the database, so we authentik does not exists, we need to recreate all of the auth providers
- // Before authentik was a provider, providers started with 0 id
+ // We changed how providers are defined in the database, so we authentik does not exists, we need to recreate all of the auth providers
+ // Before authentik was a provider, providers started with 0 id
- $isOauthAuthentik = OauthSetting::where('provider', 'authentik')->exists();
- if ($isOauthSeeded) {
- if (! $isOauthAuthentik) {
- $allProviders = OauthSetting::all();
- $notFoundProviders = $providers->diff($allProviders->pluck('provider'));
-
- $allProviders->each(function ($provider) {
- $provider->delete();
- });
- $allProviders->each(function ($provider) use ($providers) {
- $providerName = $provider->provider;
-
- $foundProvider = $providers->first(function ($provider) use ($providerName) {
- return $provider === $providerName;
- });
-
- if ($foundProvider) {
- $newProvder = new OauthSetting;
- $newProvder = $provider;
- unset($newProvder->id);
- $newProvder->save();
- }
- });
-
- foreach ($notFoundProviders as $provider) {
- OauthSetting::create([
- 'provider' => $provider,
- ]);
- }
- } else {
+ $isOauthAuthentik = OauthSetting::where('provider', 'authentik')->exists();
+ if (! $isOauthSeeded || $isOauthAuthentik) {
foreach ($providers as $provider) {
OauthSetting::updateOrCreate([
'provider' => $provider,
]);
}
+
+ return;
}
- } else {
- foreach ($providers as $provider) {
- OauthSetting::updateOrCreate([
+
+ $allProviders = OauthSetting::all();
+ $notFoundProviders = $providers->diff($allProviders->pluck('provider'));
+
+ $allProviders->each(function ($provider) {
+ $provider->delete();
+ });
+ $allProviders->each(function ($provider) {
+ $provider = new OauthSetting;
+ $provider->provider = $provider->provider;
+ unset($provider->id);
+ $provider->save();
+ });
+
+ foreach ($notFoundProviders as $provider) {
+ OauthSetting::create([
'provider' => $provider,
]);
}
+
+ } catch (\Exception $e) {
+ Log::error($e->getMessage());
}
}
}
From f26853b57661b5503328e7daa3896093733ae8c0 Mon Sep 17 00:00:00 2001
From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com>
Date: Mon, 23 Dec 2024 16:51:34 +0100
Subject: [PATCH 06/11] fix: unreachable notifications
---
.../Commands/CloudCleanupSubscriptions.php | 3 +
app/Events/ServerReachabilityChanged.php | 17 ++++++
app/Jobs/ServerCheckJob.php | 7 +--
app/Livewire/Server/Show.php | 2 +
app/Models/Server.php | 61 +++++++++++++++++--
app/Models/ServerSetting.php | 3 -
app/Models/Team.php | 2 +
7 files changed, 82 insertions(+), 13 deletions(-)
create mode 100644 app/Events/ServerReachabilityChanged.php
diff --git a/app/Console/Commands/CloudCleanupSubscriptions.php b/app/Console/Commands/CloudCleanupSubscriptions.php
index 9198b003e..9dc6e24f5 100644
--- a/app/Console/Commands/CloudCleanupSubscriptions.php
+++ b/app/Console/Commands/CloudCleanupSubscriptions.php
@@ -2,6 +2,7 @@
namespace App\Console\Commands;
+use App\Events\ServerReachabilityChanged;
use App\Models\Team;
use Illuminate\Console\Command;
@@ -92,6 +93,8 @@ class CloudCleanupSubscriptions extends Command
$server->update([
'ip' => '1.2.3.4',
]);
+
+ ServerReachabilityChanged::dispatch($server);
}
}
}
diff --git a/app/Events/ServerReachabilityChanged.php b/app/Events/ServerReachabilityChanged.php
new file mode 100644
index 000000000..fb4680146
--- /dev/null
+++ b/app/Events/ServerReachabilityChanged.php
@@ -0,0 +1,17 @@
+server->isReachableChanged();
+ }
+}
diff --git a/app/Jobs/ServerCheckJob.php b/app/Jobs/ServerCheckJob.php
index 49d8dfe08..9818d5c6a 100644
--- a/app/Jobs/ServerCheckJob.php
+++ b/app/Jobs/ServerCheckJob.php
@@ -31,12 +31,7 @@ class ServerCheckJob implements ShouldBeEncrypted, ShouldQueue
return [(new WithoutOverlapping($this->server->uuid))->dontRelease()];
}
- public function __construct(public Server $server)
- {
- if (isDev()) {
- $this->handle();
- }
- }
+ public function __construct(public Server $server) {}
public function handle()
{
diff --git a/app/Livewire/Server/Show.php b/app/Livewire/Server/Show.php
index ac5211c1b..6d267b9c8 100644
--- a/app/Livewire/Server/Show.php
+++ b/app/Livewire/Server/Show.php
@@ -4,6 +4,7 @@ namespace App\Livewire\Server;
use App\Actions\Server\StartSentinel;
use App\Actions\Server\StopSentinel;
+use App\Events\ServerReachabilityChanged;
use App\Models\Server;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Validate;
@@ -202,6 +203,7 @@ class Show extends Component
$this->server->settings->is_reachable = $this->isReachable = true;
$this->server->settings->is_usable = $this->isUsable = true;
$this->server->settings->save();
+ ServerReachabilityChanged::dispatch($this->server);
$this->dispatch('proxyStatusUpdated');
} else {
$this->dispatch('error', 'Server is not reachable.', 'Please validate your configuration and connection.
Check this documentation for further help.
Error: '.$error);
diff --git a/app/Models/Server.php b/app/Models/Server.php
index cc8211789..767327b8e 100644
--- a/app/Models/Server.php
+++ b/app/Models/Server.php
@@ -6,6 +6,7 @@ use App\Actions\Proxy\StartProxy;
use App\Actions\Server\InstallDocker;
use App\Actions\Server\StartSentinel;
use App\Enums\ProxyTypes;
+use App\Events\ServerReachabilityChanged;
use App\Jobs\CheckAndStartSentinelJob;
use App\Notifications\Server\Reachable;
use App\Notifications\Server\Unreachable;
@@ -1024,14 +1025,63 @@ $schema://$host {
$this->refresh();
$unreachableNotificationSent = (bool) $this->unreachable_notification_sent;
$isReachable = (bool) $this->settings->is_reachable;
- // If the server is reachable, send the reachable notification if it was sent before
+
+ \Log::debug('Server reachability check', [
+ 'server_id' => $this->id,
+ 'is_reachable' => $isReachable,
+ 'notification_sent' => $unreachableNotificationSent,
+ 'unreachable_count' => $this->unreachable_count,
+ ]);
+
if ($isReachable === true) {
+ $this->unreachable_count = 0;
+ $this->save();
+
if ($unreachableNotificationSent === true) {
+ \Log::debug('Server is now reachable, sending notification', [
+ 'server_id' => $this->id,
+ ]);
$this->sendReachableNotification();
}
- } else {
- // If the server is unreachable, send the unreachable notification if it was not sent before
- if ($unreachableNotificationSent === false) {
+
+ return;
+ }
+
+ $this->increment('unreachable_count');
+ \Log::debug('Incremented unreachable count', [
+ 'server_id' => $this->id,
+ 'new_count' => $this->unreachable_count,
+ ]);
+
+ if ($this->unreachable_count === 1) {
+ $this->settings->is_reachable = true;
+ $this->settings->save();
+ \Log::debug('First unreachable attempt, marking as reachable', [
+ 'server_id' => $this->id,
+ ]);
+
+ return;
+ }
+
+ if ($this->unreachable_count >= 2 && ! $unreachableNotificationSent) {
+ $failedChecks = 0;
+ for ($i = 0; $i < 3; $i++) {
+ $status = $this->serverStatus();
+ \Log::debug('Additional reachability check', [
+ 'server_id' => $this->id,
+ 'attempt' => $i + 1,
+ 'status' => $status,
+ ]);
+ sleep(5);
+ if (! $status) {
+ $failedChecks++;
+ }
+ }
+
+ if ($failedChecks === 3 && ! $unreachableNotificationSent) {
+ \Log::debug('Server confirmed unreachable after 3 attempts, sending notification', [
+ 'server_id' => $this->id,
+ ]);
$this->sendUnreachableNotification();
}
}
@@ -1065,6 +1115,7 @@ $schema://$host {
if ($this->settings->is_reachable === false) {
$this->settings->is_reachable = true;
$this->settings->save();
+ ServerReachabilityChanged::dispatch($this);
}
return ['uptime' => true, 'error' => null];
@@ -1075,6 +1126,7 @@ $schema://$host {
if ($this->settings->is_reachable === true) {
$this->settings->is_reachable = false;
$this->settings->save();
+ ServerReachabilityChanged::dispatch($this);
}
return ['uptime' => false, 'error' => $e->getMessage()];
@@ -1165,6 +1217,7 @@ $schema://$host {
$this->settings->is_reachable = true;
$this->settings->is_usable = true;
$this->settings->save();
+ ServerReachabilityChanged::dispatch($this);
return true;
}
diff --git a/app/Models/ServerSetting.php b/app/Models/ServerSetting.php
index e078372e2..f4b776cca 100644
--- a/app/Models/ServerSetting.php
+++ b/app/Models/ServerSetting.php
@@ -85,9 +85,6 @@ class ServerSetting extends Model
) {
$settings->server->restartSentinel();
}
- if ($settings->isDirty('is_reachable')) {
- $settings->server->isReachableChanged();
- }
});
}
diff --git a/app/Models/Team.php b/app/Models/Team.php
index e55cb0d19..33847a3c8 100644
--- a/app/Models/Team.php
+++ b/app/Models/Team.php
@@ -2,6 +2,7 @@
namespace App\Models;
+use App\Events\ServerReachabilityChanged;
use App\Notifications\Channels\SendsDiscord;
use App\Notifications\Channels\SendsEmail;
use App\Notifications\Channels\SendsPushover;
@@ -202,6 +203,7 @@ class Team extends Model implements SendsDiscord, SendsEmail, SendsPushover, Sen
'is_usable' => false,
'is_reachable' => false,
]);
+ ServerReachabilityChanged::dispatch($server);
}
}
From d7a0794bd995b703df90bbc370a547a8f8abb0d0 Mon Sep 17 00:00:00 2001
From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com>
Date: Mon, 23 Dec 2024 17:15:46 +0100
Subject: [PATCH 07/11] fix: instance settings migration
---
...ncrypt_instance_settings_email_columns.php | 40 +++++++++----------
1 file changed, 19 insertions(+), 21 deletions(-)
diff --git a/database/migrations/2024_12_10_122142_encrypt_instance_settings_email_columns.php b/database/migrations/2024_12_10_122142_encrypt_instance_settings_email_columns.php
index 5602e0ae9..b17e53ddf 100644
--- a/database/migrations/2024_12_10_122142_encrypt_instance_settings_email_columns.php
+++ b/database/migrations/2024_12_10_122142_encrypt_instance_settings_email_columns.php
@@ -13,28 +13,26 @@ return new class extends Migration
*/
public function up(): void
{
- if (DB::table('instance_settings')->exists()) {
- Schema::table('instance_settings', function (Blueprint $table) {
- $table->text('smtp_from_address')->nullable()->change();
- $table->text('smtp_from_name')->nullable()->change();
- $table->text('smtp_recipients')->nullable()->change();
- $table->text('smtp_host')->nullable()->change();
- $table->text('smtp_username')->nullable()->change();
- });
+ Schema::table('instance_settings', function (Blueprint $table) {
+ $table->text('smtp_from_address')->nullable()->change();
+ $table->text('smtp_from_name')->nullable()->change();
+ $table->text('smtp_recipients')->nullable()->change();
+ $table->text('smtp_host')->nullable()->change();
+ $table->text('smtp_username')->nullable()->change();
+ });
- $settings = DB::table('instance_settings')->get();
- foreach ($settings as $setting) {
- try {
- DB::table('instance_settings')->where('id', $setting->id)->update([
- 'smtp_from_address' => $setting->smtp_from_address ? Crypt::encryptString($setting->smtp_from_address) : null,
- 'smtp_from_name' => $setting->smtp_from_name ? Crypt::encryptString($setting->smtp_from_name) : null,
- 'smtp_recipients' => $setting->smtp_recipients ? Crypt::encryptString($setting->smtp_recipients) : null,
- 'smtp_host' => $setting->smtp_host ? Crypt::encryptString($setting->smtp_host) : null,
- 'smtp_username' => $setting->smtp_username ? Crypt::encryptString($setting->smtp_username) : null,
- ]);
- } catch (Exception $e) {
- \Log::error('Error encrypting instance settings email columns: '.$e->getMessage());
- }
+ $settings = DB::table('instance_settings')->get();
+ foreach ($settings as $setting) {
+ try {
+ DB::table('instance_settings')->where('id', $setting->id)->update([
+ 'smtp_from_address' => $setting->smtp_from_address ? Crypt::encryptString($setting->smtp_from_address) : null,
+ 'smtp_from_name' => $setting->smtp_from_name ? Crypt::encryptString($setting->smtp_from_name) : null,
+ 'smtp_recipients' => $setting->smtp_recipients ? Crypt::encryptString($setting->smtp_recipients) : null,
+ 'smtp_host' => $setting->smtp_host ? Crypt::encryptString($setting->smtp_host) : null,
+ 'smtp_username' => $setting->smtp_username ? Crypt::encryptString($setting->smtp_username) : null,
+ ]);
+ } catch (Exception $e) {
+ \Log::error('Error encrypting instance settings email columns: '.$e->getMessage());
}
}
}
From 0a851ec3f2de1d9e266623b68e71ca222b539868 Mon Sep 17 00:00:00 2001
From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com>
Date: Mon, 23 Dec 2024 17:41:38 +0100
Subject: [PATCH 08/11] fix: only encrypt instance email settings if there are
any
---
...ncrypt_instance_settings_email_columns.php | 36 ++++++++++---------
1 file changed, 19 insertions(+), 17 deletions(-)
diff --git a/database/migrations/2024_12_10_122142_encrypt_instance_settings_email_columns.php b/database/migrations/2024_12_10_122142_encrypt_instance_settings_email_columns.php
index b17e53ddf..83540ca3c 100644
--- a/database/migrations/2024_12_10_122142_encrypt_instance_settings_email_columns.php
+++ b/database/migrations/2024_12_10_122142_encrypt_instance_settings_email_columns.php
@@ -21,18 +21,20 @@ return new class extends Migration
$table->text('smtp_username')->nullable()->change();
});
- $settings = DB::table('instance_settings')->get();
- foreach ($settings as $setting) {
- try {
- DB::table('instance_settings')->where('id', $setting->id)->update([
- 'smtp_from_address' => $setting->smtp_from_address ? Crypt::encryptString($setting->smtp_from_address) : null,
- 'smtp_from_name' => $setting->smtp_from_name ? Crypt::encryptString($setting->smtp_from_name) : null,
- 'smtp_recipients' => $setting->smtp_recipients ? Crypt::encryptString($setting->smtp_recipients) : null,
- 'smtp_host' => $setting->smtp_host ? Crypt::encryptString($setting->smtp_host) : null,
- 'smtp_username' => $setting->smtp_username ? Crypt::encryptString($setting->smtp_username) : null,
- ]);
- } catch (Exception $e) {
- \Log::error('Error encrypting instance settings email columns: '.$e->getMessage());
+ if (DB::table('instance_settings')->exists()) {
+ $settings = DB::table('instance_settings')->get();
+ foreach ($settings as $setting) {
+ try {
+ DB::table('instance_settings')->where('id', $setting->id)->update([
+ 'smtp_from_address' => $setting->smtp_from_address ? Crypt::encryptString($setting->smtp_from_address) : null,
+ 'smtp_from_name' => $setting->smtp_from_name ? Crypt::encryptString($setting->smtp_from_name) : null,
+ 'smtp_recipients' => $setting->smtp_recipients ? Crypt::encryptString($setting->smtp_recipients) : null,
+ 'smtp_host' => $setting->smtp_host ? Crypt::encryptString($setting->smtp_host) : null,
+ 'smtp_username' => $setting->smtp_username ? Crypt::encryptString($setting->smtp_username) : null,
+ ]);
+ } catch (Exception $e) {
+ \Log::error('Error encrypting instance settings email columns: '.$e->getMessage());
+ }
}
}
}
@@ -43,11 +45,11 @@ return new class extends Migration
public function down(): void
{
Schema::table('instance_settings', function (Blueprint $table) {
- $table->text('smtp_from_address')->nullable()->change();
- $table->text('smtp_from_name')->nullable()->change();
- $table->text('smtp_recipients')->nullable()->change();
- $table->text('smtp_host')->nullable()->change();
- $table->text('smtp_username')->nullable()->change();
+ $table->string('smtp_from_address')->nullable()->change();
+ $table->string('smtp_from_name')->nullable()->change();
+ $table->string('smtp_recipients')->nullable()->change();
+ $table->string('smtp_host')->nullable()->change();
+ $table->string('smtp_username')->nullable()->change();
});
if (DB::table('instance_settings')->exists()) {
From 6dc87498dea1cdaadad02b7060093be85492a236 Mon Sep 17 00:00:00 2001
From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com>
Date: Mon, 23 Dec 2024 17:58:56 +0100
Subject: [PATCH 09/11] fix: error message
---
..._142402_update_email_encryption_values.php | 30 +++++--------------
1 file changed, 7 insertions(+), 23 deletions(-)
diff --git a/database/migrations/2024_12_23_142402_update_email_encryption_values.php b/database/migrations/2024_12_23_142402_update_email_encryption_values.php
index c21c910d1..dfb5b4a7c 100644
--- a/database/migrations/2024_12_23_142402_update_email_encryption_values.php
+++ b/database/migrations/2024_12_23_142402_update_email_encryption_values.php
@@ -6,7 +6,7 @@ use Illuminate\Support\Facades\DB;
class UpdateEmailEncryptionValues extends Migration
{
/**
- * The encryption mappings.
+ * Encryption mappings.
*/
private array $encryptionMappings = [
'tls' => 'starttls',
@@ -33,10 +33,7 @@ class UpdateEmailEncryptionValues extends Migration
]);
}
} catch (\Exception $e) {
- \Log::error('Failed to update instance_settings encryption for ID: '.$setting->id, [
- 'error' => $e->getMessage(),
- 'old_value' => $setting->smtp_encryption,
- ]);
+ \Log::error('Failed to update instance settings: '.$e->getMessage());
}
}
@@ -51,19 +48,14 @@ class UpdateEmailEncryptionValues extends Migration
]);
}
} catch (\Exception $e) {
- \Log::error('Failed to update email_notification_settings encryption for ID: '.$setting->id, [
- 'error' => $e->getMessage(),
- 'old_value' => $setting->smtp_encryption,
- ]);
+ \Log::error('Failed to update email settings: '.$e->getMessage());
}
}
DB::commit();
} catch (\Exception $e) {
DB::rollBack();
- \Log::error('Failed to complete email encryption migration', [
- 'error' => $e->getMessage(),
- ]);
+ \Log::error('Failed to update email encryption: '.$e->getMessage());
throw $e;
}
}
@@ -93,10 +85,7 @@ class UpdateEmailEncryptionValues extends Migration
]);
}
} catch (\Exception $e) {
- \Log::error('Failed to reverse instance_settings encryption for ID: '.$setting->id, [
- 'error' => $e->getMessage(),
- 'old_value' => $setting->smtp_encryption,
- ]);
+ \Log::error('Failed to reverse instance settings: '.$e->getMessage());
}
}
@@ -111,19 +100,14 @@ class UpdateEmailEncryptionValues extends Migration
]);
}
} catch (\Exception $e) {
- \Log::error('Failed to reverse email_notification_settings encryption for ID: '.$setting->id, [
- 'error' => $e->getMessage(),
- 'old_value' => $setting->smtp_encryption,
- ]);
+ \Log::error('Failed to reverse email settings: '.$e->getMessage());
}
}
DB::commit();
} catch (\Exception $e) {
DB::rollBack();
- \Log::error('Failed to complete email encryption rollback migration', [
- 'error' => $e->getMessage(),
- ]);
+ \Log::error('Failed to reverse email encryption: '.$e->getMessage());
throw $e;
}
}
From a9ec0b1c3eb14e4a4f3c7dd9bfaddc0b9770008a Mon Sep 17 00:00:00 2001
From: Andras Bacsai
Date: Mon, 23 Dec 2024 21:11:29 +0100
Subject: [PATCH 10/11] fix: update healthcheck and port configurations to use
port 8080
---
app/Models/Server.php | 4 ++--
docker-compose.prod.yml | 2 +-
docker-compose.windows.yml | 4 ++--
other/nightly/docker-compose.prod.yml | 2 +-
other/nightly/docker-compose.windows.yml | 4 ++--
5 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/app/Models/Server.php b/app/Models/Server.php
index 767327b8e..8d11e23a9 100644
--- a/app/Models/Server.php
+++ b/app/Models/Server.php
@@ -347,7 +347,7 @@ class Server extends BaseModel
'loadBalancer' => [
'servers' => [
0 => [
- 'url' => 'http://coolify:80',
+ 'url' => 'http://coolify:8080',
],
],
],
@@ -445,7 +445,7 @@ $schema://$host {
handle /terminal/ws {
reverse_proxy coolify-realtime:6002
}
- reverse_proxy coolify:80
+ reverse_proxy coolify:8080
}";
$base64 = base64_encode($caddy_file);
instant_remote_process([
diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml
index cb8f6b326..459b93ac6 100644
--- a/docker-compose.prod.yml
+++ b/docker-compose.prod.yml
@@ -58,7 +58,7 @@ services:
expose:
- "${APP_PORT:-8000}"
healthcheck:
- test: curl --fail http://127.0.0.1:80/api/health || exit 1
+ test: curl --fail http://127.0.0.1:8080/api/health || exit 1
interval: 5s
retries: 10
timeout: 2s
diff --git a/docker-compose.windows.yml b/docker-compose.windows.yml
index f2b03d209..1e2601b34 100644
--- a/docker-compose.windows.yml
+++ b/docker-compose.windows.yml
@@ -48,11 +48,11 @@ services:
- SSH_MUX_ENABLED=false
- IS_WINDOWS_DOCKER_DESKTOP=true
ports:
- - "${APP_PORT:-8000}:80"
+ - "${APP_PORT:-8000}:8080"
expose:
- "${APP_PORT:-8000}"
healthcheck:
- test: curl --fail http://localhost:80/api/health || exit 1
+ test: curl --fail http://localhost:8080/api/health || exit 1
interval: 5s
retries: 10
timeout: 2s
diff --git a/other/nightly/docker-compose.prod.yml b/other/nightly/docker-compose.prod.yml
index cb8f6b326..459b93ac6 100644
--- a/other/nightly/docker-compose.prod.yml
+++ b/other/nightly/docker-compose.prod.yml
@@ -58,7 +58,7 @@ services:
expose:
- "${APP_PORT:-8000}"
healthcheck:
- test: curl --fail http://127.0.0.1:80/api/health || exit 1
+ test: curl --fail http://127.0.0.1:8080/api/health || exit 1
interval: 5s
retries: 10
timeout: 2s
diff --git a/other/nightly/docker-compose.windows.yml b/other/nightly/docker-compose.windows.yml
index ef2de82e9..e19ec961f 100644
--- a/other/nightly/docker-compose.windows.yml
+++ b/other/nightly/docker-compose.windows.yml
@@ -48,11 +48,11 @@ services:
- SSH_MUX_ENABLED=false
- IS_WINDOWS_DOCKER_DESKTOP=true
ports:
- - "${APP_PORT:-8000}:80"
+ - "${APP_PORT:-8000}:8080"
expose:
- "${APP_PORT:-8000}"
healthcheck:
- test: curl --fail http://localhost:80/api/health || exit 1
+ test: curl --fail http://localhost:8080/api/health || exit 1
interval: 5s
retries: 10
timeout: 2s
From cec7ea8a833466cd05e682fa5f62892a63be6cec Mon Sep 17 00:00:00 2001
From: Andras Bacsai
Date: Fri, 27 Dec 2024 10:49:13 +0100
Subject: [PATCH 11/11] set the minimum docker version to 24 to support old
installations
---
config/constants.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/config/constants.php b/config/constants.php
index 99859ffb8..e220eacfd 100644
--- a/config/constants.php
+++ b/config/constants.php
@@ -47,7 +47,7 @@ return [
],
'docker' => [
- 'minimum_required_version' => '26.0',
+ 'minimum_required_version' => '24.0',
],
'ssh' => [