mirror of
https://github.com/pelican-dev/panel.git
synced 2026-05-04 18:00:48 +03:00
Compare commits
2 Commits
main
...
boy132/bac
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ec9a008e7 | ||
|
|
fcd5d005ed |
17
app/Events/Server/BackupCompleted.php
Normal file
17
app/Events/Server/BackupCompleted.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events\Server;
|
||||||
|
|
||||||
|
use App\Events\Event;
|
||||||
|
use App\Models\Backup;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class BackupCompleted extends Event
|
||||||
|
{
|
||||||
|
use SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*/
|
||||||
|
public function __construct(public Backup $backup) {}
|
||||||
|
}
|
||||||
@@ -703,6 +703,16 @@ class Settings extends Page implements HasSchemas
|
|||||||
->formatStateUsing(fn ($state): bool => (bool) $state)
|
->formatStateUsing(fn ($state): bool => (bool) $state)
|
||||||
->afterStateUpdated(fn ($state, Set $set) => $set('PANEL_SEND_REINSTALL_NOTIFICATION', (bool) $state))
|
->afterStateUpdated(fn ($state, Set $set) => $set('PANEL_SEND_REINSTALL_NOTIFICATION', (bool) $state))
|
||||||
->default(env('PANEL_SEND_REINSTALL_NOTIFICATION', config('panel.email.send_reinstall_notification'))),
|
->default(env('PANEL_SEND_REINSTALL_NOTIFICATION', config('panel.email.send_reinstall_notification'))),
|
||||||
|
Toggle::make('PANEL_SEND_BACKUP_COMPLETED_NOTIFICATION')
|
||||||
|
->label(trans('admin/setting.misc.mail_notifications.backup_completed'))
|
||||||
|
->onIcon(TablerIcon::Check)
|
||||||
|
->offIcon(TablerIcon::X)
|
||||||
|
->onColor('success')
|
||||||
|
->offColor('danger')
|
||||||
|
->live()
|
||||||
|
->formatStateUsing(fn ($state): bool => (bool) $state)
|
||||||
|
->afterStateUpdated(fn ($state, Set $set) => $set('PANEL_SEND_BACKUP_COMPLETED_NOTIFICATION', (bool) $state))
|
||||||
|
->default(env('PANEL_SEND_BACKUP_COMPLETED_NOTIFICATION', config('panel.email.send_backup_completed_notification'))),
|
||||||
]),
|
]),
|
||||||
Section::make(trans('admin/setting.misc.connections.title'))
|
Section::make(trans('admin/setting.misc.connections.title'))
|
||||||
->description(trans('admin/setting.misc.connections.helper'))
|
->description(trans('admin/setting.misc.connections.helper'))
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Api\Remote\Backups;
|
namespace App\Http\Controllers\Api\Remote\Backups;
|
||||||
|
|
||||||
|
use App\Events\Server\BackupCompleted;
|
||||||
use App\Exceptions\DisplayException;
|
use App\Exceptions\DisplayException;
|
||||||
use App\Exceptions\Http\HttpForbiddenException;
|
use App\Exceptions\Http\HttpForbiddenException;
|
||||||
use App\Extensions\Backups\BackupManager;
|
use App\Extensions\Backups\BackupManager;
|
||||||
@@ -79,6 +80,8 @@ class BackupStatusController extends Controller
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
event(new BackupCompleted($model));
|
||||||
|
|
||||||
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
|
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
37
app/Listeners/Server/BackupCompletedListener.php
Normal file
37
app/Listeners/Server/BackupCompletedListener.php
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Listeners\Server;
|
||||||
|
|
||||||
|
use App\Events\Server\BackupCompleted;
|
||||||
|
use App\Filament\Server\Resources\Backups\Pages\ListBackups;
|
||||||
|
use App\Notifications\BackupCompleted as BackupCompletedNotification;
|
||||||
|
use Filament\Actions\Action;
|
||||||
|
use Filament\Notifications\Notification;
|
||||||
|
|
||||||
|
class BackupCompletedListener
|
||||||
|
{
|
||||||
|
public function handle(BackupCompleted $event): void
|
||||||
|
{
|
||||||
|
$event->backup->loadMissing('server');
|
||||||
|
$event->backup->server->loadMissing('user');
|
||||||
|
|
||||||
|
$locale = $event->backup->server->user->language ?? 'en';
|
||||||
|
|
||||||
|
Notification::make()
|
||||||
|
->status($event->backup->is_successful ? 'success' : 'danger')
|
||||||
|
->title(trans('notifications.backup_' . ($event->backup->is_successful ? 'completed' : 'failed'), locale: $locale))
|
||||||
|
->body(trans('notifications.backup_body', ['name' => $event->backup->name, 'server' => $event->backup->server->name], $locale))
|
||||||
|
->actions([
|
||||||
|
Action::make('exclude_view')
|
||||||
|
->button()
|
||||||
|
->label(trans('notifications.view_backups', locale: $locale))
|
||||||
|
->markAsRead()
|
||||||
|
->url(fn () => ListBackups::getUrl(panel: 'server', tenant: $event->backup->server)),
|
||||||
|
])
|
||||||
|
->sendToDatabase($event->backup->server->user);
|
||||||
|
|
||||||
|
if (config()->get('panel.email.send_backup_completed_notification', true)) {
|
||||||
|
$event->backup->server->user->notify(new BackupCompletedNotification($event->backup));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
36
app/Notifications/BackupCompleted.php
Normal file
36
app/Notifications/BackupCompleted.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Notifications;
|
||||||
|
|
||||||
|
use App\Filament\Server\Resources\Backups\Pages\ListBackups;
|
||||||
|
use App\Models\Backup;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Notifications\Messages\MailMessage;
|
||||||
|
use Illuminate\Notifications\Notification;
|
||||||
|
|
||||||
|
class BackupCompleted extends Notification implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Queueable;
|
||||||
|
|
||||||
|
public function __construct(public Backup $backup) {}
|
||||||
|
|
||||||
|
/** @return string[] */
|
||||||
|
public function via(): array
|
||||||
|
{
|
||||||
|
return ['mail'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toMail(User $notifiable): MailMessage
|
||||||
|
{
|
||||||
|
$locale = $notifiable->language ?? 'en';
|
||||||
|
|
||||||
|
return (new MailMessage())
|
||||||
|
->greeting(trans('mail.greeting', ['name' => $notifiable->username], $locale))
|
||||||
|
->line(trans('mail.backup_completed.body_' . ($this->backup->is_successful ? 'success' : 'failed'), locale: $locale))
|
||||||
|
->line(trans('mail.backup_completed.backup_name', ['name' => $this->backup->name], $locale))
|
||||||
|
->line(trans('mail.backup_completed.server_name', ['name' => $this->backup->server->name], $locale))
|
||||||
|
->action(trans('mail.backup_completed.action', locale: $locale), ListBackups::getUrl(panel: 'server', tenant: $this->backup->server));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -49,6 +49,8 @@ return [
|
|||||||
'send_install_notification' => env('PANEL_SEND_INSTALL_NOTIFICATION', true),
|
'send_install_notification' => env('PANEL_SEND_INSTALL_NOTIFICATION', true),
|
||||||
// Should an email be sent to a server owner whenever their server is reinstalled?
|
// Should an email be sent to a server owner whenever their server is reinstalled?
|
||||||
'send_reinstall_notification' => env('PANEL_SEND_REINSTALL_NOTIFICATION', true),
|
'send_reinstall_notification' => env('PANEL_SEND_REINSTALL_NOTIFICATION', true),
|
||||||
|
// Should an email be sent to a server owner whenever a backup is completed?
|
||||||
|
'send_backup_completed_notification' => env('PANEL_SEND_BACKUP_COMPLETED_NOTIFICATION', true),
|
||||||
],
|
],
|
||||||
|
|
||||||
'filament' => [
|
'filament' => [
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ return [
|
|||||||
'helper' => 'Toggle which mail notifications should be sent to Users.',
|
'helper' => 'Toggle which mail notifications should be sent to Users.',
|
||||||
'server_installed' => 'Server Installed',
|
'server_installed' => 'Server Installed',
|
||||||
'server_reinstalled' => 'Server Reinstalled',
|
'server_reinstalled' => 'Server Reinstalled',
|
||||||
|
'backup_completed' => 'Backup Completed',
|
||||||
],
|
],
|
||||||
'connections' => [
|
'connections' => [
|
||||||
'title' => 'Connections',
|
'title' => 'Connections',
|
||||||
|
|||||||
@@ -28,6 +28,14 @@ return [
|
|||||||
'action' => 'Login and Begin Using',
|
'action' => 'Login and Begin Using',
|
||||||
],
|
],
|
||||||
|
|
||||||
|
'backup_completed' => [
|
||||||
|
'body_success' => 'The backup was created successfully.',
|
||||||
|
'body_failed' => 'The backup creation failed.',
|
||||||
|
'backup_name' => 'Backup Name: :name',
|
||||||
|
'server_name' => 'Server Name: :name',
|
||||||
|
'action' => 'View Backups',
|
||||||
|
],
|
||||||
|
|
||||||
'mail_tested' => [
|
'mail_tested' => [
|
||||||
'subject' => 'Panel Test Message',
|
'subject' => 'Panel Test Message',
|
||||||
'body' => 'This is a test of the Panel mail system. You\'re good to go!',
|
'body' => 'This is a test of the Panel mail system. You\'re good to go!',
|
||||||
|
|||||||
@@ -6,6 +6,10 @@ return [
|
|||||||
'installation_failed' => 'Server Installation Failed',
|
'installation_failed' => 'Server Installation Failed',
|
||||||
'reinstallation_completed' => 'Server Reinstallation Completed',
|
'reinstallation_completed' => 'Server Reinstallation Completed',
|
||||||
'reinstallation_failed' => 'Server Reinstallation Failed',
|
'reinstallation_failed' => 'Server Reinstallation Failed',
|
||||||
|
'backup_completed' => 'Backup Completed',
|
||||||
|
'backup_failed' => 'Backup Failed',
|
||||||
|
'backup_body' => 'Backup ":name" for server ":server"',
|
||||||
|
'view_backups' => 'View Backups',
|
||||||
'failed' => 'Failed',
|
'failed' => 'Failed',
|
||||||
'user_added' => [
|
'user_added' => [
|
||||||
'title' => 'Added to Server',
|
'title' => 'Added to Server',
|
||||||
|
|||||||
Reference in New Issue
Block a user