diff --git a/app/Livewire/Boarding/Index.php b/app/Livewire/Boarding/Index.php index 15eabfec5..430470fa0 100644 --- a/app/Livewire/Boarding/Index.php +++ b/app/Livewire/Boarding/Index.php @@ -7,6 +7,7 @@ use App\Models\PrivateKey; use App\Models\Project; use App\Models\Server; use App\Models\Team; +use App\Services\ConfigurationRepository; use Illuminate\Support\Collection; use Livewire\Component; use Visus\Cuid2\Cuid2; @@ -266,7 +267,7 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA== public function validateServer() { try { - config()->set('constants.ssh.mux_enabled', false); + $this->disableSshMux(); // EC2 does not have `uptime` command, lol instant_remote_process(['ls /'], $this->createdServer, true); @@ -376,6 +377,12 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA== ['private' => $this->privateKey, 'public' => $this->publicKey] = generateSSHKey(); } + private function disableSshMux(): void + { + $configRepository = app(ConfigurationRepository::class); + $configRepository->disableSshMux(); + } + public function render() { return view('livewire.boarding.index')->layout('layouts.boarding'); diff --git a/app/Models/Server.php b/app/Models/Server.php index 0f48c0efc..fedb95697 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -10,6 +10,7 @@ use App\Events\ServerReachabilityChanged; use App\Jobs\CheckAndStartSentinelJob; use App\Notifications\Server\Reachable; use App\Notifications\Server\Unreachable; +use App\Services\ConfigurationRepository; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; @@ -543,7 +544,7 @@ $schema://$host { $this->settings->save(); $sshKeyFileLocation = "id.root@{$this->uuid}"; Storage::disk('ssh-keys')->delete($sshKeyFileLocation); - Storage::disk('ssh-mux')->delete($this->muxFilename()); + $this->disableSshMux(); } public function sentinelHeartbeat(bool $isReset = false) @@ -1103,7 +1104,7 @@ $schema://$host { public function validateConnection(bool $justCheckingNewKey = false) { - config()->set('constants.ssh.mux_enabled', false); + $this->disableSshMux(); if ($this->skipServer()) { return ['uptime' => false, 'error' => 'Server skipped.']; @@ -1330,4 +1331,10 @@ $schema://$host { $this->databases()->count() == 0 && $this->services()->count() == 0; } + + private function disableSshMux(): void + { + $configRepository = app(ConfigurationRepository::class); + $configRepository->disableSshMux(); + } } diff --git a/app/Notifications/Channels/EmailChannel.php b/app/Notifications/Channels/EmailChannel.php index 2a18a2d34..4cdf8d08f 100644 --- a/app/Notifications/Channels/EmailChannel.php +++ b/app/Notifications/Channels/EmailChannel.php @@ -2,6 +2,7 @@ namespace App\Notifications\Channels; +use App\Services\ConfigurationRepository; use Exception; use Illuminate\Mail\Message; use Illuminate\Notifications\Notification; @@ -9,6 +10,13 @@ use Illuminate\Support\Facades\Mail; class EmailChannel { + private ConfigurationRepository $configRepository; + + public function __construct(ConfigurationRepository $configRepository) + { + $this->configRepository = $configRepository; + } + public function send(SendsEmail $notifiable, Notification $notification): void { try { @@ -57,34 +65,6 @@ class EmailChannel return; } - config()->set('mail.from.address', $emailSettings->smtp_from_address ?? 'test@example.com'); - config()->set('mail.from.name', $emailSettings->smtp_from_name ?? 'Test'); - - if ($emailSettings->resend_enabled) { - config()->set('mail.default', 'resend'); - config()->set('resend.api_key', $emailSettings->resend_api_key); - } - - 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' => $encryption, - 'username' => $emailSettings->smtp_username, - 'password' => $emailSettings->smtp_password, - 'timeout' => $emailSettings->smtp_timeout, - 'local_domain' => null, - '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. - ]); - } + $this->configRepository->updateMailConfig($emailSettings); } } diff --git a/app/Providers/ConfigurationServiceProvider.php b/app/Providers/ConfigurationServiceProvider.php new file mode 100644 index 000000000..3ff459ef6 --- /dev/null +++ b/app/Providers/ConfigurationServiceProvider.php @@ -0,0 +1,21 @@ +app->singleton(ConfigurationRepository::class, function ($app) { + return new ConfigurationRepository($app['config']); + }); + } + + public function boot(): void + { + // + } +} diff --git a/app/Services/ConfigurationRepository.php b/app/Services/ConfigurationRepository.php new file mode 100644 index 000000000..ff2e73eed --- /dev/null +++ b/app/Services/ConfigurationRepository.php @@ -0,0 +1,56 @@ +config = $config; + } + + public function updateMailConfig($settings): void + { + if ($settings->resend_enabled) { + $this->config->set('mail.default', 'resend'); + $this->config->set('mail.from.address', $settings->smtp_from_address ?? 'test@example.com'); + $this->config->set('mail.from.name', $settings->smtp_from_name ?? 'Test'); + $this->config->set('resend.api_key', $settings->resend_api_key); + + return; + } + + if ($settings->smtp_enabled) { + $encryption = match (strtolower($settings->smtp_encryption)) { + 'starttls' => null, + 'tls' => 'tls', + 'none' => null, + default => null, + }; + + $this->config->set('mail.default', 'smtp'); + $this->config->set('mail.from.address', $settings->smtp_from_address ?? 'test@example.com'); + $this->config->set('mail.from.name', $settings->smtp_from_name ?? 'Test'); + $this->config->set('mail.mailers.smtp', [ + 'transport' => 'smtp', + 'host' => $settings->smtp_host, + 'port' => $settings->smtp_port, + 'encryption' => $encryption, + 'username' => $settings->smtp_username, + 'password' => $settings->smtp_password, + 'timeout' => $settings->smtp_timeout, + 'local_domain' => null, + 'auto_tls' => $settings->smtp_encryption === 'none' ? '0' : '', + ]); + } + } + + public function disableSshMux(): void + { + $this->config->set('constants.ssh.mux_enabled', false); + } +} diff --git a/bootstrap/helpers/notifications.php b/bootstrap/helpers/notifications.php index b0345df7e..bee39ef01 100644 --- a/bootstrap/helpers/notifications.php +++ b/bootstrap/helpers/notifications.php @@ -1,6 +1,5 @@ set('mail.default', 'resend'); - config()->set('mail.from.address', data_get($settings, 'smtp_from_address')); - config()->set('mail.from.name', data_get($settings, 'smtp_from_name')); - config()->set('resend.api_key', data_get($settings, 'resend_api_key')); + $configRepository = app('App\Services\ConfigurationRepository'::class); + $configRepository->updateMailConfig($settings); + if (data_get($settings, 'resend_enabled')) { 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.from.address', data_get($settings, 'smtp_from_address')); - config()->set('mail.from.name', data_get($settings, 'smtp_from_name')); - 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' => $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'; } + + return null; } diff --git a/config/app.php b/config/app.php index 371ac44ec..a94cfadd8 100644 --- a/config/app.php +++ b/config/app.php @@ -199,6 +199,7 @@ return [ App\Providers\EventServiceProvider::class, App\Providers\HorizonServiceProvider::class, App\Providers\RouteServiceProvider::class, + App\Providers\ConfigurationServiceProvider::class, ], /*