Compare commits

...

3 Commits

Author SHA1 Message Date
Boy132
2ec9a008e7 fix namespace 2026-05-04 10:42:57 +02:00
Boy132
fcd5d005ed add backup completed notifications 2026-05-04 10:28:16 +02:00
Boy132
2a64ea8536 Cleanup node fqdn/ip validation (#2307) 2026-05-04 09:01:03 +02:00
12 changed files with 270 additions and 155 deletions

View 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) {}
}

View File

@@ -703,6 +703,16 @@ class Settings extends Page implements HasSchemas
->formatStateUsing(fn ($state): bool => (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'))),
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'))
->description(trans('admin/setting.misc.connections.helper'))

View File

@@ -64,9 +64,8 @@ class CreateNode extends CreateRecord
->icon(TablerIcon::Server)
->columnSpanFull()
->columns([
'default' => 2,
'sm' => 3,
'md' => 3,
'default' => 1,
'md' => 2,
'lg' => 4,
])
->schema([
@@ -76,81 +75,83 @@ class CreateNode extends CreateRecord
->autofocus()
->live(debounce: 1500)
->rules(Node::getRulesForField('fqdn'))
->prohibited(fn ($state) => is_ip($state) && request()->isSecure())
->label(fn ($state) => is_ip($state) ? trans('admin/node.ip_address') : trans('admin/node.domain'))
->placeholder(fn ($state) => is_ip($state) ? '192.168.1.1' : 'node.example.com')
->helperText(function ($state) {
->helperText(fn () => request()->isSecure() ? trans('admin/node.fqdn_ssl') : null)
->validationMessages([
'prohibited' => trans('admin/node.dns_error'),
])
->prohibited(function ($state, Get $get) {
if (!$state) {
return true;
}
if (is_ip($state)) {
return false;
}
$ip = $get('ip');
return !is_ip($ip);
})
->hintColor(function ($state, Get $get) {
if (!$state) {
return null;
}
if (is_ip($state)) {
if (request()->isSecure()) {
return trans('admin/node.fqdn_help');
return 'warning';
}
} else {
$ip = $get('ip');
return '';
return is_ip($ip) ? 'success' : 'danger';
}
return trans('admin/node.error');
return null;
})
->hintColor('danger')
->hint(function ($state) {
if (is_ip($state) && request()->isSecure()) {
return trans('admin/node.ssl_ip');
->hint(function ($state, Get $get) {
if (!$state) {
return null;
}
return '';
if (is_ip($state)) {
if (request()->isSecure()) {
return trans('admin/node.ssl_ip');
}
} else {
$ip = $get('ip');
return is_ip($ip) ? trans('admin/node.valid') . ': ' . $ip : trans('admin/node.invalid');
}
return null;
})
->afterStateUpdated(function (Set $set, ?string $state) {
$set('dns', null);
$set('ip', null);
if (!$state) {
return;
}
[$subdomain] = str($state)->explode('.', 2);
if (!is_numeric($subdomain)) {
$set('name', $subdomain);
}
if (!$state || is_ip($state)) {
$set('dns', null);
return;
}
$ip = get_ip_from_hostname($state);
if ($ip) {
$set('dns', true);
$set('ip', $ip);
} else {
$set('dns', false);
if (!is_ip($state)) {
$ip = get_ip_from_hostname($state);
if (is_ip($ip)) {
$set('ip', $ip);
} else {
$set('ip', null);
}
}
})
->maxLength(255),
TextInput::make('ip')
->disabled()
->hidden(),
ToggleButtons::make('dns')
->label(trans('admin/node.dns'))
->helperText(trans('admin/node.dns_help'))
->disabled()
->inline()
->default(null)
->hint(fn (Get $get) => $get('ip'))
->hintColor('success')
->options([
true => trans('admin/node.valid'),
false => trans('admin/node.invalid'),
])
->colors([
true => 'success',
false => 'danger',
])
->columnSpan([
'default' => 1,
'sm' => 1,
'md' => 1,
'lg' => 1,
]),
Hidden::make('ip')
->saved(false),
TextInput::make('daemon_connect')
->columnSpan(1)
->label(fn (Get $get) => $get('connection') === 'https_proxy' ? trans('admin/node.connect_port') : trans('admin/node.port'))
@@ -160,7 +161,16 @@ class CreateNode extends CreateRecord
->default(8080)
->required()
->integer(),
TextInput::make('daemon_listen')
->columnSpan(1)
->label(trans('admin/node.listen_port'))
->helperText(trans('admin/node.listen_port_help'))
->minValue(1)
->maxValue(65535)
->default(8080)
->required()
->integer()
->visible(fn (Get $get) => $get('connection') === 'https_proxy'),
TextInput::make('name')
->label(trans('admin/node.display_name'))
->columnSpan([
@@ -171,27 +181,16 @@ class CreateNode extends CreateRecord
])
->required()
->maxLength(100),
Hidden::make('scheme')
->default(fn () => request()->isSecure() ? 'https' : 'http'),
Hidden::make('behind_proxy')
->default(false),
ToggleButtons::make('connection')
->label(trans('admin/node.ssl'))
->columnSpan(1)
->columnSpan(2)
->inline()
->helperText(function (Get $get) {
->helperText(function () {
if (request()->isSecure()) {
return new HtmlString(trans('admin/node.panel_on_ssl'));
return trans('admin/node.panel_on_ssl');
}
if (is_ip($get('fqdn'))) {
return trans('admin/node.ssl_help');
}
return '';
return null;
})
->disableOptionWhen(fn (string $value) => $value === 'http' && request()->isSecure())
->options([
@@ -219,17 +218,10 @@ class CreateNode extends CreateRecord
$set('daemon_connect', $state === 'https_proxy' ? 443 : 8080);
$set('daemon_listen', 8080);
}),
TextInput::make('daemon_listen')
->columnSpan(1)
->label(trans('admin/node.listen_port'))
->helperText(trans('admin/node.listen_port_help'))
->minValue(1)
->maxValue(65535)
->default(8080)
->required()
->integer()
->visible(fn (Get $get) => $get('connection') === 'https_proxy'),
Hidden::make('scheme')
->default(fn () => request()->isSecure() ? 'https' : 'http'),
Hidden::make('behind_proxy')
->default(false),
]),
Step::make('advanced')
->label(trans('admin/node.tabs.advanced_settings'))

View File

@@ -137,74 +137,83 @@ class EditNode extends EditRecord
->autofocus()
->live(debounce: 1500)
->rules(Node::getRulesForField('fqdn'))
->prohibited(fn ($state) => is_ip($state) && request()->isSecure())
->label(fn ($state) => is_ip($state) ? trans('admin/node.ip_address') : trans('admin/node.domain'))
->placeholder(fn ($state) => is_ip($state) ? '192.168.1.1' : 'node.example.com')
->helperText(function ($state) {
->helperText(fn () => request()->isSecure() ? trans('admin/node.fqdn_ssl') : null)
->validationMessages([
'prohibited' => trans('admin/node.dns_error'),
])
->prohibited(function ($state, Get $get) {
if (!$state) {
return true;
}
if (is_ip($state)) {
return false;
}
$ip = $get('ip');
return !is_ip($ip);
})
->hintColor(function ($state, Get $get) {
if (!$state) {
return null;
}
if (is_ip($state)) {
if (request()->isSecure()) {
return trans('admin/node.fqdn_help');
return 'warning';
}
} else {
$ip = $get('ip');
return '';
return is_ip($ip) ? 'success' : 'danger';
}
return trans('admin/node.error');
return null;
})
->hintColor('danger')
->hint(function ($state) {
if (is_ip($state) && request()->isSecure()) {
return trans('admin/node.ssl_ip');
->hint(function ($state, Get $get) {
if (!$state) {
return null;
}
return '';
if (is_ip($state)) {
if (request()->isSecure()) {
return trans('admin/node.ssl_ip');
}
} else {
$ip = $get('ip');
return is_ip($ip) ? trans('admin/node.valid') . ': ' . $ip : trans('admin/node.invalid');
}
return null;
})
->afterStateUpdated(function (Set $set, ?string $state) {
$set('dns', null);
$set('ip', null);
if (!$state) {
return;
}
[$subdomain] = str($state)->explode('.', 2);
if (!is_numeric($subdomain)) {
$set('name', $subdomain);
}
if (!$state || is_ip($state)) {
$set('dns', null);
return;
}
$ip = get_ip_from_hostname($state);
if ($ip) {
$set('dns', true);
$set('ip', $ip);
} else {
$set('dns', false);
if (!is_ip($state)) {
$ip = get_ip_from_hostname($state);
if (is_ip($ip)) {
$set('ip', $ip);
} else {
$set('ip', null);
}
}
})
->maxLength(255),
TextInput::make('ip')
->disabled()
->hidden(),
ToggleButtons::make('dns')
->label(trans('admin/node.dns'))
->helperText(trans('admin/node.dns_help'))
->disabled()
->inline()
->default(null)
->hint(fn (Get $get) => $get('ip'))
->hintColor('success')
->stateCast(new BooleanStateCast(false, true))
->options([
1 => trans('admin/node.valid'),
0 => trans('admin/node.invalid'),
])
->colors([
1 => 'success',
0 => 'danger',
])
->columnSpan(1),
Hidden::make('ip')
->saved(false),
TextInput::make('daemon_connect')
->columnSpan(1)
->label(fn (Get $get) => $get('connection') === 'https_proxy' ? trans('admin/node.connect_port') : trans('admin/node.port'))
@@ -214,6 +223,16 @@ class EditNode extends EditRecord
->default(8080)
->required()
->integer(),
TextInput::make('daemon_listen')
->columnSpan(1)
->label(trans('admin/node.listen_port'))
->helperText(trans('admin/node.listen_port_help'))
->minValue(1)
->maxValue(65535)
->default(8080)
->required()
->integer()
->visible(fn (Get $get) => $get('connection') === 'https_proxy'),
TextInput::make('name')
->label(trans('admin/node.display_name'))
->columnSpan([
@@ -224,22 +243,16 @@ class EditNode extends EditRecord
])
->required()
->maxLength(100),
Hidden::make('scheme'),
Hidden::make('behind_proxy'),
ToggleButtons::make('connection')
->label(trans('admin/node.ssl'))
->columnSpan(1)
->columnSpan(2)
->inline()
->helperText(function (Get $get) {
->helperText(function () {
if (request()->isSecure()) {
return new HtmlString(trans('admin/node.panel_on_ssl'));
return trans('admin/node.panel_on_ssl');
}
if (is_ip($get('fqdn'))) {
return trans('admin/node.ssl_help');
}
return '';
return null;
})
->disableOptionWhen(fn (string $value) => $value === 'http' && request()->isSecure())
->options([
@@ -267,16 +280,10 @@ class EditNode extends EditRecord
$set('daemon_connect', $state === 'https_proxy' ? 443 : 8080);
$set('daemon_listen', 8080);
}),
TextInput::make('daemon_listen')
->columnSpan(1)
->label(trans('admin/node.listen_port'))
->helperText(trans('admin/node.listen_port_help'))
->minValue(1)
->maxValue(65535)
->default(8080)
->required()
->integer()
->visible(fn (Get $get) => $get('connection') === 'https_proxy'),
Hidden::make('scheme')
->default(fn () => request()->isSecure() ? 'https' : 'http'),
Hidden::make('behind_proxy')
->default(false),
]),
Tab::make('advanced_settings')
->label(trans('admin/node.tabs.advanced_settings'))

View File

@@ -2,6 +2,7 @@
namespace App\Http\Controllers\Api\Remote\Backups;
use App\Events\Server\BackupCompleted;
use App\Exceptions\DisplayException;
use App\Exceptions\Http\HttpForbiddenException;
use App\Extensions\Backups\BackupManager;
@@ -79,6 +80,8 @@ class BackupStatusController extends Controller
}
});
event(new BackupCompleted($model));
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
}

View 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));
}
}
}

View 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));
}
}

View File

@@ -49,6 +49,8 @@ return [
'send_install_notification' => env('PANEL_SEND_INSTALL_NOTIFICATION', true),
// Should an email be sent to a server owner whenever their server is reinstalled?
'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' => [

View File

@@ -42,13 +42,11 @@ return [
'refresh' => 'Refresh',
'custom_ip' => 'Enter Custom IP',
'domain' => 'Domain Name',
'ssl_ip' => 'You cannot connect to an IP Address over SSL',
'error' => 'This is the domain name that points to your node\'s IP Address. If you\'ve already set up this, you can verify it by checking the next field!',
'fqdn_help' => 'Your panel is currently secured via an SSL certificate and that means your nodes require one too. You must use a domain name, because you cannot get SSL certificates for IP Addresses.',
'dns' => 'DNS Record Check',
'dns_help' => 'This lets you know if your DNS record is pointing to the correct IP address.',
'valid' => 'Valid',
'invalid' => 'Invalid',
'ssl_ip' => 'Consider using a domain name instead of an ip address',
'fqdn_ssl' => 'Your panel is currently secured via an SSL certificate and that means your nodes require one too.',
'dns_error' => 'No valid DNS records were found for the provided domain name.',
'valid' => 'Valid DNS',
'invalid' => 'Invalid DNS',
'port' => 'Port',
'ports' => 'Ports',
'port_help' => 'If you are running the daemon behind Cloudflare you should set the daemon port to 8443 to allow websocket proxying over SSL.',
@@ -58,7 +56,7 @@ return [
'listen_port_help' => 'Wings will listen on this port.',
'display_name' => 'Display Name',
'ssl' => 'Communicate over SSL',
'panel_on_ssl' => 'Your Panel is using a secure SSL connection,<br>so your Daemon must too.',
'panel_on_ssl' => 'Your Panel is using a secure SSL connection, so your Daemon must too.',
'ssl_help' => 'An IP address cannot use SSL.',
'tags' => 'Tags',

View File

@@ -118,6 +118,7 @@ return [
'helper' => 'Toggle which mail notifications should be sent to Users.',
'server_installed' => 'Server Installed',
'server_reinstalled' => 'Server Reinstalled',
'backup_completed' => 'Backup Completed',
],
'connections' => [
'title' => 'Connections',

View File

@@ -28,6 +28,14 @@ return [
'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' => [
'subject' => 'Panel Test Message',
'body' => 'This is a test of the Panel mail system. You\'re good to go!',

View File

@@ -6,6 +6,10 @@ return [
'installation_failed' => 'Server Installation Failed',
'reinstallation_completed' => 'Server Reinstallation Completed',
'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',
'user_added' => [
'title' => 'Added to Server',