Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

feat(dev patches): add functionality to send test email with patch data in development mode

Andras Bacsai91cc52f81ea6
diff --git a/app/Livewire/Server/Security/Patches.php b/app/Livewire/Server/Security/Patches.php
index b7d17a61dc..eca4bbcd6c 100644
--- a/app/Livewire/Server/Security/Patches.php
+++ b/app/Livewire/Server/Security/Patches.php
@@ -6,6 +6,7 @@ use App\Actions\Server\CheckUpdates;
use App\Actions\Server\UpdatePackage;
use App\Events\ServerPackageUpdated;
use App\Models\Server;
+use App\Notifications\Server\ServerPatchCheck;
use Livewire\Component;
class Patches extends Component
@@ -96,6 +97,89 @@ class Patches extends Component
}
}
+ public function sendTestEmail()
+ {
+ if (! isDev()) {
+ $this->dispatch('error', message: 'Test email functionality is only available in development mode.');
+
+ return;
+ }
+
+ try {
+ // Get current patch data or create test data if none exists
+ $testPatchData = $this->createTestPatchData();
+
+ // Send test notification
+ $this->server->team->notify(new ServerPatchCheck($this->server, $testPatchData));
+
+ $this->dispatch('success', 'Test email sent successfully! Check your email inbox.');
+ } catch (\Exception $e) {
+ $this->dispatch('error', message: 'Failed to send test email: '.$e->getMessage());
+ }
+ }
+
+ private function createTestPatchData(): array
+ {
+ // If we have real patch data, use it
+ if (isset($this->updates) && is_array($this->updates) && count($this->updates) > 0) {
+ return [
+ 'total_updates' => $this->totalUpdates,
+ 'updates' => $this->updates,
+ 'osId' => $this->osId,
+ 'package_manager' => $this->packageManager,
+ ];
+ }
+
+ // Otherwise create realistic test data
+ return [
+ 'total_updates' => 8,
+ 'updates' => [
+ [
+ 'package' => 'docker-ce',
+ 'current_version' => '24.0.7-1',
+ 'new_version' => '25.0.1-1',
+ ],
+ [
+ 'package' => 'nginx',
+ 'current_version' => '1.20.2-1',
+ 'new_version' => '1.22.1-1',
+ ],
+ [
+ 'package' => 'kernel-generic',
+ 'current_version' => '5.15.0-89',
+ 'new_version' => '5.15.0-91',
+ ],
+ [
+ 'package' => 'openssh-server',
+ 'current_version' => '8.9p1-3',
+ 'new_version' => '9.0p1-1',
+ ],
+ [
+ 'package' => 'curl',
+ 'current_version' => '7.81.0-1',
+ 'new_version' => '7.85.0-1',
+ ],
+ [
+ 'package' => 'git',
+ 'current_version' => '2.34.1-1',
+ 'new_version' => '2.39.1-1',
+ ],
+ [
+ 'package' => 'python3',
+ 'current_version' => '3.10.6-1',
+ 'new_version' => '3.11.0-1',
+ ],
+ [
+ 'package' => 'htop',
+ 'current_version' => '3.2.1-1',
+ 'new_version' => '3.2.2-1',
+ ],
+ ],
+ 'osId' => $this->osId ?? 'ubuntu',
+ 'package_manager' => $this->packageManager ?? 'apt',
+ ];
+ }
+
public function render()
{
return view('livewire.server.security.patches');
diff --git a/resources/views/livewire/server/security/patches.blade.php b/resources/views/livewire/server/security/patches.blade.php
index 560d512bfb..f8b51f34e6 100644
--- a/resources/views/livewire/server/security/patches.blade.php
+++ b/resources/views/livewire/server/security/patches.blade.php
@@ -22,6 +22,10 @@
soon.<br/>Status notifications sent every week.<br/>You can disable notifications in the <a class='dark:text-white underline' href='{{ route('notifications.email') }}'>notification settings</a>." />
<x-forms.button type="button" wire:click="$dispatch('checkForUpdatesDispatch')">
Check Now</x-forms.button>
+ @if (isDev())
+ <x-forms.button type="button" wire:click="sendTestEmail">
+ Send Test Email (dev only)</x-forms.button>
+ @endif
</div>
<div>Update your servers semi-automatically.</div>
<div>