mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 20:24:44 +02:00
Consolidate these
This commit is contained in:
parent
b6d39c66d1
commit
3e7bff2446
@ -6,6 +6,7 @@ use App\Filament\Resources\NodeResource;
|
|||||||
use Filament\Forms;
|
use Filament\Forms;
|
||||||
use Filament\Notifications\Notification;
|
use Filament\Notifications\Notification;
|
||||||
use Filament\Resources\Pages\CreateRecord;
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
|
use Illuminate\Support\HtmlString;
|
||||||
|
|
||||||
class CreateNode extends CreateRecord
|
class CreateNode extends CreateRecord
|
||||||
{
|
{
|
||||||
@ -14,70 +15,37 @@ class CreateNode extends CreateRecord
|
|||||||
public function form(Forms\Form $form): Forms\Form
|
public function form(Forms\Form $form): Forms\Form
|
||||||
{
|
{
|
||||||
return $form
|
return $form
|
||||||
->columns(2)
|
->columns(4)
|
||||||
->schema([
|
->schema([
|
||||||
Forms\Components\TextInput::make('fqdn')
|
Forms\Components\TextInput::make('fqdn')
|
||||||
->label('Domain Name')
|
->columnSpan(2)
|
||||||
->placeholder('node.example.com')
|
|
||||||
->helperText('Node\'s Domain Name')
|
|
||||||
->required()
|
->required()
|
||||||
->autofocus()
|
->autofocus()
|
||||||
->columns(3)
|
|
||||||
->live(debounce: 500)
|
->live(debounce: 500)
|
||||||
->hidden(fn (Forms\Get $get) => !$get('isHostname'))
|
->label(fn ($state) => is_ip($state) ? 'IP Address' : 'Domain Name')
|
||||||
->disabled(fn (Forms\Get $get) => !$get('isHostname'))
|
->placeholder(fn ($state) => is_ip($state) ? '192.168.1.1' : 'node.example.com')
|
||||||
->afterStateUpdated(function (Forms\Set $set, ?string $state) {
|
->hintColor('danger')
|
||||||
$hasRecords = checkdnsrr("$state.", 'A');
|
->hint(function ($state) {
|
||||||
if (!$hasRecords) {
|
if (is_ip($state) && request()->isSecure()) {
|
||||||
Notification::make()
|
return 'You currently have a secure connection to the panel.';
|
||||||
->title('Your hostname does not appear to have a valid A record.')
|
|
||||||
->warning()
|
|
||||||
->send();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!is_ip($state) && !empty($state) && !checkdnsrr("$state.", 'A')) {
|
||||||
|
return 'Your hostname does not appear to have a valid A record.';
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
})
|
||||||
|
->helperText(fn ($state) => is_ip($state) ? 'You can also enter in the domain name instead!' : 'You can also enter the IP address instead!')
|
||||||
|
->afterStateUpdated(function (Forms\Set $set, ?string $state) {
|
||||||
|
$set('name', $state);
|
||||||
})
|
})
|
||||||
->maxLength(191),
|
->maxLength(191),
|
||||||
|
|
||||||
Forms\Components\TextInput::make('fqdn')
|
|
||||||
->label('IP Address')
|
|
||||||
->placeholder('127.0.0.1')
|
|
||||||
->helperText('Node\'s IP Address')
|
|
||||||
->required()
|
|
||||||
->ipv4()
|
|
||||||
->columns(3)
|
|
||||||
->live(debounce: 500)
|
|
||||||
->hidden(fn (Forms\Get $get) => $get('isHostname'))
|
|
||||||
->disabled(fn (Forms\Get $get) => $get('isHostname'))
|
|
||||||
->afterStateUpdated(function (Forms\Set $set, ?string $state) {
|
|
||||||
$isIp = filter_var($state, FILTER_VALIDATE_IP) !== false;
|
|
||||||
$isSecure = request()->isSecure();
|
|
||||||
|
|
||||||
if ($isIp && $isSecure) {
|
|
||||||
Notification::make()
|
|
||||||
->title('You cannot use an IP Address because you have a secure connection to the panel currently.')
|
|
||||||
->danger()
|
|
||||||
->send();
|
|
||||||
$set('name', $state);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
->maxLength(191),
|
|
||||||
|
|
||||||
Forms\Components\ToggleButtons::make('isHostname')
|
|
||||||
->label('Address Type')
|
|
||||||
->options([
|
|
||||||
true => 'Hostname',
|
|
||||||
false => 'IP Address',
|
|
||||||
])
|
|
||||||
->inline()
|
|
||||||
->live()
|
|
||||||
->afterStateUpdated(function () {
|
|
||||||
|
|
||||||
})
|
|
||||||
->default(true),
|
|
||||||
|
|
||||||
Forms\Components\TextInput::make('daemonListen')
|
Forms\Components\TextInput::make('daemonListen')
|
||||||
->columns(1)
|
->columns(1)
|
||||||
->label('Port')
|
->label('Port')
|
||||||
->helperText('If you will be running the daemon behind Cloudflare you should set the daemon port to 8443 to allow websocket proxying over SSL.')
|
->helperText('If you are running the daemon behind Cloudflare you should set the daemon port to 8443 to allow websocket proxying over SSL.')
|
||||||
->minValue(0)
|
->minValue(0)
|
||||||
->maxValue(65536)
|
->maxValue(65536)
|
||||||
->default(8080)
|
->default(8080)
|
||||||
@ -89,35 +57,25 @@ class CreateNode extends CreateRecord
|
|||||||
->required()
|
->required()
|
||||||
->dehydrated()
|
->dehydrated()
|
||||||
->inline()
|
->inline()
|
||||||
// request()->isSecure()
|
|
||||||
->helperText(function (Forms\Get $get) {
|
->helperText(function (Forms\Get $get) {
|
||||||
if (request()->isSecure()) {
|
if (request()->isSecure()) {
|
||||||
return 'Your Panel is currently using secure connection therefore so must your Daemon.
|
return 'Your Panel is using a secure (https) connection, therefore your Daemon has to as well.';
|
||||||
This automatically disables using an IP Address for a FQDN.';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter_var($get('fqdn'), FILTER_VALIDATE_IP) !== false) {
|
if (is_ip($get('fqdn'))) {
|
||||||
return 'An IP address cannot use SSL.';
|
return 'An IP address cannot use SSL.';
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
})
|
})
|
||||||
// ->helperText(fn (Forms\Get $get) => filter_var($get('fqdn'), FILTER_VALIDATE_IP) !== false ? 'An IP address cannot use SSL.' : '')
|
|
||||||
->disabled(function (Forms\Get $get, Forms\Set $set) {
|
->disabled(function (Forms\Get $get, Forms\Set $set) {
|
||||||
$isIp = filter_var($get('fqdn'), FILTER_VALIDATE_IP) !== false;
|
if (request()->isSecure()) {
|
||||||
$isSecure = request()->isSecure();
|
|
||||||
|
|
||||||
if ($isSecure) {
|
|
||||||
$set('scheme', 'https');
|
$set('scheme', 'https');
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($isIp) {
|
return false;
|
||||||
$set('scheme', 'http');
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
->options([
|
->options([
|
||||||
'http' => 'HTTP',
|
'http' => 'HTTP',
|
||||||
|
@ -11,6 +11,13 @@ if (!function_exists('is_digit')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!function_exists('is_ip')) {
|
||||||
|
function is_ip(?string $address): bool
|
||||||
|
{
|
||||||
|
return $address !== null && filter_var($address, FILTER_VALIDATE_IP) !== false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!function_exists('object_get_strict')) {
|
if (!function_exists('object_get_strict')) {
|
||||||
/**
|
/**
|
||||||
* Get an object using dot notation. An object key with a value of null is still considered valid
|
* Get an object using dot notation. An object key with a value of null is still considered valid
|
||||||
|
Loading…
x
Reference in New Issue
Block a user