143 lines
4.8 KiB
PHP
143 lines
4.8 KiB
PHP
<?php
|
|
|
|
namespace Paymenter\Extensions\Others\Security\Admin\Resources;
|
|
|
|
use Filament\Resources\Resource;
|
|
use Filament\Forms\Form;
|
|
use Filament\Tables\Table;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Forms\Components\Textarea;
|
|
use Filament\Forms\Components\Toggle;
|
|
use Filament\Forms\Components\DateTimePicker;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Columns\BadgeColumn;
|
|
use Filament\Tables\Columns\BooleanColumn;
|
|
use Filament\Tables\Actions\EditAction;
|
|
use Filament\Tables\Actions\Action;
|
|
use Filament\Tables\Actions\BulkActionGroup;
|
|
use Filament\Tables\Actions\DeleteBulkAction;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Paymenter\Extensions\Others\Security\Models\BlockedIP;
|
|
use Paymenter\Extensions\Others\Security\Admin\Resources\BlockedIPResource\Pages;
|
|
use Filament\Forms\Get;
|
|
|
|
class BlockedIPResource extends Resource
|
|
{
|
|
protected static ?string $model = BlockedIP::class;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-shield-exclamation';
|
|
protected static ?string $navigationGroup = 'Security';
|
|
protected static ?string $navigationLabel = 'Blocked IPs';
|
|
protected static ?string $pluralLabel = 'Blocked IPs';
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form->schema([
|
|
TextInput::make('ip_address')
|
|
->label('IP Address')
|
|
->required()
|
|
->ip()
|
|
->maxLength(45),
|
|
|
|
TextInput::make('reason')
|
|
->label('Reason')
|
|
->required()
|
|
->maxLength(255),
|
|
|
|
Textarea::make('notes')
|
|
->label('Notes')
|
|
->rows(3)
|
|
->maxLength(1000),
|
|
|
|
Toggle::make('is_permanent')
|
|
->label('Permanent Block')
|
|
->default(false)
|
|
->reactive(),
|
|
|
|
DateTimePicker::make('blocked_until')
|
|
->label('Blocked Until')
|
|
->nullable()
|
|
->hidden(fn (Get $get) => $get('is_permanent')),
|
|
|
|
Select::make('blocked_by')
|
|
->label('Blocked By')
|
|
->relationship('blockedBy', 'email')
|
|
->nullable()
|
|
->default(fn () => Auth::id()),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
TextColumn::make('ip_address')
|
|
->label('IP Address')
|
|
->searchable()
|
|
->sortable()
|
|
->copyable(),
|
|
|
|
TextColumn::make('reason')
|
|
->label('Reason')
|
|
->searchable()
|
|
->limit(50),
|
|
|
|
BadgeColumn::make('is_permanent')
|
|
->label('Type')
|
|
->getStateUsing(fn (BlockedIP $record) => $record->is_permanent ? 'Permanent' : 'Temporary')
|
|
->colors([
|
|
'danger' => 'Permanent',
|
|
'warning' => 'Temporary',
|
|
]),
|
|
|
|
TextColumn::make('blocked_until')
|
|
->label('Until')
|
|
->dateTime()
|
|
->sortable(),
|
|
|
|
BooleanColumn::make('is_active')
|
|
->label('Active'),
|
|
|
|
TextColumn::make('failed_login_attempts')
|
|
->label('Failed Attempts')
|
|
->sortable(),
|
|
|
|
TextColumn::make('blockedBy.email')
|
|
->label('Blocked By')
|
|
->sortable()
|
|
->default('System'),
|
|
|
|
TextColumn::make('blocked_at')
|
|
->label('Blocked At')
|
|
->dateTime()
|
|
->sortable(),
|
|
])
|
|
->actions([
|
|
EditAction::make(),
|
|
Action::make('unblock')
|
|
->label('Unblock IP')
|
|
->icon('heroicon-m-check')
|
|
->color('success')
|
|
->action(fn (BlockedIP $record) => $record->unblock(Auth::id()))
|
|
->requiresConfirmation()
|
|
->visible(fn (BlockedIP $record) => $record->is_active),
|
|
])
|
|
->bulkActions([
|
|
BulkActionGroup::make([
|
|
DeleteBulkAction::make(),
|
|
]),
|
|
])
|
|
->defaultSort('blocked_at', 'desc');
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListBlockedIPs::route('/'),
|
|
'create' => Pages\CreateBlockedIP::route('/create'),
|
|
'edit' => Pages\EditBlockedIP::route('/{record}/edit'),
|
|
];
|
|
}
|
|
}
|