diff --git a/app/Filament/Resources/NodeResource/Pages/CreateNode.php b/app/Filament/Resources/NodeResource/Pages/CreateNode.php index fcfaaf292..603385792 100644 --- a/app/Filament/Resources/NodeResource/Pages/CreateNode.php +++ b/app/Filament/Resources/NodeResource/Pages/CreateNode.php @@ -6,6 +6,7 @@ use App\Filament\Resources\NodeResource; use Filament\Forms; use Filament\Notifications\Notification; use Filament\Resources\Pages\CreateRecord; +use Illuminate\Support\HtmlString; class CreateNode extends CreateRecord { @@ -14,70 +15,37 @@ class CreateNode extends CreateRecord public function form(Forms\Form $form): Forms\Form { return $form - ->columns(2) + ->columns(4) ->schema([ Forms\Components\TextInput::make('fqdn') - ->label('Domain Name') - ->placeholder('node.example.com') - ->helperText('Node\'s Domain Name') + ->columnSpan(2) ->required() ->autofocus() - ->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) { - $hasRecords = checkdnsrr("$state.", 'A'); - if (!$hasRecords) { - Notification::make() - ->title('Your hostname does not appear to have a valid A record.') - ->warning() - ->send(); + ->label(fn ($state) => is_ip($state) ? 'IP Address' : 'Domain Name') + ->placeholder(fn ($state) => is_ip($state) ? '192.168.1.1' : 'node.example.com') + ->hintColor('danger') + ->hint(function ($state) { + if (is_ip($state) && request()->isSecure()) { + return 'You currently have a secure connection to the panel.'; } + + 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), - 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') ->columns(1) ->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) ->maxValue(65536) ->default(8080) @@ -89,35 +57,25 @@ class CreateNode extends CreateRecord ->required() ->dehydrated() ->inline() - // request()->isSecure() ->helperText(function (Forms\Get $get) { if (request()->isSecure()) { - return 'Your Panel is currently using secure connection therefore so must your Daemon. - This automatically disables using an IP Address for a FQDN.'; + return 'Your Panel is using a secure (https) connection, therefore your Daemon has to as well.'; } - if (filter_var($get('fqdn'), FILTER_VALIDATE_IP) !== false) { + if (is_ip($get('fqdn'))) { return 'An IP address cannot use SSL.'; } 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) { - $isIp = filter_var($get('fqdn'), FILTER_VALIDATE_IP) !== false; - $isSecure = request()->isSecure(); - - if ($isSecure) { + if (request()->isSecure()) { $set('scheme', 'https'); return true; } - if ($isIp) { - $set('scheme', 'http'); - - return true; - } + return false; }) ->options([ 'http' => 'HTTP', diff --git a/app/helpers.php b/app/helpers.php index 6892a8193..c2aa5cd74 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -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')) { /** * Get an object using dot notation. An object key with a value of null is still considered valid