PHP code example of fill84 / laravel-firewall

1. Go to this page and download the library: Download fill84/laravel-firewall library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fill84 / laravel-firewall example snippets


'providers' => [
    // Other providers...
    Fill84\LaravelFirewall\FirewallServiceProvider::class,
];

return [
    'suspicious_paths' => [
        'wp-admin.php',
        'wp-login.php',
        'phpinfo.php',
        // Add your own patterns...
    ],
    'max_attempts' => 3,
    'whitelist_ips' => [
        '127.0.0.1',
        // Add your trusted IPs...
    ],
    // More configuration options...
];

protected $middleware = [
    // Other middleware...
    \Fill84\LaravelFirewall\Http\Middleware\Firewall::class,
];

Route::group(['middleware' => 'firewall'], function () {
    // Your protected routes...
});

class YourController extends Controller
{
    public function __construct()
    {
        $this->middleware('firewall');
    }
}

use Fill84\LaravelFirewall\Http\Controllers\FirewallController;

Route::prefix('admin/firewall')->middleware(['auth', 'admin'])->group(function () {
    Route::get('logs', [FirewallController::class, 'logs'])->name('admin.firewall.logs');
    Route::get('logs/{id}', [FirewallController::class, 'logDetail'])->name('admin.firewall.logs.detail');
    Route::get('blocked', [FirewallController::class, 'blocked'])->name('admin.firewall.blocked');
    Route::get('stats', [FirewallController::class, 'stats'])->name('admin.firewall.stats');
    Route::post('unblock/{ip}', [FirewallController::class, 'unblock'])->name('admin.firewall.unblock');
    Route::post('block', [FirewallController::class, 'block'])->name('admin.firewall.block');
    Route::delete('cleanup', [FirewallController::class, 'cleanupLogs'])->name('admin.firewall.cleanup');
});

'suspicious_paths' => [
    'wp-admin.php',        // Exact match
    'wp-login.php',        // Exact match
    '*admin*',             // Contains 'admin'
    'config*.php',         // Starts with 'config', ends with '.php'
    '*.env',               // Any .env file
],

'max_attempts' => 3, // Block after 3 attempts in 24 hours

'whitelist_ips' => [
    '127.0.0.1',
    '192.168.1.100',
    '::1',
],

'log_detailed_info' => true, // Log headers, POST data, etc.

use Illuminate\Support\Facades\DB;

DB::table('firewall_blocks')->updateOrInsert(
    ['ip_address' => '192.168.1.100'],
    [
        'is_blocked' => true,
        'blocked_at' => now(),
        'admin_notes' => 'Manually blocked for suspicious activity',
        'updated_at' => now(),
    ]
);

use Illuminate\Support\Facades\DB;

DB::table('firewall_blocks')
    ->where('ip_address', '192.168.1.100')
    ->update([
        'is_blocked' => false,
        'unblocked_at' => now(),
    ]);

'log_detailed_info' => true,
bash
php artisan vendor:publish --tag=firewall-config
bash
php artisan vendor:publish --tag=firewall-migrations
php artisan migrate
bash
php artisan vendor:publish --tag=firewall-views
bash
php artisan vendor:publish --tag=firewall-routes
javascript
module.exports = {
  content: [
    './resources/**/*.blade.php',
    './vendor/fill84/laravel-firewall/resources/views/**/*.blade.php',
  ],
  // ... rest of your config
}
bash
# Delete logs older than 30 days
php artisan tinker
> DB::table('firewall_logs')->where('created_at', '<', now()->subDays(30))->delete();