Disallow 0.0.0.0, 127.0.0.1 and localhost as node fqdn (#1158)

* disallow `0.0.0.0`, `127.0.01` and `localhost` as node fqdn

* use rules of model
This commit is contained in:
Boy132 2025-03-26 09:03:13 +01:00 committed by GitHub
parent a73404c1b4
commit c689f6860b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 3 deletions

View File

@ -3,6 +3,7 @@
namespace App\Filament\Admin\Resources\NodeResource\Pages; namespace App\Filament\Admin\Resources\NodeResource\Pages;
use App\Filament\Admin\Resources\NodeResource; use App\Filament\Admin\Resources\NodeResource;
use App\Models\Node;
use Filament\Forms; use Filament\Forms;
use Filament\Forms\Components\Actions\Action; use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Components\Grid; use Filament\Forms\Components\Grid;
@ -44,7 +45,8 @@ class CreateNode extends CreateRecord
->required() ->required()
->autofocus() ->autofocus()
->live(debounce: 1500) ->live(debounce: 1500)
->rule('prohibited', fn ($state) => is_ip($state) && request()->isSecure()) ->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')) ->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') ->placeholder(fn ($state) => is_ip($state) ? '192.168.1.1' : 'node.example.com')
->helperText(function ($state) { ->helperText(function ($state) {

View File

@ -108,7 +108,8 @@ class EditNode extends EditRecord
->required() ->required()
->autofocus() ->autofocus()
->live(debounce: 1500) ->live(debounce: 1500)
->rule('prohibited', fn ($state) => is_ip($state) && request()->isSecure()) ->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')) ->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') ->placeholder(fn ($state) => is_ip($state) ? '192.168.1.1' : 'node.example.com')
->helperText(function ($state) { ->helperText(function ($state) {

View File

@ -89,7 +89,7 @@ class Node extends Model implements Validatable
'name' => ['required', 'string', 'min:1', 'max:100'], 'name' => ['required', 'string', 'min:1', 'max:100'],
'description' => ['string', 'nullable'], 'description' => ['string', 'nullable'],
'public' => ['boolean'], 'public' => ['boolean'],
'fqdn' => ['required', 'string'], 'fqdn' => ['required', 'string', 'notIn:0.0.0.0,127.0.0.1,localhost'],
'scheme' => ['required', 'string', 'in:http,https'], 'scheme' => ['required', 'string', 'in:http,https'],
'behind_proxy' => ['boolean'], 'behind_proxy' => ['boolean'],
'memory' => ['required', 'numeric', 'min:0'], 'memory' => ['required', 'numeric', 'min:0'],